A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
Add cross-list drag-drop for sidebar and developer panel (#7697)
Trevor Manzf7bc09fcba95
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsxindex 841fa601b2..6582bfc2c4 100644--- a/frontend/src/components/editor/actions/useNotebookActions.tsx+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx@@ -269,7 +269,7 @@ export function useNotebookActions() {label: "Helper panel",redundant: true,handle: NOOP_HANDLER,- dropdown: PANELS.flatMap(({ id, Icon, hidden }) => {+ dropdown: PANELS.flatMap(({ type: id, Icon, hidden }) => {if (hidden) {return [];}diff --git a/frontend/src/components/editor/chrome/state.ts b/frontend/src/components/editor/chrome/state.tsindex 156d606792..76c28106b8 100644--- a/frontend/src/components/editor/chrome/state.ts+++ b/frontend/src/components/editor/chrome/state.ts@@ -6,16 +6,41 @@ import { z } from "zod";import { createReducerAndAtoms } from "@/utils/createReducer";import { jotaiJsonStorage } from "@/utils/storage/jotai";import { ZodLocalStorage } from "@/utils/storage/typed";-import type { DeveloperPanelTabType, PanelType } from "./types";+import type { PanelType } from "./types";import { PANELS } from "./types";export interface ChromeState {selectedPanel: PanelType | undefined;isSidebarOpen: boolean;isDeveloperPanelOpen: boolean;- selectedDeveloperPanelTab: DeveloperPanelTabType;+ selectedDeveloperPanelTab: PanelType;}+/**+ * Layout configuration for panels in sidebar and developer panel.+ * Each array contains the ordered list of visible panel IDs for that section.+ */+export interface PanelLayout {+ sidebar: PanelType[];+ developerPanel: PanelType[];+}++const DEFAULT_PANEL_LAYOUT: PanelLayout = {+ sidebar: PANELS.filter(+ (p) => !p.hidden && p.defaultSection === "sidebar",+ ).map((p) => p.type),+ developerPanel: PANELS.filter(+ (p) => !p.hidden && p.defaultSection === "developer-panel",+ ).map((p) => p.type),+};++export const panelLayoutAtom = atomWithStorage<PanelLayout>(+ "marimo:panel-layout",+ DEFAULT_PANEL_LAYOUT,+ jotaiJsonStorage,+ { getOnInit: true },+);+const KEY = "marimo:sidebar";const storage = new ZodLocalStorage<ChromeState>(z.object({@@ -29,7 +54,7 @@ const storage = new ZodLocalStorage<ChromeState>(.string().optional().default("terminal")- .transform((v) => v as DeveloperPanelTabType),+ .transform((v) => v as PanelType),}),initialState,);@@ -81,11 +106,11 @@ const {...state,isDeveloperPanelOpen: isOpen,}),- setSelectedDeveloperPanelTab: (state, tab: DeveloperPanelTabType) => ({+ setSelectedDeveloperPanelTab: (state, tab: PanelType) => ({...state,selectedDeveloperPanelTab: tab,}),- openDeveloperPanelTab: (state, tab: DeveloperPanelTabType) => ({+ openDeveloperPanelTab: (state, tab: PanelType) => ({...state,isDeveloperPanelOpen: true,selectedDeveloperPanelTab: tab,@@ -119,13 +144,3 @@ export const exportedForTesting = {createActions,initialState,};--// TODO: probably merge this with the chrome state-export const sidebarOrderAtom = atomWithStorage<PanelType[]>(- "marimo:sidebar-order",- PANELS.filter(- (p) => !p.hidden && !p.defaultHidden && p.position === "sidebar",- ).map((p) => p.id),- jotaiJsonStorage,- { getOnInit: true },-);diff --git a/frontend/src/components/editor/chrome/types.ts b/frontend/src/components/editor/chrome/types.tsindex 86c75024d3..9ff7ba6642 100644--- a/frontend/src/components/editor/chrome/types.ts+++ b/frontend/src/components/editor/chrome/types.ts@@ -21,7 +21,11 @@ import {import { getFeatureFlag } from "@/core/config/feature-flag";import { isWasm } from "@/core/wasm/utils";+/**+ * Unified panel ID for all panels in sidebar and developer panel+ */export type PanelType =+ // Sidebar defaults| "files"| "variables"| "outline"@@ -30,160 +34,146 @@ export type PanelType =| "documentation"| "snippets"| "ai"+ // Developer panel defaults+ | "errors"+ | "scratchpad"+ | "tracing"+ | "secrets"+ | "logs"+ | "terminal"| "cache";+export type PanelSection = "sidebar" | "developer-panel";+export interface PanelDescriptor {- id: PanelType;+ type: PanelType;Icon: LucideIcon;+ /** Short label for developer panel tabs */+ label: string;+ /** Descriptive tooltip for sidebar icons */+ tooltip: string;/** If true, the panel is completely unavailable */hidden?: boolean;- /** If true, the panel is available but not shown by default */- defaultHidden?: boolean;- tooltip: string;- position: "sidebar" | "footer";+ /** Which section this panel belongs to by default */+ defaultSection: PanelSection;}-/* Panels are ordered in roughly decreasing order of importance as well as- * logically grouped.- *- * 1. Must-have panels first.- * 2. Panels that can add cells to the editor.- * 3. Nice-to-have observability panels.+/**+ * All panels in the application.+ * Panels can be in either sidebar or developer panel, configurable by user.*/export const PANELS: PanelDescriptor[] = [- // 1. Must-have panels.- //- // The files panel is at the top to orient- // users within their filesystem and give- // them a quick glance at their project structure,- // without having to leave their editor.+ // Sidebar defaults{- id: "files",+ type: "files",Icon: FolderTreeIcon,+ label: "Files",tooltip: "View files",- position: "sidebar",+ defaultSection: "sidebar",},- // Because notebooks uniquely have data in RAM,- // it's important to give humans visibility into- // what that data is.{- id: "variables",+ type: "variables",Icon: VariableIcon,+ label: "Variables",tooltip: "Explore variables and data sources",- position: "sidebar",+ defaultSection: "sidebar",},- // Every notebook has a package environment that must- // be managed.{- id: "packages",+ type: "packages",Icon: BoxIcon,+ label: "Packages",tooltip: "Manage packages",- position: "sidebar",+ defaultSection: "sidebar",},- // 2. "AI" panel.- //- // The AI panel holds both agents and in-editor chat.{- id: "ai",+ type: "ai",Icon: BotIcon,+ label: "AI",tooltip: "Chat & Agents",- position: "sidebar",+ defaultSection: "sidebar",},{- id: "snippets",+ type: "snippets",Icon: SquareDashedBottomCodeIcon,+ label: "Snippets",tooltip: "Snippets",- position: "sidebar",- defaultHidden: true,+ defaultSection: "developer-panel",},- // 3. Nice-to-have observability panels.- //- // Utility panels that provide observability- // into the state or structure of the notebook. These- // observability panels are less crucial than variables- // or datasets, so they are positioned at the end of the- // sidebar.{- id: "outline",+ type: "outline",Icon: ScrollTextIcon,+ label: "Outline",tooltip: "View outline",- position: "sidebar",+ defaultSection: "sidebar",},{- id: "documentation",+ type: "documentation",Icon: TextSearchIcon,+ label: "Docs",tooltip: "View live docs",- position: "sidebar",+ defaultSection: "sidebar",},{- // TODO(akshayka): Consider making dependencies- // default off; the minimap is a more effective- // overview.- id: "dependencies",+ type: "dependencies",Icon: NetworkIcon,+ label: "Dependencies",tooltip: "Explore dependencies",- position: "sidebar",+ defaultSection: "sidebar",},-];--export const PANEL_MAP = new Map<PanelType, PanelDescriptor>(- PANELS.map((p) => [p.id, p]),-);--export type DeveloperPanelTabType =- | "errors"- | "scratchpad"- | "tracing"- | "secrets"- | "logs"- | "terminal"- | "cache";--export interface DeveloperPanelTabDescriptor {- type: DeveloperPanelTabType;- Icon: LucideIcon;- label: string;- hidden?: boolean;-}--export const DEVELOPER_PANEL_TABS: DeveloperPanelTabDescriptor[] = [+ // Developer panel defaults{type: "errors",Icon: XCircleIcon,label: "Errors",+ tooltip: "View errors",+ defaultSection: "developer-panel",},{type: "scratchpad",Icon: NotebookPenIcon,label: "Scratchpad",+ tooltip: "Scratchpad",+ defaultSection: "developer-panel",},{type: "tracing",Icon: ActivityIcon,label: "Tracing",+ tooltip: "View tracing",+ defaultSection: "developer-panel",},{type: "secrets",Icon: KeyRoundIcon,label: "Secrets",+ tooltip: "Manage secrets",+ defaultSection: "developer-panel",hidden: isWasm(),},{type: "logs",Icon: FileTextIcon,label: "Logs",+ tooltip: "View logs",+ defaultSection: "developer-panel",},{type: "terminal",Icon: TerminalSquareIcon,label: "Terminal",+ tooltip: "Terminal",+ defaultSection: "developer-panel",},- // TODO(akshayka): The cache panel should not be default shown,- // even when it's out of feature flag. (User config to turn it on.){type: "cache",Icon: DatabaseZapIcon,label: "Cache",+ tooltip: "View cache",+ defaultSection: "developer-panel",hidden: !getFeatureFlag("cache_panel"),},];++export const PANEL_MAP = new Map<PanelType, PanelDescriptor>(+ PANELS.map((p) => [p.type, p]),+);diff --git a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsxindex 0c4a07217c..24f951b6f1 100644--- a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx+++ b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx@@ -1,5 +1,10 @@/* Copyright 2026 Marimo. All rights reserved. */-import React, { type PropsWithChildren, Suspense, useEffect } from "react";+import React, {+ type PropsWithChildren,+ Suspense,+ useEffect,+ useMemo,+} from "react";import {type ImperativePanelHandle,Panel,@@ -10,9 +15,10 @@ import { Footer } from "./footer";import { Sidebar } from "./sidebar";import "./app-chrome.css";import { TooltipProvider } from "@radix-ui/react-tooltip";-import { useAtomValue } from "jotai";+import { useAtom, useAtomValue } from "jotai";import { XIcon } from "lucide-react";import { Button } from "@/components/ui/button";+import { ReorderableList } from "@/components/ui/reorderable-list";import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";import { LazyMount } from "@/components/utils/lazy-mount";import { cellErrorCount } from "@/core/cells/cells";@@ -20,8 +26,8 @@ import { getFeatureFlag } from "@/core/config/feature-flag";import { cn } from "@/utils/cn";import { ErrorBoundary } from "../../boundary/ErrorBoundary";import { ContextAwarePanel } from "../panels/context-aware-panel/context-aware-panel";-import { useChromeActions, useChromeState } from "../state";-import { DEVELOPER_PANEL_TABS } from "../types";+import { panelLayoutAtom, useChromeActions, useChromeState } from "../state";+import { PANEL_MAP, PANELS, type PanelDescriptor } from "../types";import { BackendConnectionStatus } from "./footer-items/backend-status";import { Minimap } from "./minimap";import { PanelsWrapper } from "./panels";@@ -67,11 +73,67 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {setIsSidebarOpen,setIsDeveloperPanelOpen,setSelectedDeveloperPanelTab,+ openApplication,} = useChromeActions();const sidebarRef = React.useRef<ImperativePanelHandle>(null);const developerPanelRef = React.useRef<ImperativePanelHandle>(null);const { aiPanelTab, setAiPanelTab } = useAiPanelTab();const errorCount = useAtomValue(cellErrorCount);+ const [panelLayout, setPanelLayout] = useAtom(panelLayoutAtom);++ // Convert current developer panel items to PanelDescriptors+ const devPanelItems = useMemo(() => {+ return panelLayout.developerPanel.flatMap((id) => {+ const panel = PANEL_MAP.get(id);+ return panel ? [panel] : [];+ });+ }, [panelLayout.developerPanel]);++ const handleSetDevPanelItems = (items: PanelDescriptor[]) => {+ setPanelLayout((prev) => ({+ ...prev,+ developerPanel: items.map((item) => item.type),+ }));+ };++ const handleDevPanelReceive = (item: PanelDescriptor, fromListId: string) => {+ // Remove from the source list+ if (fromListId === "sidebar") {+ setPanelLayout((prev) => ({+ ...prev,+ sidebar: prev.sidebar.filter((id) => id !== item.type),+ }));++ // If the moved item was selected in sidebar, select the first remaining item+ if (selectedPanel === item.type) {+ const remainingSidebar = panelLayout.sidebar.filter(+ (id) => id !== item.type,+ );+ if (remainingSidebar.length > 0) {+ openApplication(remainingSidebar[0]);+ }+ }+ }++ // Select the dropped item in developer panel+ setSelectedDeveloperPanelTab(item.type);+ };++ // Get panels available for developer panel context menu+ // Only show panels that are NOT in the sidebar+ const availableDevPanels = useMemo(() => {+ const sidebarIds = new Set(panelLayout.sidebar);+ return PANELS.filter((p) => {+ if (p.hidden) {+ return false;+ }+ // Exclude panels that are in the sidebar+ if (sidebarIds.has(p.type)) {+ return false;+ }+ return true;+ });+ }, [panelLayout.sidebar]);// sync sidebaruseEffect(() => {@@ -211,6 +273,18 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {{selectedPanel === "documentation" && <LazyDocumentationPanel />}{selectedPanel === "snippets" && <LazySnippetsPanel />}{selectedPanel === "ai" && renderAiPanel()}+ {selectedPanel === "errors" && <LazyErrorsPanel />}+ {selectedPanel === "scratchpad" && <LazyScratchpadPanel />}+ {selectedPanel === "tracing" && <LazyTracingPanel />}+ {selectedPanel === "secrets" && <LazySecretsPanel />}+ {selectedPanel === "logs" && <LazyLogsPanel />}+ {selectedPanel === "terminal" && (+ <LazyTerminal+ visible={isSidebarOpen}+ onClose={() => setIsSidebarOpen(false)}+ />+ )}+ {selectedPanel === "cache" && <LazyCachePanel />}</TooltipProvider></Suspense></div>@@ -281,36 +355,47 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {<div className="flex flex-col h-full">{/* Panel header with tabs */}<div className="flex items-center justify-between border-b px-2 h-8 bg-background shrink-0">- <Tabs- value={selectedDeveloperPanelTab}- onValueChange={(v) =>- setSelectedDeveloperPanelTab(- v as typeof selectedDeveloperPanelTab,- )- }- >- <TabsList className="bg-transparent p-0 gap-1">- {DEVELOPER_PANEL_TABS.filter((tab) => !tab.hidden).map((tab) => (- <TabsTrigger- key={tab.type}- value={tab.type}- className="text-sm gap-2 px-2 pt-1 pb-0.5 items-center leading-none data-[state=active]:bg-muted"- >- {/* Color the Errors icon red when there are errors,- so users see it when they open the developer panel */}- <tab.Icon- className={cn(- "w-4 h-4",- tab.type === "errors" &&- errorCount > 0 &&- "text-destructive",- )}- />- {tab.label}- </TabsTrigger>- ))}- </TabsList>- </Tabs>+ <ReorderableList<PanelDescriptor>+ value={devPanelItems}+ setValue={handleSetDevPanelItems}+ getKey={(p) => p.type}+ availableItems={availableDevPanels}+ crossListDrag={{+ dragType: "panels",+ listId: "developer-panel",+ onReceive: handleDevPanelReceive,+ }}+ getItemLabel={(panel) => (+ <span className="flex items-center gap-2">+ <panel.Icon className="w-4 h-4 text-muted-foreground" />+ {panel.label}+ </span>+ )}+ ariaLabel="Developer panel tabs"+ className="flex flex-row gap-1"+ minItems={0}+ onAction={(panel) => setSelectedDeveloperPanelTab(panel.type)}+ renderItem={(panel) => (+ <div+ className={cn(+ "text-sm flex gap-2 px-2 pt-1 pb-0.5 items-center leading-none rounded-sm cursor-pointer",+ selectedDeveloperPanelTab === panel.type+ ? "bg-muted"+ : "hover:bg-muted/50",+ )}+ >+ <panel.Icon+ className={cn(+ "w-4 h-4",+ panel.type === "errors" &&+ errorCount > 0 &&+ "text-destructive",+ )}+ />+ {panel.label}+ </div>+ )}+ /><div className="border-l border-border h-4 mx-1" /><BackendConnectionStatus /><div className="flex-1" />@@ -323,60 +408,39 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {</Button></div>{/* Panel content */}- <div className="flex-1 overflow-hidden">- {selectedDeveloperPanelTab === "errors" && (- <LazyMount isOpen={isDeveloperPanelOpen}>- <Suspense fallback={<div />}>- <LazyErrorsPanel />- </Suspense>- </LazyMount>- )}- {selectedDeveloperPanelTab === "scratchpad" && (- <LazyMount isOpen={isDeveloperPanelOpen}>- <Suspense fallback={<div />}>- <LazyScratchpadPanel />- </Suspense>- </LazyMount>- )}- {selectedDeveloperPanelTab === "tracing" && (- <LazyMount isOpen={isDeveloperPanelOpen}>- <Suspense fallback={<div />}>- <LazyTracingPanel />- </Suspense>- </LazyMount>- )}- {selectedDeveloperPanelTab === "secrets" && (- <LazyMount isOpen={isDeveloperPanelOpen}>- <Suspense fallback={<div />}>- <LazySecretsPanel />- </Suspense>- </LazyMount>- )}- {selectedDeveloperPanelTab === "logs" && (- <LazyMount isOpen={isDeveloperPanelOpen}>- <Suspense fallback={<div />}>- <LazyLogsPanel />- </Suspense>- </LazyMount>- )}- {selectedDeveloperPanelTab === "terminal" && (- <LazyMount isOpen={isDeveloperPanelOpen}>- <Suspense fallback={<div />}>+ <Suspense fallback={<div />}>+ <div className="flex-1 overflow-hidden">+ {selectedDeveloperPanelTab === "files" && <LazyFileExplorerPanel />}+ {selectedDeveloperPanelTab === "variables" && <LazySessionPanel />}+ {selectedDeveloperPanelTab === "dependencies" && (+ <LazyDependencyGraphPanel />+ )}+ {selectedDeveloperPanelTab === "packages" && <LazyPackagesPanel />}+ {selectedDeveloperPanelTab === "outline" && <LazyOutlinePanel />}+ {selectedDeveloperPanelTab === "documentation" && (+ <LazyDocumentationPanel />+ )}+ {selectedDeveloperPanelTab === "snippets" && <LazySnippetsPanel />}+ {selectedDeveloperPanelTab === "ai" && renderAiPanel()}+ {selectedDeveloperPanelTab === "errors" && <LazyErrorsPanel />}+ {selectedDeveloperPanelTab === "scratchpad" && (+ <LazyScratchpadPanel />+ )}+ {selectedDeveloperPanelTab === "tracing" && <LazyTracingPanel />}+ {selectedDeveloperPanelTab === "secrets" && <LazySecretsPanel />}+ {selectedDeveloperPanelTab === "logs" && <LazyLogsPanel />}+ {/* LazyMount needed for Terminal to avoid spurious connection */}+ {selectedDeveloperPanelTab === "terminal" && (+ <LazyMount isOpen={isDeveloperPanelOpen}><LazyTerminalvisible={isDeveloperPanelOpen}onClose={() => setIsDeveloperPanelOpen(false)}/>- </Suspense>- </LazyMount>- )}- {selectedDeveloperPanelTab === "cache" && (- <LazyMount isOpen={isDeveloperPanelOpen}>- <Suspense fallback={<div />}>- <LazyCachePanel />- </Suspense>- </LazyMount>- )}- </div>+ </LazyMount>+ )}+ {selectedDeveloperPanelTab === "cache" && <LazyCachePanel />}+ </div>+ </Suspense></div></Panel>);diff --git a/frontend/src/components/editor/chrome/wrapper/sidebar.tsx b/frontend/src/components/editor/chrome/wrapper/sidebar.tsxindex ddd01e6a53..dbbae98eca 100644--- a/frontend/src/components/editor/chrome/wrapper/sidebar.tsx+++ b/frontend/src/components/editor/chrome/wrapper/sidebar.tsx@@ -8,72 +8,105 @@ import { useMemo } from "react";import { ReorderableList } from "@/components/ui/reorderable-list";import { Tooltip } from "@/components/ui/tooltip";import { notebookQueuedOrRunningCountAtom } from "@/core/cells/cells";-import { snippetsEnabledAtom } from "@/core/config/config";import { cn } from "@/utils/cn";import { FeedbackButton } from "../components/feedback-button";-import { sidebarOrderAtom, useChromeActions, useChromeState } from "../state";+import { panelLayoutAtom, useChromeActions, useChromeState } from "../state";import { PANEL_MAP, PANELS, type PanelDescriptor } from "../types";export const Sidebar: React.FC = () => {- const { selectedPanel } = useChromeState();- const { toggleApplication } = useChromeActions();- const [sidebarOrder, setSidebarOrder] = useAtom(sidebarOrderAtom);- const snippetsEnabled = useAtomValue(snippetsEnabledAtom);+ const { selectedPanel, selectedDeveloperPanelTab } = useChromeState();+ const { toggleApplication, setSelectedDeveloperPanelTab } =+ useChromeActions();+ const [panelLayout, setPanelLayout] = useAtom(panelLayoutAtom);const renderIcon = ({ Icon }: PanelDescriptor, className?: string) => {return <Icon className={cn("h-5 w-5", className)} />;};- // Get all available sidebar panels- // Panels with defaultHidden are only available if explicitly enabled (e.g., snippets)- const availableSidebarPanels = useMemo(- () =>- PANELS.filter((p) => {- if (p.hidden || p.position !== "sidebar") {- return false;- }- // Show defaultHidden panels only if enabled via config- if (p.defaultHidden && p.id === "snippets" && !snippetsEnabled) {- return false;- }- return true;- }),- [snippetsEnabled],- );+ // Get panels available for sidebar context menu+ // Only show panels that are NOT in the developer panel+ const availableSidebarPanels = useMemo(() => {+ const devPanelIds = new Set(panelLayout.developerPanel);+ return PANELS.filter((p) => {+ if (p.hidden) {+ return false;+ }+ // Exclude panels that are in the developer panel+ if (devPanelIds.has(p.type)) {+ return false;+ }+ return true;+ });+ }, [panelLayout.developerPanel]);++ // Convert current sidebar items to PanelDescriptors+ const sidebarItems = useMemo(() => {+ return panelLayout.sidebar.flatMap((id) => {+ const panel = PANEL_MAP.get(id);+ return panel ? [panel] : [];+ });+ }, [panelLayout.sidebar]);++ const handleSetSidebarItems = (items: PanelDescriptor[]) => {+ setPanelLayout((prev) => ({+ ...prev,+ sidebar: items.map((item) => item.type),+ }));+ };++ const handleReceive = (item: PanelDescriptor, fromListId: string) => {+ // Remove from the source list+ if (fromListId === "developer-panel") {+ setPanelLayout((prev) => ({+ ...prev,+ developerPanel: prev.developerPanel.filter((id) => id !== item.type),+ }));- const currentItems = sidebarOrder- .map((id) => PANEL_MAP.get(id))- .filter(Boolean);+ // If the moved item was selected in dev panel, select the first remaining item+ if (selectedDeveloperPanelTab === item.type) {+ const remainingDevPanels = panelLayout.developerPanel.filter(+ (id) => id !== item.type,+ );+ if (remainingDevPanels.length > 0) {+ setSelectedDeveloperPanelTab(remainingDevPanels[0]);+ }+ }+ }- const handleSetValue = (panels: PanelDescriptor[]) => {- setSidebarOrder(panels.map((p) => p.id));+ // Select the dropped item in sidebar+ toggleApplication(item.type);};return (<div className="h-full pt-4 pb-1 px-1 flex flex-col items-start text-muted-foreground text-md select-none no-print text-sm z-50 dark:bg-background print:hidden hide-on-fullscreen"><ReorderableList<PanelDescriptor>- value={currentItems}- setValue={handleSetValue}+ value={sidebarItems}+ setValue={handleSetSidebarItems}+ getKey={(p) => p.type}availableItems={availableSidebarPanels}+ crossListDrag={{+ dragType: "panels",+ listId: "sidebar",+ onReceive: handleReceive,+ }}getItemLabel={(panel) => (- <span className="flex items-center gap-2 [">+ <span className="flex items-center gap-2">{renderIcon(panel, "h-4 w-4 text-muted-foreground")}- {panel.tooltip}+ {panel.label}</span>)}- ariaLabel="Reorderable sidebar panels"+ ariaLabel="Sidebar panels"className="flex flex-col gap-0"- onAction={(panel) => toggleApplication(panel.id)}- renderItem={(panel) => {- return (- <SidebarItem- tooltip={panel.tooltip}- selected={selectedPanel === panel.id}- >- {renderIcon(panel)}- </SidebarItem>- );- }}+ minItems={0}+ onAction={(panel) => toggleApplication(panel.type)}+ renderItem={(panel) => (+ <SidebarItem+ tooltip={panel.tooltip}+ selected={selectedPanel === panel.type}+ >+ {renderIcon(panel)}+ </SidebarItem>+ )}/><FeedbackButton><SidebarItem tooltip="Send feedback!" selected={false}>diff --git a/frontend/src/components/ui/reorderable-list.tsx b/frontend/src/components/ui/reorderable-list.tsxindex 10c6606e1c..f30822db14 100644--- a/frontend/src/components/ui/reorderable-list.tsx+++ b/frontend/src/components/ui/reorderable-list.tsx@@ -2,7 +2,12 @@import type React from "react";import { useMemo } from "react";-import { ListBox, ListBoxItem, useDragAndDrop } from "react-aria-components";+import {+ type DropItem,+ ListBox,+ ListBoxItem,+ useDragAndDrop,+} from "react-aria-components";import { Logger } from "@/utils/Logger";import {ContextMenu,@@ -12,15 +17,37 @@ import {} from "./context-menu";import "./reorderable-list.css";-export interface ReorderableListProps<T extends { id: string | number }> {+interface DragData<T> {+ itemId: string;+ sourceListId: string;+ item: T;+}++function getDragMimeType(dragType: string): string {+ return `application/x-reorderable-${dragType}`;+}++function parseDragData<T>(text: string): DragData<T> | null {+ try {+ return JSON.parse(text) as DragData<T>;+ } catch {+ return null;+ }+}++export interface ReorderableListProps<T> {/**- * The current list of items+ * The current list of items.*/value: T[];/*** Callback when items are reordered*/setValue: (items: T[]) => void;+ /**+ * Function to get a unique key for each item. Used for drag-drop and rendering.+ */+ getKey: (item: T) => string;/*** Render function for each item.* Note: Avoid interactive elements (buttons) inside - they break drag behavior.@@ -50,49 +77,148 @@ export interface ReorderableListProps<T extends { id: string | number }> {* Additional class name for the list container*/className?: string;+ /**+ * Configuration for cross-list drag-drop. When set, items can be dragged+ * between lists that share the same `dragType`.+ */+ crossListDrag?: {+ /** Identifier that links lists together - same dragType = can share items */+ dragType: string;+ /** Unique identifier for this list */+ listId: string;+ /**+ * Callback when an item is received from another list.+ * At this point, setValue has been called with the new item included,+ * but the parent component may not have re-rendered yet.+ * Use this to remove the item from the source list and handle any side effects.+ */+ onReceive: (item: T, fromListId: string, insertIndex: number) => void;+ };}/**- * A generic reorderable list component using react-aria-components and react-stately.- * Items can be reordered via drag and drop.+ * A generic reorderable list component using react-aria-components.+ * Items can be reordered via drag and drop within the list.+ *+ * For cross-list drag-drop, set the same `dragType` on multiple lists+ * and provide an `onReceive` callback to handle items dropped from other lists.** @example* ```tsx- * interface MyItem {- * id: string;- * name: string;- * }- *- * const [items, setItems] = useState<MyItem[]>([...]);- *+ * // Single list reordering* <ReorderableList* value={items}* setValue={setItems}+ * getKey={(item) => item.id}* renderItem={(item) => <div>{item.name}</div>}- * ariaLabel="My reorderable list"+ * />+ *+ * // Cross-list drag-drop+ * <ReorderableList+ * value={sidebarItems}+ * setValue={setSidebarItems}+ * getKey={(item) => item.type}+ * renderItem={(item) => <div>{item.name}</div>}+ * crossListDrag={{+ * dragType: "panels",+ * listId: "sidebar",+ * onReceive: (item, fromListId) => {+ * // Remove from source list+ * setOtherItems(prev => prev.filter(i => i.type !== item.type));+ * },+ * }}* />* ```*/-export const ReorderableList = <T extends { id: string | number }>({+export const ReorderableList = <T extends object>({value,setValue,+ getKey,renderItem,onAction,availableItems,- getItemLabel = (item) => String(item.id),+ getItemLabel,minItems = 1,ariaLabel = "Reorderable list",className,+ crossListDrag,}: ReorderableListProps<T>) => {+ const mimeType = crossListDrag+ ? getDragMimeType(crossListDrag.dragType)+ : null;+ const onReceive = crossListDrag?.onReceive;++ // Shared handler for cross-list drops+ const handleCrossListDrop = async (+ items: DropItem[],+ insertIndex: number,+ ) => {+ if (!mimeType || !crossListDrag?.listId || !onReceive) {+ return;+ }++ for (const dragItem of items) {+ if (dragItem.kind !== "text" || !dragItem.types.has(mimeType)) {+ continue;+ }++ const text = await dragItem.getText(mimeType);+ const data = parseDragData<T>(text);+ if (!data) {+ continue;+ }++ // Only accept drops from different lists+ if (data.sourceListId === crossListDrag.listId) {+ continue;+ }++ // Skip if item already exists in this list+ if (value.some((item) => getKey(item) === getKey(data.item))) {+ continue;+ }++ // Add to this list and notify parent+ setValue([+ ...value.slice(0, insertIndex),+ data.item,+ ...value.slice(insertIndex),+ ]);+ onReceive(data.item, data.sourceListId, insertIndex);+ }+ };+const { dragAndDropHooks } = useDragAndDrop<T>({- getItems: (keys) => [...keys].map((key) => ({ "text/plain": String(key) })),+ getItems: (keys) =>+ [...keys].map((key) => {+ const item = value.find((i) => getKey(i) === key);+ const baseData: Record<string, string> = {+ "text/plain": String(key),+ };++ // Add cross-list drag data if dragType is set+ if (mimeType && crossListDrag?.listId && item) {+ const dragData: DragData<T> = {+ itemId: String(key),+ sourceListId: crossListDrag.listId,+ item,+ };+ baseData[mimeType] = JSON.stringify(dragData);+ }++ return baseData;+ }),++ // Accept drops from lists with the same dragType+ acceptedDragTypes: mimeType ? [mimeType, "text/plain"] : ["text/plain"],+onReorder(e) {const keySet = new Set(e.keys);- const draggedItems = value.filter((item) => keySet.has(item.id));- const remaining = value.filter((item) => !keySet.has(item.id));+ const draggedItems = value.filter((item) => keySet.has(getKey(item)));+ const remaining = value.filter((item) => !keySet.has(getKey(item)));const targetIndex = remaining.findIndex(- (item) => item.id === e.target.key,+ (item) => getKey(item) === e.target.key,);const insertIndex =e.target.dropPosition === "before" ? targetIndex : targetIndex + 1;@@ -103,19 +229,34 @@ export const ReorderableList = <T extends { id: string | number }>({...remaining.slice(insertIndex),]);},++ // Handle drops from other lists (on a specific item)+ async onInsert(e) {+ const targetIndex = value.findIndex(+ (item) => getKey(item) === e.target.key,+ );+ const insertIndex =+ e.target.dropPosition === "before" ? targetIndex : targetIndex + 1;+ await handleCrossListDrop(e.items, insertIndex);+ },++ // Handle drops on empty list or root+ async onRootDrop(e) {+ await handleCrossListDrop(e.items, value.length);+ },});// Track which items are currently in the list- const currentItemIds = useMemo(- () => new Set(value.map((item) => item.id)),- [value],+ const currentItemKeys = useMemo(+ () => new Set(value.map((item) => getKey(item))),+ [value, getKey],);const handleToggleItem = (item: T, isChecked: boolean) => {if (isChecked) {setValue([...value, item]);} else if (value.length > minItems) {- setValue(value.filter((v) => v.id !== item.id));+ setValue(value.filter((v) => getKey(v) !== getKey(item)));}};@@ -124,12 +265,12 @@ export const ReorderableList = <T extends { id: string | number }>({return;}- const item = value.find((i) => i.id === key);+ const item = value.find((i) => getKey(i) === key);if (!item) {Logger.warn("handleAction: item not found for key", {key,- availableIds: value.map((v) => v.id),+ availableKeys: value.map((v) => getKey(v)),});return;}@@ -137,19 +278,36 @@ export const ReorderableList = <T extends { id: string | number }>({onAction(item);};+ // When list is empty, show a drop zone placeholder+ const isEmpty = value.length === 0;+const listBox = (<ListBoxaria-label={ariaLabel}selectionMode="none"- items={value}dragAndDropHooks={dragAndDropHooks}className={className}onAction={handleAction}>- {(item) => (- <ListBoxItem className="active:cursor-grabbing data-[dragging]:opacity-60">+ {value.map((item) => (+ <ListBoxItem+ key={getKey(item)}+ id={getKey(item)}+ className="active:cursor-grabbing data-[dragging]:opacity-60 outline-none"+ >{renderItem(item)}</ListBoxItem>+ ))}+ {/*+ * When the list is empty, render an invisible placeholder item.+ * This ensures the ListBox maintains minimum dimensions so users can:+ * 1. Right-click to access the context menu and add items back+ * 2. Drag items from another list into this empty list+ */}+ {isEmpty && (+ <ListBoxItem id="__empty__" className="min-h-[40px] min-w-[40px]">+ <span />+ </ListBoxItem>)}</ListBox>);@@ -164,19 +322,20 @@ export const ReorderableList = <T extends { id: string | number }>({<ContextMenuTrigger asChild={true}>{listBox}</ContextMenuTrigger><ContextMenuContent>{availableItems.map((item) => {- const isChecked = currentItemIds.has(item.id);+ const key = getKey(item);+ const isChecked = currentItemKeys.has(key);const isDisabled = isChecked && value.length <= minItems;return (<ContextMenuCheckboxItem- key={item.id}+ key={key}checked={isChecked}disabled={isDisabled}onCheckedChange={(checked) => {handleToggleItem(item, checked);}}>- {getItemLabel(item)}+ {getItemLabel ? getItemLabel(item) : key}</ContextMenuCheckboxItem>);})}