Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Give a sidebar row one menu, and run it one step smaller (#11608)

Michael Hana11beed72e55
diff --git a/studio/frontend/src/components/app-sidebar.tsx b/studio/frontend/src/components/app-sidebar.tsx
index 2f66a9ac57e..6fd7b9a25fe 100644
--- a/studio/frontend/src/components/app-sidebar.tsx
+++ b/studio/frontend/src/components/app-sidebar.tsx
@@ -25,6 +25,9 @@ import {
ContextMenuItem,
ContextMenuLabel,
ContextMenuSeparator,
+ ContextMenuSub,
+ ContextMenuSubContent,
+ ContextMenuSubTrigger,
ContextMenuTrigger,
} from "@/components/ui/context-menu";
import {
@@ -228,6 +231,7 @@ import {
useMemo,
useRef,
useState,
+ type ComponentType,
type ReactNode,
} from "react";
import { isDownloadCancelled } from "@/lib/native-files";
@@ -355,11 +359,77 @@ type RowSort = {
value: SidebarChatSort;
set: (next: SidebarChatSort) => void;
};
+// The list a chat row is rendered in: its ids, for shift-click ranges and for the order a drag
+// rewrites; the sort a drop switches to Manual; and, where the list is a folder's or Recents',
+// the project a chat dragged in from elsewhere joins.
+type ChatListContext = {
+ scope: string;
+ ids: string[];
+ /** The section the row is drawn in, and its folder when it is a folder's chat. */
+ section: SidebarSection;
+ folderId?: string;
+ /** The last row drawn in the folder's block, for a line landing below it. */
+ blockEnd?: { scope: string; id: string };
+ /** The list a drag reorders, when it is wider than `ids`: Pinned mixes in folders. */
+ orderIds?: string[];
+ sort?: RowSort;
+};
+
+// The list a folder row drags within: Projects for an unpinned folder, Pinned for a pinned one.
+type ProjectOrderContext = {
+ scope: string;
+ orderedIds: string[];
+ section: SidebarSection;
+ /** The folders alone, for shift-click ranges, where the list holds chats too. */
+ selectionIds?: string[];
+ /** The list's sort, where a reorder has to switch it to Manual. */
+ sort?: RowSort;
+};
+
// One row of the Pinned list, which holds folders and chats together.
type PinnedRow =
| { kind: "project"; id: string; project: ProjectRecord }
| { kind: "chat"; id: string; item: SidebarItem };
+// A row's menu is written once and rendered into both the 3-dot dropdown and the right-click
+// menu, which offer the same actions. Typed as the props the rows pass, not as a union of the
+// two component types, which would stop checking every call site.
+interface RowMenuParts {
+ Item: ComponentType<{
+ children?: ReactNode;
+ className?: string;
+ disabled?: boolean;
+ title?: string;
+ variant?: "default" | "destructive";
+ onSelect?: (event: Event) => void;
+ }>;
+ Separator: ComponentType<Record<string, never>>;
+ Sub: ComponentType<{ children?: ReactNode }>;
+ SubTrigger: ComponentType<{ children?: ReactNode }>;
+ SubContent: ComponentType<{
+ children?: ReactNode;
+ className?: string;
+ sideOffset?: number;
+ alignOffset?: number;
+ }>;
+}
+
+const DROPDOWN_ROW_MENU: RowMenuParts = {
+ Item: DropdownMenuItem,
+ Separator: DropdownMenuSeparator,
+ Sub: DropdownMenuSub,
+ SubTrigger: DropdownMenuSubTrigger,
+ SubContent: DropdownMenuSubContent,
+};
+
+const CONTEXT_ROW_MENU: RowMenuParts = {
+ Item: ContextMenuItem,
+ Separator: ContextMenuSeparator,
+ Sub: ContextMenuSub,
+ SubTrigger: ContextMenuSubTrigger,
+ SubContent: ContextMenuSubContent,
+};
+
// The kebab shows itself while its menu is open; the quick-action beside it was hover-only, so
// it slid in over the title. The row reserves room for both, so reveal both.
const REVEAL_WITH_OPEN_MENU_PROJECT_CHAT =
@@ -1973,26 +2043,27 @@ export function AppSidebar() {
function renderMoveRowItems(
item: SidebarDragItem,
orderedIds: string[],
- sort?: RowSort,
+ sort: RowSort | undefined,
+ P: RowMenuParts,
) {
if (!coarsePointer) return null;
const at = orderedIds.indexOf(item.id);
return (
<>
- <DropdownMenuItem
+ <P.Item
disabled={at <= 0}
onSelect={() => reorderRowBy(item, orderedIds, sort, -1)}
>
<ChevronUp strokeWidth={1.75} className="size-icon" />
<span>{t("shell.organize.moveUp")}</span>
- </DropdownMenuItem>
- <DropdownMenuItem
+ </P.Item>
+ <P.Item
disabled={at === -1 || at >= orderedIds.length - 1}
onSelect={() => reorderRowBy(item, orderedIds, sort, 1)}
>
<ChevronDown strokeWidth={1.75} className="size-icon" />
<span>{t("shell.organize.moveDown")}</span>
- </DropdownMenuItem>
+ </P.Item>
</>
);
}
@@ -3084,11 +3155,21 @@ export function AppSidebar() {
);
}
- /** Bulk actions for selected folders, on right-click of any project row. */
- function renderProjectContextMenu() {
- if (projectSelectionCount === 0) return null;
+ /** A folder row's right-click menu. One row gets the same menu its 3-dot opens; a real
+ * selection of several gets the bulk actions, which right-click is the only pointer way to. */
+ function renderProjectContextMenu(
+ project: ProjectRecord,
+ order: ProjectOrderContext,
+ ) {
+ if (projectSelectionCount <= 1) {
+ return (
+ <ContextMenuContent className="unsloth-plus-menu sidebar-row-menu menu-flat-destructive w-52">
+ {renderProjectRowMenuItems(project, order, CONTEXT_ROW_MENU)}
+ </ContextMenuContent>
+ );
+ }
return (
- <ContextMenuContent className="unsloth-plus-menu menu-flat-destructive w-52">
+ <ContextMenuContent className="unsloth-plus-menu sidebar-row-menu menu-flat-destructive w-48">
{projectSelectionCount > 1 && (
<ContextMenuLabel>
{t("shell.selection.countSelected", {
@@ -3118,11 +3199,18 @@ export function AppSidebar() {
);
}
- /** Bulk actions for the current selection, on right-click of any chat row. */
- function renderChatContextMenu() {
- if (selectionCount === 0) return null;
+ /** A chat row's right-click menu, on the same terms as a folder's: the row's own menu for
+ * one row, the bulk actions for a selection of several. */
+ function renderChatContextMenu(item: SidebarItem, list: ChatListContext) {
+ if (selectionCount <= 1) {
+ return (
+ <ContextMenuContent className="unsloth-plus-menu sidebar-row-menu menu-flat-destructive w-52">
+ {renderChatRowMenuItems(item, list, CONTEXT_ROW_MENU)}
+ </ContextMenuContent>
+ );
+ }
return (
- <ContextMenuContent className="unsloth-plus-menu menu-flat-destructive w-52">
+ <ContextMenuContent className="unsloth-plus-menu sidebar-row-menu menu-flat-destructive w-48">
{selectionCount > 1 && (
<ContextMenuLabel>
{t("shell.selection.countSelected", { count: selectionCount })}
@@ -3161,24 +3249,249 @@ export function AppSidebar() {
);
}
+ /** Every action a chat row offers. Rendered into the 3-dot dropdown and, unchanged, into
+ * the row's right-click menu, so the two never drift apart. */
+ function renderChatRowMenuItems(
+ item: SidebarItem,
+ list: ChatListContext,
+ P: RowMenuParts,
+ ) {
+ const threadIds = getSidebarItemThreadIds(item);
+ const isPinned = pinnedIdSet.has(item.id);
+ // A compare row outside a project spans two sandboxes, and there is no
+ // honest single folder to offer for it.
+ const sandboxSessionId =
+ item.type === "single" || item.projectId
+ ? sandboxSessionIdFor(threadIds[0] ?? item.id, item.projectId)
+ : undefined;
+ // A compare row's id is the pair id while runningByThreadId is per pane thread; aggregate.
+ const isGenerating =
+ item.type === "compare"
+ ? (item.threadIds ?? []).some((id) => Boolean(runningByThreadId[id]))
+ : Boolean(runningByThreadId[item.id]);
+ const alreadyUnread = threadIds.some((threadId) =>
+ unreadThreadIds.has(threadId),
+ );
+ return (
+ <>
+ <P.Item
+ onSelect={() => openRenameChat(item, true, list?.scope)}
+ >
+ <HugeiconsIcon icon={Edit03Icon} strokeWidth={1.75} className="size-icon" />
+ <span>Rename</span>
+ </P.Item>
+ <P.Item onSelect={() => togglePinnedChat(item.id)}>
+ <HugeiconsIcon icon={isPinned ? PinOffIcon : PinIcon} strokeWidth={1.75} className="size-icon" />
+ <span>{isPinned ? "Unpin" : "Pin"}</span>
+ </P.Item>
+ {renderMoveRowItems(
+ {
+ kind: "chat",
+ id: item.id,
+ section: list.section,
+ scope: list.scope,
+ projectId: item.projectId ?? null,
+ },
+ list.orderIds ?? list.ids,
+ list.sort,
+ P,
+ )}
+ {/* The dot a finished reply leaves, put back or taken off by hand. */}
+ <P.Item
+ onSelect={() =>
+ alreadyUnread
+ ? clearThreadsUnread(threadIds)
+ : markThreadsUnread(threadIds, rowIdByThreadId)
+ }
+ >
+ <HugeiconsIcon icon={alreadyUnread ? ViewIcon : ViewOffSlashIcon} strokeWidth={1.75} className="size-icon" />
+ <span>
+ {alreadyUnread
+ ? t("shell.selection.markRead")
+ : t("shell.selection.markUnread")}
+ </span>
+ </P.Item>
+ <P.Item
+ disabled={!canForkChatRow(item) || isGenerating || forkInFlight}
+ title="Copy this chat into a new one, from its last message"
+ onSelect={() => void forkChatFromRow(item)}
+ >
+ <GitBranchIcon strokeWidth={1.75} className="size-icon" />
+ <span>Fork</span>
+ </P.Item>
+ {/* Rename through Fork act on the row; the rule sets off what reaches outside it. */}
+ <P.Separator />
+ {sandboxSessionId ? (
+ isTauri ? (
+ <P.Item
+ title="Open the folder this chat's tool calls read and write"
+ onSelect={() => {
+ void (async () => {
+ try {
+ // A chat moved between projects keeps the sandbox it wrote to, so its own
+ // history names the folder, not current membership. A failed read is
+ // reported below rather than caught per pane.
+ const ids =
+ threadIds.length > 0 ? threadIds : [item.id];
+ const distinct = await sandboxSessionIdsHolding(ids);
+ if (distinct.length > 1) {
+ toast.error("This chat wrote to more than one folder.", {
+ description:
+ "It ran tools on both sides of a move, so open the folder from a tool card instead.",
+ });
+ return;
+ }
+ await revealSandbox(distinct[0] ?? sandboxSessionId);
+ } catch (error) {
+ toast.error("Could not open the chat folder.", {
+ description:
+ error instanceof Error
+ ? error.message
+ : String(error),
+ });
+ }
+ })();
+ }}
+ >
+ <HugeiconsIcon icon={FolderOpenIcon} strokeWidth={1.75} className="size-icon" />
+ <span>Open chat folder</span>
+ </P.Item>
+ ) : (
+ <OpenChatFolderUnavailableItem Item={P.Item} />
+ )
+ ) : null}
+ <P.Sub>
+ <P.SubTrigger>
+ <HugeiconsIcon icon={FolderExportIcon} strokeWidth={1.75} className="size-icon" />
+ <span>Project</span>
+ </P.SubTrigger>
+ <P.SubContent
+ sideOffset={0}
+ alignOffset={-4}
+ className="unsloth-plus-menu sidebar-row-menu w-48"
+ >
+ {/* Actions above the rule, destinations below it. */}
+ <P.Item
+ onSelect={() => {
+ setProjectCreateMoveTarget(item);
+ setCreatingProject(true);
+ }}
+ >
+ <HugeiconsIcon icon={FolderAddIcon} strokeWidth={1.75} className="size-icon" />
+ <span>New project</span>
+ </P.Item>
+ <P.Sub>
+ <P.SubTrigger>
+ <HugeiconsIcon icon={FolderAttachmentIcon} strokeWidth={1.75} className="size-icon" />
+ <span>Project sources</span>
+ </P.SubTrigger>
+ <P.SubContent sideOffset={8} alignOffset={-4} className="unsloth-plus-menu sidebar-row-menu w-48">
+ {projects.length === 0 && (
+ <P.Item disabled>No projects yet</P.Item>
+ )}
+ {projects.map((project) => (
+ <P.Item
+ key={project.id}
+ onSelect={async () => {
+ try {
+ await saveChatToProjectSources(item, project.id);
+ } catch {
+ toast.error("Failed to save to project sources.");
+ }
+ }}
+ >
+ <HugeiconsIcon icon={Folder01Icon} strokeWidth={1.75} className="size-icon" />
+ <span className="truncate">{project.name}</span>
+ </P.Item>
+ ))}
+ </P.SubContent>
+ </P.Sub>
+ <P.Separator />
+ <P.Item
+ disabled={!item.projectId}
+ onSelect={() => void moveChatToProject(item, null)}
+ >
+ <span>Recents</span>
+ </P.Item>
+ {projects.map((project) => (
+ <P.Item
+ key={project.id}
+ disabled={item.projectId === project.id}
+ onSelect={() => void moveChatToProject(item, project.id)}
+ >
+ <HugeiconsIcon icon={Folder01Icon} strokeWidth={1.75} className="size-icon" />
+ <span className="truncate">{project.name}</span>
+ </P.Item>
+ ))}
+ </P.SubContent>
+ </P.Sub>
+ <P.Sub>
+ <P.SubTrigger>
+ <HugeiconsIcon icon={Download01Icon} strokeWidth={1.75} className="size-icon" />
+ <span>Export</span>
+ </P.SubTrigger>
+ <P.SubContent sideOffset={8} alignOffset={-4} className="unsloth-plus-menu sidebar-row-menu w-48">
+ {chatExportOptions().map(({ label, format }) => (
+ <P.Item
+ key={label}
+ onSelect={async () => {
+ try {
+ const ids = item.type === "single"
+ ? [item.id]
+ : (await listStoredChatThreads({ pairId: item.id })).map((t) => t.id);
+ for (const id of ids) {
+ await exportConversationByFormat(id, format);
+ }
+ } catch (error) {
+ if (!isDownloadCancelled(error)) {
+ toast.error("Export failed.");
+ }
+ }
+ }}
+ >
+ {label}
+ </P.Item>
+ ))}
+ <P.Separator />
+ {/* Bulk export and import live in Settings -> Data. */}
+ <P.Item
+ onSelect={() =>
+ useSettingsDialogStore.getState().openDialog("data")
+ }
+ >
+ Export all chats…
+ </P.Item>
+ </P.SubContent>
+ </P.Sub>
+ <P.Separator />
+ <P.Item onSelect={() => void handleArchiveThread(item)}>
+ <HugeiconsIcon icon={Archive03Icon} strokeWidth={1.75} className="size-icon" />
+ <span>Archive</span>
+ </P.Item>
+ <P.Item
+ variant="destructive"
+ onSelect={() =>
+ confirmDeleteChats
+ ? openDeleteDialog({ kind: "chat", item })
+ : void deleteChatWithCleanup(item, {
+ deleteFiles: alwaysDeleteChatFiles,
+ })
+ }
+ >
+ <HugeiconsIcon icon={Delete02Icon} strokeWidth={1.75} className="size-icon" />
+ <span>Delete</span>
+ </P.Item>
+ </>
+ );
+ }
+
function renderChatSidebarItem(
item: SidebarItem,
variant: "project" | "recent",
// The list this row is rendered in: its ids, for shift-click ranges and for the order a drag
// rewrites; the sort a drop switches to Manual; and, where the list is a folder's or Recents',
// the project a chat dragged in from elsewhere joins.
- list: {
- scope: string;
- ids: string[];
- /** The section the row is drawn in, and its folder when it is a folder's chat. */
- section: SidebarSection;
- folderId?: string;
- /** The last row drawn in the folder's block, for a line landing below it. */
- blockEnd?: { scope: string; id: string };
- /** The list a drag reorders, when it is wider than `ids`: Pinned mixes in folders. */
- orderIds?: string[];
- sort?: RowSort;
- },
+ list: ChatListContext,
) {
const threadIds = getSidebarItemThreadIds(item);
const isPinned = pinnedIdSet.has(item.id);
@@ -3419,7 +3732,7 @@ export function AppSidebar() {
side="bottom"
align="start"
sideOffset={0}
- className="unsloth-plus-menu menu-flat-destructive w-56"
+ className="unsloth-plus-menu sidebar-row-menu menu-flat-destructive w-52"
trigger={(triggerRef) => (
<button
ref={triggerRef}
@@ -3434,233 +3747,70 @@ export function AppSidebar() {
</button>
)}
>
- <DropdownMenuItem
- onSelect={() => openRenameChat(item, true, list?.scope)}
- >
- <HugeiconsIcon icon={Edit03Icon} strokeWidth={1.75} className="size-icon" />
- <span>Rename</span>
- </DropdownMenuItem>
- <DropdownMenuItem onSelect={() => togglePinnedChat(item.id)}>
- <HugeiconsIcon icon={isPinned ? PinOffIcon : PinIcon} strokeWidth={1.75} className="size-icon" />
- <span>{isPinned ? "Unpin" : "Pin"}</span>
- </DropdownMenuItem>
- {renderMoveRowItems(
- {
- kind: "chat",
- id: item.id,
- section: list.section,
- scope: list.scope,
- projectId: item.projectId ?? null,
- },
- list.orderIds ?? list.ids,
- list.sort,
- )}
- {/* The dot a finished reply leaves, put back or taken off by hand. */}
- <DropdownMenuItem
- onSelect={() =>
- alreadyUnread
- ? clearThreadsUnread(threadIds)
- : markThreadsUnread(threadIds, rowIdByThreadId)
- }
- >
- <HugeiconsIcon icon={alreadyUnread ? ViewIcon : ViewOffSlashIcon} strokeWidth={1.75} className="size-icon" />
- <span>
- {alreadyUnread
- ? t("shell.selection.markRead")
- : t("shell.selection.markUnread")}
- </span>
- </DropdownMenuItem>
- <DropdownMenuItem
- disabled={!canForkChatRow(item) || isGenerating || forkInFlight}
- title="Copy this chat into a new one, from its last message"
- onSelect={() => void forkChatFromRow(item)}
- >
- <GitBranchIcon strokeWidth={1.75} className="size-icon" />
- <span>Fork</span>
- </DropdownMenuItem>
- {/* Rename through Fork act on the row; the rule sets off what reaches outside it. */}
- <DropdownMenuSeparator />
- {sandboxSessionId ? (
- isTauri ? (
- <DropdownMenuItem
- title="Open the folder this chat's tool calls read and write"
- onSelect={() => {
- void (async () => {
- try {
- // A chat moved between projects keeps the sandbox it wrote to, so its own
- // history names the folder, not current membership. A failed read is
- // reported below rather than caught per pane.
- const ids =
- threadIds.length > 0 ? threadIds : [item.id];
- const distinct = await sandboxSessionIdsHolding(ids);
- if (distinct.length > 1) {
- toast.error("This chat wrote to more than one folder.", {
- description:
- "It ran tools on both sides of a move, so open the folder from a tool card instead.",
- });
- return;
- }
- await revealSandbox(distinct[0] ?? sandboxSessionId);
- } catch (error) {
- toast.error("Could not open the chat folder.", {
- description:
- error instanceof Error
- ? error.message
- : String(error),
- });
- }
- })();
- }}
- >
- <HugeiconsIcon icon={FolderOpenIcon} strokeWidth={1.75} className="size-icon" />
- <span>Open chat folder</span>
- </DropdownMenuItem>
- ) : (
- <OpenChatFolderUnavailableItem />
- )
- ) : null}
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>
- <HugeiconsIcon icon={FolderExportIcon} strokeWidth={1.75} className="size-icon" />
- <span>Project</span>
- </DropdownMenuSubTrigger>
- <DropdownMenuSubContent
- sideOffset={0}
- alignOffset={-4}
- className="unsloth-plus-menu w-52"
- >
- {/* Actions above the rule, destinations below it. */}
- <DropdownMenuItem
- onSelect={() => {
- setProjectCreateMoveTarget(item);
- setCreatingProject(true);
- }}
- >
- <HugeiconsIcon icon={FolderAddIcon} strokeWidth={1.75} className="size-icon" />
- <span>New project</span>
- </DropdownMenuItem>
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>
- <HugeiconsIcon icon={FolderAttachmentIcon} strokeWidth={1.75} className="size-icon" />
- <span>Project sources</span>
- </DropdownMenuSubTrigger>
- <DropdownMenuSubContent sideOffset={8} alignOffset={-4} className="unsloth-plus-menu w-52">
- {projects.length === 0 && (
- <DropdownMenuItem disabled>No projects yet</DropdownMenuItem>
- )}
- {projects.map((project) => (
- <DropdownMenuItem
- key={project.id}
- onSelect={async () => {
- try {
- await saveChatToProjectSources(item, project.id);
- } catch {
- toast.error("Failed to save to project sources.");
- }
- }}
- >
- <HugeiconsIcon icon={Folder01Icon} strokeWidth={1.75} className="size-icon" />
- <span className="truncate">{project.name}</span>
- </DropdownMenuItem>
- ))}
- </DropdownMenuSubContent>
- </DropdownMenuSub>
- <DropdownMenuSeparator />
- <DropdownMenuItem
- disabled={!item.projectId}
- onSelect={() => void moveChatToProject(item, null)}
- >
- <span>Recents</span>
- </DropdownMenuItem>
- {projects.map((project) => (
- <DropdownMenuItem
- key={project.id}
- disabled={item.projectId === project.id}
- onSelect={() => void moveChatToProject(item, project.id)}
- >
- <HugeiconsIcon icon={Folder01Icon} strokeWidth={1.75} className="size-icon" />
- <span className="truncate">{project.name}</span>
- </DropdownMenuItem>
- ))}
- </DropdownMenuSubContent>
- </DropdownMenuSub>
- <DropdownMenuSub>
- <DropdownMenuSubTrigger>
- <HugeiconsIcon icon={Download01Icon} strokeWidth={1.75} className="size-icon" />
- <span>Export</span>
- </DropdownMenuSubTrigger>
- <DropdownMenuSubContent sideOffset={8} alignOffset={-4} className="unsloth-plus-menu w-52">
- {chatExportOptions().map(({ label, format }) => (
- <DropdownMenuItem
- key={label}
- onSelect={async () => {
- try {
- const ids = item.type === "single"
- ? [item.id]
- : (await listStoredChatThreads({ pairId: item.id })).map((t) => t.id);
- for (const id of ids) {
- await exportConversationByFormat(id, format);
- }
- } catch (error) {
- if (!isDownloadCancelled(error)) {
- toast.error("Export failed.");
- }
- }
- }}
- >
- {label}
- </DropdownMenuItem>
- ))}
- <DropdownMenuSeparator />
- {/* Bulk export and import live in Settings -> Data. */}
- <DropdownMenuItem
- onSelect={() =>
- useSettingsDialogStore.getState().openDialog("data")
- }
- >
- Export all chats…
- </DropdownMenuItem>
- </DropdownMenuSubContent>
- </DropdownMenuSub>
- <DropdownMenuSeparator />
- <DropdownMenuItem onSelect={() => void handleArchiveThread(item)}>
- <HugeiconsIcon icon={Archive03Icon} strokeWidth={1.75} className="size-icon" />
- <span>Archive</span>
- </DropdownMenuItem>
- <DropdownMenuItem
- variant="destructive"
- onSelect={() =>
- confirmDeleteChats
- ? openDeleteDialog({ kind: "chat", item })
- : void deleteChatWithCleanup(item, {
- deleteFiles: alwaysDeleteChatFiles,
- })
- }
- >
- <HugeiconsIcon icon={Delete02Icon} strokeWidth={1.75} className="size-icon" />
- <span>Delete</span>
- </DropdownMenuItem>
+ {renderChatRowMenuItems(item, list, DROPDOWN_ROW_MENU)}
</NonModalDropdownMenu>
</SidebarMenuItem>
</ContextMenuTrigger>
- {renderChatContextMenu()}
+ {renderChatContextMenu(item, list)}
</ContextMenu>
);
}
/** One folder row and the chats under it. `order` is the list it drags within: Projects for an
* unpinned folder, Pinned for a pinned one, so neither renumbers the other. */
+ /** Every action a folder row offers, for its 3-dot menu and its right-click menu alike. */
+ function renderProjectRowMenuItems(
+ project: ProjectRecord,
+ order: ProjectOrderContext,
+ P: RowMenuParts,
+ ) {
+ const isProjectPinned = pinnedProjectIdSet.has(project.id);
+ return (
+ <>
+ <P.Item onSelect={() => openProject(project.id)}>
+ <HugeiconsIcon icon={Folder01Icon} strokeWidth={1.75} className="size-icon" />
+ <span>Project home</span>
+ </P.Item>
+ {/* No "New chat" here: the row's own pencil does it. */}
+ <P.Item onSelect={() => toggleProjectPin(project.id)}>
+ <HugeiconsIcon icon={isProjectPinned ? PinOffIcon : PinIcon} strokeWidth={1.75} className="size-icon" />
+ <span>{isProjectPinned ? "Unpin" : "Pin"}</span>
+ </P.Item>
+ {/* Name, instructions and folders are one dialog, so Edit rather than Rename. */}
+ <P.Item onSelect={() => setEditingProject(project)}>
+ <HugeiconsIcon icon={Edit03Icon} strokeWidth={1.75} className="size-icon" />
+ <span>Edit</span>
+ </P.Item>
+ {renderMoveRowItems(
+ {
+ kind: "project",
+ id: project.id,
+ section: order.section,
+ scope: order.scope,
+ projectId: null,
+ },
+ order.orderedIds,
+ order.sort,
+ P,
+ )}
+ <P.Separator />
+ <P.Item
+ variant="destructive"
+ onSelect={() => {
+ // Start each delete with the file toggle off: Cancel closes programmatically and skips the
+ openDeleteDialog({ kind: "project", project });
+ }}
+ >
+ <HugeiconsIcon icon={Delete02Icon} strokeWidth={1.75} className="size-icon" />
+ <span>Delete project</span>
+ </P.Item>
+ </>
+ );
+ }
+
function renderProjectFolderRow(
project: ProjectRecord,
- order: {
- scope: string;
- orderedIds: string[];
- section: SidebarSection;
- /** The folders alone, for shift-click ranges, where the list holds chats too. */
- selectionIds?: string[];
- /** The list's sort, where a reorder has to switch it to Manual. */
- sort?: RowSort;
- },
+ order: ProjectOrderContext,
) {
const projectChats =
sortedChatsByProjectId.get(project.id) ?? [];
@@ -3778,7 +3928,7 @@ export function AppSidebar() {
side="bottom"
align="start"
sideOffset={0}
- className="unsloth-plus-menu menu-flat-destructive w-56"
+ className="unsloth-plus-menu sidebar-row-menu menu-flat-destructive w-52"
trigger={(triggerRef) => (
<button
ref={triggerRef}
@@ -3793,46 +3943,11 @@ export function AppSidebar() {
</button>
)}
>
- <DropdownMenuItem onSelect={() => openProject(project.id)}>
- <HugeiconsIcon icon={Folder01Icon} strokeWidth={1.75} className="size-icon" />
- <span>Project home</span>
- </DropdownMenuItem>
- {/* No "New chat" here: the row's own pencil does it. */}
- <DropdownMenuItem onSelect={() => toggleProjectPin(project.id)}>
- <HugeiconsIcon icon={isProjectPinned ? PinOffIcon : PinIcon} strokeWidth={1.75} className="size-icon" />
- <span>{isProjectPinned ? "Unpin" : "Pin"}</span>
- </DropdownMenuItem>
- {/* Name, instructions and folders are one dialog, so Edit rather than Rename. */}
- <DropdownMenuItem onSelect={() => setEditingProject(project)}>
- <HugeiconsIcon icon={Edit03Icon} strokeWidth={1.75} className="size-icon" />
- <span>Edit</span>
- </DropdownMenuItem>
- {renderMoveRowItems(
- {
- kind: "project",
- id: project.id,
- section: order.section,
- scope: order.scope,
- projectId: null,
- },
- order.orderedIds,
- order.sort,
- )}
- <DropdownMenuSeparator />
- <DropdownMenuItem
- variant="destructive"
- onSelect={() => {
- // Start each delete with the file toggle off: Cancel closes programmatically and skips the
- openDeleteDialog({ kind: "project", project });
- }}
- >
- <HugeiconsIcon icon={Delete02Icon} strokeWidth={1.75} className="size-icon" />
- <span>Delete project</span>
- </DropdownMenuItem>
+ {renderProjectRowMenuItems(project, order, DROPDOWN_ROW_MENU)}
</NonModalDropdownMenu>
</SidebarMenuItem>
</ContextMenuTrigger>
- {renderProjectContextMenu()}
+ {renderProjectContextMenu(project, order)}
</ContextMenu>
{expanded &&
visibleChats.map((chat) =>
diff --git a/studio/frontend/src/components/ui/context-menu.tsx b/studio/frontend/src/components/ui/context-menu.tsx
index 6f494b0fd40..444486ed417 100644
--- a/studio/frontend/src/components/ui/context-menu.tsx
+++ b/studio/frontend/src/components/ui/context-menu.tsx
@@ -140,14 +140,19 @@ function ContextMenuSubContent({
...props
}: React.ComponentProps<typeof ContextMenuPrimitive.SubContent>) {
return (
- <ContextMenuPrimitive.SubContent
- data-slot="context-menu-sub-content"
- className={cn(
- "data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 bg-popover text-popover-foreground min-w-32 rounded-md border p-1 shadow-lg duration-100 z-50 origin-(--radix-context-menu-content-transform-origin) overflow-hidden",
- className,
- )}
- {...props}
- />
+ // Portaled like DropdownMenuSubContent, for the same reason: rendered inline, the fixed
+ // popper wrapper sits inside ContextMenuContent, whose open animation transforms it. That
+ // makes it the containing block and its overflow clips the submenu away.
+ <ContextMenuPrimitive.Portal>
+ <ContextMenuPrimitive.SubContent
+ data-slot="context-menu-sub-content"
+ className={cn(
+ "data-open:animate-in data-closed:animate-out data-closed:fade-out-0 data-open:fade-in-0 data-closed:zoom-out-95 data-open:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 bg-popover text-popover-foreground min-w-32 rounded-md border p-1 shadow-lg duration-100 z-50 origin-(--radix-context-menu-content-transform-origin) overflow-hidden",
+ className,
+ )}
+ {...props}
+ />
+ </ContextMenuPrimitive.Portal>
);
}
diff --git a/studio/frontend/src/features/chat/components/open-chat-folder-item.tsx b/studio/frontend/src/features/chat/components/open-chat-folder-item.tsx
index 59415c2e962..f007eb61649 100644
--- a/studio/frontend/src/features/chat/components/open-chat-folder-item.tsx
+++ b/studio/frontend/src/features/chat/components/open-chat-folder-item.tsx
@@ -9,7 +9,7 @@ import {
} from "@/components/ui/tooltip";
import { FolderOpenIcon } from "@hugeicons/core-free-icons";
import { HugeiconsIcon } from "@hugeicons/react";
-import { useState } from "react";
+import { useState, type ComponentProps, type ComponentType } from "react";
/**
* "Open chat folder" for a browser session, where the backend's file manager is not the user's.
@@ -19,11 +19,16 @@ import { useState } from "react";
* tooltip opens on hover, which a screen reader never reaches and a touch device does not have, so
* `title` describes the row and selecting it opens the hint rather than doing nothing.
*/
-export function OpenChatFolderUnavailableItem() {
+export function OpenChatFolderUnavailableItem({
+ // The sidebar renders this row into its right-click menu too, which is a different Radix set.
+ Item = DropdownMenuItem,
+}: {
+ Item?: ComponentType<ComponentProps<typeof DropdownMenuItem>>;
+} = {}) {
const [hintOpen, setHintOpen] = useState(false);
return (
- <DropdownMenuItem
+ <Item
aria-disabled={true}
title="Only the desktop app can open a chat's files folder. In a browser, download a file from the tool result that wrote it."
className="relative opacity-50"
@@ -52,6 +57,6 @@ export function OpenChatFolderUnavailableItem() {
file from the tool result that wrote it.
</TooltipContent>
</Tooltip>
- </DropdownMenuItem>
+ </Item>
);
}
diff --git a/studio/frontend/src/index.css b/studio/frontend/src/index.css
index c8e84401e7d..9f687e3788b 100644
--- a/studio/frontend/src/index.css
+++ b/studio/frontend/src/index.css
@@ -2596,7 +2596,9 @@ html[data-chat-font] .aui-root {
/* Compact items; also applied to portaled sub-content. */
.unsloth-plus-menu :is(
[data-slot="dropdown-menu-item"],
- [data-slot="dropdown-menu-sub-trigger"]
+ [data-slot="dropdown-menu-sub-trigger"],
+ [data-slot="context-menu-item"],
+ [data-slot="context-menu-sub-trigger"]
) {
@apply gap-3 pl-3 pr-3 py-2 text-ui-14;
cursor: pointer;
@@ -2605,20 +2607,55 @@ html[data-chat-font] .aui-root {
border-radius: 12px;
}
- .unsloth-plus-menu [data-slot="dropdown-menu-label"] {
+ .unsloth-plus-menu :is(
+ [data-slot="dropdown-menu-label"],
+ [data-slot="context-menu-label"]
+ ) {
@apply pl-3 pr-3 py-1.5 text-ui-12;
}
+ /* A sidebar row's menu, one step down from the composer menus this shares a look with.
+ It carries the most rows of any menu in the app and was running tall. */
+ .unsloth-plus-menu.sidebar-row-menu[data-slot] {
+ /* Concentric as above: item radius (10px) + side gutter (8px). */
+ border-radius: 18px !important;
+ padding-top: calc(0.375rem * var(--ui-space-scale, 1));
+ padding-bottom: calc(0.375rem * var(--ui-space-scale, 1));
+ padding-left: calc(8px * var(--ui-space-scale, 1));
+ padding-right: calc(8px * var(--ui-space-scale, 1));
+ /* Retunes every .size-icon inside, sub-menus included. */
+ --icon-size: var(--ui-icon-size-sm);
+ }
+
+ .unsloth-plus-menu.sidebar-row-menu :is(
+ [data-slot="dropdown-menu-item"],
+ [data-slot="dropdown-menu-sub-trigger"],
+ [data-slot="context-menu-item"],
+ [data-slot="context-menu-sub-trigger"]
+ ) {
+ @apply gap-2.5 pl-2.5 pr-2.5 py-1.5 text-ui-13;
+ border-radius: 10px;
+ }
+
+ .unsloth-plus-menu.sidebar-row-menu :is(
+ [data-slot="dropdown-menu-label"],
+ [data-slot="context-menu-label"]
+ ) {
+ @apply pl-2.5 pr-2.5 py-1 text-ui-11;
+ }
+
/* Active (green) items keep their primary text and icon color on hover. */
- .unsloth-plus-menu [data-slot="dropdown-menu-item"].text-primary:is(:hover, :focus, :focus-visible, [data-highlighted]),
- .unsloth-plus-menu [data-slot="dropdown-menu-item"].text-primary:is(:hover, :focus, :focus-visible, [data-highlighted]) svg {
+ .unsloth-plus-menu :is([data-slot="dropdown-menu-item"], [data-slot="context-menu-item"]).text-primary:is(:hover, :focus, :focus-visible, [data-highlighted]),
+ .unsloth-plus-menu :is([data-slot="dropdown-menu-item"], [data-slot="context-menu-item"]).text-primary:is(:hover, :focus, :focus-visible, [data-highlighted]) svg {
color: var(--primary) !important;
}
/* Light hover: neutral grey, not the green accent. */
.unsloth-plus-menu :is(
[data-slot="dropdown-menu-item"],
- [data-slot="dropdown-menu-sub-trigger"]
+ [data-slot="dropdown-menu-sub-trigger"],
+ [data-slot="context-menu-item"],
+ [data-slot="context-menu-sub-trigger"]
):is(:hover, :focus, :focus-visible, [data-highlighted], [data-state="open"]) {
background-color: rgb(0 0 0 / calc(0.06 * var(--contrast-wash-gain, 1))) !important;
}
@@ -2626,7 +2663,9 @@ html[data-chat-font] .aui-root {
/* Dark hover: the accent nearly matches the surface, so use a clear overlay. */
.dark .unsloth-plus-menu :is(
[data-slot="dropdown-menu-item"],
- [data-slot="dropdown-menu-sub-trigger"]
+ [data-slot="dropdown-menu-sub-trigger"],
+ [data-slot="context-menu-item"],
+ [data-slot="context-menu-sub-trigger"]
):is(:hover, :focus, :focus-visible, [data-highlighted], [data-state="open"]) {
background-color: rgb(255 255 255 / calc(0.1 * var(--contrast-wash-gain, 1))) !important;
}
@@ -2636,30 +2675,49 @@ html[data-chat-font] .aui-root {
foreground. The active green rule above still wins via higher specificity. */
.unsloth-plus-menu :is(
[data-slot="dropdown-menu-item"],
- [data-slot="dropdown-menu-sub-trigger"]
+ [data-slot="dropdown-menu-sub-trigger"],
+ [data-slot="context-menu-item"],
+ [data-slot="context-menu-sub-trigger"]
):is(:hover, :focus, :focus-visible, [data-highlighted], [data-state="open"]),
.unsloth-plus-menu :is(
[data-slot="dropdown-menu-item"],
- [data-slot="dropdown-menu-sub-trigger"]
+ [data-slot="dropdown-menu-sub-trigger"],
+ [data-slot="context-menu-item"],
+ [data-slot="context-menu-sub-trigger"]
):is(:hover, :focus, :focus-visible, [data-highlighted], [data-state="open"]) * {
color: inherit !important;
}
.unsloth-plus-menu :is(
[data-slot="dropdown-menu-item"],
- [data-slot="dropdown-menu-sub-trigger"]
+ [data-slot="dropdown-menu-sub-trigger"],
+ [data-slot="context-menu-item"],
+ [data-slot="context-menu-sub-trigger"]
)
svg:not(.unsloth-tick) {
width: var(--ui-icon-size) !important;
height: var(--ui-icon-size) !important;
}
+ /* The rule above pins svg size with !important, straight off --ui-icon-size, so a glyph
+ never sees the --icon-size the row menu retunes. Same rule, one class deeper. */
+ .unsloth-plus-menu.sidebar-row-menu :is(
+ [data-slot="dropdown-menu-item"],
+ [data-slot="dropdown-menu-sub-trigger"],
+ [data-slot="context-menu-item"],
+ [data-slot="context-menu-sub-trigger"]
+ )
+ svg:not(.unsloth-tick) {
+ width: var(--icon-size) !important;
+ height: var(--icon-size) !important;
+ }
+
/* Destructive items keep red text and a red-tinted hover, not the grey one. */
- .unsloth-plus-menu [data-slot="dropdown-menu-item"][data-variant="destructive"],
- .unsloth-plus-menu [data-slot="dropdown-menu-item"][data-variant="destructive"] * {
+ .unsloth-plus-menu :is([data-slot="dropdown-menu-item"], [data-slot="context-menu-item"])[data-variant="destructive"],
+ .unsloth-plus-menu :is([data-slot="dropdown-menu-item"], [data-slot="context-menu-item"])[data-variant="destructive"] * {
color: var(--destructive) !important;
}
- .unsloth-plus-menu [data-slot="dropdown-menu-item"][data-variant="destructive"]:is(:hover, :focus, :focus-visible, [data-highlighted]) {
+ .unsloth-plus-menu :is([data-slot="dropdown-menu-item"], [data-slot="context-menu-item"])[data-variant="destructive"]:is(:hover, :focus, :focus-visible, [data-highlighted]) {
background-color: color-mix(in oklab, var(--destructive) 10%, transparent) !important;
}
diff --git a/studio/frontend/tests/sidebar-row-actions.test.ts b/studio/frontend/tests/sidebar-row-actions.test.ts
index bb284f8226d..53338a6dfbf 100644
--- a/studio/frontend/tests/sidebar-row-actions.test.ts
+++ b/studio/frontend/tests/sidebar-row-actions.test.ts
@@ -242,9 +242,9 @@ test("a chat row forks from its own menu", async () => {
// Below Mark as unread, and before the rule that sets off the rest.
assert.match(
APP_SIDEBAR,
- /t\("shell\.selection\.markUnread"\)\}\n\s*<\/span>\n\s*<\/DropdownMenuItem>\n\s*<DropdownMenuItem\n\s*disabled=\{!canForkChatRow\(item\)/,
+ /t\("shell\.selection\.markUnread"\)\}\n\s*<\/span>\n\s*<\/P\.Item>\n\s*<P\.Item\n\s*disabled=\{!canForkChatRow\(item\)/,
);
- assert.match(APP_SIDEBAR, /<span>Fork<\/span>\n\s*<\/DropdownMenuItem>\n\s*\{\/\*[^]*?\*\/\}\n\s*<DropdownMenuSeparator \/>/);
+ assert.match(APP_SIDEBAR, /<span>Fork<\/span>\n\s*<\/P\.Item>\n\s*\{\/\*[^]*?\*\/\}\n\s*<P\.Separator \/>/);
// A comparison has two threads and no single tip to fork from.
assert.match(ROW_MENU, /export function canForkChatRow[^]*?return item\.type === "single";/);
// The fork carries the settings on screen, not the ones the row was last written with.
diff --git a/studio/frontend/tests/sidebar-row-drag.test.ts b/studio/frontend/tests/sidebar-row-drag.test.ts
index f698cd556d8..193ec404943 100644
--- a/studio/frontend/tests/sidebar-row-drag.test.ts
+++ b/studio/frontend/tests/sidebar-row-drag.test.ts
@@ -936,7 +936,7 @@ test("alt and an arrow reorder a row without a pointer", async () => {
APP_SIDEBAR,
/orderedIds: order\.orderedIds,\n\s*sort: order\.sort,\n\s*\}\)\}/,
);
- assert.match(APP_SIDEBAR, /order\.orderedIds,\n\s*order\.sort,\n\s*\)\}/);
+ assert.match(APP_SIDEBAR, /order\.orderedIds,\n\s*order\.sort,\n\s*P,\n\s*\)\}/);
assert.match(
APP_SIDEBAR,
/selectionIds: pinnedProjectRowIds,\n\s*section: "pinned",\n\s*sort: \{ value: pinnedSort, set: setPinnedSort \},/,
diff --git a/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts b/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts
index 1d4aeb6177c..ada2d2323bd 100644
--- a/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts
+++ b/studio/frontend/tests/sidebar-row-menu-and-pinned-folders.test.ts
@@ -108,7 +108,7 @@ test("the Project submenu puts its actions above the destinations", () => {
assert.ok(sub.length > 0, "the Project submenu moved");
const newProject = sub.indexOf("<span>New project</span>");
const sources = sub.indexOf("<span>Project sources</span>");
- const rule = sub.indexOf("<DropdownMenuSeparator />");
+ const rule = sub.indexOf("<P.Separator />");
const recents = sub.indexOf("<span>Recents</span>");
for (const [name, at] of Object.entries({
newProject,
diff --git a/studio/frontend/tests/sidebar-selection-coverage.test.ts b/studio/frontend/tests/sidebar-selection-coverage.test.ts
index 4a156101067..bb9fb0536a3 100644
--- a/studio/frontend/tests/sidebar-selection-coverage.test.ts
+++ b/studio/frontend/tests/sidebar-selection-coverage.test.ts
@@ -33,7 +33,7 @@ test("folder rows select too, and open their own bulk menu", async () => {
/handleProjectSelectionClick\(\n\s*event,\n\s*project\.id,\n\s*order\.selectionIds \?\? order\.orderedIds,\n\s*\)/,
);
assert.match(source, /selectProjectForContextMenu\(project\.id\)/);
- assert.match(source, /\{renderProjectContextMenu\(\)\}/);
+ assert.match(source, /\{renderProjectContextMenu\(project, order\)\}/);
assert.match(source, /selectedProjectIds\.has\(project\.id\)/);
});
@@ -161,3 +161,135 @@ test("both sidebar expanders read translated labels", async () => {
const uses = source.match(/shell\.navigation\.show(More|Less)/g) ?? [];
assert.equal(uses.length, 4, "both expanders read both keys");
});
+
+
+// One menu per row, whichever way it is opened. Right-click used to render the bulk menu even
+// for a single row, so the same chat offered "Delete chats" on right-click and the whole
+// Rename/Project/Export menu from its 3-dot.
+
+test("a row's right-click menu and its 3-dot menu render the same items", () => {
+ for (const [kind, render] of [
+ ["chat", "renderChatRowMenuItems"],
+ ["project", "renderProjectRowMenuItems"],
+ ] as const) {
+ const calls = APP_SIDEBAR.match(new RegExp(`${render}\\(`, "g")) ?? [];
+ // Its declaration, the dropdown call and the context-menu call.
+ assert.equal(
+ calls.length,
+ 3,
+ `${kind} rows should build their menu once and render it in both places`,
+ );
+ assert.match(
+ APP_SIDEBAR,
+ new RegExp(`${render}\\([^)]*DROPDOWN_ROW_MENU\\)`),
+ `${kind}: the 3-dot menu should render the shared items`,
+ );
+ assert.match(
+ APP_SIDEBAR,
+ new RegExp(`${render}\\([^)]*CONTEXT_ROW_MENU\\)`),
+ `${kind}: the right-click menu should render the same shared items`,
+ );
+ }
+});
+
+test("the bulk menu is reached only by a selection of more than one", () => {
+ for (const [name, count] of [
+ ["renderChatContextMenu", "selectionCount"],
+ ["renderProjectContextMenu", "projectSelectionCount"],
+ ] as const) {
+ const body = bodyOf(APP_SIDEBAR, name);
+ // One row takes the row's own menu and returns before the bulk content below.
+ assert.match(
+ body,
+ new RegExp(`if \\(${count} <= 1\\) \\{`),
+ `${name} should send a single row to the row menu`,
+ );
+ const guard = body.indexOf(`${count} <= 1`);
+ const bulk = body.indexOf("shell.selection.");
+ assert.ok(guard >= 0 && bulk > guard, `${name}: the guard should precede the bulk items`);
+ }
+});
+
+test("the shared menu items are written against the injected family", () => {
+ // Nothing inside either row menu may name a family directly, or the two would drift again.
+ for (const name of ["renderChatRowMenuItems", "renderProjectRowMenuItems"]) {
+ const body = bodyOf(APP_SIDEBAR, name);
+ assert.doesNotMatch(
+ body,
+ /<DropdownMenu|<ContextMenu/,
+ `${name} should use P.Item and friends, not one family's components`,
+ );
+ assert.match(body, /<P\.Item/);
+ }
+ // The two helpers these bodies call take the family too, rather than hardcoding the dropdown.
+ assert.match(APP_SIDEBAR, /function renderMoveRowItems\([^)]*P: RowMenuParts,\n\s*\)/s);
+ assert.match(APP_SIDEBAR, /<OpenChatFolderUnavailableItem Item=\{P\.Item\} \/>/);
+});
+
+
+// The row menu is the longest in the app, so it runs one step below the composer menus it
+// shares a look with. Scoped to .sidebar-row-menu: .unsloth-plus-menu alone dresses a dozen
+// other surfaces that must not move.
+
+test("every row-menu surface takes the compact class", () => {
+ const surfaces = APP_SIDEBAR.match(/className="unsloth-plus-menu[^"]*"/g) ?? [];
+ const rowMenus = surfaces.filter((c) => c.includes("menu-flat-destructive"));
+ assert.ok(rowMenus.length >= 6, "expected both 3-dot menus and both right-click menus");
+ for (const cls of rowMenus) {
+ assert.match(cls, /sidebar-row-menu/, `a row menu surface missed the class: ${cls}`);
+ }
+ // Sub-content is portaled out of the menu, so it carries the class itself.
+ for (const sub of APP_SIDEBAR.match(/<P\.SubContent[^>]*className="[^"]*"/g) ?? []) {
+ assert.match(sub, /sidebar-row-menu/, `a submenu missed the class: ${sub}`);
+ }
+});
+
+test("the compact class is scoped, and both menu families get the same rules", () => {
+ const CSS = readSrc("index.css");
+ // Sized only through the modifier, never on .unsloth-plus-menu itself.
+ assert.match(CSS, /\.unsloth-plus-menu\.sidebar-row-menu\[data-slot\] \{/);
+ assert.match(CSS, /--icon-size: var\(--ui-icon-size-sm\);/);
+ // A glyph is an svg, and the base rule pins svg size with !important straight off
+ // --ui-icon-size, so retuning --icon-size alone leaves every icon full size.
+ const svgRules = CSS.split("\n\t.unsloth-plus-menu").filter((r) =>
+ r.includes("svg:not(.unsloth-tick)"),
+ );
+ assert.equal(svgRules.length, 2, "expected a base svg rule and a row-menu override");
+ const scoped = svgRules.find((r) => r.startsWith(".sidebar-row-menu"));
+ assert.ok(scoped, "the row menu needs its own svg size rule");
+ assert.match(scoped, /width: var\(--icon-size\) !important;/);
+ assert.match(scoped, /height: var\(--icon-size\) !important;/);
+ // A right-click menu and a 3-dot menu must dress alike, so every item rule names both slots.
+ const plusRules = CSS.split("\n\t.unsloth-plus-menu").slice(1);
+ for (const rule of plusRules) {
+ const head = rule.slice(0, rule.indexOf("{"));
+ if (!head.includes('dropdown-menu-item')) continue;
+ assert.match(
+ head,
+ /context-menu-item/,
+ `a plus-menu item rule styles only the dropdown family: ${head.trim()}`,
+ );
+ }
+});
+
+
+// Rendered inline, a submenu's fixed popper wrapper sits inside the parent menu, whose open
+// animation transforms it. That makes it the containing block and its overflow clips the
+// submenu away. Both families portal out, so Project and Export survive either menu.
+
+test("both menu families portal their submenus out of the parent", () => {
+ for (const [file, primitive] of [
+ ["components/ui/dropdown-menu.tsx", "DropdownMenuPrimitive"],
+ ["components/ui/context-menu.tsx", "ContextMenuPrimitive"],
+ ] as const) {
+ const source = readSrc(file);
+ const at = source.indexOf(`<${primitive}.SubContent`);
+ assert.ok(at > 0, `${file}: no SubContent element`);
+ const before = source.slice(0, at);
+ assert.match(
+ before.slice(-400),
+ new RegExp(`<${primitive}\\.Portal>`),
+ `${file}: SubContent should be wrapped in a Portal`,
+ );
+ }
+});