/* Copyright 2026 Marimo. All rights reserved. */ import type { WritableAtom } from "jotai"; import { atomWithStorage } from "jotai/utils"; import { store } from "@/core/state/jotai"; import { jotaiJsonStorage } from "@/utils/storage/jotai"; export type SessionPanelSection = "variables" | "datasources"; export type FileExplorerPanelSection = "files" | "remote-storage"; export interface PanelAccordionState
{ openSections: Section[]; hasUserInteracted: boolean; } export const sessionPanelAtom = atomWithStorage< PanelAccordionState >( "marimo:session-panel:state", { openSections: ["variables"], hasUserInteracted: false }, jotaiJsonStorage, { getOnInit: true }, ); export const fileExplorerPanelAtom = atomWithStorage< PanelAccordionState >( "marimo:file-explorer-panel:state", { openSections: ["files"], hasUserInteracted: false }, jotaiJsonStorage, { getOnInit: true }, ); /** * Expand an accordion section without collapsing others. Leaves * `hasUserInteracted` untouched so auto-open heuristics are unaffected. */ export function expandAccordionSection
( panelAtom: WritableAtom< PanelAccordionState
, [(prev: PanelAccordionState
) => PanelAccordionState
], void >, section: Section, ): void { store.set(panelAtom, (prev) => prev.openSections.includes(section) ? prev : { ...prev, openSections: [...prev.openSections, section] }, ); }