@kopexa/sidebar 17.1.74 → 17.2.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.
@@ -0,0 +1,691 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/v2/from-config.tsx
23
+ var from_config_exports = {};
24
+ __export(from_config_exports, {
25
+ SidebarV2FromConfig: () => SidebarV2FromConfig
26
+ });
27
+ module.exports = __toCommonJS(from_config_exports);
28
+ var import_drawer = require("@kopexa/drawer");
29
+ var import_shared_utils2 = require("@kopexa/shared-utils");
30
+ var import_react3 = require("motion/react");
31
+ var import_react4 = require("react");
32
+
33
+ // src/v2/components.tsx
34
+ var import_button = require("@kopexa/button");
35
+ var import_icons = require("@kopexa/icons");
36
+ var import_shared_utils = require("@kopexa/shared-utils");
37
+ var import_theme = require("@kopexa/theme");
38
+ var import_tooltip2 = require("@kopexa/tooltip");
39
+ var import_react2 = require("react");
40
+
41
+ // src/v2/context.tsx
42
+ var import_react_utils = require("@kopexa/react-utils");
43
+ var import_tooltip = require("@kopexa/tooltip");
44
+ var import_use_is_mobile = require("@kopexa/use-is-mobile");
45
+ var import_react = require("react");
46
+ var import_jsx_runtime = require("react/jsx-runtime");
47
+ var PIN_COOKIE_MAX_AGE = 60 * 60 * 24 * 7;
48
+ var [Provider, useSidebarV2] = (0, import_react_utils.createContext)({
49
+ name: "SidebarV2Context",
50
+ errorMessage: "useSidebarV2 must be used within <SidebarV2> (the provider component)."
51
+ });
52
+
53
+ // src/v2/types.ts
54
+ function panelItemHasChildren(item) {
55
+ return "children" in item && Array.isArray(item.children);
56
+ }
57
+ function panelItemIsSection(item) {
58
+ return "section" in item;
59
+ }
60
+
61
+ // src/v2/components.tsx
62
+ var import_jsx_runtime2 = require("react/jsx-runtime");
63
+ function SidebarV2Rail({ className, ...props }) {
64
+ const { tone } = useSidebarV2();
65
+ const light = tone === "light";
66
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
67
+ "nav",
68
+ {
69
+ "data-slot": "sidebar-v2-rail",
70
+ className: (0, import_shared_utils.cn)(
71
+ "flex w-(--kpx-rail-width) shrink-0 flex-col overflow-hidden bg-sidebar py-2 text-sidebar-foreground",
72
+ // Light tone: the dark rail floats as a rounded card on the light
73
+ // surround. Dark tone: full-height, flush to the edge.
74
+ light ? "m-2 rounded-2xl shadow-sm" : "h-full",
75
+ className
76
+ ),
77
+ ...props
78
+ }
79
+ );
80
+ }
81
+ var SidebarV2Workspace = (0, import_react2.forwardRef)(({ name, role, logo, className, appearance = "rail", ...props }, ref) => {
82
+ if (appearance === "bar") {
83
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
84
+ "button",
85
+ {
86
+ ref,
87
+ type: "button",
88
+ "data-slot": "sidebar-v2-workspace",
89
+ "aria-label": role ? `${name} \u2013 ${role}` : name,
90
+ className: (0, import_shared_utils.cn)(
91
+ "group/ws flex cursor-pointer items-center gap-2 rounded-lg py-1 pr-2 pl-1",
92
+ "outline-hidden ring-ring transition-colors hover:bg-foreground/5 focus-visible:ring-2",
93
+ className
94
+ ),
95
+ ...props,
96
+ children: [
97
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "flex size-7 shrink-0 items-center justify-center rounded-md bg-primary text-xs font-semibold text-primary-foreground", children: logo != null ? logo : name.charAt(0).toUpperCase() }),
98
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "flex min-w-0 flex-col text-left leading-tight", children: [
99
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "truncate text-sm font-semibold text-foreground", children: name }),
100
+ role && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "truncate text-xs text-muted-foreground", children: role })
101
+ ] }),
102
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons.ChevronDownIcon, { className: "size-4 shrink-0 text-muted-foreground" })
103
+ ]
104
+ }
105
+ );
106
+ }
107
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
108
+ "button",
109
+ {
110
+ ref,
111
+ type: "button",
112
+ "data-slot": "sidebar-v2-workspace",
113
+ "aria-label": role ? `${name} \u2013 ${role}` : name,
114
+ className: (0, import_shared_utils.cn)(
115
+ "group/ws relative mx-auto mt-1 flex cursor-pointer items-center justify-center rounded-lg p-1",
116
+ "outline-hidden ring-sidebar-ring transition-colors",
117
+ "hover:bg-sidebar-accent focus-visible:ring-2",
118
+ className
119
+ ),
120
+ ...props,
121
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "relative flex size-9 shrink-0 items-center justify-center rounded-lg bg-primary text-sm font-semibold text-primary-foreground", children: [
122
+ logo != null ? logo : name.charAt(0).toUpperCase(),
123
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons.ChevronDownIcon, { className: "absolute -right-1 -bottom-1 size-3.5 rounded-full bg-sidebar p-px text-sidebar-foreground/60" })
124
+ ] })
125
+ }
126
+ );
127
+ });
128
+ SidebarV2Workspace.displayName = "SidebarV2Workspace";
129
+ function railButtonClasses(active) {
130
+ return (0, import_shared_utils.cn)(
131
+ "group/rail relative mx-auto flex size-11 shrink-0 cursor-pointer items-center justify-center rounded-xl",
132
+ "outline-hidden ring-sidebar-ring transition-colors",
133
+ "text-sidebar-foreground/85 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground",
134
+ "focus-visible:ring-2",
135
+ active && "bg-sidebar-accent text-sidebar-accent-foreground"
136
+ );
137
+ }
138
+ function RailInner({
139
+ icon: Icon,
140
+ active,
141
+ badge
142
+ }) {
143
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
144
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
145
+ "span",
146
+ {
147
+ "aria-hidden": true,
148
+ className: (0, import_shared_utils.cn)(
149
+ "absolute top-1/2 left-0 h-5 w-0.5 -translate-x-[0.6rem] -translate-y-1/2 rounded-r bg-primary transition-opacity",
150
+ active ? "opacity-100" : "opacity-0"
151
+ )
152
+ }
153
+ ),
154
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Icon, { className: "size-5 shrink-0" }),
155
+ badge != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "absolute -top-0.5 -right-0.5 flex h-4 min-w-4 items-center justify-center rounded-full bg-primary px-1 text-[0.5625rem] font-semibold text-primary-foreground", children: badge })
156
+ ] });
157
+ }
158
+ function SidebarV2RailLink({
159
+ icon,
160
+ label,
161
+ href,
162
+ badge
163
+ }) {
164
+ const { renderLink, isActive, resetPanelSelection } = useSidebarV2();
165
+ const active = isActive(href);
166
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_tooltip2.Tooltip, { content: label, side: "right", children: renderLink({
167
+ href,
168
+ className: railButtonClasses(active),
169
+ "data-active": active,
170
+ "aria-current": active ? "page" : void 0,
171
+ "aria-label": label,
172
+ // Navigating to a destination link clears any open panel preview,
173
+ // even when the route doesn't change (e.g. already on it).
174
+ onClick: resetPanelSelection,
175
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RailInner, { icon, label, active, badge })
176
+ }) });
177
+ }
178
+ function SidebarV2RailItem({
179
+ icon,
180
+ label,
181
+ active,
182
+ hasPanel,
183
+ onClick,
184
+ onMouseEnter,
185
+ onMouseLeave,
186
+ badge
187
+ }) {
188
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_tooltip2.Tooltip, { content: label, side: "right", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
189
+ "button",
190
+ {
191
+ type: "button",
192
+ "data-active": active,
193
+ "aria-label": label,
194
+ "aria-expanded": hasPanel ? active : void 0,
195
+ onClick,
196
+ onMouseEnter,
197
+ onMouseLeave,
198
+ className: railButtonClasses(active),
199
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RailInner, { icon, label, active, badge })
200
+ }
201
+ ) });
202
+ }
203
+ function SidebarV2Panel({
204
+ title,
205
+ subtitle,
206
+ floating,
207
+ hidePin,
208
+ action,
209
+ children,
210
+ className
211
+ }) {
212
+ const { togglePin, pinned, tone } = useSidebarV2();
213
+ const light = tone === "light";
214
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
215
+ "div",
216
+ {
217
+ "data-slot": "sidebar-v2-panel",
218
+ "data-floating": floating,
219
+ className: (0, import_shared_utils.cn)(
220
+ "flex h-full w-(--kpx-panel-width) shrink-0 flex-col",
221
+ // Surface. The flyout is a distinct floating card (white on light),
222
+ // so it reads as an overlay rather than a flat full-height slab.
223
+ floating ? light ? "bg-background text-foreground" : "bg-sidebar text-sidebar-foreground" : light ? "bg-muted text-foreground" : "bg-sidebar text-sidebar-foreground",
224
+ floating ? (
225
+ // Floating card: rounded, soft layered shadow, hairline ring.
226
+ (0, import_shared_utils.cn)(
227
+ "overflow-hidden rounded-2xl shadow-2xl shadow-black/20 ring-1",
228
+ light ? "ring-black/5" : "ring-white/10"
229
+ )
230
+ ) : (
231
+ // Pinned: light blends into the surround (no border); dark keeps a
232
+ // hairline against the rail.
233
+ light ? "" : "border-l border-sidebar-border/40"
234
+ ),
235
+ className
236
+ ),
237
+ children: [
238
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "flex items-start gap-2 px-3 pt-3 pb-1.5", children: [
239
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "min-w-0 flex-1", children: [
240
+ title && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
241
+ "div",
242
+ {
243
+ className: (0, import_shared_utils.cn)(
244
+ "truncate text-sm font-semibold",
245
+ light ? "text-foreground" : "text-sidebar-foreground"
246
+ ),
247
+ children: title
248
+ }
249
+ ),
250
+ subtitle && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
251
+ "div",
252
+ {
253
+ className: (0, import_shared_utils.cn)(
254
+ "truncate text-xs",
255
+ light ? "text-muted-foreground" : "text-sidebar-foreground/70"
256
+ ),
257
+ children: subtitle
258
+ }
259
+ )
260
+ ] }),
261
+ action != null ? action : !hidePin && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
262
+ import_tooltip2.Tooltip,
263
+ {
264
+ content: pinned ? "Panel l\xF6sen" : "Panel anheften",
265
+ side: "bottom",
266
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
267
+ import_button.IconButton,
268
+ {
269
+ variant: "ghost",
270
+ size: "sm",
271
+ "aria-label": pinned ? "Panel l\xF6sen" : "Panel anheften",
272
+ onClick: togglePin,
273
+ className: (0, import_shared_utils.cn)(
274
+ "-mr-1 shrink-0",
275
+ light ? "text-muted-foreground hover:bg-foreground/5 hover:text-foreground" : "text-sidebar-foreground/60 hover:bg-sidebar-accent hover:text-sidebar-accent-foreground"
276
+ ),
277
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icons.PanelLeftIcon, { className: "size-4" })
278
+ }
279
+ )
280
+ }
281
+ )
282
+ ] }),
283
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "flex min-h-0 flex-1 flex-col gap-0.5 overflow-auto p-2", children })
284
+ ]
285
+ }
286
+ );
287
+ }
288
+ function panelRowLight(active) {
289
+ return (0, import_shared_utils.cn)(
290
+ "flex h-8 w-full items-center gap-2.5 rounded-md px-2 text-sm outline-hidden ring-ring transition-colors focus-visible:ring-2 [&>svg]:size-4 [&>svg]:shrink-0",
291
+ active ? "bg-primary/10 font-medium text-primary" : "text-foreground/80 hover:bg-foreground/5"
292
+ );
293
+ }
294
+ function SidebarV2PanelLabel({
295
+ className,
296
+ ...props
297
+ }) {
298
+ const { tone } = useSidebarV2();
299
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
300
+ "div",
301
+ {
302
+ "data-slot": "sidebar-v2-panel-label",
303
+ className: (0, import_shared_utils.cn)(
304
+ "px-2 pt-3 pb-1 text-[0.6875rem] font-medium uppercase tracking-wide",
305
+ tone === "light" ? "text-muted-foreground" : "text-sidebar-foreground/50",
306
+ className
307
+ ),
308
+ ...props
309
+ }
310
+ );
311
+ }
312
+ function SidebarV2PanelLeaf({
313
+ item,
314
+ active: activeProp
315
+ }) {
316
+ const { renderLink, isActive, tone } = useSidebarV2();
317
+ const light = tone === "light";
318
+ const Icon = item.icon;
319
+ const active = activeProp != null ? activeProp : isActive(item.href);
320
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: renderLink({
321
+ href: item.href,
322
+ "data-active": active,
323
+ "aria-current": active ? "page" : void 0,
324
+ className: light ? panelRowLight(active) : (0, import_theme.sidebarMenuButton)({ size: "md" }),
325
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
326
+ Icon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
327
+ Icon,
328
+ {
329
+ className: (0, import_shared_utils.cn)(
330
+ light ? active ? void 0 : "text-muted-foreground" : "text-sidebar-foreground/75"
331
+ )
332
+ }
333
+ ),
334
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "min-w-0 flex-1 truncate", children: item.label }),
335
+ item.badge != null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
336
+ "span",
337
+ {
338
+ className: (0, import_shared_utils.cn)(
339
+ "ml-auto rounded-full px-1.5 text-[0.625rem] font-medium",
340
+ light ? "bg-foreground/10 text-foreground/70" : "bg-sidebar-accent text-sidebar-accent-foreground"
341
+ ),
342
+ children: item.badge
343
+ }
344
+ )
345
+ ] })
346
+ }) });
347
+ }
348
+ function SidebarV2PanelGroup({
349
+ item
350
+ }) {
351
+ var _a;
352
+ const { openGroup, toggleGroup, activeHref, renderLink, tone } = useSidebarV2();
353
+ const light = tone === "light";
354
+ const Icon = item.icon;
355
+ const key = (_a = item.value) != null ? _a : item.label;
356
+ let bestChildHref = null;
357
+ let bestLen = -1;
358
+ for (const c of item.children) {
359
+ if (activeHref === c.href) {
360
+ bestChildHref = c.href;
361
+ break;
362
+ }
363
+ if (activeHref.startsWith(`${c.href}/`) && c.href.length > bestLen) {
364
+ bestChildHref = c.href;
365
+ bestLen = c.href.length;
366
+ }
367
+ }
368
+ const containsActive = bestChildHref !== null;
369
+ const open = openGroup === key || openGroup === null && containsActive;
370
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
371
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
372
+ "button",
373
+ {
374
+ type: "button",
375
+ "data-state": open ? "open" : "closed",
376
+ "aria-expanded": open,
377
+ onClick: () => toggleGroup(key),
378
+ className: (0, import_shared_utils.cn)(
379
+ light ? panelRowLight(false) : (0, import_theme.sidebarMenuButton)({ size: "md" }),
380
+ "cursor-pointer",
381
+ containsActive && (light ? "font-medium text-foreground" : "font-medium")
382
+ ),
383
+ children: [
384
+ Icon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
385
+ Icon,
386
+ {
387
+ className: light ? "text-muted-foreground" : "text-sidebar-foreground/75"
388
+ }
389
+ ),
390
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "min-w-0 flex-1 truncate text-left", children: item.label }),
391
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
392
+ import_icons.ChevronRightIcon,
393
+ {
394
+ className: (0, import_shared_utils.cn)(
395
+ "size-3.5! shrink-0 transition-transform",
396
+ light ? "text-muted-foreground" : "text-sidebar-foreground/60",
397
+ open && "rotate-90"
398
+ )
399
+ }
400
+ )
401
+ ]
402
+ }
403
+ ),
404
+ open && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
405
+ "div",
406
+ {
407
+ className: (0, import_shared_utils.cn)(
408
+ "my-0.5 ml-[1.05rem] flex flex-col border-l pl-3",
409
+ light ? "border-border" : "border-sidebar-border"
410
+ ),
411
+ children: item.children.map((child) => {
412
+ const active = child.href === bestChildHref;
413
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: renderLink({
414
+ href: child.href,
415
+ "data-active": active,
416
+ "aria-current": active ? "page" : void 0,
417
+ className: (0, import_shared_utils.cn)(
418
+ "relative block rounded-md px-2 py-1.5 text-[0.8125rem] outline-hidden transition-colors focus-visible:ring-2",
419
+ "before:absolute before:top-1/2 before:-left-3 before:h-px before:w-2.5",
420
+ light ? active ? "bg-primary/10 font-medium text-primary ring-ring before:bg-primary" : "text-muted-foreground ring-ring hover:bg-foreground/5 hover:text-foreground before:bg-border" : active ? "bg-sidebar-accent font-medium text-sidebar-accent-foreground ring-sidebar-ring before:bg-primary" : "text-sidebar-foreground/80 ring-sidebar-ring hover:bg-sidebar-accent/60 hover:text-sidebar-accent-foreground before:bg-sidebar-foreground/30"
421
+ ),
422
+ children: child.label
423
+ }) }, child.href);
424
+ })
425
+ }
426
+ )
427
+ ] });
428
+ }
429
+ function SidebarV2PanelItems({
430
+ items
431
+ }) {
432
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: items.map((item, idx) => {
433
+ var _a;
434
+ if (panelItemIsSection(item)) {
435
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SidebarV2PanelLabel, { children: item.section }, `section-${item.section}-${idx}`);
436
+ }
437
+ if (panelItemHasChildren(item)) {
438
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SidebarV2PanelGroup, { item }, (_a = item.value) != null ? _a : item.label);
439
+ }
440
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SidebarV2PanelLeaf, { item }, item.href);
441
+ }) });
442
+ }
443
+
444
+ // src/v2/from-config.tsx
445
+ var import_jsx_runtime3 = require("react/jsx-runtime");
446
+ var RAIL_WIDTH = "4rem";
447
+ var PANEL_WIDTH = "15rem";
448
+ var railVars = {
449
+ "--kpx-rail-width": RAIL_WIDTH,
450
+ "--kpx-panel-width": PANEL_WIDTH
451
+ };
452
+ function entryValue(entry) {
453
+ var _a;
454
+ if (entry.type === "divider") return "divider";
455
+ return entry.type === "panel" ? (_a = entry.value) != null ? _a : entry.label : entry.label;
456
+ }
457
+ function SidebarV2FromConfig({
458
+ items,
459
+ header
460
+ }) {
461
+ var _a, _b, _c;
462
+ const {
463
+ pinned,
464
+ flyoutTrigger,
465
+ flyoutValue,
466
+ openFlyout,
467
+ setFlyout,
468
+ closeFlyout,
469
+ selectedRail,
470
+ setSelectedRail,
471
+ isActive,
472
+ isMobile,
473
+ drawerOpen,
474
+ setDrawerOpen,
475
+ setPanelHost,
476
+ panelOverrideActive,
477
+ navPreviewActive
478
+ } = useSidebarV2();
479
+ const hoverMode = flyoutTrigger === "hover" && !pinned && !isMobile;
480
+ const closeTimer = (0, import_react4.useRef)(null);
481
+ const cancelClose = (0, import_react4.useCallback)(() => {
482
+ if (closeTimer.current) clearTimeout(closeTimer.current);
483
+ closeTimer.current = null;
484
+ }, []);
485
+ const scheduleClose = (0, import_react4.useCallback)(() => {
486
+ cancelClose();
487
+ closeTimer.current = setTimeout(() => closeFlyout(), 160);
488
+ }, [cancelClose, closeFlyout]);
489
+ (0, import_react4.useEffect)(() => cancelClose, [cancelClose]);
490
+ (0, import_react4.useEffect)(() => {
491
+ if (pinned || isMobile || !flyoutValue) return;
492
+ const onPointerDown = (event) => {
493
+ const t = event.target;
494
+ if (!t) return;
495
+ if (t.closest('[data-slot="sidebar-v2-rail"]')) return;
496
+ if (t.closest('[data-floating="true"]')) return;
497
+ closeFlyout();
498
+ };
499
+ const onKeyDown = (event) => {
500
+ if (event.key === "Escape") closeFlyout();
501
+ };
502
+ document.addEventListener("pointerdown", onPointerDown);
503
+ document.addEventListener("keydown", onKeyDown);
504
+ return () => {
505
+ document.removeEventListener("pointerdown", onPointerDown);
506
+ document.removeEventListener("keydown", onKeyDown);
507
+ };
508
+ }, [pinned, isMobile, flyoutValue, closeFlyout]);
509
+ const panels = (0, import_react4.useMemo)(
510
+ () => items.filter(
511
+ (e) => e.type === "panel"
512
+ ),
513
+ [items]
514
+ );
515
+ const activeRailValue = (0, import_react4.useMemo)(() => {
516
+ const match = panels.find(
517
+ (p) => p.items.some((item) => {
518
+ if (panelItemIsSection(item)) return false;
519
+ return panelItemHasChildren(item) ? item.children.some((c) => isActive(c.href)) : isActive(item.href);
520
+ })
521
+ );
522
+ return match ? entryValue(match) : null;
523
+ }, [panels, isActive]);
524
+ const shownValue = pinned ? selectedRail != null ? selectedRail : activeRailValue : flyoutValue;
525
+ const shownPanel = (_a = panels.find((p) => entryValue(p) === shownValue)) != null ? _a : null;
526
+ const topEntries = items.filter((e) => e.slot !== "bottom");
527
+ const bottomEntries = items.filter((e) => e.slot === "bottom");
528
+ function renderRailEntry(entry, index) {
529
+ if (entry.type === "divider") {
530
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
531
+ "div",
532
+ {
533
+ "aria-hidden": true,
534
+ className: "mx-3 my-1.5 h-px shrink-0 bg-sidebar-border/70"
535
+ },
536
+ `rail-divider-${index}`
537
+ );
538
+ }
539
+ const value = entryValue(entry);
540
+ if (entry.type === "link") {
541
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
542
+ SidebarV2RailLink,
543
+ {
544
+ icon: entry.icon,
545
+ label: entry.label,
546
+ href: entry.href,
547
+ badge: entry.badge
548
+ },
549
+ value
550
+ );
551
+ }
552
+ if (entry.type === "action") {
553
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
554
+ SidebarV2RailItem,
555
+ {
556
+ icon: entry.icon,
557
+ label: entry.label,
558
+ active: false,
559
+ onClick: entry.onSelect
560
+ },
561
+ value
562
+ );
563
+ }
564
+ const active = flyoutValue ? value === flyoutValue : value === (selectedRail != null ? selectedRail : activeRailValue);
565
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
566
+ SidebarV2RailItem,
567
+ {
568
+ icon: entry.icon,
569
+ label: entry.label,
570
+ active,
571
+ hasPanel: true,
572
+ onClick: () => {
573
+ if (pinned) setSelectedRail(value);
574
+ else openFlyout(value);
575
+ },
576
+ onMouseEnter: hoverMode ? () => {
577
+ cancelClose();
578
+ setFlyout(value);
579
+ } : void 0,
580
+ onMouseLeave: hoverMode ? scheduleClose : void 0
581
+ },
582
+ value
583
+ );
584
+ }
585
+ const railContent = /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
586
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden", children: [
587
+ header && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
588
+ header,
589
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "mx-3 my-1 h-px shrink-0 bg-sidebar-border/60" })
590
+ ] }),
591
+ topEntries.map(renderRailEntry)
592
+ ] }),
593
+ bottomEntries.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "flex shrink-0 flex-col gap-1 pt-1", children: bottomEntries.map(renderRailEntry) })
594
+ ] });
595
+ const navData = pinned && shownPanel && (navPreviewActive || !panelOverrideActive) ? shownPanel : null;
596
+ const [bufferedPanel, setBufferedPanel] = (0, import_react4.useState)(navData);
597
+ (0, import_react4.useEffect)(() => {
598
+ if (navData) {
599
+ setBufferedPanel(navData);
600
+ return;
601
+ }
602
+ const t = setTimeout(() => setBufferedPanel(null), 220);
603
+ return () => clearTimeout(t);
604
+ }, [navData]);
605
+ const navToRender = navData != null ? navData : bufferedPanel;
606
+ const renderNav = (!panelOverrideActive || navPreviewActive) && navToRender;
607
+ const panelContent = navToRender && renderNav ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
608
+ SidebarV2Panel,
609
+ {
610
+ title: (_b = navToRender.title) != null ? _b : navToRender.label,
611
+ subtitle: navToRender.subtitle,
612
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SidebarV2PanelItems, { items: navToRender.items })
613
+ },
614
+ entryValue(navToRender)
615
+ ) : null;
616
+ const docked = Boolean(navData) || panelOverrideActive;
617
+ const showFlyout = !pinned && Boolean(shownPanel);
618
+ if (isMobile) {
619
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
620
+ import_drawer.Drawer.Root,
621
+ {
622
+ open: drawerOpen,
623
+ onOpenChange: setDrawerOpen,
624
+ placement: "left",
625
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_drawer.Drawer.Content, { className: "w-auto max-w-[85vw] border-0 bg-sidebar p-0 [&>button]:hidden", children: [
626
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_drawer.Drawer.Header, { className: "sr-only", children: [
627
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_drawer.Drawer.Title, { children: "Navigation" }),
628
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_drawer.Drawer.Description, { children: "Hauptnavigation" })
629
+ ] }),
630
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "flex h-full", style: railVars, children: [
631
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SidebarV2Rail, { children: railContent }),
632
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
633
+ "div",
634
+ {
635
+ ref: setPanelHost,
636
+ "data-slot": "sidebar-v2-panel-zone",
637
+ className: "flex min-h-0",
638
+ children: panelContent
639
+ }
640
+ )
641
+ ] })
642
+ ] })
643
+ }
644
+ );
645
+ }
646
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_jsx_runtime3.Fragment, { children: [
647
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SidebarV2Rail, { style: { gridArea: "rail" }, children: railContent }),
648
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
649
+ "div",
650
+ {
651
+ ref: setPanelHost,
652
+ "data-slot": "sidebar-v2-panel-zone",
653
+ className: (0, import_shared_utils2.cn)(
654
+ "relative shrink-0 transition-[width] duration-200 ease-out motion-reduce:transition-none",
655
+ pinned && "overflow-hidden"
656
+ ),
657
+ style: { gridArea: "panel", width: docked ? PANEL_WIDTH : "0px" },
658
+ children: [
659
+ panelContent,
660
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_react3.AnimatePresence, { children: showFlyout && shownPanel && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
661
+ import_react3.motion.div,
662
+ {
663
+ "data-floating": "true",
664
+ className: "absolute inset-y-2 left-1 z-30",
665
+ initial: { x: -14, opacity: 0 },
666
+ animate: { x: 0, opacity: 1 },
667
+ exit: { x: -14, opacity: 0 },
668
+ transition: { duration: 0.16, ease: "easeOut" },
669
+ onMouseEnter: hoverMode ? cancelClose : void 0,
670
+ onMouseLeave: hoverMode ? scheduleClose : void 0,
671
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
672
+ SidebarV2Panel,
673
+ {
674
+ floating: true,
675
+ title: (_c = shownPanel.title) != null ? _c : shownPanel.label,
676
+ subtitle: shownPanel.subtitle,
677
+ children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SidebarV2PanelItems, { items: shownPanel.items })
678
+ }
679
+ )
680
+ },
681
+ "sidebar-v2-flyout"
682
+ ) })
683
+ ]
684
+ }
685
+ )
686
+ ] });
687
+ }
688
+ // Annotate the CommonJS export names for ESM import in node:
689
+ 0 && (module.exports = {
690
+ SidebarV2FromConfig
691
+ });