import type { BookPageNumbers, BookPageSetup } from '@trek/shared'; import { BOOK_THEME_PRESETS } from '@trek/shared'; import { MousePointerClick, Palette } from 'lucide-react'; import { useStudioStore } from '../../../store/studioStore'; import '../../../styles/studio-panels.css'; import { StudioBackgroundSection } from '../StudioBackgroundSection'; import { Choice, Line, NumField, Section, Switch } from '../StudioControls'; import { PanelHead } from '../StudioPanelHead'; import type { JourneySource, StudioT } from '../StudioSidebar'; import { Swatches } from '../StudioSwatches'; import { ThemeSheet } from '../theme/ThemeSheet'; /** * The inspector with nothing selected: the page and the book. * * What the panel is for comes first, in a line at its top, since an empty * inspector is the first thing a new book shows. Then the page that is open, * its background; the book's theme, as the Theme panel draws it, with the way * to that panel; and the page numbers, which are no property of any element, * because the number a page carries depends on where its spread sits. The page * size sits in the head. */ type Folio = BookPageNumbers['position']; const FOLIO_POSITIONS: readonly Folio[] = ['outer', 'inner', 'centre']; /** The book's theme as a little page and its name, and the button to the Theme panel. */ function ThemeSummary({ t, onOpenTheme }: { t: StudioT; onOpenTheme?: () => void }) { const theme = useStudioStore((s) => s.doc?.theme); const preset = theme?.id ? BOOK_THEME_PRESETS.find((p) => p.id === theme.id) : undefined; return (
{theme ? (
{preset && {t(preset.labelKey)}}
) : (

{t('studio.theme.intro')}

)} {onOpenTheme && ( )}
); } /** Whether the pages carry numbers, and where, from which number, how large, in what colour. */ function PageNumbersSection({ folios, setPageNumbers, t, }: { folios: BookPageNumbers; setPageNumbers: (patch: Partial) => void; t: StudioT; }) { return (
setPageNumbers({ show: !folios.show })} /> {folios.show && ( <>
({ value: pos, label: t(`journey.studio.folio.${pos}`) }))} onPick={(position) => setPageNumbers({ position })} />
setPageNumbers({ startAt: Math.round(v) })} /> setPageNumbers({ size: v })} />
setPageNumbers({ margin: v })} />
setPageNumbers({ autoColor: !folios.autoColor })} />
{/* Picking a colour is the other way to turn automatic off, so the row stays reachable and simply reads as inactive. */}
setPageNumbers({ color: c, autoColor: false })} />
)}
); } export function StudioDocumentInspector({ spreadIndex, page, source, setPageNumbers, onOpenTheme, t, }: { spreadIndex: number; page: BookPageSetup; source: JourneySource; setPageNumbers: (patch: Partial) => void; /** Opens the Theme panel in the rail; without it the summary offers no button. */ onOpenTheme?: () => void; t: StudioT; }) { return ( ); }