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
Consolidate developer tools into dedicated "Developer Panel" (#7458)
Trevor Manz40340b1f26a6
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsxindex a5c5d15dda..9854e62729 100644--- a/frontend/src/components/editor/actions/useNotebookActions.tsx+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx@@ -269,15 +269,15 @@ export function useNotebookActions() {label: "Helper panel",redundant: true,handle: NOOP_HANDLER,- dropdown: PANELS.flatMap(({ type, Icon, hidden }) => {+ dropdown: PANELS.flatMap(({ id, Icon, hidden }) => {if (hidden) {return [];}return {- label: startCase(type),- rightElement: renderCheckboxElement(selectedPanel === type),+ label: startCase(id),+ rightElement: renderCheckboxElement(selectedPanel === id),icon: <Icon size={14} strokeWidth={1.5} />,- handle: () => toggleApplication(type),+ handle: () => toggleApplication(id),};}),},diff --git a/frontend/src/components/editor/chrome/state.ts b/frontend/src/components/editor/chrome/state.tsindex c3b444e0fd..32448b8e87 100644--- a/frontend/src/components/editor/chrome/state.ts+++ b/frontend/src/components/editor/chrome/state.ts@@ -1,15 +1,19 @@/* Copyright 2024 Marimo. All rights reserved. */import { useAtomValue } from "jotai";+import { atomWithStorage } from "jotai/utils";import { z } from "zod";import { createReducerAndAtoms } from "@/utils/createReducer";+import { jotaiJsonStorage } from "@/utils/storage/jotai";import { ZodLocalStorage } from "@/utils/storage/typed";-import type { PanelType } from "./types";+import type { DeveloperPanelTabType, PanelType } from "./types";+import { PANELS } from "./types";export interface ChromeState {selectedPanel: PanelType | undefined;isSidebarOpen: boolean;- isTerminalOpen: boolean;+ isDeveloperPanelOpen: boolean;+ selectedDeveloperPanelTab: DeveloperPanelTabType;}const KEY = "marimo:sidebar";@@ -20,7 +24,12 @@ const storage = new ZodLocalStorage<ChromeState>(.optional().transform((v) => v as PanelType),isSidebarOpen: z.boolean(),- isTerminalOpen: z.boolean(),+ isDeveloperPanelOpen: z.boolean().optional().default(false),+ selectedDeveloperPanelTab: z+ .string()+ .optional()+ .default("terminal")+ .transform((v) => v as DeveloperPanelTabType),}),initialState,);@@ -29,7 +38,8 @@ function initialState(): ChromeState {return {selectedPanel: "variables", // initial panelisSidebarOpen: false,- isTerminalOpen: false,+ isDeveloperPanelOpen: false,+ selectedDeveloperPanelTab: "terminal",};}@@ -63,13 +73,22 @@ const {...state,isSidebarOpen: isOpen,}),- toggleTerminal: (state) => ({+ toggleDeveloperPanel: (state) => ({+ ...state,+ isDeveloperPanelOpen: !state.isDeveloperPanelOpen,+ }),+ setIsDeveloperPanelOpen: (state, isOpen: boolean) => ({...state,- isTerminalOpen: !state.isTerminalOpen,+ isDeveloperPanelOpen: isOpen,}),- setIsTerminalOpen: (state, isOpen: boolean) => ({+ setSelectedDeveloperPanelTab: (state, tab: DeveloperPanelTabType) => ({...state,- isTerminalOpen: isOpen,+ selectedDeveloperPanelTab: tab,+ }),+ openDeveloperPanelTab: (state, tab: DeveloperPanelTabType) => ({+ ...state,+ isDeveloperPanelOpen: true,+ selectedDeveloperPanelTab: tab,}),},[(_prevState, newState) => storage.set(KEY, newState)],@@ -100,3 +119,11 @@ 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.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 088f63a938..f4042b1164 100644--- a/frontend/src/components/editor/chrome/types.ts+++ b/frontend/src/components/editor/chrome/types.ts@@ -15,6 +15,7 @@ import {NotebookPenIcon,ScrollTextIcon,SquareDashedBottomCodeIcon,+ TerminalSquareIcon,TextSearchIcon,XCircleIcon,} from "lucide-react";@@ -23,23 +24,18 @@ import { isWasm } from "@/core/wasm/utils";export type PanelType =| "files"- | "errors"| "variables"| "outline"| "dependencies"- | "tracing"| "packages"| "documentation"| "snippets"| "datasources"- | "scratchpad"| "ai"- | "cache"- | "secrets"- | "logs";+ | "cache";export interface PanelDescriptor {- type: PanelType;+ id: PanelType;Icon: LucideIcon;hidden?: boolean;tooltip: string;@@ -61,7 +57,7 @@ export const PANELS: PanelDescriptor[] = [// them a quick glance at their project structure,// without having to leave their editor.{- type: "files",+ id: "files",Icon: FolderTreeIcon,tooltip: "View files",position: "sidebar",@@ -70,13 +66,13 @@ export const PANELS: PanelDescriptor[] = [// it's important to give humans visibility into// what that data is.{- type: "variables",+ id: "variables",Icon: FunctionSquareIcon,tooltip: "Explore variables",position: "sidebar",},{- type: "datasources",+ id: "datasources",Icon: DatabaseIcon,tooltip: "Explore data sources",position: "sidebar",@@ -84,7 +80,7 @@ export const PANELS: PanelDescriptor[] = [// Every notebook has a package environment that must// be managed.{- type: "packages",+ id: "packages",Icon: BoxIcon,tooltip: "Manage packages",position: "sidebar",@@ -93,24 +89,15 @@ export const PANELS: PanelDescriptor[] = [//// The AI panel holds both agents and in-editor chat.{- type: "ai",+ id: "ai",Icon: BotIcon,tooltip: "Chat & Agents",position: "sidebar",},- // Scratchpad is the only way users can- // code without DAG restrictions, so it is- // privileged.- {- type: "scratchpad",- Icon: NotebookPenIcon,- tooltip: "Scratchpad",- position: "sidebar",- },{// TODO(akshayka): Consider making snippets default// off, user configuration to enable.- type: "snippets",+ id: "snippets",Icon: SquareDashedBottomCodeIcon,tooltip: "Snippets",position: "sidebar",@@ -123,60 +110,86 @@ export const PANELS: PanelDescriptor[] = [// or datasets, so they are positioned at the end of the// sidebar.{- type: "outline",+ id: "outline",Icon: ScrollTextIcon,tooltip: "View outline",position: "sidebar",},{- type: "documentation",+ id: "documentation",Icon: TextSearchIcon,tooltip: "View live docs",position: "sidebar",},- {- type: "logs",- Icon: FileTextIcon,- tooltip: "Notebook logs",- position: "sidebar",- },{// TODO(akshayka): Consider making dependencies// default off; the minimap is a more effective// overview.- type: "dependencies",+ id: "dependencies",Icon: NetworkIcon,tooltip: "Explore dependencies",position: "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[] = [+ {+ type: "errors",+ Icon: XCircleIcon,+ label: "Errors",+ },+ {+ type: "scratchpad",+ Icon: NotebookPenIcon,+ label: "Scratchpad",+ },{type: "tracing",Icon: ActivityIcon,- tooltip: "Tracing",- position: "sidebar",+ label: "Tracing",},{- // Not supported in WebAssembly yettype: "secrets",Icon: KeyRoundIcon,- tooltip: "Secrets",+ label: "Secrets",hidden: isWasm(),- position: "sidebar",+ },+ {+ type: "logs",+ Icon: FileTextIcon,+ label: "Logs",+ },+ {+ type: "terminal",+ Icon: TerminalSquareIcon,+ label: "Terminal",},// TODO(akshayka): The cache panel should not be default shown,- // even when it's out of feature flag. (User config to- // turn it on.)+ // even when it's out of feature flag. (User config to turn it on.){type: "cache",Icon: DatabaseZapIcon,- tooltip: "Manage cache",- position: "sidebar",+ label: "Cache",hidden: !getFeatureFlag("cache_panel"),},- {- type: "errors",- Icon: XCircleIcon,- tooltip: "View errors",- position: "footer",- },];diff --git a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsxindex eeded15d3f..3fa968f44b 100644--- a/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx+++ b/frontend/src/components/editor/chrome/wrapper/app-chrome.tsx@@ -20,6 +20,7 @@ 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 { Minimap } from "./minimap";import { PanelsWrapper } from "./panels";import { PendingAICells } from "./pending-ai-cells";@@ -57,8 +58,17 @@ const LazyVariablePanel = React.lazy(() => import("../panels/variable-panel"));const LazyCachePanel = React.lazy(() => import("../panels/cache-panel"));export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {- const { isSidebarOpen, isTerminalOpen, selectedPanel } = useChromeState();- const { setIsSidebarOpen, setIsTerminalOpen } = useChromeActions();+ const {+ isSidebarOpen,+ isDeveloperPanelOpen,+ selectedPanel,+ selectedDeveloperPanelTab,+ } = useChromeState();+ const {+ setIsSidebarOpen,+ setIsDeveloperPanelOpen,+ setSelectedDeveloperPanelTab,+ } = useChromeActions();const sidebarRef = React.useRef<ImperativePanelHandle>(null);const terminalRef = React.useRef<ImperativePanelHandle>(null);const { aiPanelTab, setAiPanelTab } = useAiPanelTab();@@ -87,17 +97,17 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {});}, [isSidebarOpen]);- // sync terminal+ // sync paneluseEffect(() => {if (!terminalRef.current) {return;}const isCurrentlyCollapsed = terminalRef.current.isCollapsed();- if (isTerminalOpen && isCurrentlyCollapsed) {+ if (isDeveloperPanelOpen && isCurrentlyCollapsed) {terminalRef.current.expand();}- if (!isTerminalOpen && !isCurrentlyCollapsed) {+ if (!isDeveloperPanelOpen && !isCurrentlyCollapsed) {terminalRef.current.collapse();}@@ -109,7 +119,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {window.dispatchEvent(new Event("resize"));});});- }, [isTerminalOpen]);+ }, [isDeveloperPanelOpen]);const appBodyPanel = (<Panel id="app" key="app" className="relative h-full">@@ -128,12 +138,12 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {/>);- const terminalResizeHandle = (+ const panelResizeHandle = (<PanelResizeHandleonDragging={handleDragging}className={cn("border-border no-print z-20",- isTerminalOpen ? "resize-handle" : "resize-handle-collapsed",+ isDeveloperPanelOpen ? "resize-handle" : "resize-handle-collapsed","horizontal",)}/>@@ -194,7 +204,6 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {<Suspense><TooltipProvider>{selectedPanel === "files" && <LazyFileExplorerPanel />}- {selectedPanel === "errors" && <LazyErrorsPanel />}{selectedPanel === "variables" && <LazyVariablePanel />}{selectedPanel === "dependencies" && <LazyDependencyGraphPanel />}{selectedPanel === "packages" && <LazyPackagesPanel />}@@ -202,12 +211,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {{selectedPanel === "datasources" && <LazyDataSourcesPanel />}{selectedPanel === "documentation" && <LazyDocumentationPanel />}{selectedPanel === "snippets" && <LazySnippetsPanel />}- {selectedPanel === "scratchpad" && <LazyScratchpadPanel />}{selectedPanel === "ai" && renderAiPanel()}- {selectedPanel === "logs" && <LazyLogsPanel />}- {selectedPanel === "tracing" && <LazyTracingPanel />}- {selectedPanel === "secrets" && <LazySecretsPanel />}- {selectedPanel === "cache" && <LazyCachePanel />}</TooltipProvider></Suspense></div>@@ -247,19 +251,19 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {</Panel>);- const terminalPanel = (+ const bottomPanel = (<Panelref={terminalRef}// This cannot by dynamic and must be constant// so that the size is preserved between page loads- id="app-chrome-terminal"- data-testid="terminal"- key={"terminal"}+ id="app-chrome-panel"+ data-testid="panel"+ key={"panel"}collapsedSize={0}collapsible={true}className={cn("dark:bg-(--slate-1) no-print print:hidden hide-on-fullscreen",- isTerminalOpen && "border-(--slate-7)",+ isDeveloperPanelOpen && "border-t",)}minSize={10}// We can't make the default size greater than 0, otherwise it will start open@@ -271,18 +275,98 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {terminalRef.current?.resize(30);}}}- onCollapse={() => setIsTerminalOpen(false)}- onExpand={() => setIsTerminalOpen(true)}+ onCollapse={() => setIsDeveloperPanelOpen(false)}+ onExpand={() => setIsDeveloperPanelOpen(true)}>- {terminalResizeHandle}- <LazyMount isOpen={isTerminalOpen}>- <Suspense fallback={<div />}>- <LazyTerminal- visible={isTerminalOpen}- onClose={() => setIsTerminalOpen(false)}- />- </Suspense>- </LazyMount>+ {panelResizeHandle}+ <div className="flex flex-col h-full">+ {/* Panel header with tabs */}+ <div className="flex items-center justify-between border-b px-2 py-1 bg-background shrink-0">+ <Tabs+ value={selectedDeveloperPanelTab}+ onValueChange={(v) =>+ setSelectedDeveloperPanelTab(+ v as typeof selectedDeveloperPanelTab,+ )+ }+ >+ <TabsList className="h-7 bg-transparent p-0">+ {DEVELOPER_PANEL_TABS.filter((tab) => !tab.hidden).map((tab) => (+ <TabsTrigger+ key={tab.type}+ value={tab.type}+ className="text-xs gap-1.5 px-2 py-1 data-[state=active]:bg-muted"+ >+ <tab.Icon className="w-3.5 h-3.5" />+ {tab.label}+ </TabsTrigger>+ ))}+ </TabsList>+ </Tabs>+ <Button+ size="xs"+ variant="text"+ onClick={() => setIsDeveloperPanelOpen(false)}+ >+ <XIcon className="w-4 h-4" />+ </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 />}>+ <LazyTerminal+ visible={isDeveloperPanelOpen}+ onClose={() => setIsDeveloperPanelOpen(false)}+ />+ </Suspense>+ </LazyMount>+ )}+ {selectedDeveloperPanelTab === "cache" && (+ <LazyMount isOpen={isDeveloperPanelOpen}>+ <Suspense fallback={<div />}>+ <LazyCachePanel />+ </Suspense>+ </LazyMount>+ )}+ </div>+ </div></Panel>);@@ -296,7 +380,7 @@ export const AppChrome: React.FC<PropsWithChildren> = ({ children }) => {<Panel id="app-chrome-body"><PanelGroup autoSaveId="marimo:chrome:v1:l1" direction="vertical">{appBodyPanel}- <IfCapability capability="terminal">{terminalPanel}</IfCapability>+ <IfCapability capability="terminal">{bottomPanel}</IfCapability></PanelGroup></Panel><ContextAwarePanel />diff --git a/frontend/src/components/editor/chrome/wrapper/footer.tsx b/frontend/src/components/editor/chrome/wrapper/footer.tsxindex 89d4f96ed1..ee838dbd1b 100644--- a/frontend/src/components/editor/chrome/wrapper/footer.tsx+++ b/frontend/src/components/editor/chrome/wrapper/footer.tsx@@ -1,17 +1,15 @@/* Copyright 2024 Marimo. All rights reserved. */import { useAtomValue } from "jotai";-import { TerminalSquareIcon } from "lucide-react";+import { TerminalSquareIcon, XCircleIcon } from "lucide-react";import type React from "react";import { Tooltip } from "@/components/ui/tooltip";import { cellErrorCount } from "@/core/cells/cells";import { IfCapability } from "@/core/config/if-capability";import { useHotkey } from "@/hooks/useHotkey";import { cn } from "@/utils/cn";-import { invariant } from "@/utils/invariant";import { ShowInKioskMode } from "../../kiosk-mode";import { useChromeActions, useChromeState } from "../state";-import { PANELS, type PanelDescriptor } from "../types";import { FooterItem } from "./footer-item";import { AIStatusIcon } from "./footer-items/ai-status";import { BackendConnection } from "./footer-items/backend-status";@@ -22,39 +20,40 @@ import { RTCStatus } from "./footer-items/rtc-status";import { RuntimeSettings } from "./footer-items/runtime-settings";export const Footer: React.FC = () => {- const { selectedPanel, isTerminalOpen } = useChromeState();- const { toggleApplication, toggleTerminal } = useChromeActions();+ const { isDeveloperPanelOpen, selectedDeveloperPanelTab } = useChromeState();+ const { toggleDeveloperPanel, openDeveloperPanelTab } = useChromeActions();const errorCount = useAtomValue(cellErrorCount);- const renderIcon = ({ Icon }: PanelDescriptor, className?: string) => {- return <Icon className={cn("h-5 w-5", className)} />;- };-- const errorPanel = PANELS.find((p) => p.type === "errors");- invariant(errorPanel, "Error panel not found");-useHotkey("global.toggleTerminal", () => {- toggleTerminal();+ toggleDeveloperPanel();+ });++ useHotkey("global.togglePanel", () => {+ toggleDeveloperPanel();});return (<footer className="h-10 py-2 bg-background flex items-center text-muted-foreground text-md px-1 border-t border-border select-none no-print text-sm shadow-[0_0_4px_1px_rgba(0,0,0,0.1)] z-50 print:hidden hide-on-fullscreen overflow-x-auto overflow-y-hidden scrollbar-thin"><FooterItem- tooltip={errorPanel.tooltip}- selected={selectedPanel === errorPanel.type}- onClick={() => toggleApplication(errorPanel.type)}+ tooltip="View errors"+ selected={+ isDeveloperPanelOpen && selectedDeveloperPanelTab === "errors"+ }+ onClick={() => openDeveloperPanelTab("errors")}data-testid="footer-errors">- {renderIcon(errorPanel, errorCount > 0 ? "text-destructive" : "")}+ <XCircleIcon+ className={cn("h-5 w-5", errorCount > 0 && "text-destructive")}+ /><span className="ml-1 font-mono mt-0.5">{errorCount}</span></FooterItem><IfCapability capability="terminal"><FooterItem- tooltip="Open terminal"- selected={isTerminalOpen}- onClick={() => toggleTerminal()}- data-testid="footer-terminal"+ tooltip="Toggle developer panel"+ selected={isDeveloperPanelOpen}+ onClick={() => toggleDeveloperPanel()}+ data-testid="footer-panel"><TerminalSquareIcon className="h-5 w-5" /></FooterItem>diff --git a/frontend/src/components/editor/chrome/wrapper/sidebar.tsx b/frontend/src/components/editor/chrome/wrapper/sidebar.tsxindex 7b6950ffc9..b1eebcd865 100644--- a/frontend/src/components/editor/chrome/wrapper/sidebar.tsx+++ b/frontend/src/components/editor/chrome/wrapper/sidebar.tsx@@ -1,40 +1,67 @@/* Copyright 2024 Marimo. All rights reserved. */-import { useAtomValue } from "jotai";+import { useAtom, useAtomValue } from "jotai";import { MessageCircleQuestionIcon } from "lucide-react";import type React from "react";import type { PropsWithChildren } from "react";+import { useMemo } from "react";+import { ReorderableList } from "@/components/ui/reorderable-list";import { Tooltip } from "@/components/ui/tooltip";import { notebookQueuedOrRunningCountAtom } from "@/core/cells/cells";import { cn } from "@/utils/cn";import { FeedbackButton } from "../components/feedback-button";-import { useChromeActions, useChromeState } from "../state";-import { PANELS, type PanelDescriptor } from "../types";+import { sidebarOrderAtom, 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 renderIcon = ({ Icon }: PanelDescriptor, className?: string) => {return <Icon className={cn("h-5 w-5", className)} />;};- const sidebarItems = PANELS.filter(- (p) => !p.hidden && p.position === "sidebar",+ // Get all available sidebar panels+ const availableSidebarPanels = useMemo(+ () => PANELS.filter((p) => !p.hidden && p.position === "sidebar"),+ [],);+ const currentItems = sidebarOrder+ .map((id) => PANEL_MAP.get(id))+ .filter(Boolean);++ const handleSetValue = (panels: PanelDescriptor[]) => {+ setSidebarOrder(panels.map((p) => p.id));+ };+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">- {sidebarItems.map((p) => (- <SidebarItem- key={p.type}- tooltip={p.tooltip}- selected={selectedPanel === p.type}- onClick={() => toggleApplication(p.type)}- >- {renderIcon(p)}- </SidebarItem>- ))}+ <ReorderableList<PanelDescriptor>+ value={currentItems}+ setValue={handleSetValue}+ availableItems={availableSidebarPanels}+ getItemLabel={(panel) => (+ <span className="flex items-center gap-2 [">+ {renderIcon(panel, "h-4 w-4 text-muted-foreground")}+ {panel.tooltip}+ </span>+ )}+ ariaLabel="Reorderable sidebar panels"+ className="flex flex-col gap-0"+ renderItem={(panel) => {+ return (+ <SidebarItem+ tooltip={panel.tooltip}+ selected={selectedPanel === panel.id}+ onClick={() => toggleApplication(panel.id)}+ >+ {renderIcon(panel)}+ </SidebarItem>+ );+ }}+ /><FeedbackButton><SidebarItem tooltip="Send feedback!" selected={false}><MessageCircleQuestionIcon className="h-5 w-5" />diff --git a/frontend/src/components/editor/output/MarimoErrorOutput.tsx b/frontend/src/components/editor/output/MarimoErrorOutput.tsxindex 3327052544..f4813ab563 100644--- a/frontend/src/components/editor/output/MarimoErrorOutput.tsx+++ b/frontend/src/components/editor/output/MarimoErrorOutput.tsx@@ -142,7 +142,7 @@ export const MarimoErrorOutput = ({);const openScratchpad = () => {- chromeActions.openApplication("scratchpad");+ chromeActions.openDeveloperPanelTab("scratchpad");};const renderMessages = () => {@@ -158,10 +158,6 @@ export const MarimoErrorOutput = ({!hasPipHint &&syntaxErrors.some((error) => error.msg.includes("use os.subprocess"));- const openTerminal = () => {- chromeActions.setIsTerminalOpen(true);- };-messages.push(<div key="syntax-unknown">{syntaxErrors.map((error, idx) => (@@ -190,7 +186,7 @@ export const MarimoErrorOutput = ({size="xs"variant="outline"className="mt-2 font-normal"- onClick={openTerminal}+ onClick={() => chromeActions.openDeveloperPanelTab("terminal")}><TerminalIcon className="h-3.5 w-3.5 mr-1.5" /><span>Open terminal</span>diff --git a/frontend/src/components/terminal/hooks.ts b/frontend/src/components/terminal/hooks.tsindex 5158aeb33b..dd84c6947f 100644--- a/frontend/src/components/terminal/hooks.ts+++ b/frontend/src/components/terminal/hooks.ts@@ -25,11 +25,11 @@ import { useTerminalActions } from "./state";*/export function useTerminalCommands() {const { addCommand } = useTerminalActions();- const { setIsTerminalOpen } = useChromeActions();+ const { openDeveloperPanelTab } = useChromeActions();const sendCommand = (text: string) => {// First, ensure the terminal is open- setIsTerminalOpen(true);+ openDeveloperPanelTab("terminal");// Add the command to the queueaddCommand(text);diff --git a/frontend/src/components/ui/context-menu.tsx b/frontend/src/components/ui/context-menu.tsxindex 1b952df2f1..59ac3c0d2b 100644--- a/frontend/src/components/ui/context-menu.tsx+++ b/frontend/src/components/ui/context-menu.tsx@@ -19,6 +19,7 @@ import {MenuShortcut,menuContentCommon,menuControlCheckVariants,+ menuControlVariants,menuItemVariants,menuLabelVariants,menuSeparatorVariants,@@ -122,7 +123,7 @@ const ContextMenuCheckboxItem = React.forwardRef<>(({ className, children, checked, ...props }, ref) => (<ContextMenuPrimitive.CheckboxItemref={ref}- className={menuControlCheckVariants({ className })}+ className={menuControlVariants({ className })}checked={checked}{...props}>diff --git a/frontend/src/components/ui/reorderable-list.css b/frontend/src/components/ui/reorderable-list.cssnew file mode 100644index 0000000000..6c19f7822c--- /dev/null+++ b/frontend/src/components/ui/reorderable-list.css@@ -0,0 +1,3 @@+.react-aria-DropIndicator[data-drop-target] {+ outline: 1px solid var(--blue-9);+}diff --git a/frontend/src/components/ui/reorderable-list.tsx b/frontend/src/components/ui/reorderable-list.tsxnew file mode 100644index 0000000000..4594e3d0b7--- /dev/null+++ b/frontend/src/components/ui/reorderable-list.tsx@@ -0,0 +1,160 @@+/* Copyright 2024 Marimo. All rights reserved. */++import type React from "react";+import { useMemo } from "react";+import { ListBox, ListBoxItem, useDragAndDrop } from "react-aria-components";+import {+ ContextMenu,+ ContextMenuCheckboxItem,+ ContextMenuContent,+ ContextMenuTrigger,+} from "./context-menu";+import "./reorderable-list.css";++export interface ReorderableListProps<T extends { id: string | number }> {+ /**+ * The current list of items+ */+ value: T[];+ /**+ * Callback when items are reordered+ */+ setValue: (items: T[]) => void;+ /**+ * Render function for each item+ */+ renderItem: (item: T) => React.ReactNode;+ /**+ * All available items that can be added to the list+ */+ availableItems?: T[];+ /**+ * Function to get the label for an item in the context menu+ */+ getItemLabel?: (item: T) => React.ReactNode;+ /**+ * Minimum number of items that must remain in the list (default: 1)+ */+ minItems?: number;+ /**+ * Aria label for accessibility+ */+ ariaLabel?: string;+ /**+ * Additional class name for the list container+ */+ className?: string;+}++/**+ * A generic reorderable list component using react-aria-components and react-stately.+ * Items can be reordered via drag and drop.+ *+ * @example+ * ```tsx+ * interface MyItem {+ * id: string;+ * name: string;+ * }+ *+ * const [items, setItems] = useState<MyItem[]>([...]);+ *+ * <ReorderableList+ * value={items}+ * setValue={setItems}+ * renderItem={(item) => <div>{item.name}</div>}+ * ariaLabel="My reorderable list"+ * />+ * ```+ */+export function ReorderableList<T extends { id: string | number }>({+ value,+ setValue,+ renderItem,+ availableItems,+ getItemLabel = (item) => String(item.id),+ minItems = 1,+ ariaLabel = "Reorderable list",+ className,+}: ReorderableListProps<T>) {+ const { dragAndDropHooks } = useDragAndDrop<T>({+ getItems: (keys) => [...keys].map((key) => ({ "text/plain": String(key) })),+ 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 targetIndex = remaining.findIndex(+ (item) => item.id === e.target.key,+ );+ const insertIndex =+ e.target.dropPosition === "before" ? targetIndex : targetIndex + 1;++ setValue([+ ...remaining.slice(0, insertIndex),+ ...draggedItems,+ ...remaining.slice(insertIndex),+ ]);+ },+ });++ // Track which items are currently in the list+ const currentItemIds = useMemo(+ () => new Set(value.map((item) => item.id)),+ [value],+ );++ const handleToggleItem = (item: T, isChecked: boolean) => {+ if (isChecked) {+ setValue([...value, item]);+ } else if (value.length > minItems) {+ setValue(value.filter((v) => v.id !== item.id));+ }+ };++ const listBox = (+ <ListBox+ aria-label={ariaLabel}+ selectionMode="single"+ items={value}+ dragAndDropHooks={dragAndDropHooks}+ className={className}+ >+ {(item) => (+ <ListBoxItem className="active:cursor-grabbing data-[dragging]:opacity-60">+ {renderItem(item)}+ </ListBoxItem>+ )}+ </ListBox>+ );++ // Only show context menu if availableItems is provided+ if (!availableItems) {+ return listBox;+ }++ return (+ <ContextMenu>+ <ContextMenuTrigger asChild={true}>{listBox}</ContextMenuTrigger>+ <ContextMenuContent>+ {availableItems.map((item) => {+ const isChecked = currentItemIds.has(item.id);+ const isDisabled = isChecked && value.length <= minItems;++ return (+ <ContextMenuCheckboxItem+ key={item.id}+ checked={isChecked}+ disabled={isDisabled}+ onCheckedChange={(checked) => {+ handleToggleItem(item, checked);+ }}+ >+ {getItemLabel(item)}+ </ContextMenuCheckboxItem>+ );+ })}+ </ContextMenuContent>+ </ContextMenu>+ );+}diff --git a/frontend/src/core/hotkeys/hotkeys.ts b/frontend/src/core/hotkeys/hotkeys.tsindex cfaee058d7..3ec1eccdeb 100644--- a/frontend/src/core/hotkeys/hotkeys.ts+++ b/frontend/src/core/hotkeys/hotkeys.ts@@ -351,6 +351,11 @@ const DEFAULT_HOT_KEY = {group: "Other",key: "Ctrl-`",},+ "global.togglePanel": {+ name: "Toggle developer panel",+ group: "Other",+ key: "Mod-j",+ },"global.collapseAllSections": {name: "Collapse all sections",group: "Editing",