import type { BookElement, BookPageNumbers, BookPageSetup, BookSpread, JourneyStats } from '@trek/shared' import { withThemeLinks } from '@trek/shared' import { ClipboardCopy, Copy, Lock, Trash2, Unlock } from 'lucide-react' import type { ReactNode } from 'react' import { useStudioStore } from '../../store/studioStore' import { Tooltip } from '../shared/Tooltip' import '../../styles/studio-panels.css' import { PanelHead } from './StudioPanelHead' import { selectionTitle } from './studioLayerRows' import { StudioArrangeSection } from './StudioArrangeSection' import { TravelInspector } from './StudioTravelInspector' import { StudioStickerInspector } from './StudioStickerInspector' import { LineInspector } from './StudioLineInspector' import { StudioDocumentInspector } from './inspector/StudioDocumentInspector' import { StudioPositionSection } from './inspector/StudioPositionSection' import { StudioTextInspector } from './inspector/StudioTextInspector' import { StudioPhotoInspector } from './inspector/StudioPhotoInspector' import { StudioShapeInspector } from './inspector/StudioShapeInspector' import { StudioIconInspector } from './inspector/StudioIconInspector' import { selectionKey } from './inspector/inspectorModel' import type { RailSection } from './sidebar/railSections' import type { JourneySource } from './StudioSidebar' /** * Properties of whatever is selected. * * ── What it shows, and in what order ───────────────────────────────────── * * Deliberately narrow: what the selected thing actually has, and nothing else. * A panel that lists every property of every element with most of them greyed * out reads as a settings dialog, not as a tool. * * The order is the same for every kind, because the panel is used by muscle * memory more than by reading: * * 1. **what it is and what it says**: a text's words, a photo's crop, a * shape's outline, a sticker's colours, a map's scope and framing; * 2. **where it sits**: the position and size, folded unless the element is * turned or faded (or is a sticker, which is turned as a matter of course), * and for several at once their angle and opacity without the frame; * 3. **how it looks**: type, colour, fill, frame; * 4. **the effects**: folded, and open on an element that uses them; * 5. **arrange**: lining up, stacking, grouping, the style clipboard. * * Every group mounts afresh for each selection (inspector/inspectorModel.ts), * so a folded group opens for the element that uses it and closes again for * the next one, and nothing is remembered behind the person's back. * * Duplicate, lock and delete are in the panel head rather than in a group of * their own: they act on the element rather than describing it. */ type Set = (patch: Partial) => void export function StudioInspector({ spreadIndex, page, stats, path, source, setPageNumbers, t, locale, onOpenPanel, }: { spreadIndex: number page: BookPageSetup setPageNumbers: (patch: Partial) => void /** Live journey figures, so a travel element can be brought up to date. */ stats: JourneyStats | null /** The journey's recorded way, thinned, so a map of the whole journey can be given it again. */ path: [number, number][][] /** The journal itself, so a bound mark can be re-set from it. */ source: JourneySource t: (k: string) => string locale: string /** Opens a panel of the rail on the other side: the Theme panel, or the Layers panel beside the selection. */ onOpenPanel?: (section: RailSection) => void }) { const doc = useStudioStore(s => s.doc) const selection = useStudioStore(s => s.selection) const update = useStudioStore(s => s.updateElement) const commit = useStudioStore(s => s.commit) const spread = doc?.spreads[spreadIndex] const sel = spread?.elements.filter(e => selection.includes(e.id)) ?? [] const el = sel[0] if (!el) { return ( onOpenPanel('theme'))} t={t} /> ) } const one = sel.length === 1 // A property edit is one undo step on its own; only drags open a gesture. const set: Set = patch => commit(d => ({ ...d, spreads: d.spreads.map((sp, i) => (i !== spreadIndex ? sp : { ...sp, // A colour or face set by hand stops following the theme; a link set here takes the theme's value. elements: sp.elements.map(e => (selection.includes(e.id) ? withThemeLinks({ ...e, ...patch } as BookElement, patch, d.theme) : e)), })), })) const live: Set = patch => update(spreadIndex, el.id, patch) return ( ) } /** Copy to another page, duplicate, lock and delete: what you do to the selection, in the head. */ function SelectionActions({ spreadIndex, el, selection, set, t }: { spreadIndex: number el: BookElement selection: string[] set: Set t: (k: string) => string }) { const duplicate = useStudioStore(s => s.duplicate) const copy = useStudioStore(s => s.copy) const removeElements = useStudioStore(s => s.removeElements) const lockLabel = t(el.locked ? 'journey.studio.unlock' : 'journey.studio.lock') return ( <> ) } /** The groups of the selected kind, each placing the position group after what the element is. */ function KindInspector({ el, one, spreadIndex, spread, page, selection, stats, path, source, set, live, position, t, locale }: { el: BookElement one: boolean spreadIndex: number spread: BookSpread | undefined page: BookPageSetup selection: string[] stats: JourneyStats | null path: [number, number][][] source: JourneySource set: Set live: Set position: ReactNode t: (k: string) => string locale: string }) { const theme = useStudioStore(s => s.doc?.theme) switch (el.kind) { case 'text': return ( ) case 'photo': return ( ) case 'shape': return ( ) case 'icon': return case 'sticker': return case 'line': return case 'map': case 'stats': case 'countries': case 'badge': case 'list': return default: return <>{position} } }