@kumix/ui 0.3.6 → 0.3.7
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/dist/components/agents/ai-sidebar.d.ts +17 -1
- package/dist/components/agents/ai-sidebar.d.ts.map +1 -1
- package/dist/components/agents/ai-sidebar.js +90 -14
- package/dist/components/agents/ai-sidebar.js.map +1 -1
- package/dist/components/agents/chat-app.d.ts +10 -5
- package/dist/components/agents/chat-app.d.ts.map +1 -1
- package/dist/components/agents/chat-app.js +54 -5
- package/dist/components/agents/chat-app.js.map +1 -1
- package/dist/components/agents/citations.d.ts.map +1 -1
- package/dist/components/agents/citations.js +5 -6
- package/dist/components/agents/citations.js.map +1 -1
- package/dist/components/agents/tool-approval.d.ts.map +1 -1
- package/dist/components/agents/tool-approval.js +1 -1
- package/dist/components/agents/tool-approval.js.map +1 -1
- package/dist/components/motion/action-swap.d.ts.map +1 -1
- package/dist/components/motion/action-swap.js +2 -2
- package/dist/components/motion/action-swap.js.map +1 -1
- package/dist/components/motion/animated-sidebar.js +1 -0
- package/dist/components/motion/animated-sidebar.js.map +1 -1
- package/dist/components/motion/availability-scheduler/copy-menu.js +1 -1
- package/dist/components/motion/availability-scheduler/day-row.d.ts +5 -2
- package/dist/components/motion/availability-scheduler/day-row.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/day-row.js +18 -8
- package/dist/components/motion/availability-scheduler/day-row.js.map +1 -1
- package/dist/components/motion/availability-scheduler/index.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/index.js +27 -5
- package/dist/components/motion/availability-scheduler/index.js.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts +3 -1
- package/dist/components/motion/availability-scheduler/time-select.d.ts.map +1 -1
- package/dist/components/motion/availability-scheduler/time-select.js +3 -1
- package/dist/components/motion/availability-scheduler/time-select.js.map +1 -1
- package/dist/components/motion/bottom-sheet.d.ts.map +1 -1
- package/dist/components/motion/bottom-sheet.js +2 -1
- package/dist/components/motion/bottom-sheet.js.map +1 -1
- package/dist/components/motion/command-palette.d.ts.map +1 -1
- package/dist/components/motion/command-palette.js +3 -1
- package/dist/components/motion/command-palette.js.map +1 -1
- package/dist/components/motion/context-menu.d.ts.map +1 -1
- package/dist/components/motion/context-menu.js +16 -6
- package/dist/components/motion/context-menu.js.map +1 -1
- package/dist/components/motion/cylinder-carousel.d.ts.map +1 -1
- package/dist/components/motion/cylinder-carousel.js +4 -3
- package/dist/components/motion/cylinder-carousel.js.map +1 -1
- package/dist/components/motion/expandable-action-bar.d.ts +6 -0
- package/dist/components/motion/expandable-action-bar.d.ts.map +1 -1
- package/dist/components/motion/expandable-action-bar.js +38 -9
- package/dist/components/motion/expandable-action-bar.js.map +1 -1
- package/dist/components/motion/hold-action-button.d.ts +1 -1
- package/dist/components/motion/hold-action-button.d.ts.map +1 -1
- package/dist/components/motion/hold-action-button.js +64 -50
- package/dist/components/motion/hold-action-button.js.map +1 -1
- package/dist/components/motion/morphing-tabs.d.ts.map +1 -1
- package/dist/components/motion/morphing-tabs.js +59 -18
- package/dist/components/motion/morphing-tabs.js.map +1 -1
- package/dist/components/motion/notification-stack.d.ts.map +1 -1
- package/dist/components/motion/notification-stack.js +28 -11
- package/dist/components/motion/notification-stack.js.map +1 -1
- package/dist/components/motion/popover-morph.d.ts.map +1 -1
- package/dist/components/motion/popover-morph.js +26 -11
- package/dist/components/motion/popover-morph.js.map +1 -1
- package/dist/components/motion/popover.d.ts.map +1 -1
- package/dist/components/motion/popover.js +39 -28
- package/dist/components/motion/popover.js.map +1 -1
- package/dist/components/motion/preview-rail.d.ts.map +1 -1
- package/dist/components/motion/preview-rail.js +42 -13
- package/dist/components/motion/preview-rail.js.map +1 -1
- package/dist/components/motion/pull-to-refresh.d.ts.map +1 -1
- package/dist/components/motion/pull-to-refresh.js +8 -7
- package/dist/components/motion/pull-to-refresh.js.map +1 -1
- package/dist/components/motion/range-slider-bubble.d.ts.map +1 -1
- package/dist/components/motion/range-slider-bubble.js +2 -1
- package/dist/components/motion/range-slider-bubble.js.map +1 -1
- package/dist/components/motion/range-slider-fluid.d.ts.map +1 -1
- package/dist/components/motion/range-slider-fluid.js +2 -1
- package/dist/components/motion/range-slider-fluid.js.map +1 -1
- package/dist/components/motion/range-slider-ruler.d.ts.map +1 -1
- package/dist/components/motion/range-slider-ruler.js +2 -1
- package/dist/components/motion/range-slider-ruler.js.map +1 -1
- package/dist/components/motion/range-slider-wave.d.ts.map +1 -1
- package/dist/components/motion/range-slider-wave.js +2 -1
- package/dist/components/motion/range-slider-wave.js.map +1 -1
- package/dist/components/motion/range-slider.d.ts.map +1 -1
- package/dist/components/motion/range-slider.js +2 -1
- package/dist/components/motion/range-slider.js.map +1 -1
- package/dist/components/motion/select.d.ts +15 -1
- package/dist/components/motion/select.d.ts.map +1 -1
- package/dist/components/motion/select.js +15 -4
- package/dist/components/motion/select.js.map +1 -1
- package/dist/components/motion/slide-action-button.d.ts.map +1 -1
- package/dist/components/motion/slide-action-button.js +3 -2
- package/dist/components/motion/slide-action-button.js.map +1 -1
- package/dist/components/motion/swipeable-list.d.ts.map +1 -1
- package/dist/components/motion/swipeable-list.js +2 -1
- package/dist/components/motion/swipeable-list.js.map +1 -1
- package/dist/components/motion/table/index.d.ts.map +1 -1
- package/dist/components/motion/table/index.js +64 -6
- package/dist/components/motion/table/index.js.map +1 -1
- package/dist/components/motion/table/table-header.d.ts.map +1 -1
- package/dist/components/motion/table/table-header.js +3 -2
- package/dist/components/motion/table/table-header.js.map +1 -1
- package/dist/components/motion/text-reveal.d.ts.map +1 -1
- package/dist/components/motion/text-reveal.js +72 -48
- package/dist/components/motion/text-reveal.js.map +1 -1
- package/dist/components/motion/tooltip.d.ts.map +1 -1
- package/dist/components/motion/tooltip.js +35 -15
- package/dist/components/motion/tooltip.js.map +1 -1
- package/dist/components/motion/wheel-picker.d.ts.map +1 -1
- package/dist/components/motion/wheel-picker.js +4 -3
- package/dist/components/motion/wheel-picker.js.map +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- package/dist/components/ui/attachment.d.ts +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button-group.d.ts +1 -1
- package/dist/components/ui/button.d.ts +2 -2
- package/dist/components/ui/field.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/{copy-menu-Bk5GP9Gp.js → copy-menu-1FKoMc9o.js} +9 -2
- package/dist/copy-menu-1FKoMc9o.js.map +1 -0
- package/dist/hooks/use-dismiss.d.ts +34 -0
- package/dist/hooks/use-dismiss.d.ts.map +1 -0
- package/dist/hooks/use-dismiss.js +78 -0
- package/dist/hooks/use-dismiss.js.map +1 -0
- package/dist/hooks/use-favicon.d.ts +17 -0
- package/dist/hooks/use-favicon.d.ts.map +1 -0
- package/dist/hooks/use-favicon.js +35 -0
- package/dist/hooks/use-favicon.js.map +1 -0
- package/dist/hooks/use-hover-gesture.d.ts +38 -0
- package/dist/hooks/use-hover-gesture.d.ts.map +1 -0
- package/dist/hooks/use-hover-gesture.js +46 -0
- package/dist/hooks/use-hover-gesture.js.map +1 -0
- package/dist/hooks/use-slider.d.ts.map +1 -1
- package/dist/hooks/use-slider.js +3 -2
- package/dist/hooks/use-slider.js.map +1 -1
- package/dist/hooks/use-tap-gesture.d.ts +47 -0
- package/dist/hooks/use-tap-gesture.d.ts.map +1 -0
- package/dist/hooks/use-tap-gesture.js +51 -0
- package/dist/hooks/use-tap-gesture.js.map +1 -0
- package/dist/hooks/use-touch-capable.d.ts +15 -0
- package/dist/hooks/use-touch-capable.d.ts.map +1 -0
- package/dist/hooks/use-touch-capable.js +29 -0
- package/dist/hooks/use-touch-capable.js.map +1 -0
- package/dist/lib/touch.d.ts +66 -0
- package/dist/lib/touch.d.ts.map +1 -0
- package/dist/lib/touch.js +79 -0
- package/dist/lib/touch.js.map +1 -0
- package/dist/types-smkWN_7x.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/copy-menu-Bk5GP9Gp.js.map +0 -1
|
@@ -14,9 +14,25 @@ interface SidebarResourceMove {
|
|
|
14
14
|
targetId: string | null;
|
|
15
15
|
position: SidebarResourceDropPosition;
|
|
16
16
|
}
|
|
17
|
+
/**
|
|
18
|
+
* The moves this row can make right now, the same four the keyboard offers on
|
|
19
|
+
* `Alt+Shift+Arrow`. A pointer drag is the fast path for them; a finger has no
|
|
20
|
+
* drag to give, so the row menu carries them too. Absent keys are moves this
|
|
21
|
+
* row cannot make from where it sits.
|
|
22
|
+
*/
|
|
23
|
+
interface SidebarResourceMoveCommands {
|
|
24
|
+
up?: () => void;
|
|
25
|
+
down?: () => void;
|
|
26
|
+
into?: {
|
|
27
|
+
label: string;
|
|
28
|
+
run: () => void;
|
|
29
|
+
};
|
|
30
|
+
out?: () => void;
|
|
31
|
+
}
|
|
17
32
|
interface SidebarResourceMenuControls {
|
|
18
33
|
close: () => void;
|
|
19
34
|
rename: () => void;
|
|
35
|
+
moves: SidebarResourceMoveCommands;
|
|
20
36
|
}
|
|
21
37
|
interface AISidebarProps {
|
|
22
38
|
items?: SidebarResource[];
|
|
@@ -37,5 +53,5 @@ interface AISidebarProps {
|
|
|
37
53
|
}
|
|
38
54
|
declare function AISidebar({ items, defaultItems, onItemsChange, onMove, onMoveError, onRename, activeId, defaultActiveId, onActiveChange, defaultExpandedIds, renderIcon, renderMenu, ariaLabel, className }: AISidebarProps): import("react").JSX.Element;
|
|
39
55
|
//#endregion
|
|
40
|
-
export { AISidebar, AISidebarProps, SidebarResource, SidebarResourceDropPosition, SidebarResourceKind, SidebarResourceMenuControls, SidebarResourceMove };
|
|
56
|
+
export { AISidebar, AISidebarProps, SidebarResource, SidebarResourceDropPosition, SidebarResourceKind, SidebarResourceMenuControls, SidebarResourceMove, SidebarResourceMoveCommands };
|
|
41
57
|
//# sourceMappingURL=ai-sidebar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sidebar.d.ts","names":[],"sources":["../../../src/components/agents/ai-sidebar.tsx"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"ai-sidebar.d.ts","names":[],"sources":["../../../src/components/agents/ai-sidebar.tsx"],"mappings":";;KAgCY;UAEK;EACf;EACA;EACA,MAAM;EACN,WAAW;EACX;;KAGU;UAEK;EACf;EACA;EACA,UAAU;;;;;;;;UASK;EACf;EACA;EACA;IAAS;IAAe;;EACxB;;UAGe;EACf;EACA;EACA,OAAO;;UAGQ;EACf,QAAQ;EACR,eAAe;EACf,iBAAiB,OAAO;;EAExB,UAAU,MAAM,+BAA+B;EAC/C,eAAe,gBAAgB,MAAM;EACrC,YAAY,MAAM,iBAAiB,yBAAyB;EAC5D;EACA;EACA,kBAAkB;EAClB;EACA,cAAc,MAAM,oBAAoB;EACxC,cAAc,MAAM,iBAAiB,UAAU,gCAAgC;EAC/E;EACA;;iBA+bc,YACd,OACA,cACA,eACA,QACA,aACA,UACA,UACA,iBACA,gBACA,oBACA,YACA,YACA,WACA,aACC,iCAAc,IAAA"}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useTouchCapable } from "../../hooks/use-touch-capable.js";
|
|
2
3
|
import { EASE_OUT, SPRING_LAYOUT } from "../../lib/ease.js";
|
|
3
4
|
import { MorphPopover, MorphPopoverContent, MorphPopoverTrigger } from "../motion/popover-morph.js";
|
|
4
5
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
5
6
|
import { cn } from "@kumix/utils";
|
|
6
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
7
8
|
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
|
8
|
-
import { Bookmark, FileText, Folder, FolderOpen, MoreHorizontal, Pencil } from "lucide-react";
|
|
9
|
+
import { ArrowDown, ArrowUp, Bookmark, FileText, Folder, FolderInput, FolderOpen, MoreHorizontal, Pencil, Undo2 } from "lucide-react";
|
|
9
10
|
//#region src/components/agents/ai-sidebar.tsx
|
|
10
11
|
const ROW_REVEAL = {
|
|
11
12
|
duration: .16,
|
|
@@ -144,8 +145,23 @@ function MarqueeLabel({ active, children }) {
|
|
|
144
145
|
})
|
|
145
146
|
});
|
|
146
147
|
}
|
|
147
|
-
function
|
|
148
|
+
function ResourceMenuAction({ icon: Icon, onSelect, children }) {
|
|
149
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
150
|
+
type: "button",
|
|
151
|
+
onClick: onSelect,
|
|
152
|
+
className: "flex h-8 w-full items-center gap-2 rounded-lg px-2.5 text-left text-foreground text-xs outline-none transition-colors hover:bg-muted focus-visible:bg-muted focus-visible:ring-2 focus-visible:ring-ring",
|
|
153
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
154
|
+
"aria-hidden": "true",
|
|
155
|
+
className: "size-3.5 shrink-0"
|
|
156
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
157
|
+
className: "min-w-0 truncate",
|
|
158
|
+
children
|
|
159
|
+
})]
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
function ResourceRow({ row, active, expanded, focused, draggingId, dropTarget, menuOpen, moves, renaming, onDragEnd, onDragOver, onDragStart, onDrop, onFocus, onKeyDown, onMenuOpenChange, onRenameCancel, onRenameCommit, onRenameStart, onSelect, onToggle, renderIcon, renderMenu, setRef }) {
|
|
148
163
|
const reduce = useReducedMotion() ?? false;
|
|
164
|
+
const canTouch = useTouchCapable();
|
|
149
165
|
const [hovered, setHovered] = useState(false);
|
|
150
166
|
const inputRef = useRef(null);
|
|
151
167
|
const skipRenameBlurRef = useRef(false);
|
|
@@ -163,24 +179,48 @@ function ResourceRow({ row, active, expanded, focused, draggingId, dropTarget, m
|
|
|
163
179
|
inputRef.current?.select();
|
|
164
180
|
});
|
|
165
181
|
}, [renaming, row.item.label]);
|
|
182
|
+
const runFromMenu = (action) => () => {
|
|
183
|
+
onMenuOpenChange(false);
|
|
184
|
+
action();
|
|
185
|
+
};
|
|
166
186
|
const menu = renderMenu?.(row.item, {
|
|
167
187
|
close: () => onMenuOpenChange(false),
|
|
168
188
|
rename: () => {
|
|
169
189
|
onMenuOpenChange(false);
|
|
170
190
|
onRenameStart();
|
|
171
|
-
}
|
|
172
|
-
}) ?? /* @__PURE__ */ jsxs("button", {
|
|
173
|
-
type: "button",
|
|
174
|
-
onClick: () => {
|
|
175
|
-
onMenuOpenChange(false);
|
|
176
|
-
onRenameStart();
|
|
177
191
|
},
|
|
178
|
-
|
|
179
|
-
|
|
192
|
+
moves
|
|
193
|
+
}) ?? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
194
|
+
/* @__PURE__ */ jsx(ResourceMenuAction, {
|
|
195
|
+
icon: Pencil,
|
|
196
|
+
onSelect: runFromMenu(onRenameStart),
|
|
197
|
+
children: "Rename"
|
|
198
|
+
}),
|
|
199
|
+
moves.up || moves.down || moves.into || moves.out ? /* @__PURE__ */ jsx("div", {
|
|
180
200
|
"aria-hidden": "true",
|
|
181
|
-
className: "
|
|
182
|
-
}),
|
|
183
|
-
|
|
201
|
+
className: "my-1 h-px bg-border"
|
|
202
|
+
}) : null,
|
|
203
|
+
moves.up ? /* @__PURE__ */ jsx(ResourceMenuAction, {
|
|
204
|
+
icon: ArrowUp,
|
|
205
|
+
onSelect: runFromMenu(moves.up),
|
|
206
|
+
children: "Move up"
|
|
207
|
+
}) : null,
|
|
208
|
+
moves.down ? /* @__PURE__ */ jsx(ResourceMenuAction, {
|
|
209
|
+
icon: ArrowDown,
|
|
210
|
+
onSelect: runFromMenu(moves.down),
|
|
211
|
+
children: "Move down"
|
|
212
|
+
}) : null,
|
|
213
|
+
moves.into ? /* @__PURE__ */ jsxs(ResourceMenuAction, {
|
|
214
|
+
icon: FolderInput,
|
|
215
|
+
onSelect: runFromMenu(moves.into.run),
|
|
216
|
+
children: ["Move into ", moves.into.label]
|
|
217
|
+
}) : null,
|
|
218
|
+
moves.out ? /* @__PURE__ */ jsx(ResourceMenuAction, {
|
|
219
|
+
icon: Undo2,
|
|
220
|
+
onSelect: runFromMenu(moves.out),
|
|
221
|
+
children: "Move out"
|
|
222
|
+
}) : null
|
|
223
|
+
] });
|
|
184
224
|
return /* @__PURE__ */ jsxs(motion.div, {
|
|
185
225
|
ref: setRef,
|
|
186
226
|
layout: "position",
|
|
@@ -265,7 +305,7 @@ function ResourceRow({ row, active, expanded, focused, draggingId, dropTarget, m
|
|
|
265
305
|
tabIndex: -1,
|
|
266
306
|
"aria-label": `Actions for ${row.item.label}`,
|
|
267
307
|
onClick: (event) => event.stopPropagation(),
|
|
268
|
-
className: "grid size-7 shrink-0 place-items-center rounded-lg
|
|
308
|
+
className: cn("grid size-7 shrink-0 place-items-center rounded-lg outline-none transition-opacity hover:bg-foreground/5 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring group-hover/resource:opacity-100 group-data-[menu-open=true]/resource:opacity-100", canTouch ? "opacity-100" : "opacity-0"),
|
|
269
309
|
children: /* @__PURE__ */ jsx(MoreHorizontal, {
|
|
270
310
|
"aria-hidden": "true",
|
|
271
311
|
className: "size-4"
|
|
@@ -364,6 +404,41 @@ function AISidebar({ items, defaultItems = [], onItemsChange, onMove, onMoveErro
|
|
|
364
404
|
return next;
|
|
365
405
|
});
|
|
366
406
|
}, []);
|
|
407
|
+
const moveCommands = useCallback((row) => {
|
|
408
|
+
if (row.item.disabled) return {};
|
|
409
|
+
const index = flat.findIndex(({ item }) => item.id === row.item.id);
|
|
410
|
+
const previous = flat[index - 1];
|
|
411
|
+
const next = flat[index + 1];
|
|
412
|
+
const parentId = row.parentId;
|
|
413
|
+
const commands = {};
|
|
414
|
+
if (previous) commands.up = () => void performMove({
|
|
415
|
+
itemId: row.item.id,
|
|
416
|
+
targetId: previous.item.id,
|
|
417
|
+
position: "before"
|
|
418
|
+
});
|
|
419
|
+
if (next) commands.down = () => void performMove({
|
|
420
|
+
itemId: row.item.id,
|
|
421
|
+
targetId: next.item.id,
|
|
422
|
+
position: "after"
|
|
423
|
+
});
|
|
424
|
+
if (previous && canContain(previous.item) && previous.item.id !== parentId) commands.into = {
|
|
425
|
+
label: previous.item.label,
|
|
426
|
+
run: () => {
|
|
427
|
+
setExpandedIds((current) => new Set(current).add(previous.item.id));
|
|
428
|
+
performMove({
|
|
429
|
+
itemId: row.item.id,
|
|
430
|
+
targetId: previous.item.id,
|
|
431
|
+
position: "inside"
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
if (parentId) commands.out = () => void performMove({
|
|
436
|
+
itemId: row.item.id,
|
|
437
|
+
targetId: parentId,
|
|
438
|
+
position: "after"
|
|
439
|
+
});
|
|
440
|
+
return commands;
|
|
441
|
+
}, [flat, performMove]);
|
|
367
442
|
const handleKeyDown = useCallback((event, row) => {
|
|
368
443
|
const index = flat.findIndex(({ item }) => item.id === row.item.id);
|
|
369
444
|
const previous = flat[index - 1];
|
|
@@ -497,6 +572,7 @@ function AISidebar({ items, defaultItems = [], onItemsChange, onMove, onMoveErro
|
|
|
497
572
|
draggingId,
|
|
498
573
|
dropTarget,
|
|
499
574
|
menuOpen: menuOpenId === row.item.id,
|
|
575
|
+
moves: moveCommands(row),
|
|
500
576
|
renaming: renamingId === row.item.id,
|
|
501
577
|
onFocus: () => setFocusedId(row.item.id),
|
|
502
578
|
onSelect: () => select(row.item.id),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ai-sidebar.js","names":[],"sources":["../../../src/components/agents/ai-sidebar.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type DragEvent,\n type KeyboardEvent,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { Bookmark, FileText, Folder, FolderOpen, MoreHorizontal, Pencil } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\nimport { MorphPopover, MorphPopoverContent, MorphPopoverTrigger } from \"../motion/popover-morph\";\n\nexport type SidebarResourceKind = \"folder\" | \"project\" | \"file\" | \"bookmark\";\n\nexport interface SidebarResource {\n id: string;\n label: string;\n kind: SidebarResourceKind;\n children?: SidebarResource[];\n disabled?: boolean;\n}\n\nexport type SidebarResourceDropPosition = \"before\" | \"inside\" | \"after\";\n\nexport interface SidebarResourceMove {\n itemId: string;\n targetId: string | null;\n position: SidebarResourceDropPosition;\n}\n\nexport interface SidebarResourceMenuControls {\n close: () => void;\n rename: () => void;\n}\n\nexport interface AISidebarProps {\n items?: SidebarResource[];\n defaultItems?: SidebarResource[];\n onItemsChange?: (items: SidebarResource[]) => void;\n /** Reject the promise to roll the optimistic move back. */\n onMove?: (move: SidebarResourceMove) => void | Promise<void>;\n onMoveError?: (error: unknown, move: SidebarResourceMove) => void;\n onRename?: (item: SidebarResource, label: string) => void | Promise<void>;\n activeId?: string | null;\n defaultActiveId?: string | null;\n onActiveChange?: (id: string) => void;\n defaultExpandedIds?: string[];\n renderIcon?: (item: SidebarResource) => ReactNode;\n renderMenu?: (item: SidebarResource, controls: SidebarResourceMenuControls) => ReactNode;\n ariaLabel?: string;\n className?: string;\n}\n\ninterface FlatResource {\n item: SidebarResource;\n depth: number;\n parentId: string | null;\n}\n\ninterface DropTarget {\n id: string | null;\n position: SidebarResourceDropPosition;\n}\n\nconst ROW_REVEAL = {\n duration: 0.16,\n ease: EASE_OUT,\n} as const;\n\nfunction canContain(item: SidebarResource) {\n return item.kind === \"folder\" || item.kind === \"project\";\n}\n\nfunction flattenResources(\n items: SidebarResource[],\n expanded: Set<string>,\n depth = 0,\n parentId: string | null = null,\n): FlatResource[] {\n return items.flatMap((item) => {\n const row = { item, depth, parentId };\n if (!item.children?.length || !expanded.has(item.id)) return [row];\n return [row, ...flattenResources(item.children, expanded, depth + 1, item.id)];\n });\n}\n\nfunction findResource(items: SidebarResource[], id: string): SidebarResource | undefined {\n for (const item of items) {\n if (item.id === id) return item;\n const child = item.children ? findResource(item.children, id) : undefined;\n if (child) return child;\n }\n}\n\nfunction containsResource(item: SidebarResource, id: string): boolean {\n return item.id === id || item.children?.some((child) => containsResource(child, id)) === true;\n}\n\nfunction removeResource(\n items: SidebarResource[],\n id: string,\n): { items: SidebarResource[]; removed?: SidebarResource } {\n let removed: SidebarResource | undefined;\n const next: SidebarResource[] = [];\n\n for (const item of items) {\n if (item.id === id) {\n removed = item;\n continue;\n }\n\n if (item.children?.length) {\n const childResult = removeResource(item.children, id);\n if (childResult.removed) {\n removed = childResult.removed;\n next.push({ ...item, children: childResult.items });\n continue;\n }\n }\n\n next.push(item);\n }\n\n return { items: next, removed };\n}\n\nfunction insertResource(\n items: SidebarResource[],\n resource: SidebarResource,\n targetId: string | null,\n position: SidebarResourceDropPosition,\n): SidebarResource[] {\n if (targetId === null) return [...items, resource];\n\n const next: SidebarResource[] = [];\n for (const item of items) {\n if (item.id === targetId) {\n if (position === \"before\") next.push(resource, item);\n else if (position === \"after\") next.push(item, resource);\n else next.push({ ...item, children: [...(item.children ?? []), resource] });\n continue;\n }\n\n if (item.children?.length) {\n next.push({\n ...item,\n children: insertResource(item.children, resource, targetId, position),\n });\n } else {\n next.push(item);\n }\n }\n return next;\n}\n\nfunction moveResource(\n items: SidebarResource[],\n move: SidebarResourceMove,\n): SidebarResource[] | null {\n const source = findResource(items, move.itemId);\n if (!source || source.disabled) return null;\n if (move.targetId && containsResource(source, move.targetId)) return null;\n\n const target = move.targetId ? findResource(items, move.targetId) : undefined;\n if (move.position === \"inside\" && (!target || target.disabled || !canContain(target)))\n return null;\n\n const removed = removeResource(items, move.itemId);\n if (!removed.removed) return null;\n return insertResource(removed.items, removed.removed, move.targetId, move.position);\n}\n\nfunction renameResource(items: SidebarResource[], id: string, label: string): SidebarResource[] {\n return items.map((item) => ({\n ...item,\n label: item.id === id ? label : item.label,\n children: item.children ? renameResource(item.children, id, label) : undefined,\n }));\n}\n\nfunction defaultIcon(item: SidebarResource, expanded: boolean) {\n const Icon =\n item.kind === \"folder\" || item.kind === \"project\"\n ? expanded\n ? FolderOpen\n : Folder\n : item.kind === \"bookmark\"\n ? Bookmark\n : FileText;\n return <Icon className=\"size-4\" />;\n}\n\nfunction MarqueeLabel({ active, children }: { active: boolean; children: string }) {\n const reduce = useReducedMotion() ?? false;\n const viewportRef = useRef<HTMLSpanElement>(null);\n const labelRef = useRef<HTMLSpanElement>(null);\n const [distance, setDistance] = useState(0);\n\n useEffect(() => {\n const measure = () => {\n const viewport = viewportRef.current;\n const label = labelRef.current;\n if (!viewport || !label) return;\n setDistance(label.scrollWidth > viewport.clientWidth ? label.scrollWidth + 24 : 0);\n };\n measure();\n const observer = new ResizeObserver(measure);\n if (viewportRef.current) observer.observe(viewportRef.current);\n if (labelRef.current) observer.observe(labelRef.current);\n return () => observer.disconnect();\n }, []);\n\n const running = active && distance > 0 && !reduce;\n\n return (\n <span ref={viewportRef} className=\"block min-w-0 flex-1 overflow-hidden\">\n <motion.span\n className=\"flex w-max items-center gap-6 whitespace-nowrap\"\n animate={{ x: running ? [0, -distance] : 0 }}\n transition={\n running\n ? {\n duration: Math.max(2.4, distance / 34),\n ease: \"linear\",\n repeat: Number.POSITIVE_INFINITY,\n repeatDelay: 2,\n }\n : ROW_REVEAL\n }\n >\n <span ref={labelRef}>{children}</span>\n {running ? <span aria-hidden=\"true\">{children}</span> : null}\n </motion.span>\n </span>\n );\n}\n\ninterface ResourceRowProps {\n row: FlatResource;\n active: boolean;\n expanded: boolean;\n focused: boolean;\n draggingId: string | null;\n dropTarget: DropTarget | null;\n menuOpen: boolean;\n renaming: boolean;\n onDragEnd: () => void;\n onDragOver: (event: DragEvent<HTMLDivElement>, row: FlatResource) => void;\n onDragStart: (event: DragEvent<HTMLDivElement>, id: string) => void;\n onDrop: (event: DragEvent<HTMLDivElement>) => void;\n onFocus: () => void;\n onKeyDown: (event: KeyboardEvent<HTMLDivElement>) => void;\n onMenuOpenChange: (open: boolean) => void;\n onRenameCancel: () => void;\n onRenameCommit: (label: string) => void;\n onRenameStart: () => void;\n onSelect: () => void;\n onToggle: () => void;\n renderIcon?: (item: SidebarResource) => ReactNode;\n renderMenu?: AISidebarProps[\"renderMenu\"];\n setRef: (node: HTMLDivElement | null) => void;\n}\n\nfunction ResourceRow({\n row,\n active,\n expanded,\n focused,\n draggingId,\n dropTarget,\n menuOpen,\n renaming,\n onDragEnd,\n onDragOver,\n onDragStart,\n onDrop,\n onFocus,\n onKeyDown,\n onMenuOpenChange,\n onRenameCancel,\n onRenameCommit,\n onRenameStart,\n onSelect,\n onToggle,\n renderIcon,\n renderMenu,\n setRef,\n}: ResourceRowProps) {\n const reduce = useReducedMotion() ?? false;\n const [hovered, setHovered] = useState(false);\n const inputRef = useRef<HTMLInputElement>(null);\n const skipRenameBlurRef = useRef(false);\n const draggedRef = useRef(false);\n const [draft, setDraft] = useState(row.item.label);\n const acceptsChildren = canContain(row.item);\n const isDragging = draggingId === row.item.id;\n const dropPosition = dropTarget?.id === row.item.id ? dropTarget.position : null;\n\n useEffect(() => {\n if (!renaming) return;\n skipRenameBlurRef.current = false;\n setDraft(row.item.label);\n requestAnimationFrame(() => {\n inputRef.current?.focus();\n inputRef.current?.select();\n });\n }, [renaming, row.item.label]);\n\n const menu = renderMenu?.(row.item, {\n close: () => onMenuOpenChange(false),\n rename: () => {\n onMenuOpenChange(false);\n onRenameStart();\n },\n }) ?? (\n <button\n type=\"button\"\n onClick={() => {\n onMenuOpenChange(false);\n onRenameStart();\n }}\n className=\"flex h-8 w-full items-center gap-2 rounded-lg px-2.5 text-left text-foreground text-xs outline-none transition-colors hover:bg-muted focus-visible:bg-muted focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Pencil aria-hidden=\"true\" className=\"size-3.5\" />\n Rename\n </button>\n );\n\n return (\n <motion.div\n ref={setRef}\n layout=\"position\"\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n role=\"treeitem\"\n aria-level={row.depth + 1}\n aria-selected={acceptsChildren ? undefined : active}\n aria-expanded={acceptsChildren ? expanded : undefined}\n aria-disabled={row.item.disabled || undefined}\n tabIndex={focused ? 0 : -1}\n draggable={!row.item.disabled && !renaming}\n data-menu-open={menuOpen || undefined}\n data-drop={dropPosition ?? undefined}\n data-dragging={isDragging || undefined}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n onClick={(event) => {\n if (event.defaultPrevented || draggedRef.current || renaming || row.item.disabled) return;\n if (acceptsChildren) onToggle();\n else onSelect();\n }}\n onDoubleClick={(event) => {\n if (acceptsChildren || row.item.disabled) return;\n event.preventDefault();\n onRenameStart();\n }}\n onMouseEnter={() => setHovered(true)}\n onMouseLeave={() => setHovered(false)}\n onDragStartCapture={(event) => {\n draggedRef.current = true;\n onDragStart(event, row.item.id);\n }}\n onDragEndCapture={() => {\n onDragEnd();\n requestAnimationFrame(() => {\n draggedRef.current = false;\n });\n }}\n onDragOver={(event) => onDragOver(event, row)}\n onDrop={onDrop}\n className={cn(\n \"group/resource relative flex min-h-9 min-w-0 cursor-pointer items-center gap-2.5 rounded-xl pr-3 text-sm outline-none\",\n \"text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\",\n \"focus-visible:bg-muted/70 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset\",\n \"data-[menu-open=true]:bg-muted data-[menu-open=true]:text-foreground\",\n \"data-[dragging=true]:opacity-40\",\n \"data-[drop=inside]:bg-primary/10 data-[drop=inside]:ring-1 data-[drop=inside]:ring-primary/45\",\n \"data-[drop=before]:before:absolute data-[drop=before]:before:-top-0.5 data-[drop=before]:before:right-2 data-[drop=before]:before:left-2 data-[drop=before]:before:h-0.5 data-[drop=before]:before:rounded-full data-[drop=before]:before:bg-primary\",\n \"data-[drop=after]:after:absolute data-[drop=after]:after:right-2 data-[drop=after]:after:-bottom-0.5 data-[drop=after]:after:left-2 data-[drop=after]:after:h-0.5 data-[drop=after]:after:rounded-full data-[drop=after]:after:bg-primary\",\n !acceptsChildren && active && \"bg-muted text-foreground\",\n row.item.disabled && \"cursor-not-allowed opacity-45\",\n )}\n style={{ paddingLeft: `${12 + row.depth * 16}px` }}\n >\n <span aria-hidden=\"true\" className=\"grid size-5 shrink-0 place-items-center\">\n {renderIcon?.(row.item) ?? defaultIcon(row.item, expanded)}\n </span>\n\n {renaming ? (\n <input\n ref={inputRef}\n value={draft}\n aria-label={`Rename ${row.item.label}`}\n onChange={(event) => setDraft(event.target.value)}\n draggable={false}\n onClick={(event) => event.stopPropagation()}\n onDoubleClick={(event) => event.stopPropagation()}\n onBlur={() => {\n if (!skipRenameBlurRef.current) onRenameCommit(draft);\n }}\n onKeyDown={(event) => {\n event.stopPropagation();\n if (event.key === \"Enter\") {\n skipRenameBlurRef.current = true;\n onRenameCommit(draft);\n }\n if (event.key === \"Escape\") {\n skipRenameBlurRef.current = true;\n onRenameCancel();\n }\n }}\n className=\"mx-1 h-7 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-foreground text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n />\n ) : (\n <MarqueeLabel active={hovered || menuOpen}>{row.item.label}</MarqueeLabel>\n )}\n\n {!renaming && !row.item.disabled ? (\n <MorphPopover open={menuOpen} onOpenChange={onMenuOpenChange}>\n <MorphPopoverTrigger>\n <button\n type=\"button\"\n draggable={false}\n tabIndex={-1}\n aria-label={`Actions for ${row.item.label}`}\n onClick={(event) => event.stopPropagation()}\n className=\"grid size-7 shrink-0 place-items-center rounded-lg opacity-0 outline-none transition-opacity hover:bg-foreground/5 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring group-hover/resource:opacity-100 group-data-[menu-open=true]/resource:opacity-100\"\n >\n <MoreHorizontal aria-hidden=\"true\" className=\"size-4\" />\n </button>\n </MorphPopoverTrigger>\n <MorphPopoverContent\n side=\"bottom\"\n align=\"end\"\n sideOffset={8}\n radius={12}\n className=\"w-40 p-1.5\"\n >\n <div data-sidebar-resource-menu={row.item.id}>{menu}</div>\n </MorphPopoverContent>\n </MorphPopover>\n ) : null}\n </motion.div>\n );\n}\n\nexport function AISidebar({\n items,\n defaultItems = [],\n onItemsChange,\n onMove,\n onMoveError,\n onRename,\n activeId,\n defaultActiveId = null,\n onActiveChange,\n defaultExpandedIds = [],\n renderIcon,\n renderMenu,\n ariaLabel = \"Resources\",\n className,\n}: AISidebarProps) {\n const [internalItems, setInternalItems] = useState(items ?? defaultItems);\n const [internalActiveId, setInternalActiveId] = useState(defaultActiveId);\n const [expandedIds, setExpandedIds] = useState(() => new Set(defaultExpandedIds));\n const [focusedId, setFocusedId] = useState<string | null>(activeId ?? defaultActiveId);\n const [draggingId, setDraggingId] = useState<string | null>(null);\n const [dropTarget, setDropTarget] = useState<DropTarget | null>(null);\n const [menuOpenId, setMenuOpenId] = useState<string | null>(null);\n const [renamingId, setRenamingId] = useState<string | null>(null);\n const [announcement, setAnnouncement] = useState(\"\");\n const rowRefs = useRef(new Map<string, HTMLDivElement>());\n const movePendingRef = useRef(false);\n const renderedItems = internalItems;\n const selectedId = activeId ?? internalActiveId;\n\n useEffect(() => {\n if (items) setInternalItems(items);\n }, [items]);\n\n const flat = useMemo(\n () => flattenResources(renderedItems, expandedIds),\n [expandedIds, renderedItems],\n );\n\n useEffect(() => {\n if (focusedId && flat.some((row) => row.item.id === focusedId)) return;\n setFocusedId(flat[0]?.item.id ?? null);\n }, [flat, focusedId]);\n\n useEffect(() => {\n if (!menuOpenId) return;\n const frame = requestAnimationFrame(() => {\n const menus = Array.from(\n document.querySelectorAll<HTMLElement>(\"[data-sidebar-resource-menu]\"),\n );\n menus\n .find((menu) => menu.dataset.sidebarResourceMenu === menuOpenId)\n ?.querySelector<HTMLElement>(\"button, a[href]\")\n ?.focus();\n });\n return () => cancelAnimationFrame(frame);\n }, [menuOpenId]);\n\n const updateItems = useCallback(\n (next: SidebarResource[]) => {\n setInternalItems(next);\n onItemsChange?.(next);\n },\n [onItemsChange],\n );\n\n const performMove = useCallback(\n async (move: SidebarResourceMove) => {\n if (movePendingRef.current) {\n setAnnouncement(\"Wait for the current move to finish.\");\n return;\n }\n const before = renderedItems;\n const next = moveResource(before, move);\n if (!next || next === before) return;\n\n movePendingRef.current = true;\n updateItems(next);\n setDropTarget(null);\n setDraggingId(null);\n const moved = findResource(before, move.itemId);\n const target = move.targetId ? findResource(before, move.targetId) : null;\n setAnnouncement(\n target\n ? `Moved ${moved?.label ?? \"item\"} ${move.position} ${target.label}.`\n : `Moved ${moved?.label ?? \"item\"} to the top level.`,\n );\n\n try {\n await onMove?.(move);\n } catch (error) {\n updateItems(before);\n setAnnouncement(`Move failed. ${moved?.label ?? \"Item\"} was restored.`);\n onMoveError?.(error, move);\n } finally {\n movePendingRef.current = false;\n }\n },\n [onMove, onMoveError, renderedItems, updateItems],\n );\n\n const focusRow = useCallback((id: string) => {\n setFocusedId(id);\n requestAnimationFrame(() => rowRefs.current.get(id)?.focus());\n }, []);\n\n const select = useCallback(\n (id: string) => {\n if (activeId === undefined) setInternalActiveId(id);\n onActiveChange?.(id);\n },\n [activeId, onActiveChange],\n );\n\n const toggle = useCallback((id: string) => {\n setExpandedIds((current) => {\n const next = new Set(current);\n if (next.has(id)) next.delete(id);\n else next.add(id);\n return next;\n });\n }, []);\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>, row: FlatResource) => {\n const index = flat.findIndex(({ item }) => item.id === row.item.id);\n const previous = flat[index - 1];\n const next = flat[index + 1];\n const moveModifier = event.altKey && event.shiftKey;\n\n if (event.key === \"ArrowDown\" && !moveModifier && next) {\n event.preventDefault();\n focusRow(next.item.id);\n return;\n }\n if (event.key === \"ArrowUp\" && !moveModifier && previous) {\n event.preventDefault();\n focusRow(previous.item.id);\n return;\n }\n if (event.key === \"Home\" && flat[0]) {\n event.preventDefault();\n focusRow(flat[0].item.id);\n return;\n }\n if (event.key === \"End\" && flat.at(-1)) {\n event.preventDefault();\n focusRow(flat.at(-1)?.item.id ?? row.item.id);\n return;\n }\n\n if (row.item.disabled) {\n if (event.key === \"ArrowLeft\" && row.parentId) {\n event.preventDefault();\n focusRow(row.parentId);\n } else if (\n moveModifier ||\n [\"ArrowRight\", \"Enter\", \" \", \"F2\", \"ContextMenu\"].includes(event.key) ||\n (event.shiftKey && event.key === \"F10\")\n ) {\n event.preventDefault();\n }\n return;\n }\n\n if (moveModifier && event.key === \"ArrowUp\" && previous) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: previous.item.id, position: \"before\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowDown\" && next) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: next.item.id, position: \"after\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowRight\" && previous && canContain(previous.item)) {\n event.preventDefault();\n setExpandedIds((current) => new Set(current).add(previous.item.id));\n void performMove({ itemId: row.item.id, targetId: previous.item.id, position: \"inside\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowLeft\" && row.parentId) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: row.parentId, position: \"after\" });\n return;\n }\n\n if (event.key === \"ArrowRight\" && canContain(row.item)) {\n event.preventDefault();\n if (!expandedIds.has(row.item.id)) toggle(row.item.id);\n else if (next?.parentId === row.item.id) focusRow(next.item.id);\n } else if (event.key === \"ArrowLeft\") {\n event.preventDefault();\n if (expandedIds.has(row.item.id)) toggle(row.item.id);\n else if (row.parentId) focusRow(row.parentId);\n } else if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n if (canContain(row.item)) toggle(row.item.id);\n else select(row.item.id);\n } else if (event.key === \"F2\") {\n event.preventDefault();\n setRenamingId(row.item.id);\n } else if (event.key === \"ContextMenu\" || (event.shiftKey && event.key === \"F10\")) {\n event.preventDefault();\n setMenuOpenId(row.item.id);\n }\n },\n [expandedIds, flat, focusRow, performMove, select, toggle],\n );\n\n return (\n <>\n <div\n role=\"tree\"\n aria-label={ariaLabel}\n aria-multiselectable=\"false\"\n onDragOver={(event) => {\n if (!draggingId || event.target !== event.currentTarget) return;\n event.preventDefault();\n setDropTarget({ id: null, position: \"after\" });\n }}\n onDrop={(event) => {\n event.preventDefault();\n if (draggingId && dropTarget) {\n void performMove({\n itemId: draggingId,\n targetId: dropTarget.id,\n position: dropTarget.position,\n });\n }\n }}\n className={cn(\n \"relative flex min-w-0 flex-col gap-0.5 [overflow-anchor:none] group-data-[state=collapsed]/sidebar:hidden\",\n draggingId && \"select-none pb-9\",\n className,\n )}\n >\n <AnimatePresence initial={false}>\n {flat.map((row) => (\n <ResourceRow\n key={row.item.id}\n row={row}\n active={selectedId === row.item.id}\n expanded={expandedIds.has(row.item.id)}\n focused={focusedId === row.item.id}\n draggingId={draggingId}\n dropTarget={dropTarget}\n menuOpen={menuOpenId === row.item.id}\n renaming={renamingId === row.item.id}\n onFocus={() => setFocusedId(row.item.id)}\n onSelect={() => select(row.item.id)}\n onToggle={() => toggle(row.item.id)}\n onKeyDown={(event) => handleKeyDown(event, row)}\n onRenameStart={() => setRenamingId(row.item.id)}\n onRenameCancel={() => setRenamingId(null)}\n onRenameCommit={(label) => {\n const trimmed = label.trim();\n setRenamingId(null);\n if (!trimmed || trimmed === row.item.label) return;\n const before = renderedItems;\n updateItems(renameResource(before, row.item.id, trimmed));\n void Promise.resolve(onRename?.(row.item, trimmed)).catch(() => {\n updateItems(before);\n setAnnouncement(`Rename failed. ${row.item.label} was restored.`);\n });\n }}\n onMenuOpenChange={(open) => {\n setMenuOpenId(open ? row.item.id : null);\n if (!open) focusRow(row.item.id);\n }}\n onDragStart={(event, id) => {\n setDraggingId(id);\n event.dataTransfer.effectAllowed = \"move\";\n event.dataTransfer.setData(\"text/plain\", id);\n }}\n onDragEnd={() => {\n setDraggingId(null);\n setDropTarget(null);\n }}\n onDragOver={(event, targetRow) => {\n if (!draggingId || draggingId === targetRow.item.id) return;\n const source = findResource(renderedItems, draggingId);\n if (source && containsResource(source, targetRow.item.id)) return;\n event.preventDefault();\n event.stopPropagation();\n const rect = event.currentTarget.getBoundingClientRect();\n const ratio = (event.clientY - rect.top) / rect.height;\n const position =\n !targetRow.item.disabled &&\n canContain(targetRow.item) &&\n ratio >= 0.25 &&\n ratio <= 0.75\n ? \"inside\"\n : ratio < 0.5\n ? \"before\"\n : \"after\";\n setDropTarget({ id: targetRow.item.id, position });\n }}\n onDrop={(event) => {\n event.preventDefault();\n event.stopPropagation();\n if (draggingId && dropTarget) {\n void performMove({\n itemId: draggingId,\n targetId: dropTarget.id,\n position: dropTarget.position,\n });\n }\n }}\n renderIcon={renderIcon}\n renderMenu={renderMenu}\n setRef={(node) => {\n if (node) rowRefs.current.set(row.item.id, node);\n else rowRefs.current.delete(row.item.id);\n }}\n />\n ))}\n </AnimatePresence>\n\n {draggingId ? (\n <div\n aria-hidden=\"true\"\n data-active={dropTarget?.id === null || undefined}\n className=\"absolute inset-x-1 bottom-0 flex h-8 items-center justify-center rounded-lg border border-border border-dashed text-[10px] text-muted-foreground data-[active=true]:border-primary/50 data-[active=true]:bg-primary/10 data-[active=true]:text-foreground\"\n >\n Move to top level\n </div>\n ) : null}\n </div>\n <span className=\"sr-only\" aria-live=\"polite\">\n {announcement}\n </span>\n </>\n );\n}\n"],"mappings":";;;;;;;;;AAuEA,MAAM,aAAa;CACjB,UAAU;CACV,MAAM;AACR;AAEA,SAAS,WAAW,MAAuB;CACzC,OAAO,KAAK,SAAS,YAAY,KAAK,SAAS;AACjD;AAEA,SAAS,iBACP,OACA,UACA,QAAQ,GACR,WAA0B,MACV;CAChB,OAAO,MAAM,SAAS,SAAS;EAC7B,MAAM,MAAM;GAAE;GAAM;GAAO;EAAS;EACpC,IAAI,CAAC,KAAK,UAAU,UAAU,CAAC,SAAS,IAAI,KAAK,EAAE,GAAG,OAAO,CAAC,GAAG;EACjE,OAAO,CAAC,KAAK,GAAG,iBAAiB,KAAK,UAAU,UAAU,QAAQ,GAAG,KAAK,EAAE,CAAC;CAC/E,CAAC;AACH;AAEA,SAAS,aAAa,OAA0B,IAAyC;CACvF,KA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U;KACjB,MAAM,eAAe;KACrB,MAAM,gBAAgB;KACtB,IAAI,cAAc,YAChB,YAAiB;MACf,QAAQ;MACR,UAAU,WAAW;MACrB,UAAU,WAAW;KACvB,CAAC;IAEL;IACY;IACA;IACZ,SAAS,SAAS;KAChB,IAAI,MAAM,QAAQ,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI;UAC1C,QAAQ,QAAQ,OAAO,IAAI,KAAK,EAAE;IACzC;GACD,GA3EM,IAAI,KAAK,EA2Ef,CACF;EACc,CAAA,GAEhB,aACC,oBAAC,OAAD;GACE,eAAY;GACZ,eAAa,YAAY,OAAO,QAAQ,KAAA;GACxC,WAAU;GACX,UAAA;EAEI,CAAA,IACH,IACD;CACL,CAAA,GAAA,oBAAC,QAAD;EAAM,WAAU;EAAU,aAAU;EACjC,UAAA;CACG,CAAA,CACN,EAAA,CAAA;AAEN"}
|
|
1
|
+
{"version":3,"file":"ai-sidebar.js","names":[],"sources":["../../../src/components/agents/ai-sidebar.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type DragEvent,\n type KeyboardEvent,\n type ReactNode,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport {\n ArrowDown,\n ArrowUp,\n Bookmark,\n FileText,\n Folder,\n FolderInput,\n FolderOpen,\n type LucideIcon,\n MoreHorizontal,\n Pencil,\n Undo2,\n} from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useTouchCapable } from \"../../hooks/use-touch-capable\";\nimport { EASE_OUT, SPRING_LAYOUT } from \"../../lib/ease\";\nimport { MorphPopover, MorphPopoverContent, MorphPopoverTrigger } from \"../motion/popover-morph\";\n\nexport type SidebarResourceKind = \"folder\" | \"project\" | \"file\" | \"bookmark\";\n\nexport interface SidebarResource {\n id: string;\n label: string;\n kind: SidebarResourceKind;\n children?: SidebarResource[];\n disabled?: boolean;\n}\n\nexport type SidebarResourceDropPosition = \"before\" | \"inside\" | \"after\";\n\nexport interface SidebarResourceMove {\n itemId: string;\n targetId: string | null;\n position: SidebarResourceDropPosition;\n}\n\n/**\n * The moves this row can make right now, the same four the keyboard offers on\n * `Alt+Shift+Arrow`. A pointer drag is the fast path for them; a finger has no\n * drag to give, so the row menu carries them too. Absent keys are moves this\n * row cannot make from where it sits.\n */\nexport interface SidebarResourceMoveCommands {\n up?: () => void;\n down?: () => void;\n into?: { label: string; run: () => void };\n out?: () => void;\n}\n\nexport interface SidebarResourceMenuControls {\n close: () => void;\n rename: () => void;\n moves: SidebarResourceMoveCommands;\n}\n\nexport interface AISidebarProps {\n items?: SidebarResource[];\n defaultItems?: SidebarResource[];\n onItemsChange?: (items: SidebarResource[]) => void;\n /** Reject the promise to roll the optimistic move back. */\n onMove?: (move: SidebarResourceMove) => void | Promise<void>;\n onMoveError?: (error: unknown, move: SidebarResourceMove) => void;\n onRename?: (item: SidebarResource, label: string) => void | Promise<void>;\n activeId?: string | null;\n defaultActiveId?: string | null;\n onActiveChange?: (id: string) => void;\n defaultExpandedIds?: string[];\n renderIcon?: (item: SidebarResource) => ReactNode;\n renderMenu?: (item: SidebarResource, controls: SidebarResourceMenuControls) => ReactNode;\n ariaLabel?: string;\n className?: string;\n}\n\ninterface FlatResource {\n item: SidebarResource;\n depth: number;\n parentId: string | null;\n}\n\ninterface DropTarget {\n id: string | null;\n position: SidebarResourceDropPosition;\n}\n\nconst ROW_REVEAL = {\n duration: 0.16,\n ease: EASE_OUT,\n} as const;\n\nfunction canContain(item: SidebarResource) {\n return item.kind === \"folder\" || item.kind === \"project\";\n}\n\nfunction flattenResources(\n items: SidebarResource[],\n expanded: Set<string>,\n depth = 0,\n parentId: string | null = null,\n): FlatResource[] {\n return items.flatMap((item) => {\n const row = { item, depth, parentId };\n if (!item.children?.length || !expanded.has(item.id)) return [row];\n return [row, ...flattenResources(item.children, expanded, depth + 1, item.id)];\n });\n}\n\nfunction findResource(items: SidebarResource[], id: string): SidebarResource | undefined {\n for (const item of items) {\n if (item.id === id) return item;\n const child = item.children ? findResource(item.children, id) : undefined;\n if (child) return child;\n }\n}\n\nfunction containsResource(item: SidebarResource, id: string): boolean {\n return item.id === id || item.children?.some((child) => containsResource(child, id)) === true;\n}\n\nfunction removeResource(\n items: SidebarResource[],\n id: string,\n): { items: SidebarResource[]; removed?: SidebarResource } {\n let removed: SidebarResource | undefined;\n const next: SidebarResource[] = [];\n\n for (const item of items) {\n if (item.id === id) {\n removed = item;\n continue;\n }\n\n if (item.children?.length) {\n const childResult = removeResource(item.children, id);\n if (childResult.removed) {\n removed = childResult.removed;\n next.push({ ...item, children: childResult.items });\n continue;\n }\n }\n\n next.push(item);\n }\n\n return { items: next, removed };\n}\n\nfunction insertResource(\n items: SidebarResource[],\n resource: SidebarResource,\n targetId: string | null,\n position: SidebarResourceDropPosition,\n): SidebarResource[] {\n if (targetId === null) return [...items, resource];\n\n const next: SidebarResource[] = [];\n for (const item of items) {\n if (item.id === targetId) {\n if (position === \"before\") next.push(resource, item);\n else if (position === \"after\") next.push(item, resource);\n else next.push({ ...item, children: [...(item.children ?? []), resource] });\n continue;\n }\n\n if (item.children?.length) {\n next.push({\n ...item,\n children: insertResource(item.children, resource, targetId, position),\n });\n } else {\n next.push(item);\n }\n }\n return next;\n}\n\nfunction moveResource(\n items: SidebarResource[],\n move: SidebarResourceMove,\n): SidebarResource[] | null {\n const source = findResource(items, move.itemId);\n if (!source || source.disabled) return null;\n if (move.targetId && containsResource(source, move.targetId)) return null;\n\n const target = move.targetId ? findResource(items, move.targetId) : undefined;\n if (move.position === \"inside\" && (!target || target.disabled || !canContain(target)))\n return null;\n\n const removed = removeResource(items, move.itemId);\n if (!removed.removed) return null;\n return insertResource(removed.items, removed.removed, move.targetId, move.position);\n}\n\nfunction renameResource(items: SidebarResource[], id: string, label: string): SidebarResource[] {\n return items.map((item) => ({\n ...item,\n label: item.id === id ? label : item.label,\n children: item.children ? renameResource(item.children, id, label) : undefined,\n }));\n}\n\nfunction defaultIcon(item: SidebarResource, expanded: boolean) {\n const Icon =\n item.kind === \"folder\" || item.kind === \"project\"\n ? expanded\n ? FolderOpen\n : Folder\n : item.kind === \"bookmark\"\n ? Bookmark\n : FileText;\n return <Icon className=\"size-4\" />;\n}\n\nfunction MarqueeLabel({ active, children }: { active: boolean; children: string }) {\n const reduce = useReducedMotion() ?? false;\n const viewportRef = useRef<HTMLSpanElement>(null);\n const labelRef = useRef<HTMLSpanElement>(null);\n const [distance, setDistance] = useState(0);\n\n useEffect(() => {\n const measure = () => {\n const viewport = viewportRef.current;\n const label = labelRef.current;\n if (!viewport || !label) return;\n setDistance(label.scrollWidth > viewport.clientWidth ? label.scrollWidth + 24 : 0);\n };\n measure();\n const observer = new ResizeObserver(measure);\n if (viewportRef.current) observer.observe(viewportRef.current);\n if (labelRef.current) observer.observe(labelRef.current);\n return () => observer.disconnect();\n }, []);\n\n const running = active && distance > 0 && !reduce;\n\n return (\n <span ref={viewportRef} className=\"block min-w-0 flex-1 overflow-hidden\">\n <motion.span\n className=\"flex w-max items-center gap-6 whitespace-nowrap\"\n animate={{ x: running ? [0, -distance] : 0 }}\n transition={\n running\n ? {\n duration: Math.max(2.4, distance / 34),\n ease: \"linear\",\n repeat: Number.POSITIVE_INFINITY,\n repeatDelay: 2,\n }\n : ROW_REVEAL\n }\n >\n <span ref={labelRef}>{children}</span>\n {running ? <span aria-hidden=\"true\">{children}</span> : null}\n </motion.span>\n </span>\n );\n}\n\nfunction ResourceMenuAction({\n icon: Icon,\n onSelect,\n children,\n}: {\n icon: LucideIcon;\n onSelect: () => void;\n children: ReactNode;\n}) {\n return (\n <button\n type=\"button\"\n onClick={onSelect}\n className=\"flex h-8 w-full items-center gap-2 rounded-lg px-2.5 text-left text-foreground text-xs outline-none transition-colors hover:bg-muted focus-visible:bg-muted focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <Icon aria-hidden=\"true\" className=\"size-3.5 shrink-0\" />\n <span className=\"min-w-0 truncate\">{children}</span>\n </button>\n );\n}\n\ninterface ResourceRowProps {\n row: FlatResource;\n active: boolean;\n expanded: boolean;\n focused: boolean;\n draggingId: string | null;\n dropTarget: DropTarget | null;\n menuOpen: boolean;\n moves: SidebarResourceMoveCommands;\n renaming: boolean;\n onDragEnd: () => void;\n onDragOver: (event: DragEvent<HTMLDivElement>, row: FlatResource) => void;\n onDragStart: (event: DragEvent<HTMLDivElement>, id: string) => void;\n onDrop: (event: DragEvent<HTMLDivElement>) => void;\n onFocus: () => void;\n onKeyDown: (event: KeyboardEvent<HTMLDivElement>) => void;\n onMenuOpenChange: (open: boolean) => void;\n onRenameCancel: () => void;\n onRenameCommit: (label: string) => void;\n onRenameStart: () => void;\n onSelect: () => void;\n onToggle: () => void;\n renderIcon?: (item: SidebarResource) => ReactNode;\n renderMenu?: AISidebarProps[\"renderMenu\"];\n setRef: (node: HTMLDivElement | null) => void;\n}\n\nfunction ResourceRow({\n row,\n active,\n expanded,\n focused,\n draggingId,\n dropTarget,\n menuOpen,\n moves,\n renaming,\n onDragEnd,\n onDragOver,\n onDragStart,\n onDrop,\n onFocus,\n onKeyDown,\n onMenuOpenChange,\n onRenameCancel,\n onRenameCommit,\n onRenameStart,\n onSelect,\n onToggle,\n renderIcon,\n renderMenu,\n setRef,\n}: ResourceRowProps) {\n const reduce = useReducedMotion() ?? false;\n const canTouch = useTouchCapable();\n const [hovered, setHovered] = useState(false);\n const inputRef = useRef<HTMLInputElement>(null);\n const skipRenameBlurRef = useRef(false);\n const draggedRef = useRef(false);\n const [draft, setDraft] = useState(row.item.label);\n const acceptsChildren = canContain(row.item);\n const isDragging = draggingId === row.item.id;\n const dropPosition = dropTarget?.id === row.item.id ? dropTarget.position : null;\n\n useEffect(() => {\n if (!renaming) return;\n skipRenameBlurRef.current = false;\n setDraft(row.item.label);\n requestAnimationFrame(() => {\n inputRef.current?.focus();\n inputRef.current?.select();\n });\n }, [renaming, row.item.label]);\n\n const runFromMenu = (action: () => void) => () => {\n onMenuOpenChange(false);\n action();\n };\n\n const menu = renderMenu?.(row.item, {\n close: () => onMenuOpenChange(false),\n rename: () => {\n onMenuOpenChange(false);\n onRenameStart();\n },\n moves,\n }) ?? (\n <>\n <ResourceMenuAction icon={Pencil} onSelect={runFromMenu(onRenameStart)}>\n Rename\n </ResourceMenuAction>\n {moves.up || moves.down || moves.into || moves.out ? (\n <div aria-hidden=\"true\" className=\"my-1 h-px bg-border\" />\n ) : null}\n {moves.up ? (\n <ResourceMenuAction icon={ArrowUp} onSelect={runFromMenu(moves.up)}>\n Move up\n </ResourceMenuAction>\n ) : null}\n {moves.down ? (\n <ResourceMenuAction icon={ArrowDown} onSelect={runFromMenu(moves.down)}>\n Move down\n </ResourceMenuAction>\n ) : null}\n {moves.into ? (\n <ResourceMenuAction icon={FolderInput} onSelect={runFromMenu(moves.into.run)}>\n Move into {moves.into.label}\n </ResourceMenuAction>\n ) : null}\n {moves.out ? (\n <ResourceMenuAction icon={Undo2} onSelect={runFromMenu(moves.out)}>\n Move out\n </ResourceMenuAction>\n ) : null}\n </>\n );\n\n return (\n <motion.div\n ref={setRef}\n layout=\"position\"\n transition={reduce ? { duration: 0 } : SPRING_LAYOUT}\n role=\"treeitem\"\n aria-level={row.depth + 1}\n aria-selected={acceptsChildren ? undefined : active}\n aria-expanded={acceptsChildren ? expanded : undefined}\n aria-disabled={row.item.disabled || undefined}\n tabIndex={focused ? 0 : -1}\n draggable={!row.item.disabled && !renaming}\n data-menu-open={menuOpen || undefined}\n data-drop={dropPosition ?? undefined}\n data-dragging={isDragging || undefined}\n onFocus={onFocus}\n onKeyDown={onKeyDown}\n onClick={(event) => {\n if (event.defaultPrevented || draggedRef.current || renaming || row.item.disabled) return;\n if (acceptsChildren) onToggle();\n else onSelect();\n }}\n onDoubleClick={(event) => {\n if (acceptsChildren || row.item.disabled) return;\n event.preventDefault();\n onRenameStart();\n }}\n onMouseEnter={() => setHovered(true)}\n onMouseLeave={() => setHovered(false)}\n onDragStartCapture={(event) => {\n draggedRef.current = true;\n onDragStart(event, row.item.id);\n }}\n onDragEndCapture={() => {\n onDragEnd();\n requestAnimationFrame(() => {\n draggedRef.current = false;\n });\n }}\n onDragOver={(event) => onDragOver(event, row)}\n onDrop={onDrop}\n className={cn(\n \"group/resource relative flex min-h-9 min-w-0 cursor-pointer items-center gap-2.5 rounded-xl pr-3 text-sm outline-none\",\n \"text-muted-foreground transition-colors hover:bg-muted hover:text-foreground\",\n \"focus-visible:bg-muted/70 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset\",\n \"data-[menu-open=true]:bg-muted data-[menu-open=true]:text-foreground\",\n \"data-[dragging=true]:opacity-40\",\n \"data-[drop=inside]:bg-primary/10 data-[drop=inside]:ring-1 data-[drop=inside]:ring-primary/45\",\n \"data-[drop=before]:before:absolute data-[drop=before]:before:-top-0.5 data-[drop=before]:before:right-2 data-[drop=before]:before:left-2 data-[drop=before]:before:h-0.5 data-[drop=before]:before:rounded-full data-[drop=before]:before:bg-primary\",\n \"data-[drop=after]:after:absolute data-[drop=after]:after:right-2 data-[drop=after]:after:-bottom-0.5 data-[drop=after]:after:left-2 data-[drop=after]:after:h-0.5 data-[drop=after]:after:rounded-full data-[drop=after]:after:bg-primary\",\n !acceptsChildren && active && \"bg-muted text-foreground\",\n row.item.disabled && \"cursor-not-allowed opacity-45\",\n )}\n style={{ paddingLeft: `${12 + row.depth * 16}px` }}\n >\n <span aria-hidden=\"true\" className=\"grid size-5 shrink-0 place-items-center\">\n {renderIcon?.(row.item) ?? defaultIcon(row.item, expanded)}\n </span>\n\n {renaming ? (\n <input\n ref={inputRef}\n value={draft}\n aria-label={`Rename ${row.item.label}`}\n onChange={(event) => setDraft(event.target.value)}\n draggable={false}\n onClick={(event) => event.stopPropagation()}\n onDoubleClick={(event) => event.stopPropagation()}\n onBlur={() => {\n if (!skipRenameBlurRef.current) onRenameCommit(draft);\n }}\n onKeyDown={(event) => {\n event.stopPropagation();\n if (event.key === \"Enter\") {\n skipRenameBlurRef.current = true;\n onRenameCommit(draft);\n }\n if (event.key === \"Escape\") {\n skipRenameBlurRef.current = true;\n onRenameCancel();\n }\n }}\n className=\"mx-1 h-7 min-w-0 flex-1 rounded-md border border-border bg-background px-2 text-foreground text-sm outline-none focus-visible:ring-2 focus-visible:ring-ring\"\n />\n ) : (\n <MarqueeLabel active={hovered || menuOpen}>{row.item.label}</MarqueeLabel>\n )}\n\n {!renaming && !row.item.disabled ? (\n <MorphPopover open={menuOpen} onOpenChange={onMenuOpenChange}>\n <MorphPopoverTrigger>\n <button\n type=\"button\"\n draggable={false}\n tabIndex={-1}\n aria-label={`Actions for ${row.item.label}`}\n onClick={(event) => event.stopPropagation()}\n className={cn(\n \"grid size-7 shrink-0 place-items-center rounded-lg outline-none transition-opacity hover:bg-foreground/5 focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring group-hover/resource:opacity-100 group-data-[menu-open=true]/resource:opacity-100\",\n // A finger never hovers, and this menu is the only path to\n // rename and move without a drag — keep it on screen there.\n canTouch ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <MoreHorizontal aria-hidden=\"true\" className=\"size-4\" />\n </button>\n </MorphPopoverTrigger>\n <MorphPopoverContent\n side=\"bottom\"\n align=\"end\"\n sideOffset={8}\n radius={12}\n className=\"w-40 p-1.5\"\n >\n <div data-sidebar-resource-menu={row.item.id}>{menu}</div>\n </MorphPopoverContent>\n </MorphPopover>\n ) : null}\n </motion.div>\n );\n}\n\nexport function AISidebar({\n items,\n defaultItems = [],\n onItemsChange,\n onMove,\n onMoveError,\n onRename,\n activeId,\n defaultActiveId = null,\n onActiveChange,\n defaultExpandedIds = [],\n renderIcon,\n renderMenu,\n ariaLabel = \"Resources\",\n className,\n}: AISidebarProps) {\n const [internalItems, setInternalItems] = useState(items ?? defaultItems);\n const [internalActiveId, setInternalActiveId] = useState(defaultActiveId);\n const [expandedIds, setExpandedIds] = useState(() => new Set(defaultExpandedIds));\n const [focusedId, setFocusedId] = useState<string | null>(activeId ?? defaultActiveId);\n const [draggingId, setDraggingId] = useState<string | null>(null);\n const [dropTarget, setDropTarget] = useState<DropTarget | null>(null);\n const [menuOpenId, setMenuOpenId] = useState<string | null>(null);\n const [renamingId, setRenamingId] = useState<string | null>(null);\n const [announcement, setAnnouncement] = useState(\"\");\n const rowRefs = useRef(new Map<string, HTMLDivElement>());\n const movePendingRef = useRef(false);\n const renderedItems = internalItems;\n const selectedId = activeId ?? internalActiveId;\n\n useEffect(() => {\n if (items) setInternalItems(items);\n }, [items]);\n\n const flat = useMemo(\n () => flattenResources(renderedItems, expandedIds),\n [expandedIds, renderedItems],\n );\n\n useEffect(() => {\n if (focusedId && flat.some((row) => row.item.id === focusedId)) return;\n setFocusedId(flat[0]?.item.id ?? null);\n }, [flat, focusedId]);\n\n useEffect(() => {\n if (!menuOpenId) return;\n const frame = requestAnimationFrame(() => {\n const menus = Array.from(\n document.querySelectorAll<HTMLElement>(\"[data-sidebar-resource-menu]\"),\n );\n menus\n .find((menu) => menu.dataset.sidebarResourceMenu === menuOpenId)\n ?.querySelector<HTMLElement>(\"button, a[href]\")\n ?.focus();\n });\n return () => cancelAnimationFrame(frame);\n }, [menuOpenId]);\n\n const updateItems = useCallback(\n (next: SidebarResource[]) => {\n setInternalItems(next);\n onItemsChange?.(next);\n },\n [onItemsChange],\n );\n\n const performMove = useCallback(\n async (move: SidebarResourceMove) => {\n if (movePendingRef.current) {\n setAnnouncement(\"Wait for the current move to finish.\");\n return;\n }\n const before = renderedItems;\n const next = moveResource(before, move);\n if (!next || next === before) return;\n\n movePendingRef.current = true;\n updateItems(next);\n setDropTarget(null);\n setDraggingId(null);\n const moved = findResource(before, move.itemId);\n const target = move.targetId ? findResource(before, move.targetId) : null;\n setAnnouncement(\n target\n ? `Moved ${moved?.label ?? \"item\"} ${move.position} ${target.label}.`\n : `Moved ${moved?.label ?? \"item\"} to the top level.`,\n );\n\n try {\n await onMove?.(move);\n } catch (error) {\n updateItems(before);\n setAnnouncement(`Move failed. ${moved?.label ?? \"Item\"} was restored.`);\n onMoveError?.(error, move);\n } finally {\n movePendingRef.current = false;\n }\n },\n [onMove, onMoveError, renderedItems, updateItems],\n );\n\n const focusRow = useCallback((id: string) => {\n setFocusedId(id);\n requestAnimationFrame(() => rowRefs.current.get(id)?.focus());\n }, []);\n\n const select = useCallback(\n (id: string) => {\n if (activeId === undefined) setInternalActiveId(id);\n onActiveChange?.(id);\n },\n [activeId, onActiveChange],\n );\n\n const toggle = useCallback((id: string) => {\n setExpandedIds((current) => {\n const next = new Set(current);\n if (next.has(id)) next.delete(id);\n else next.add(id);\n return next;\n });\n }, []);\n\n // The same four moves `Alt+Shift+Arrow` performs, handed to the row menu so\n // they survive on a device with no drag and no modifier keys.\n const moveCommands = useCallback(\n (row: FlatResource): SidebarResourceMoveCommands => {\n if (row.item.disabled) return {};\n const index = flat.findIndex(({ item }) => item.id === row.item.id);\n const previous = flat[index - 1];\n const next = flat[index + 1];\n const parentId = row.parentId;\n const commands: SidebarResourceMoveCommands = {};\n\n if (previous) {\n commands.up = () =>\n void performMove({\n itemId: row.item.id,\n targetId: previous.item.id,\n position: \"before\",\n });\n }\n if (next) {\n commands.down = () =>\n void performMove({\n itemId: row.item.id,\n targetId: next.item.id,\n position: \"after\",\n });\n }\n // Only offer the reparent when it lands somewhere new — the row above a\n // folder's first child is the folder it already lives in.\n if (previous && canContain(previous.item) && previous.item.id !== parentId) {\n commands.into = {\n label: previous.item.label,\n run: () => {\n setExpandedIds((current) => new Set(current).add(previous.item.id));\n void performMove({\n itemId: row.item.id,\n targetId: previous.item.id,\n position: \"inside\",\n });\n },\n };\n }\n if (parentId) {\n commands.out = () =>\n void performMove({\n itemId: row.item.id,\n targetId: parentId,\n position: \"after\",\n });\n }\n\n return commands;\n },\n [flat, performMove],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent<HTMLDivElement>, row: FlatResource) => {\n const index = flat.findIndex(({ item }) => item.id === row.item.id);\n const previous = flat[index - 1];\n const next = flat[index + 1];\n const moveModifier = event.altKey && event.shiftKey;\n\n if (event.key === \"ArrowDown\" && !moveModifier && next) {\n event.preventDefault();\n focusRow(next.item.id);\n return;\n }\n if (event.key === \"ArrowUp\" && !moveModifier && previous) {\n event.preventDefault();\n focusRow(previous.item.id);\n return;\n }\n if (event.key === \"Home\" && flat[0]) {\n event.preventDefault();\n focusRow(flat[0].item.id);\n return;\n }\n if (event.key === \"End\" && flat.at(-1)) {\n event.preventDefault();\n focusRow(flat.at(-1)?.item.id ?? row.item.id);\n return;\n }\n\n if (row.item.disabled) {\n if (event.key === \"ArrowLeft\" && row.parentId) {\n event.preventDefault();\n focusRow(row.parentId);\n } else if (\n moveModifier ||\n [\"ArrowRight\", \"Enter\", \" \", \"F2\", \"ContextMenu\"].includes(event.key) ||\n (event.shiftKey && event.key === \"F10\")\n ) {\n event.preventDefault();\n }\n return;\n }\n\n if (moveModifier && event.key === \"ArrowUp\" && previous) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: previous.item.id, position: \"before\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowDown\" && next) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: next.item.id, position: \"after\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowRight\" && previous && canContain(previous.item)) {\n event.preventDefault();\n setExpandedIds((current) => new Set(current).add(previous.item.id));\n void performMove({ itemId: row.item.id, targetId: previous.item.id, position: \"inside\" });\n return;\n }\n if (moveModifier && event.key === \"ArrowLeft\" && row.parentId) {\n event.preventDefault();\n void performMove({ itemId: row.item.id, targetId: row.parentId, position: \"after\" });\n return;\n }\n\n if (event.key === \"ArrowRight\" && canContain(row.item)) {\n event.preventDefault();\n if (!expandedIds.has(row.item.id)) toggle(row.item.id);\n else if (next?.parentId === row.item.id) focusRow(next.item.id);\n } else if (event.key === \"ArrowLeft\") {\n event.preventDefault();\n if (expandedIds.has(row.item.id)) toggle(row.item.id);\n else if (row.parentId) focusRow(row.parentId);\n } else if (event.key === \"Enter\" || event.key === \" \") {\n event.preventDefault();\n if (canContain(row.item)) toggle(row.item.id);\n else select(row.item.id);\n } else if (event.key === \"F2\") {\n event.preventDefault();\n setRenamingId(row.item.id);\n } else if (event.key === \"ContextMenu\" || (event.shiftKey && event.key === \"F10\")) {\n event.preventDefault();\n setMenuOpenId(row.item.id);\n }\n },\n [expandedIds, flat, focusRow, performMove, select, toggle],\n );\n\n return (\n <>\n <div\n role=\"tree\"\n aria-label={ariaLabel}\n aria-multiselectable=\"false\"\n onDragOver={(event) => {\n if (!draggingId || event.target !== event.currentTarget) return;\n event.preventDefault();\n setDropTarget({ id: null, position: \"after\" });\n }}\n onDrop={(event) => {\n event.preventDefault();\n if (draggingId && dropTarget) {\n void performMove({\n itemId: draggingId,\n targetId: dropTarget.id,\n position: dropTarget.position,\n });\n }\n }}\n className={cn(\n \"relative flex min-w-0 flex-col gap-0.5 [overflow-anchor:none] group-data-[state=collapsed]/sidebar:hidden\",\n draggingId && \"select-none pb-9\",\n className,\n )}\n >\n <AnimatePresence initial={false}>\n {flat.map((row) => (\n <ResourceRow\n key={row.item.id}\n row={row}\n active={selectedId === row.item.id}\n expanded={expandedIds.has(row.item.id)}\n focused={focusedId === row.item.id}\n draggingId={draggingId}\n dropTarget={dropTarget}\n menuOpen={menuOpenId === row.item.id}\n moves={moveCommands(row)}\n renaming={renamingId === row.item.id}\n onFocus={() => setFocusedId(row.item.id)}\n onSelect={() => select(row.item.id)}\n onToggle={() => toggle(row.item.id)}\n onKeyDown={(event) => handleKeyDown(event, row)}\n onRenameStart={() => setRenamingId(row.item.id)}\n onRenameCancel={() => setRenamingId(null)}\n onRenameCommit={(label) => {\n const trimmed = label.trim();\n setRenamingId(null);\n if (!trimmed || trimmed === row.item.label) return;\n const before = renderedItems;\n updateItems(renameResource(before, row.item.id, trimmed));\n void Promise.resolve(onRename?.(row.item, trimmed)).catch(() => {\n updateItems(before);\n setAnnouncement(`Rename failed. ${row.item.label} was restored.`);\n });\n }}\n onMenuOpenChange={(open) => {\n setMenuOpenId(open ? row.item.id : null);\n if (!open) focusRow(row.item.id);\n }}\n onDragStart={(event, id) => {\n setDraggingId(id);\n event.dataTransfer.effectAllowed = \"move\";\n event.dataTransfer.setData(\"text/plain\", id);\n }}\n onDragEnd={() => {\n setDraggingId(null);\n setDropTarget(null);\n }}\n onDragOver={(event, targetRow) => {\n if (!draggingId || draggingId === targetRow.item.id) return;\n const source = findResource(renderedItems, draggingId);\n if (source && containsResource(source, targetRow.item.id)) return;\n event.preventDefault();\n event.stopPropagation();\n const rect = event.currentTarget.getBoundingClientRect();\n const ratio = (event.clientY - rect.top) / rect.height;\n const position =\n !targetRow.item.disabled &&\n canContain(targetRow.item) &&\n ratio >= 0.25 &&\n ratio <= 0.75\n ? \"inside\"\n : ratio < 0.5\n ? \"before\"\n : \"after\";\n setDropTarget({ id: targetRow.item.id, position });\n }}\n onDrop={(event) => {\n event.preventDefault();\n event.stopPropagation();\n if (draggingId && dropTarget) {\n void performMove({\n itemId: draggingId,\n targetId: dropTarget.id,\n position: dropTarget.position,\n });\n }\n }}\n renderIcon={renderIcon}\n renderMenu={renderMenu}\n setRef={(node) => {\n if (node) rowRefs.current.set(row.item.id, node);\n else rowRefs.current.delete(row.item.id);\n }}\n />\n ))}\n </AnimatePresence>\n\n {draggingId ? (\n <div\n aria-hidden=\"true\"\n data-active={dropTarget?.id === null || undefined}\n className=\"absolute inset-x-1 bottom-0 flex h-8 items-center justify-center rounded-lg border border-border border-dashed text-[10px] text-muted-foreground data-[active=true]:border-primary/50 data-[active=true]:bg-primary/10 data-[active=true]:text-foreground\"\n >\n Move to top level\n </div>\n ) : null}\n </div>\n <span className=\"sr-only\" aria-live=\"polite\">\n {announcement}\n </span>\n </>\n );\n}\n"],"mappings":";;;;;;;;;;AAkGA,MAAM,aAAa;CACjB,UAAU;CACV,MAAM;AACR;AAEA,SAAS,WAAW,MAAuB;CACzC,OAAO,KAAK,SAAS,YAAY,KAAK,SAAS;AACjD;AAEA,SAAS,iBACP,OACA,UACA,QAAQ,GACR,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AAI,KAAK,EA4Ef,CACF;EACc,CAAA,GAEhB,aACC,oBAAC,OAAD;GACE,eAAY;GACZ,eAAa,YAAY,OAAO,QAAQ,KAAA;GACxC,WAAU;GACX,UAAA;EAEI,CAAA,IACH,IACD;CACL,CAAA,GAAA,oBAAC,QAAD;EAAM,WAAU;EAAU,aAAU;EACjC,UAAA;CACG,CAAA,CACN,EAAA,CAAA;AAEN"}
|
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ComponentProps } from "react";
|
|
1
|
+
import { AnimatedSidebarProviderProps } from "../motion/animated-sidebar.js";
|
|
3
2
|
//#region src/components/agents/chat-app.d.ts
|
|
4
|
-
|
|
3
|
+
interface ChatAppProps extends AnimatedSidebarProviderProps {
|
|
4
|
+
/** Docked sidebar width as a CSS length. Default `17rem`. */
|
|
5
5
|
sidebarWidth?: string;
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Shell width in px under which the sidebar folds off-canvas. Ignored while
|
|
8
|
+
* `open` is controlled — the consumer owns the state then.
|
|
9
|
+
*/
|
|
10
|
+
collapseSidebarBelow?: number;
|
|
11
|
+
}
|
|
12
|
+
declare function ChatApp({ children, className, sidebarWidth, collapseSidebarBelow, style, ...props }: ChatAppProps): import("react").JSX.Element;
|
|
8
13
|
//#endregion
|
|
9
14
|
export { ChatApp, ChatAppProps };
|
|
10
15
|
//# sourceMappingURL=chat-app.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-app.d.ts","names":[],"sources":["../../../src/components/agents/chat-app.tsx"],"mappings":"
|
|
1
|
+
{"version":3,"file":"chat-app.d.ts","names":[],"sources":["../../../src/components/agents/chat-app.tsx"],"mappings":";;UAuBiB,qBAAqB;;EAEpC;;;;;EAKA;;iBA0Cc,UACd,UACA,WACA,cACA,sBACA,UACG,SACF,+BAAY,IAAA"}
|
|
@@ -1,17 +1,66 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { AnimatedSidebarProvider } from "../motion/animated-sidebar.js";
|
|
2
|
+
import { AnimatedSidebarProvider, useAnimatedSidebar } from "../motion/animated-sidebar.js";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
3
4
|
import { cn } from "@kumix/utils";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
6
|
//#region src/components/agents/chat-app.tsx
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Shell width below which a docked sidebar leaves too little room for the
|
|
9
|
+
* conversation: the default sidebar is 17rem, so under 600px the conversation
|
|
10
|
+
* pane is left with barely 330px — narrower than a phone.
|
|
11
|
+
*
|
|
12
|
+
* Deliberately not AnimatedSidebar's own 767px mobile query: that one asks
|
|
13
|
+
* whether the *viewport* is a phone (and swaps the sidebar for an off-canvas
|
|
14
|
+
* sheet), this one asks whether the *shell's own box* — which may be a column,
|
|
15
|
+
* a split view or a panel inside a much wider page — still fits both panes.
|
|
16
|
+
*/
|
|
17
|
+
const MIN_DOCKED_WIDTH = 600;
|
|
18
|
+
/**
|
|
19
|
+
* Folds the sidebar away while the shell is too narrow to carry both panes,
|
|
20
|
+
* and brings it back when it isn't. Only crossings are acted on, so a manual
|
|
21
|
+
* toggle at either size stays put until the shell actually changes shape.
|
|
22
|
+
*
|
|
23
|
+
* Mount is not a crossing in the opening direction: a shell that merely has
|
|
24
|
+
* room says nothing about whether the caller wanted the sidebar open, so the
|
|
25
|
+
* first measurement leaves `defaultOpen` alone. Too narrow at mount *is* the
|
|
26
|
+
* fold condition itself, so that half applies immediately.
|
|
27
|
+
*/
|
|
28
|
+
function ShellFit({ minWidth }) {
|
|
29
|
+
const { open, setOpen } = useAnimatedSidebar();
|
|
30
|
+
const markerRef = useRef(null);
|
|
31
|
+
const narrowRef = useRef(null);
|
|
32
|
+
const openRef = useRef(open);
|
|
33
|
+
openRef.current = open;
|
|
34
|
+
useEffect(() => {
|
|
35
|
+
const shell = markerRef.current?.parentElement;
|
|
36
|
+
if (!shell) return;
|
|
37
|
+
const observer = new ResizeObserver(([entry]) => {
|
|
38
|
+
const narrow = entry.contentRect.width < minWidth;
|
|
39
|
+
if (narrowRef.current === narrow) return;
|
|
40
|
+
const first = narrowRef.current === null;
|
|
41
|
+
narrowRef.current = narrow;
|
|
42
|
+
if (first && !narrow) return;
|
|
43
|
+
const wanted = !narrow;
|
|
44
|
+
if (openRef.current === wanted) return;
|
|
45
|
+
setOpen(wanted);
|
|
46
|
+
});
|
|
47
|
+
observer.observe(shell);
|
|
48
|
+
return () => observer.disconnect();
|
|
49
|
+
}, [minWidth, setOpen]);
|
|
50
|
+
return /* @__PURE__ */ jsx("div", {
|
|
51
|
+
ref: markerRef,
|
|
52
|
+
className: "hidden"
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
function ChatApp({ children, className, sidebarWidth = "17rem", collapseSidebarBelow = MIN_DOCKED_WIDTH, style, ...props }) {
|
|
56
|
+
return /* @__PURE__ */ jsxs(AnimatedSidebarProvider, {
|
|
8
57
|
...props,
|
|
9
58
|
style: {
|
|
10
59
|
...style,
|
|
11
60
|
"--sidebar-width": sidebarWidth
|
|
12
61
|
},
|
|
13
62
|
className: cn("min-h-0 w-full overflow-hidden rounded-2xl border border-border bg-background", className),
|
|
14
|
-
children
|
|
63
|
+
children: [props.open === void 0 ? /* @__PURE__ */ jsx(ShellFit, { minWidth: collapseSidebarBelow }) : null, children]
|
|
15
64
|
});
|
|
16
65
|
}
|
|
17
66
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chat-app.js","names":[],"sources":["../../../src/components/agents/chat-app.tsx"],"sourcesContent":["\"use client\";\n\nimport
|
|
1
|
+
{"version":3,"file":"chat-app.js","names":[],"sources":["../../../src/components/agents/chat-app.tsx"],"sourcesContent":["\"use client\";\n\nimport { useEffect, useRef } from \"react\";\n\nimport { cn } from \"@kumix/utils\";\nimport {\n AnimatedSidebarProvider,\n type AnimatedSidebarProviderProps,\n useAnimatedSidebar,\n} from \"../motion/animated-sidebar\";\n\n/**\n * Shell width below which a docked sidebar leaves too little room for the\n * conversation: the default sidebar is 17rem, so under 600px the conversation\n * pane is left with barely 330px — narrower than a phone.\n *\n * Deliberately not AnimatedSidebar's own 767px mobile query: that one asks\n * whether the *viewport* is a phone (and swaps the sidebar for an off-canvas\n * sheet), this one asks whether the *shell's own box* — which may be a column,\n * a split view or a panel inside a much wider page — still fits both panes.\n */\nconst MIN_DOCKED_WIDTH = 600;\n\nexport interface ChatAppProps extends AnimatedSidebarProviderProps {\n /** Docked sidebar width as a CSS length. Default `17rem`. */\n sidebarWidth?: string;\n /**\n * Shell width in px under which the sidebar folds off-canvas. Ignored while\n * `open` is controlled — the consumer owns the state then.\n */\n collapseSidebarBelow?: number;\n}\n\n/**\n * Folds the sidebar away while the shell is too narrow to carry both panes,\n * and brings it back when it isn't. Only crossings are acted on, so a manual\n * toggle at either size stays put until the shell actually changes shape.\n *\n * Mount is not a crossing in the opening direction: a shell that merely has\n * room says nothing about whether the caller wanted the sidebar open, so the\n * first measurement leaves `defaultOpen` alone. Too narrow at mount *is* the\n * fold condition itself, so that half applies immediately.\n */\nfunction ShellFit({ minWidth }: { minWidth: number }) {\n const { open, setOpen } = useAnimatedSidebar();\n const markerRef = useRef<HTMLDivElement>(null);\n const narrowRef = useRef<boolean | null>(null);\n const openRef = useRef(open);\n openRef.current = open;\n\n useEffect(() => {\n const shell = markerRef.current?.parentElement;\n if (!shell) return;\n const observer = new ResizeObserver(([entry]) => {\n const narrow = entry.contentRect.width < minWidth;\n if (narrowRef.current === narrow) return;\n const first = narrowRef.current === null;\n narrowRef.current = narrow;\n if (first && !narrow) return;\n const wanted = !narrow;\n // Already where the shell wants it — saying so again would only be an\n // onOpenChange the caller never asked for.\n if (openRef.current === wanted) return;\n setOpen(wanted);\n });\n observer.observe(shell);\n return () => observer.disconnect();\n }, [minWidth, setOpen]);\n\n return <div ref={markerRef} className=\"hidden\" />;\n}\n\nexport function ChatApp({\n children,\n className,\n sidebarWidth = \"17rem\",\n collapseSidebarBelow = MIN_DOCKED_WIDTH,\n style,\n ...props\n}: ChatAppProps) {\n return (\n <AnimatedSidebarProvider\n {...props}\n style={{ ...style, \"--sidebar-width\": sidebarWidth }}\n className={cn(\n \"min-h-0 w-full overflow-hidden rounded-2xl border border-border bg-background\",\n className,\n )}\n >\n {/* A controlled `open` is the consumer's to change; fitting the shell\n would fire an onOpenChange they never asked for. */}\n {props.open === undefined ? <ShellFit minWidth={collapseSidebarBelow} /> : null}\n {children}\n </AnimatedSidebarProvider>\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAM,mBAAmB;;;;;;;;;;;AAsBzB,SAAS,SAAS,EAAE,YAAkC;CACpD,MAAM,EAAE,MAAM,YAAY,mBAAmB;CAC7C,MAAM,YAAY,OAAuB,IAAI;CAC7C,MAAM,YAAY,OAAuB,IAAI;CAC7C,MAAM,UAAU,OAAO,IAAI;CAC3B,QAAQ,UAAU;CAElB,gBAAgB;EACd,MAAM,QAAQ,UAAU,SAAS;EACjC,IAAI,CAAC,OAAO;EACZ,MAAM,WAAW,IAAI,gBAAgB,CAAC,WAAW;GAC/C,MAAM,SAAS,MAAM,YAAY,QAAQ;GACzC,IAAI,UAAU,YAAY,QAAQ;GAClC,MAAM,QAAQ,UAAU,YAAY;GACpC,UAAU,UAAU;GACpB,IAAI,SAAS,CAAC,QAAQ;GACtB,MAAM,SAAS,CAAC;GAGhB,IAAI,QAAQ,YAAY,QAAQ;GAChC,QAAQ,MAAM;EAChB,CAAC;EACD,SAAS,QAAQ,KAAK;EACtB,aAAa,SAAS,WAAW;CACnC,GAAG,CAAC,UAAU,OAAO,CAAC;CAEtB,OAAO,oBAAC,OAAD;EAAK,KAAK;EAAW,WAAU;CAAU,CAAA;AAClD;AAEA,SAAgB,QAAQ,EACtB,UACA,WACA,eAAe,SACf,uBAAuB,kBACvB,OACA,GAAG,SACY;CACf,OACE,qBAAC,yBAAD;EACE,GAAI;EACJ,OAAO;GAAE,GAAG;GAAO,mBAAmB;EAAa;EACnD,WAAW,GACT,iFACA,SACF;EANF,UAAA,CAUG,MAAM,SAAS,KAAA,IAAY,oBAAC,UAAD,EAAU,UAAU,qBAAuB,CAAA,IAAI,MAC1E,QACsB;;AAE7B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"citations.d.ts","names":[],"sources":["../../../src/components/agents/citations.tsx"],"mappings":";;UAWiB;EACf;EACA,OAAO;EACP,SAAS;EACT;;UAGe;EACf,WAAW;EACX,QAAQ;EACR;EACA;EACA,gBAAgB;EAChB;EACA;;UAGe;EACf;EACA;;EAEA;EACA;;UAGe;EACf,WAAW;EACX;EACA;;UAGe;EACf,WAAW;EACX;EACA;;iBAOc,WAAW,YAAY,OAAO,UAAU,aAAa,gCAAa,IAAA;iBAelE,kBAAkB,KAAK;EAAe;EAAc;oBAAoB,IAAA;
|
|
1
|
+
{"version":3,"file":"citations.d.ts","names":[],"sources":["../../../src/components/agents/citations.tsx"],"mappings":";;UAWiB;EACf;EACA,OAAO;EACP,SAAS;EACT;;UAGe;EACf,WAAW;EACX,QAAQ;EACR;EACA;EACA,gBAAgB;EAChB;EACA;;UAGe;EACf;EACA;;EAEA;EACA;;UAGe;EACf,WAAW;EACX;EACA;;UAGe;EACf,WAAW;EACX;EACA;;iBAOc,WAAW,YAAY,OAAO,UAAU,aAAa,gCAAa,IAAA;iBAelE,kBAAkB,KAAK;EAAe;EAAc;oBAAoB,IAAA;iBAyBxE,gBAAgB,WAAW,OAAW,aAAa,qCAAkB,IAAA;iBA6DrE,eAAe,WAAW,UAAU,aAAa,oCAAiB,IAAA;iBAiClE,YACd,WACA,OACA,MACA,aACA,cACA,UACA,aACC,iCAAc,IAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useFavicon } from "../../hooks/use-favicon.js";
|
|
2
3
|
import { EASE_OUT, SPRING_LAYOUT, SPRING_SWAP } from "../../lib/ease.js";
|
|
3
|
-
import { getFaviconUrl } from "../../lib/favicon.js";
|
|
4
4
|
import { AgentDisclosure } from "./agent-disclosure.js";
|
|
5
5
|
import { useCallback, useId, useState } from "react";
|
|
6
6
|
import { cn } from "@kumix/utils";
|
|
@@ -20,18 +20,17 @@ function Citation({ citationId, index, idPrefix, className }) {
|
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
function CitationFavicon({ url, className }) {
|
|
23
|
-
const favicon =
|
|
24
|
-
const [failedUrl, setFailedUrl] = useState(null);
|
|
23
|
+
const favicon = useFavicon(url);
|
|
25
24
|
return /* @__PURE__ */ jsx("span", {
|
|
26
25
|
"aria-hidden": "true",
|
|
27
26
|
className: cn("grid size-5 shrink-0 place-items-center text-muted-foreground", className),
|
|
28
|
-
children: favicon
|
|
29
|
-
|
|
27
|
+
children: favicon.src ? /* @__PURE__ */ jsx("img", {
|
|
28
|
+
ref: favicon.ref,
|
|
29
|
+
src: favicon.src,
|
|
30
30
|
alt: "",
|
|
31
31
|
width: 16,
|
|
32
32
|
height: 16,
|
|
33
33
|
referrerPolicy: "no-referrer",
|
|
34
|
-
onError: () => setFailedUrl(favicon),
|
|
35
34
|
className: "size-4 rounded-sm object-contain"
|
|
36
35
|
}) : /* @__PURE__ */ jsx(Globe2, { className: "size-3.5" })
|
|
37
36
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"citations.js","names":[],"sources":["../../../src/components/agents/citations.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useId, useState } from \"react\";\nimport { BookOpenText, ChevronDown, ExternalLink, Globe2 } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { EASE_OUT, SPRING_LAYOUT, SPRING_SWAP } from \"../../lib/ease\";\nimport { getFaviconUrl } from \"../../lib/favicon\";\nimport { AgentDisclosure } from \"./agent-disclosure\";\n\nexport interface CitationItem {\n id: string;\n title: ReactNode;\n domain?: ReactNode;\n url?: string;\n}\n\nexport interface CitationsProps {\n citations: CitationItem[];\n title?: ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n idPrefix?: string;\n className?: string;\n}\n\nexport interface CitationProps {\n citationId: string;\n index: number;\n /** Must match the related Citations idPrefix. */\n idPrefix: string;\n className?: string;\n}\n\nexport interface CitationListProps {\n citations: CitationItem[];\n idPrefix?: string;\n className?: string;\n}\n\nexport interface CitationStackProps {\n citations: CitationItem[];\n limit?: number;\n className?: string;\n}\n\nfunction citationTargetId(prefix: string, citationId: string) {\n return `${prefix}-${citationId.replace(/[^a-zA-Z0-9_-]/g, \"-\")}`;\n}\n\nexport function Citation({ citationId, index, idPrefix, className }: CitationProps) {\n return (\n <a\n href={`#${citationTargetId(idPrefix, citationId)}`}\n aria-label={`View citation ${index}`}\n className={cn(\n \"mx-0.5 inline-flex min-w-4 -translate-y-0.5 items-center justify-center rounded-md bg-muted/60 px-1 py-0.5 font-semibold text-[10px] text-muted-foreground leading-none no-underline outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\",\n className,\n )}\n >\n {index}\n </a>\n );\n}\n\nexport function CitationFavicon({ url, className }: { url?: string; className?: string }) {\n const favicon = url ? getFaviconUrl(url) : null;\n const [failedUrl, setFailedUrl] = useState<string | null>(null);\n\n return (\n <span\n aria-hidden=\"true\"\n className={cn(\"grid size-5 shrink-0 place-items-center text-muted-foreground\", className)}\n >\n {favicon && failedUrl !== favicon ? (\n <img\n src={favicon}\n alt=\"\"\n width={16}\n height={16}\n referrerPolicy=\"no-referrer\"\n onError={() => setFailedUrl(favicon)}\n className=\"size-4 rounded-sm object-contain\"\n />\n ) : (\n <Globe2 className=\"size-3.5\" />\n )}\n </span>\n );\n}\n\nexport function CitationStack({ citations, limit = 3, className }: CitationStackProps) {\n return (\n <span aria-hidden=\"true\" className={cn(\"flex -space-x-1.5\", className)}>\n {citations.slice(0, limit).map((citation) => (\n <CitationFavicon\n key={citation.id}\n url={citation.url}\n className=\"size-6 rounded-full bg-background ring-2 ring-background\"\n />\n ))}\n </span>\n );\n}\n\nfunction CitationRow({\n citation,\n index,\n idPrefix,\n}: {\n citation: CitationItem;\n index: number;\n idPrefix: string;\n}) {\n const content = (\n <>\n <CitationFavicon url={citation.url} />\n <span className=\"flex min-w-0 flex-1 flex-wrap items-baseline gap-x-2 gap-y-0.5\">\n <span className=\"truncate font-medium text-foreground/80 text-sm transition-colors group-hover/citation:text-foreground\">\n {citation.title}\n </span>\n {citation.domain ? (\n <span className=\"min-w-0 truncate text-muted-foreground/60 text-xs\">\n {citation.domain}\n </span>\n ) : null}\n </span>\n <span className=\"flex shrink-0 items-center gap-1.5\">\n <span className=\"grid size-5 place-items-center rounded-md bg-foreground/5 font-semibold text-[10px] text-muted-foreground tabular-nums\">\n {index}\n </span>\n {citation.url ? (\n <ExternalLink className=\"size-3.5 text-muted-foreground/40 transition-colors group-hover/citation:text-muted-foreground\" />\n ) : null}\n </span>\n </>\n );\n const className =\n \"group/citation flex items-center gap-2 rounded-md px-1.5 py-1 outline-none focus-visible:ring-2 focus-visible:ring-ring\";\n const id = citationTargetId(idPrefix, citation.id);\n\n return citation.url ? (\n <a id={id} href={citation.url} target=\"_blank\" rel=\"noreferrer noopener\" className={className}>\n {content}\n </a>\n ) : (\n <div id={id} className={className}>\n {content}\n </div>\n );\n}\n\nexport function CitationList({ citations, idPrefix, className }: CitationListProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const resolvedPrefix = idPrefix ?? `citation-list-${baseId.replace(/:/g, \"\")}`;\n\n return (\n <div className={cn(\"grid gap-0.5\", className)}>\n <AnimatePresence mode=\"popLayout\">\n {citations.map((citation, index) => (\n <motion.div\n layout=\"position\"\n key={citation.id}\n initial={reduce ? { opacity: 1 } : { opacity: 0, y: 6 }}\n animate={{ opacity: 1, y: 0 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, y: -3 }}\n transition={\n reduce\n ? { duration: 0 }\n : {\n opacity: { duration: 0.18, ease: EASE_OUT },\n y: SPRING_LAYOUT,\n layout: SPRING_LAYOUT,\n }\n }\n >\n <CitationRow citation={citation} index={index + 1} idPrefix={resolvedPrefix} />\n </motion.div>\n ))}\n </AnimatePresence>\n </div>\n );\n}\n\nexport function Citations({\n citations,\n title = \"Sources\",\n open,\n defaultOpen = false,\n onOpenChange,\n idPrefix,\n className,\n}: CitationsProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const contentId = `${baseId}-content`;\n const resolvedPrefix = idPrefix ?? `citation-${baseId.replace(/:/g, \"\")}`;\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const currentOpen = open ?? internalOpen;\n const setOpen = useCallback(\n (next: boolean) => {\n if (open === undefined) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [onOpenChange, open],\n );\n\n return (\n <div className={cn(\"w-full text-sm\", className)}>\n <button\n type=\"button\"\n aria-expanded={currentOpen}\n aria-controls={contentId}\n onClick={() => setOpen(!currentOpen)}\n className=\"group -ml-1 flex min-h-8 items-center gap-2 rounded-lg px-1 text-left text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <BookOpenText className=\"size-4\" />\n <span className=\"font-medium\">{title}</span>\n <span className=\"rounded-full bg-muted px-1.5 py-0.5 font-semibold text-[10px] tabular-nums\">\n {citations.length}\n </span>\n <motion.span\n aria-hidden=\"true\"\n animate={{ rotate: currentOpen ? 180 : 0 }}\n transition={reduce ? { duration: 0 } : SPRING_SWAP}\n className=\"text-muted-foreground/60\"\n >\n <ChevronDown className=\"size-3.5\" />\n </motion.span>\n </button>\n\n <AgentDisclosure id={contentId} open={currentOpen}>\n <CitationList citations={citations} idPrefix={resolvedPrefix} className=\"mt-1\" />\n </AgentDisclosure>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAgDA,SAAS,iB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EACxB,WACA,QAAQ,WACR,MACA,cAAc,OACd,cACA,UACA,aACiB;CACjB,MAAM,SAAS,iBAAiB,KAAK;CACrC,MAAM,SAAS,MAAM;CACrB,MAAM,YAAY,GAAG,OAAO;CAC5B,MAAM,iBAAiB,YAAY,YAAY,OAAO,QAAQ,MAAM,EAAE;CACtE,MAAM,CAAC,cAAc,mBAAmB,SAAS,WAAW;CAC5D,MAAM,cAAc,QAAQ;CAC5B,MAAM,UAAU,aACb,SAAkB;EACjB,IAAI,SAAS,KAAA,GAAW,gBAAgB,IAAI;EAC5C,eAAe,IAAI;CACrB,GACA,CAAC,cAAc,IAAI,CACrB;CAEA,OACE,qBAAC,OAAD;EAAK,WAAW,GAAG,kBAAkB,SAAS;EAA9C,UAAA,CACE,qBAAC,UAAD;GACE,MAAK;GACL,iBAAe;GACf,iBAAe;GACf,eAAe,QAAQ,CAAC,WAAW;GACnC,WAAU;GALZ,UAAA;IAOE,oBAAC,cAAD,EAAc,WAAU,SAAU,CAAA;IAClC,oBAAC,QAAD;KAAM,WAAU;KAAe,UAAA;IAAY,CAAA;IAC3C,oBAAC,QAAD;KAAM,WAAU;KACb,UAAA,UAAU;IACP,CAAA;IACN,oBAAC,OAAO,MAAR;KACE,eAAY;KACZ,SAAS,EAAE,QAAQ,cAAc,MAAM,EAAE;KACzC,YAAY,SAAS,EAAE,UAAU,EAAE,IAAI;KACvC,WAAU;KAEV,UAAA,oBAAC,aAAD,EAAa,WAAU,WAAY,CAAA;IACxB,CAAA;GACP;EAER,CAAA,GAAA,oBAAC,iBAAD;GAAiB,IAAI;GAAW,MAAM;GACpC,UAAA,oBAAC,cAAD;IAAyB;IAAW,UAAU;IAAgB,WAAU;GAAQ,CAAA;EACjE,CAAA,CACd;;AAET"}
|
|
1
|
+
{"version":3,"file":"citations.js","names":[],"sources":["../../../src/components/agents/citations.tsx"],"sourcesContent":["\"use client\";\n\nimport { type ReactNode, useCallback, useId, useState } from \"react\";\nimport { BookOpenText, ChevronDown, ExternalLink, Globe2 } from \"lucide-react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\n\nimport { cn } from \"@kumix/utils\";\nimport { useFavicon } from \"../../hooks/use-favicon\";\nimport { EASE_OUT, SPRING_LAYOUT, SPRING_SWAP } from \"../../lib/ease\";\nimport { AgentDisclosure } from \"./agent-disclosure\";\n\nexport interface CitationItem {\n id: string;\n title: ReactNode;\n domain?: ReactNode;\n url?: string;\n}\n\nexport interface CitationsProps {\n citations: CitationItem[];\n title?: ReactNode;\n open?: boolean;\n defaultOpen?: boolean;\n onOpenChange?: (open: boolean) => void;\n idPrefix?: string;\n className?: string;\n}\n\nexport interface CitationProps {\n citationId: string;\n index: number;\n /** Must match the related Citations idPrefix. */\n idPrefix: string;\n className?: string;\n}\n\nexport interface CitationListProps {\n citations: CitationItem[];\n idPrefix?: string;\n className?: string;\n}\n\nexport interface CitationStackProps {\n citations: CitationItem[];\n limit?: number;\n className?: string;\n}\n\nfunction citationTargetId(prefix: string, citationId: string) {\n return `${prefix}-${citationId.replace(/[^a-zA-Z0-9_-]/g, \"-\")}`;\n}\n\nexport function Citation({ citationId, index, idPrefix, className }: CitationProps) {\n return (\n <a\n href={`#${citationTargetId(idPrefix, citationId)}`}\n aria-label={`View citation ${index}`}\n className={cn(\n \"mx-0.5 inline-flex min-w-4 -translate-y-0.5 items-center justify-center rounded-md bg-muted/60 px-1 py-0.5 font-semibold text-[10px] text-muted-foreground leading-none no-underline outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\",\n className,\n )}\n >\n {index}\n </a>\n );\n}\n\nexport function CitationFavicon({ url, className }: { url?: string; className?: string }) {\n const favicon = useFavicon(url);\n\n return (\n <span\n aria-hidden=\"true\"\n className={cn(\"grid size-5 shrink-0 place-items-center text-muted-foreground\", className)}\n >\n {favicon.src ? (\n <img\n ref={favicon.ref}\n src={favicon.src}\n alt=\"\"\n width={16}\n height={16}\n referrerPolicy=\"no-referrer\"\n className=\"size-4 rounded-sm object-contain\"\n />\n ) : (\n <Globe2 className=\"size-3.5\" />\n )}\n </span>\n );\n}\n\nexport function CitationStack({ citations, limit = 3, className }: CitationStackProps) {\n return (\n <span aria-hidden=\"true\" className={cn(\"flex -space-x-1.5\", className)}>\n {citations.slice(0, limit).map((citation) => (\n <CitationFavicon\n key={citation.id}\n url={citation.url}\n className=\"size-6 rounded-full bg-background ring-2 ring-background\"\n />\n ))}\n </span>\n );\n}\n\nfunction CitationRow({\n citation,\n index,\n idPrefix,\n}: {\n citation: CitationItem;\n index: number;\n idPrefix: string;\n}) {\n const content = (\n <>\n <CitationFavicon url={citation.url} />\n <span className=\"flex min-w-0 flex-1 flex-wrap items-baseline gap-x-2 gap-y-0.5\">\n <span className=\"truncate font-medium text-foreground/80 text-sm transition-colors group-hover/citation:text-foreground\">\n {citation.title}\n </span>\n {citation.domain ? (\n <span className=\"min-w-0 truncate text-muted-foreground/60 text-xs\">\n {citation.domain}\n </span>\n ) : null}\n </span>\n <span className=\"flex shrink-0 items-center gap-1.5\">\n <span className=\"grid size-5 place-items-center rounded-md bg-foreground/5 font-semibold text-[10px] text-muted-foreground tabular-nums\">\n {index}\n </span>\n {citation.url ? (\n <ExternalLink className=\"size-3.5 text-muted-foreground/40 transition-colors group-hover/citation:text-muted-foreground\" />\n ) : null}\n </span>\n </>\n );\n const className =\n \"group/citation flex items-center gap-2 rounded-md px-1.5 py-1 outline-none focus-visible:ring-2 focus-visible:ring-ring\";\n const id = citationTargetId(idPrefix, citation.id);\n\n return citation.url ? (\n <a id={id} href={citation.url} target=\"_blank\" rel=\"noreferrer noopener\" className={className}>\n {content}\n </a>\n ) : (\n <div id={id} className={className}>\n {content}\n </div>\n );\n}\n\nexport function CitationList({ citations, idPrefix, className }: CitationListProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const resolvedPrefix = idPrefix ?? `citation-list-${baseId.replace(/:/g, \"\")}`;\n\n return (\n <div className={cn(\"grid gap-0.5\", className)}>\n <AnimatePresence mode=\"popLayout\">\n {citations.map((citation, index) => (\n <motion.div\n layout=\"position\"\n key={citation.id}\n initial={reduce ? { opacity: 1 } : { opacity: 0, y: 6 }}\n animate={{ opacity: 1, y: 0 }}\n exit={reduce ? { opacity: 0 } : { opacity: 0, y: -3 }}\n transition={\n reduce\n ? { duration: 0 }\n : {\n opacity: { duration: 0.18, ease: EASE_OUT },\n y: SPRING_LAYOUT,\n layout: SPRING_LAYOUT,\n }\n }\n >\n <CitationRow citation={citation} index={index + 1} idPrefix={resolvedPrefix} />\n </motion.div>\n ))}\n </AnimatePresence>\n </div>\n );\n}\n\nexport function Citations({\n citations,\n title = \"Sources\",\n open,\n defaultOpen = false,\n onOpenChange,\n idPrefix,\n className,\n}: CitationsProps) {\n const reduce = useReducedMotion() ?? false;\n const baseId = useId();\n const contentId = `${baseId}-content`;\n const resolvedPrefix = idPrefix ?? `citation-${baseId.replace(/:/g, \"\")}`;\n const [internalOpen, setInternalOpen] = useState(defaultOpen);\n const currentOpen = open ?? internalOpen;\n const setOpen = useCallback(\n (next: boolean) => {\n if (open === undefined) setInternalOpen(next);\n onOpenChange?.(next);\n },\n [onOpenChange, open],\n );\n\n return (\n <div className={cn(\"w-full text-sm\", className)}>\n <button\n type=\"button\"\n aria-expanded={currentOpen}\n aria-controls={contentId}\n onClick={() => setOpen(!currentOpen)}\n className=\"group -ml-1 flex min-h-8 items-center gap-2 rounded-lg px-1 text-left text-muted-foreground outline-none transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring\"\n >\n <BookOpenText className=\"size-4\" />\n <span className=\"font-medium\">{title}</span>\n <span className=\"rounded-full bg-muted px-1.5 py-0.5 font-semibold text-[10px] tabular-nums\">\n {citations.length}\n </span>\n <motion.span\n aria-hidden=\"true\"\n animate={{ rotate: currentOpen ? 180 : 0 }}\n transition={reduce ? { duration: 0 } : SPRING_SWAP}\n className=\"text-muted-foreground/60\"\n >\n <ChevronDown className=\"size-3.5\" />\n </motion.span>\n </button>\n\n <AgentDisclosure id={contentId} open={currentOpen}>\n <CitationList citations={citations} idPrefix={resolvedPrefix} className=\"mt-1\" />\n </AgentDisclosure>\n </div>\n );\n}\n"],"mappings":";;;;;;;;;;AAgDA,SAAS,iBAAiB,QAAgB,YAAoB;CAC5D,OAAO,GAAG,OAAO,GAAG,WAAW,QAAQ,mBAAmB,GAAG;AAC/D;AAEA,SAAgB,SAAS,EAAE,YAAY,OAAO,UAAU,aAA4B;CAClF,OACE,oBAAC,KAAD;EACE,MAAM,IAAI,iBAAiB,UAAU,UAAU;EAC/C,cAAY,iBAAiB;EAC7B,WAAW,GACT,0RACA,SACF;EAEC,UAAA;CACA,CAAA;AAEP;AAEA,SAAgB,gBAAgB,EAAE,KAAK,aAAmD;CACxF,MAAM,UAAU,WAAW,GAAG;CAE9B,OACE,oBAAC,QAAD;EACE,eAAY;EACZ,WAAW,GAAG,iEAAiE,SAAS;EAEvF,UAAA,QAAQ,MACP,oBAAC,OAAD;GACE,KAAK,QAAQ;GACb,KAAK,QAAQ;GACb,KAAI;GACJ,OAAO;GACP,QAAQ;GACR,gBAAe;GACf,WAAU;EACX,CAAA,IAED,oBAAC,QAAD,EAAQ,WAAU,WAAY,CAAA;CAE5B,CAAA;AAEV;AAEA,SAAgB,cAAc,EAAE,WAAW,QAAQ,GAAG,aAAiC;CACrF,OACE,oBAAC,QAAD;EAAM,eAAY;EAAO,WAAW,GAAG,qBAAqB,SAAS;EAClE,UAAA,UAAU,MAAM,GAAG,KAAK,CAAC,CAAC,KAAK,aAC9B,oBAAC,iBAAD;GAEE,KAAK,SAAS;GACd,WAAU;EACX,GAHM,SAAS,EAGf,CACF;CACG,CAAA;AAEV;AAEA,SAAS,YAAY,EACnB,UACA,OACA,YAKC;CACD,MAAM,UACJ,qBAAA,YAAA,EAAA,UAAA;EACE,oBAAC,iBAAD,EAAiB,KAAK,SAAS,IAAM,CAAA;EACrC,qBAAC,QAAD;GAAM,WAAU;GAAhB,UAAA,CACE,oBAAC,QAAD;IAAM,WAAU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