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
fix: change KeyboardShortcut control to CommandPalette, amd some mobile fixes (#824)
Myles Scolnick86dbd0bc1e97
diff --git a/frontend/src/components/editor/actions/useNotebookActions.tsx b/frontend/src/components/editor/actions/useNotebookActions.tsxindex c623340e85..6a8f8f3731 100644--- a/frontend/src/components/editor/actions/useNotebookActions.tsx+++ b/frontend/src/components/editor/actions/useNotebookActions.tsx@@ -19,7 +19,7 @@ import {PanelLeftIcon,CheckIcon,} from "lucide-react";-import { commandPaletteAtom } from "../CommandPalette";+import { commandPaletteAtom } from "../controls/command-palette";import {disabledCellIds,enabledCellIds,diff --git a/frontend/src/components/editor/cell/cell-actions.tsx b/frontend/src/components/editor/cell/cell-actions.tsxindex a89999a592..0f12d24c6b 100644--- a/frontend/src/components/editor/cell/cell-actions.tsx+++ b/frontend/src/components/editor/cell/cell-actions.tsx@@ -78,10 +78,12 @@ export const CellActionsDropdown = ({ children, ...props }: Props) => {<CommandItemkey={action.label}onSelect={() => {+ if (action.disableClick) {+ return;+ }action.handle();setOpen(false);}}- disabled={action.disableClick}variant={action.variant}><div className="flex items-center flex-1">diff --git a/frontend/src/components/editor/Controls.tsx b/frontend/src/components/editor/controls/Controls.tsxsimilarity index 87%rename from frontend/src/components/editor/Controls.tsxrename to frontend/src/components/editor/controls/Controls.tsxindex 4bab8cceb3..d059069434 100644--- a/frontend/src/components/editor/Controls.tsx+++ b/frontend/src/components/editor/controls/Controls.tsx@@ -10,19 +10,20 @@ import {import { cn } from "@/utils/cn";import { Button } from "@/components/editor/inputs/Inputs";-import { KeyboardShortcuts } from "@/components/editor/KeyboardShortcuts";-import { ShutdownButton } from "@/components/editor/ShutdownButton";+import { KeyboardShortcuts } from "@/components/editor/controls/keyboard-shortcuts";+import { ShutdownButton } from "@/components/editor/controls/shutdown-button";import { RecoveryButton } from "@/components/editor/RecoveryButton";-import { Tooltip } from "../ui/tooltip";-import { renderShortcut } from "../shortcuts/renderShortcut";-import { useCellActions } from "../../core/cells/cells";-import { AppConfigButton } from "../app-config/app-config-button";-import { LayoutSelect } from "./renderers/layout-select";-import { NotebookMenuDropdown } from "@/components/editor/notebook-menu-dropdown";+import { Tooltip } from "../../ui/tooltip";+import { renderShortcut } from "../../shortcuts/renderShortcut";+import { useCellActions } from "../../../core/cells/cells";+import { AppConfigButton } from "../../app-config/app-config-button";+import { LayoutSelect } from "../renderers/layout-select";+import { NotebookMenuDropdown } from "@/components/editor/controls/notebook-menu-dropdown";import { FindReplace } from "@/components/find-replace/find-replace";import { AppConfig } from "@/core/config/config-schema";-import { useShouldShowInterrupt } from "./cell/useShouldShowInterrupt";+import { useShouldShowInterrupt } from "../cell/useShouldShowInterrupt";+import { CommandPaletteButton } from "./command-palette-button";interface ControlsProps {filename: string | null;@@ -142,6 +143,7 @@ export const Controls = ({</Button></Tooltip>+ <CommandPaletteButton /><KeyboardShortcuts /></div>diff --git a/frontend/src/components/editor/controls/command-palette-button.tsx b/frontend/src/components/editor/controls/command-palette-button.tsxnew file mode 100644index 0000000000..a4ae4d1dd3--- /dev/null+++ b/frontend/src/components/editor/controls/command-palette-button.tsx@@ -0,0 +1,21 @@+/* Copyright 2024 Marimo. All rights reserved. */+import { renderShortcut } from "@/components/shortcuts/renderShortcut";+import { Tooltip } from "@/components/ui/tooltip";+import { CommandIcon } from "lucide-react";+import React from "react";+import { Button } from "../inputs/Inputs";+import { useSetAtom } from "jotai";+import { commandPaletteAtom } from "./command-palette";++export const CommandPaletteButton: React.FC = () => {+ const setCommandPaletteOpen = useSetAtom(commandPaletteAtom);+ const toggle = () => setCommandPaletteOpen((value) => !value);++ return (+ <Tooltip content={renderShortcut("global.commandPalette")}>+ <Button onClick={toggle} shape="rectangle" color="white">+ <CommandIcon strokeWidth={1.5} />+ </Button>+ </Tooltip>+ );+};diff --git a/frontend/src/components/editor/CommandPalette.tsx b/frontend/src/components/editor/controls/command-palette.tsxsimilarity index 91%rename from frontend/src/components/editor/CommandPalette.tsxrename to frontend/src/components/editor/controls/command-palette.tsxindex 6c77ef8864..f1a2364961 100644--- a/frontend/src/components/editor/CommandPalette.tsx+++ b/frontend/src/components/editor/controls/command-palette.tsx@@ -10,16 +10,16 @@ import {CommandSeparator,CommandShortcut,} from "@/components/ui/command";-import { useRegisteredActions } from "../../core/hotkeys/actions";-import { useRecentCommands } from "../../hooks/useRecentCommands";-import { Kbd } from "../ui/kbd";-import { prettyPrintHotkey } from "../shortcuts/renderShortcut";+import { useRegisteredActions } from "../../../core/hotkeys/actions";+import { useRecentCommands } from "../../../hooks/useRecentCommands";+import { Kbd } from "../../ui/kbd";+import { prettyPrintHotkey } from "../../shortcuts/renderShortcut";import { HOTKEYS, HotkeyAction, isHotkeyAction } from "@/core/hotkeys/hotkeys";import { atom, useAtom } from "jotai";-import { useNotebookActions } from "./actions/useNotebookActions";+import { useNotebookActions } from "../actions/useNotebookActions";import { Objects } from "@/utils/objects";import { parseShortcut } from "@/core/hotkeys/shortcuts";-import { isParentAction, flattenActions } from "./actions/types";+import { isParentAction, flattenActions } from "../actions/types";export const commandPaletteAtom = atom(false);diff --git a/frontend/src/components/editor/KeyboardShortcuts.tsx b/frontend/src/components/editor/controls/keyboard-shortcuts.tsxsimilarity index 59%rename from frontend/src/components/editor/KeyboardShortcuts.tsxrename to frontend/src/components/editor/controls/keyboard-shortcuts.tsxindex 310ac61776..a92baa5414 100644--- a/frontend/src/components/editor/KeyboardShortcuts.tsx+++ b/frontend/src/components/editor/controls/keyboard-shortcuts.tsx@@ -1,33 +1,32 @@/* Copyright 2024 Marimo. All rights reserved. */-import { useRef } from "react";-import { KeyboardIcon } from "lucide-react";+import { useState } from "react";-import { Button } from "@/components/editor/inputs/Inputs";-import { useHotkey } from "../../hooks/useHotkey";-import { Tooltip } from "../ui/tooltip";-import { Kbd } from "../ui/kbd";+import { useHotkey } from "../../../hooks/useHotkey";+import { Kbd } from "../../ui/kbd";import {Dialog,DialogContent,DialogPortal,DialogOverlay,- DialogTrigger,+ DialogHeader,DialogTitle,-} from "../ui/dialog";-import { prettyPrintHotkey, renderShortcut } from "../shortcuts/renderShortcut";+} from "../../ui/dialog";+import { prettyPrintHotkey } from "../../shortcuts/renderShortcut";import { HOTKEYS, HotkeyAction, HotkeyGroup } from "@/core/hotkeys/hotkeys";-export const KeyboardShortcuts = (): JSX.Element => {- const ref = useRef<HTMLButtonElement | null>(null);+export const KeyboardShortcuts: React.FC = () => {+ const [isOpen, setIsOpen] = useState(false);- useHotkey("global.showHelp", () => {- ref.current?.click();- });+ useHotkey("global.showHelp", () => setIsOpen((v) => !v));++ if (!isOpen) {+ return null;+ }const renderItem = (action: HotkeyAction) => {const hotkey = HOTKEYS.getHotkey(action);return (- <div className="keyboard-shortcut" key={action}>+ <div className="keyboard-shortcut flex flex-col" key={action}><div className="flex gap-1">{prettyPrintHotkey(hotkey.key).map((key) => (<Kbd key={key}>{key}</Kbd>@@ -42,7 +41,7 @@ export const KeyboardShortcuts = (): JSX.Element => {const renderGroup = (group: HotkeyGroup) => {const items = groups[group];return (- <div className="keyboard-shortcut-group">+ <div className="keyboard-shortcut-group gap-2 flex flex-col"><h3 className="text-lg font-medium">{group}</h3>{items.map((item) => renderItem(item))}@@ -51,23 +50,17 @@ export const KeyboardShortcuts = (): JSX.Element => {};return (- <Dialog>- <Tooltip content={renderShortcut("global.showHelp")}>- <DialogTrigger asChild={true}>- <Button ref={ref} shape="rectangle" color="white">- <KeyboardIcon className="help-icon" strokeWidth={1.5} />- </Button>- </DialogTrigger>- </Tooltip>-+ <Dialog open={isOpen} onOpenChange={(open) => setIsOpen(open)}>{/* Manually portal so we can adjust positioning: shortcuts modal is too large to offset from top for some screens. */}<DialogPortal className="sm:items-center sm:top-0"><DialogOverlay /><DialogContentusePortal={false}- className="max-h-[90vh] overflow-y-auto min-w-[850px]"+ className="max-h-screen sm:max-h-[90vh] overflow-y-auto sm:max-w-[850px]">- <DialogTitle>Shortcuts</DialogTitle>+ <DialogHeader>+ <DialogTitle>Shortcuts</DialogTitle>+ </DialogHeader><div className="flex flex-row gap-3"><div className="w-1/2">{renderGroup("Editing")}diff --git a/frontend/src/components/editor/notebook-menu-dropdown.tsx b/frontend/src/components/editor/controls/notebook-menu-dropdown.tsxsimilarity index 93%rename from frontend/src/components/editor/notebook-menu-dropdown.tsxrename to frontend/src/components/editor/controls/notebook-menu-dropdown.tsxindex d5d97feb3f..7f210005bd 100644--- a/frontend/src/components/editor/notebook-menu-dropdown.tsx+++ b/frontend/src/components/editor/controls/notebook-menu-dropdown.tsx@@ -13,9 +13,9 @@ import {DropdownMenuSubTrigger,DropdownMenuTrigger,} from "@/components/ui/dropdown-menu";-import { renderMinimalShortcut } from "../shortcuts/renderShortcut";-import { useNotebookActions } from "./actions/useNotebookActions";-import { ActionButton } from "./actions/types";+import { renderMinimalShortcut } from "../../shortcuts/renderShortcut";+import { useNotebookActions } from "../actions/useNotebookActions";+import { ActionButton } from "../actions/types";export const NotebookMenuDropdown: React.FC = () => {const actions = useNotebookActions();diff --git a/frontend/src/components/editor/ShutdownButton.tsx b/frontend/src/components/editor/controls/shutdown-button.tsxsimilarity index 77%rename from frontend/src/components/editor/ShutdownButton.tsxrename to frontend/src/components/editor/controls/shutdown-button.tsxindex abf478e8bf..6839e193c8 100644--- a/frontend/src/components/editor/ShutdownButton.tsx+++ b/frontend/src/components/editor/controls/shutdown-button.tsx@@ -1,18 +1,16 @@/* Copyright 2024 Marimo. All rights reserved. */-import { AlertDialogDestructiveAction } from "../ui/alert-dialog";-import { Button } from "./inputs/Inputs";-import { Tooltip } from "../ui/tooltip";-import { useImperativeModal } from "../modal/ImperativeModal";+import { AlertDialogDestructiveAction } from "../../ui/alert-dialog";+import { Button } from "../inputs/Inputs";+import { Tooltip } from "../../ui/tooltip";+import { useImperativeModal } from "../../modal/ImperativeModal";import { XIcon } from "lucide-react";-interface ShutdownButtonProps {+interface Props {onShutdown: (e: React.MouseEvent<HTMLButtonElement>) => void;}-export const ShutdownButton = ({- onShutdown,-}: ShutdownButtonProps): JSX.Element => {+export const ShutdownButton: React.FC<Props> = ({ onShutdown }) => {const { openConfirm, closeModal } = useImperativeModal();return (diff --git a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsxindex 40c268d45c..f29dac1d36 100644--- a/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx+++ b/frontend/src/components/editor/renderers/vertical-layout/vertical-layout-wrapper.tsx@@ -16,7 +16,7 @@ export const VerticalLayoutWrapper: React.FC<PropsWithChildren<Props>> = ({children,}) => {return (- <div className={cn("sm:px-16 md:px-32", className)}>+ <div className={cn("px-1 sm:px-16 md:px-32", className)}><divclassName={cn(// Large mobile bottom padding due to mobile browser navigation bardiff --git a/frontend/src/components/indicator.tsx b/frontend/src/components/indicator.tsxnew file mode 100644index 0000000000..69c0f159cb--- /dev/null+++ b/frontend/src/components/indicator.tsx@@ -0,0 +1,19 @@+/* Copyright 2024 Marimo. All rights reserved. */+export const TailwindIndicator = () => {+ if (process.env.NODE_ENV === "production") {+ return null;+ }++ return (+ <div className="fixed bottom-2 right-3 z-50 flex size-5 items-center justify-center rounded-lg bg-gray-800 py-3 px-4 font-mono text-xs text-white">+ <div className="block sm:hidden">xs</div>+ <div className="hidden sm:block md:hidden lg:hidden xl:hidden 2xl:hidden">+ sm+ </div>+ <div className="hidden md:block lg:hidden xl:hidden 2xl:hidden">md</div>+ <div className="hidden lg:block xl:hidden 2xl:hidden">lg</div>+ <div className="hidden xl:block 2xl:hidden">xl</div>+ <div className="hidden 2xl:block">2xl</div>+ </div>+ );+};diff --git a/frontend/src/core/App.tsx b/frontend/src/core/App.tsxindex 50cd848b93..ea113e7c51 100644--- a/frontend/src/core/App.tsx+++ b/frontend/src/core/App.tsx@@ -11,7 +11,7 @@ import {sendShutdown,} from "@/core/network/requests";-import { Controls } from "@/components/editor/Controls";+import { Controls } from "@/components/editor/controls/Controls";import { DirCompletionInput } from "@/components/editor/DirCompletionInput";import { FilenameForm } from "@/components/editor/FilenameForm";import { WebSocketState } from "./websocket/types";diff --git a/frontend/src/core/MarimoApp.tsx b/frontend/src/core/MarimoApp.tsxindex 2c43b199c8..768e75a3f5 100644--- a/frontend/src/core/MarimoApp.tsx+++ b/frontend/src/core/MarimoApp.tsx@@ -10,7 +10,7 @@ import { TooltipProvider } from "../components/ui/tooltip";import { Toaster } from "../components/ui/toaster";import { ModalProvider } from "../components/modal/ImperativeModal";import { DayPickerProvider } from "react-day-picker";-import { CommandPalette } from "../components/editor/CommandPalette";+import { CommandPalette } from "../components/editor/controls/command-palette";import { useAppConfig, useUserConfig } from "@/core/config/config";import { initialMode } from "./mode";import { AppChrome } from "../components/editor/chrome/wrapper/app-chrome";@@ -20,6 +20,7 @@ import { useAsyncData } from "@/hooks/useAsyncData";import { isPyodide } from "./pyodide/utils";import { PyodideBridge } from "./pyodide/bridge";import { LargeSpinner } from "@/components/icons/large-spinner";+import { TailwindIndicator } from "@/components/indicator";/*** The root component of the Marimo app.@@ -62,6 +63,7 @@ export const MarimoApp: React.FC = memo(() => {>{body}</CssVariables>+ <TailwindIndicator /></ModalProvider></PyodideLoader></DayPickerProvider>diff --git a/frontend/src/core/codemirror/cm.ts b/frontend/src/core/codemirror/cm.tsindex 911c571af6..82361a9cc1 100644--- a/frontend/src/core/codemirror/cm.ts+++ b/frontend/src/core/codemirror/cm.ts@@ -112,6 +112,9 @@ export const basicBundle = (// Having fixed position prevents tooltips from being repositioned// and bouncing distractinglyposition: "fixed",+ // This the z-index multiple tooltips being stacked+ // For example, if we have a hover tooltip and a completion tooltip+ parent: document.querySelector<HTMLElement>("#App") ?? undefined,}),scrollActiveLineIntoView(),theme === "dark" ? oneDark : [],diff --git a/frontend/src/css/Header.css b/frontend/src/css/Header.cssindex 94e30b8e65..c1e89f8c12 100644--- a/frontend/src/css/Header.css+++ b/frontend/src/css/Header.css@@ -60,7 +60,6 @@/* [shortcut] [auto:whitespace] [description] */grid-template-columns: 1fr auto 1fr;display: grid;- margin: 15px 5px;align-items: baseline;}diff --git a/frontend/src/css/common.css b/frontend/src/css/common.cssindex 4b439dde61..9604e78d39 100644--- a/frontend/src/css/common.css+++ b/frontend/src/css/common.css@@ -1,6 +1,10 @@/* Hover actions */-.hover-action {- display: none !important;++/* Ignore for touch devices */+@media (hover: hover) and (pointer: fine) {+ .hover-action {+ display: none !important;+ }}.hover-action:hover {diff --git a/frontend/tailwind.config.js b/frontend/tailwind.config.jsindex 1e30e91340..9706210330 100644--- a/frontend/tailwind.config.js+++ b/frontend/tailwind.config.js@@ -1,6 +1,7 @@/* Copyright 2024 Marimo. All rights reserved. */const plugin = require("tailwindcss/plugin");+const { fontFamily } = require("tailwindcss/defaultTheme");/** @type {import('tailwindcss').Config} */module.exports = {@@ -96,8 +97,9 @@ module.exports = {},},fontFamily: {- prose: "var(--text-font)",- code: "var(--monospace-font)",+ prose: ["var(--text-font)", ...fontFamily.sans],+ code: ["var(--monospace-font)", ...fontFamily.mono],+ heading: ["var(--heading-font)", ...fontFamily.sans],},borderRadius: {lg: "var(--radius)",