diff --git a/src/controller.ts b/src/controller.ts index be5c088..1c5ebb1 100644 --- a/src/controller.ts +++ b/src/controller.ts @@ -408,6 +408,7 @@ export class Controller { if (dialogs.length) this.closeDialog(dialogs.reduce((top, x) => (x.z > top.z ? x : top)).key) else if (this.inlineSession) this.stopInline() else if (this.store.get().selected) this.select(null) + else if (this.store.get().rail) this.setRail(false) else return e.preventDefault() return diff --git a/src/persist.ts b/src/persist.ts index 12c17c1..c31e346 100644 --- a/src/persist.ts +++ b/src/persist.ts @@ -1,12 +1,21 @@ -// Remembering small UI preferences across reloads (rail open, section -// collapsed). Editors reload the page constantly to preview; losing the -// panel state every time is the papercut this removes. All access is +// Remembering small UI preferences across reloads (rail open/width, section +// collapsed, dev tab). Editors reload the page constantly to preview; losing +// the panel state every time is the papercut this removes. All access is // guarded: private mode, sandboxed iframes and some embeds throw. export function readPersist(key: string, fallback: T): T { try { const raw = localStorage.getItem(key) if (raw === null) return fallback - return (typeof fallback === 'boolean' ? raw === 'true' : JSON.parse(raw)) as T + if (typeof fallback === 'boolean') return (raw === 'true') as T + if (typeof fallback === 'number') { + const n = Number(raw) + return (Number.isFinite(n) ? n : fallback) as T + } + try { + return JSON.parse(raw) as T + } catch { + return (typeof fallback === 'string' ? raw : fallback) as T + } } catch { return fallback } diff --git a/src/ui/DevPanel.tsx b/src/ui/DevPanel.tsx index d3237b3..09b5800 100644 --- a/src/ui/DevPanel.tsx +++ b/src/ui/DevPanel.tsx @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react' import type { CmsNode, JSONSchema } from '../api' import { blockEditors, fieldEditors, inlineEditors } from '../registry' import { Icon } from './Icon' -import { useCtrl, useEditorState, useRegistryVersion } from './hooks' +import { useCtrl, useEditorState, usePersistentState, useRegistryVersion } from './hooks' type Tab = 'requests' | 'selection' | 'registry' @@ -10,7 +10,8 @@ type Tab = 'requests' | 'selection' | 'registry' export function DevPanel() { const ctrl = useCtrl() const open = useEditorState((s) => s.dev) - const [tab, setTab] = useState('requests') + const [saved, setTab] = usePersistentState('cms-onpage.devtab', 'requests') + const tab: Tab = saved === 'selection' || saved === 'registry' ? saved : 'requests' if (!open) return null return (