Files
TREK/shared/src/book/book-layout-locks.ts
T
Maurice 84e18e4954 fix(studio): paste style, the page background, layouts and fill page keep the engine's rules
Paste style wrote the copied fields straight onto the element, although a
pasted look is meant to be the style operation the assistant sends. It now
runs the engine's own restyle (bookElementStyled): a colour or face pasted by
hand takes the element off the theme, so the next theme applied no longer
brings the old colour back; a plain fill replaces the paint of the shape it
lands on instead of staying hidden under it; and a line takes another line's
look without its points, which are its course, not its look.

A background picked by hand in the inspector kept the page's link to the
theme, so the next theme applied set the page back to the theme's colour. The
picker and the background operation now paint through one helper that takes
the link away (withSpreadPaintByHand). Giving one page's background to every
page carries that page's link along, or takes the others' away when it was
painted by hand.

A built-in layout, a book's own layout and laying a page out again from its
entry ignored locks in the Studio: a locked shape was dropped and a locked
photo poured into a slot unlocked, while the assistant's layout operation left
both where they were. All four now lay a page out around its locked elements
through one function (layoutAroundLocks), which the engine's layout operation
uses too.

Fill page and fill spread kept the photo in its group, so the background
picture was selected and dragged with its caption and listed under the group
at the front. It leaves its group as the engine's fill does, and a group left
with one member goes.
2026-10-24 04:06:27 +00:00

28 lines
1.5 KiB
TypeScript

import { MAX_SPREAD_ELEMENTS, type BookSpread } from './book.schema';
/**
* A page laid out again around its locked elements.
*
* A lock protects a finished part of a page while the rest is reworked, so a
* layout arranges only what is not locked: every locked element stays where
* it is, at its place in the paint order, and a locked group keeps its name
* through a layout that writes the page's groups anew. One rule for the
* assistant's `layout` operation and for the Studio's layouts, so a lock holds
* whichever of them lays the page out.
*
* `lay` gets the page without its locked elements and answers it laid out,
* or null when it lays nothing. The answer is null too when the layout and
* the locked elements together would not fit on one page.
*/
export function layoutAroundLocks(spread: BookSpread, lay: (free: BookSpread) => BookSpread | null): BookSpread | null {
const locked = spread.elements.flatMap((el, i) => (el.locked ? [{ el, i }] : []));
const next = lay({ ...spread, elements: spread.elements.filter((e) => !e.locked) });
if (!next) return null;
const elements = next.elements.slice();
for (const { el, i } of locked) elements.splice(Math.min(i, elements.length), 0, el);
if (elements.length > MAX_SPREAD_ELEMENTS) return null;
const have = new Set((next.groups ?? []).map((g) => g.id));
const lost = (spread.groups ?? []).filter((g) => !have.has(g.id) && locked.some(({ el }) => el.group === g.id));
return { ...next, elements, ...(lost.length ? { groups: [...(next.groups ?? []), ...lost] } : {}) };
}