import type { BookElement, BookPageNumbers, BookPageSetup, BookShapeId, JourneyStats } from '@trek/shared' import { AlignCenter, AlignJustify, AlignLeft, AlignRight, ArrowDown, ArrowUp, ChevronsDown, ChevronsUp, ClipboardCopy, Copy, Italic, Lock, Trash2, Unlock, } from 'lucide-react' import { useMemo, useRef, useState } from 'react' import { useStudioStore } from '../../store/studioStore' import { photoSrc } from './bookRender' import { FRAME_SHAPES, SHAPE_GROUPS } from './shapes' import { ShapeGlyph } from './StudioElementsPanel' import { TravelInspector } from './StudioTravelInspector' import { Swatches } from './StudioSwatches' import { formatBookCoords } from '@trek/shared' import { iconComponent, iconLabel, searchIcons } from './iconLibrary' import { Choice, Line, NumField, Section, Switch } from './StudioControls' import { StudioFontPicker } from './StudioFontPicker' import { WeightLine } from './StudioTypeControls' import { italicTitle } from './fontPicker' import type { JourneySource } from './StudioSidebar' import { Tooltip } from '../shared/Tooltip' /** How many icons the swap grid offers at once. A search narrows it below this. */ const ICON_CHOICES = 60 /** * 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: **what it says** first, then **how it looks**, * then **where it sits**, then **what is in front of what**. A photo's crop and * a mark's words are the same step in that sequence, so they sit in the same * place on the panel. * * The frame's numbers are folded away by default. They are the least-used group * in the panel — dragging is how anyone actually positions an element — and * four number fields left open at the top pushed everything worth looking at * below the fold. * * ── What is not here any more ──────────────────────────────────────────── * * Duplicate, lock and delete are in the panel head rather than in a section of * their own: they act on the element rather than describing it, and a group * called "Arrange" that held two of those next to the stacking buttons was the * one group in the panel whose name did not say what was inside it. */ export function StudioInspector({ spreadIndex, page, stats, path, source, setPageNumbers, t, locale, }: { 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 }) { const [iconQuery, setIconQuery] = useState('') /* * A page of results, memoised because the inspector re-renders on every * pointer move of a drag and the library is fourteen hundred names long. */ const iconChoices = useMemo(() => searchIcons(iconQuery).slice(0, ICON_CHOICES), [iconQuery]) 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 raise = useStudioStore(s => s.raise) const duplicate = useStudioStore(s => s.duplicate) const copy = useStudioStore(s => s.copy) const removeElements = useStudioStore(s => s.removeElements) const spread = doc?.spreads[spreadIndex] const sel = spread?.elements.filter(e => selection.includes(e.id)) ?? [] if (!sel.length) { /* * Nothing selected, so this is where the *book's* own settings belong. * The panel was showing one line of hint text and nothing else, and page * numbers have nowhere else to go: they are not a property of any element, * because the number a page carries depends on where its spread sits. */ const folios = page.pageNumbers return ( ) } const el = sel[0] const one = sel.length === 1 // A property edit is one undo step on its own; only drags open a gesture. const set = (patch: Partial) => commit(d => ({ ...d, spreads: d.spreads.map((sp, i) => (i !== spreadIndex ? sp : { ...sp, elements: sp.elements.map(e => (selection.includes(e.id) ? ({ ...e, ...patch } as BookElement) : e)), })), })) const live = (patch: Partial) => update(spreadIndex, el.id, patch) /** * Stretch the picture over the page it is on, or over both pages, bleed * included. * * One commit rather than `set` followed by `raise`: the frame, the rotation * put back to zero (a turned picture leaves bare corners), the cover crop and * the move to the back are one press, and one press comes back with one * undo. Which page is the one under the frame's centre; a cover has only * the one. */ const fill = (scope: 'page' | 'spread') => commit(d => ({ ...d, spreads: d.spreads.map((sp, i) => { if (i !== spreadIndex) return sp const bleed = page.bleed const onRight = sp.role === 'inner' && scope === 'page' && el.frame.x + el.frame.w / 2 >= page.pageWidth const frame = { x: onRight ? page.pageWidth - bleed : -bleed, y: -bleed, w: (scope === 'spread' ? 2 : 1) * page.pageWidth + 2 * bleed, h: page.pageHeight + 2 * bleed, } const filled = { ...el, frame, rotation: 0, fit: 'cover' } as BookElement return { ...sp, elements: [filled, ...sp.elements.filter(e => e.id !== el.id)] } }), })) return (