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
Revert "minimal create cell buttons" (#7230)
Shahmir Varqha4a922ac7a6fa
diff --git a/frontend/e2e-tests/py/bad_button.py b/frontend/e2e-tests/py/bad_button.pyindex 3ea54faf54..bcf1d3d171 100644--- a/frontend/e2e-tests/py/bad_button.py+++ b/frontend/e2e-tests/py/bad_button.py@@ -2,28 +2,27 @@# [tool.marimo.runtime]# auto_instantiate = true# ///-import marimo-__generated_with = "0.17.6"+__generated_with = "0.0.1"app = marimo.App()@app.cell-def _():+def __():import marimo as mo- return (mo,)+ return mo,@app.cell-def _(mo):- b = mo.ui.button(value=None, label="Bad button", on_click=lambda v: v + 1)+def __(mo):+ b = mo.ui.button(value=None, label='Bad button', on_click=lambda v: v + 1)b- return (b,)+ return b,@app.cell-def _(b):+def __(b):b.valuereturndiff --git a/frontend/src/components/editor/cell/CreateCellButton.tsx b/frontend/src/components/editor/cell/CreateCellButton.tsxindex b6a0102c7c..198d0dbd49 100644--- a/frontend/src/components/editor/cell/CreateCellButton.tsx+++ b/frontend/src/components/editor/cell/CreateCellButton.tsx@@ -2,11 +2,11 @@import { DatabaseIcon, DiamondPlusIcon, PlusIcon } from "lucide-react";import { Button } from "@/components/editor/inputs/Inputs";import {- DropdownMenu,- DropdownMenuContent,- DropdownMenuItem,- DropdownMenuTrigger,-} from "@/components/ui/dropdown-menu";+ ContextMenu,+ ContextMenuContent,+ ContextMenuItem,+ ContextMenuTrigger,+} from "@/components/ui/context-menu";import { maybeAddMarimoImport } from "@/core/cells/add-missing-import";import { useCellActions } from "@/core/cells/cells";import { LanguageAdapters } from "@/core/codemirror/language/LanguageAdapters";@@ -29,85 +29,115 @@ export const CreateCellButton = ({tooltipContent: React.ReactNode;onClick: ((opts: { code: string; hideCode?: boolean }) => void) | undefined;}) => {- const { createNewCell, addSetupCellIfDoesntExist } = useCellActions();-const baseTooltipContent =getConnectionTooltip(connectionState) || tooltipContent;const finalTooltipContent = isAppInteractionDisabled(connectionState) ? (baseTooltipContent) : (- <div>{baseTooltipContent}</div>+ <div className="flex flex-col gap-4">+ <div>{baseTooltipContent}</div>+ <div className="text-xs text-muted-foreground font-medium pt-1 -mt-2 border-t border-border">+ Right-click for cell types+ </div>+ </div>);- const addPythonCell = () => {- onClick?.({ code: "" });- };-- // NB: When adding the marimo import for markdown and SQL, we run it- // automatically regardless of whether autoinstantiate or lazy execution is- // enabled; the user experience is confusing otherwise (how does the user- // know they need to run import marimo as mo. first?).- const addMarkdownCell = () => {- maybeAddMarimoImport({ autoInstantiate: true, createNewCell });- onClick?.({- code: LanguageAdapters.markdown.defaultCode,- hideCode: true,- });- };-- const addSQLCell = () => {- maybeAddMarimoImport({ autoInstantiate: true, createNewCell });- onClick?.({ code: LanguageAdapters.sql.defaultCode });- };-- const addSetupCell = () => {- addSetupCellIfDoesntExist({});- };-- const renderIcon = (icon: React.ReactNode) => {- return <div className="mr-3 text-muted-foreground">{icon}</div>;- };-return (- <DropdownMenu>- <DropdownMenuTrigger asChild={true}>+ <CreateCellButtonContextMenu onClick={onClick}>+ <Tooltip content={finalTooltipContent}><Button+ onClick={() => onClick?.({ code: "" })}className={cn(- "shoulder-button hover-action border-none shadow-none! bg-transparent! focus-visible:outline-none",+ "shoulder-button hover-action",isAppInteractionDisabled(connectionState) && " inactive-button",)}onMouseDown={Events.preventFocus}+ shape="circle"size="small"color="hint-green"data-testid="create-cell-button">- <Tooltip content={finalTooltipContent}>- <PlusIcon- strokeWidth={3.2}- size={16}- className="opacity-60 hover:opacity-90"- />- </Tooltip>+ <PlusIcon strokeWidth={1.8} /></Button>- </DropdownMenuTrigger>- <DropdownMenuContent>- <DropdownMenuItem onClick={addPythonCell}>- {renderIcon(<PythonIcon />)}+ </Tooltip>+ </CreateCellButtonContextMenu>+ );+};++const CreateCellButtonContextMenu = (props: {+ onClick: ((opts: { code: string; hideCode?: boolean }) => void) | undefined;+ children: React.ReactNode;+}) => {+ const { children, onClick } = props;+ const { createNewCell, addSetupCellIfDoesntExist } = useCellActions();++ if (!onClick) {+ return children;+ }++ // NB: When adding the marimo import for markdown and SQL, we run it+ // automatically regardless of whether autoinstantiate or lazy execution is+ // enabled; the user experience is confusing otherwise (how does the user+ // know they need to run import marimo as mo. first?).+ return (+ <ContextMenu>+ <ContextMenuTrigger>{children}</ContextMenuTrigger>+ <ContextMenuContent>+ <ContextMenuItem+ key="python"+ onSelect={(evt) => {+ evt.stopPropagation();+ onClick({ code: "" });+ }}+ >+ <div className="mr-3 text-muted-foreground">+ <PythonIcon />+ </div>Python cell- </DropdownMenuItem>- <DropdownMenuItem onClick={addMarkdownCell}>- {renderIcon(<MarkdownIcon />)}+ </ContextMenuItem>++ <ContextMenuItem+ key="markdown"+ onSelect={(evt) => {+ evt.stopPropagation();+ maybeAddMarimoImport({ autoInstantiate: true, createNewCell });+ onClick({+ code: LanguageAdapters.markdown.defaultCode,+ hideCode: true,+ });+ }}+ >+ <div className="mr-3 text-muted-foreground">+ <MarkdownIcon />+ </div>Markdown cell- </DropdownMenuItem>- <DropdownMenuItem onClick={addSQLCell}>- {renderIcon(<DatabaseIcon size={13} strokeWidth={1.5} />)}+ </ContextMenuItem>+ <ContextMenuItem+ key="sql"+ onSelect={(evt) => {+ evt.stopPropagation();+ maybeAddMarimoImport({ autoInstantiate: true, createNewCell });+ onClick({ code: LanguageAdapters.sql.defaultCode });+ }}+ >+ <div className="mr-3 text-muted-foreground">+ <DatabaseIcon size={13} strokeWidth={1.5} />+ </div>SQL cell- </DropdownMenuItem>- <DropdownMenuItem onClick={addSetupCell}>- {renderIcon(<DiamondPlusIcon size={13} strokeWidth={1.5} />)}+ </ContextMenuItem>+ <ContextMenuItem+ key="setup"+ onSelect={(evt) => {+ evt.stopPropagation();+ addSetupCellIfDoesntExist({});+ }}+ >+ <div className="mr-3 text-muted-foreground">+ <DiamondPlusIcon size={13} strokeWidth={1.5} />+ </div>Setup cell- </DropdownMenuItem>- </DropdownMenuContent>- </DropdownMenu>+ </ContextMenuItem>+ </ContextMenuContent>+ </ContextMenu>);};diff --git a/frontend/src/components/editor/notebook-cell.tsx b/frontend/src/components/editor/notebook-cell.tsxindex 4bbdbd7e97..290479f737 100644--- a/frontend/src/components/editor/notebook-cell.tsx+++ b/frontend/src/components/editor/notebook-cell.tsx@@ -489,7 +489,7 @@ const EditableCellComponent = ({const outputArea = hasOutput && (<div className="relative" onDoubleClick={showHiddenCodeIfMarkdown}>- <div className="absolute top-5 -left-8 z-20 print:hidden">+ <div className="absolute top-5 -left-8 z-10 print:hidden"><CollapseToggleisCollapsed={isCollapsed}onClick={() => {@@ -580,7 +580,6 @@ const EditableCellComponent = ({ref={cellContainerRef}{...cellDomProps(cellId, cellData.name)}>- <CellLeftSideActions cellId={cellId} actions={actions} />{cellOutput === "above" && outputArea}<div className={cn("tray")} data-hidden={isMarkdownCodeHidden}><StagedAICellBackground cellId={cellId} />@@ -599,6 +598,17 @@ const EditableCellComponent = ({onRun={runCell}/></div>+ <CellLeftSideActions+ cellId={cellId}+ className={cn(+ isMarkdownCodeHidden && hasOutputAbove && "-top-7",+ isMarkdownCodeHidden && hasOutputBelow && "-bottom-8",+ isMarkdownCodeHidden &&+ isCellButtonsInline &&+ "-left-[3.8rem]",+ )}+ actions={actions}+ /><CellEditortheme={theme}showPlaceholder={showPlaceholder}@@ -830,26 +840,21 @@ const CellLeftSideActions = memo(return (<divclassName={cn(- "absolute flex flex-col justify-center h-full left-[-26px] z-20 border-b-0!",+ "absolute flex flex-col gap-[2px] justify-center h-full left-[-34px] z-20",className,)}>- <div className="-mt-1">- <CreateCellButton- tooltipContent={renderShortcut("cell.createAbove")}- connectionState={connection.state}- onClick={isConnected ? createAbove : undefined}- />- </div>- <div className="flex-1 pointer-events-none w-3" />- {/* <div className="flex-1 pointer-events-none bg-border w-px mx-auto hover-action opacity-70" /> */}- <div className="-mb-2">- <CreateCellButton- tooltipContent={renderShortcut("cell.createBelow")}- connectionState={connection.state}- onClick={isConnected ? createBelow : undefined}- />- </div>+ <CreateCellButton+ tooltipContent={renderShortcut("cell.createAbove")}+ connectionState={connection.state}+ onClick={isConnected ? createAbove : undefined}+ />+ <div className="flex-1" />+ <CreateCellButton+ tooltipContent={renderShortcut("cell.createBelow")}+ connectionState={connection.state}+ onClick={isConnected ? createBelow : undefined}+ /></div>);},