mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-21 19:40:34 +00:00
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.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { bookElementId, spreadPaint, withSpreadPaint, type BookPageSetup } from '@trek/shared';
|
||||
import { bookElementId, spreadPaint, withSpreadPaintByHand, type BookPageSetup } from '@trek/shared';
|
||||
import { Check, CopyCheck, ImageOff } from 'lucide-react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useStudioStore } from '../../store/studioStore';
|
||||
@@ -37,9 +37,10 @@ export function StudioBackgroundSection({
|
||||
}) {
|
||||
const spread = useStudioStore((s) => s.doc?.spreads[spreadIndex]);
|
||||
const commit = useStudioStore((s) => s.commit);
|
||||
// A colour picked here is the person's, so the page stops following the theme's paper (as the assistant's does).
|
||||
const channel = usePaintChannel((paint) => (doc) => ({
|
||||
...doc,
|
||||
spreads: doc.spreads.map((sp, i) => (i === spreadIndex ? withSpreadPaint(sp, paint) : sp)),
|
||||
spreads: doc.spreads.map((sp, i) => (i === spreadIndex ? withSpreadPaintByHand(sp, paint) : sp)),
|
||||
}));
|
||||
|
||||
// "Applied" stands in the button for a moment, so a press that changed pages out of sight is seen to have worked.
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { BookElement, BookPageSetup, BookPhotoElement, BookSpread } from '@trek/shared';
|
||||
import { tidyGroups, withoutGroup } from '@trek/shared';
|
||||
import type { ReactNode } from 'react';
|
||||
|
||||
import { useStudioStore } from '../../../store/studioStore';
|
||||
@@ -44,8 +45,9 @@ function filled(sp: BookSpread, el: BookPhotoElement, page: BookPageSetup, scope
|
||||
w: (scope === 'spread' ? 2 : 1) * page.pageWidth + 2 * bleed,
|
||||
h: page.pageHeight + 2 * bleed,
|
||||
};
|
||||
const photo = { ...el, frame, rotation: 0, fit: 'cover' } as BookElement;
|
||||
return { ...sp, elements: [photo, ...sp.elements.filter((e) => e.id !== el.id)] };
|
||||
// A picture that is the page is nobody's lockup: it leaves its group, as the assistant's fill takes it out.
|
||||
const photo = { ...withoutGroup(el), frame, rotation: 0, fit: 'cover' } as BookElement;
|
||||
return tidyGroups({ ...sp, elements: [photo, ...sp.elements.filter((e) => e.id !== el.id)] });
|
||||
}
|
||||
|
||||
export function StudioPhotoInspector({
|
||||
|
||||
@@ -2,7 +2,7 @@ import {
|
||||
MAX_SPREAD_ELEMENTS,
|
||||
bookPhotoElementSchema,
|
||||
spreadPaint,
|
||||
withSpreadPaint,
|
||||
withSpreadPaintByHand,
|
||||
type BookDocument,
|
||||
type BookElement,
|
||||
type BookPageSetup,
|
||||
@@ -77,20 +77,27 @@ export function withoutBackgroundPhoto(spread: BookSpread, page: BookPageSetup):
|
||||
const isCover = (spread: BookSpread) => spread.role === 'cover' || spread.role === 'back';
|
||||
|
||||
/**
|
||||
* Every page given the background of page `from`: its paint and colour,
|
||||
* nothing else. "Every page" is every page of its kind: an inside page
|
||||
* gives its background to the inside of the book, a cover to the covers,
|
||||
* since a cover is designed on its own and an inside page's paper is rarely
|
||||
* what the cover wants.
|
||||
* Every page given the background of page `from`: its paint and colour, and
|
||||
* whether it follows the theme, nothing else. "Every page" is every page of
|
||||
* its kind: an inside page gives its background to the inside of the book, a
|
||||
* cover to the covers, since a cover is designed on its own and an inside
|
||||
* page's paper is rarely what the cover wants. A page that follows the
|
||||
* theme's paper gives that link along; one painted by hand takes the others'
|
||||
* away, so the next theme applied leaves them all as they were made.
|
||||
*/
|
||||
export function backgroundToAll(doc: BookDocument, from: number): BookDocument {
|
||||
const source = doc.spreads[from];
|
||||
if (!source) return doc;
|
||||
const paint = spreadPaint(source);
|
||||
const kind = isCover(source);
|
||||
const link = source.backgroundToken;
|
||||
const given = (sp: BookSpread): BookSpread => {
|
||||
const painted = withSpreadPaintByHand(sp, paint);
|
||||
return link ? { ...painted, backgroundToken: link } : painted;
|
||||
};
|
||||
return {
|
||||
...doc,
|
||||
spreads: doc.spreads.map((sp, i) => (i === from || isCover(sp) !== kind ? sp : withSpreadPaint(sp, paint))),
|
||||
spreads: doc.spreads.map((sp, i) => (i === from || isCover(sp) !== kind ? sp : given(sp))),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -145,4 +145,35 @@ describe('the Templates panel', () => {
|
||||
fireEvent.click(screen.getByText('journey.studio.tpl.grid4'));
|
||||
expect(spreadOf(1)?.elements.filter((e) => e.kind === 'photo')).toHaveLength(4);
|
||||
});
|
||||
|
||||
it('leaves what is locked where it is, as the assistant does, and lays out the rest', () => {
|
||||
const locked = normalizeBookDocument({
|
||||
...book(),
|
||||
spreads: [
|
||||
book().spreads[0],
|
||||
{
|
||||
id: 'sp-in',
|
||||
role: 'inner',
|
||||
background: null,
|
||||
entryId: 4,
|
||||
parked: [],
|
||||
elements: [
|
||||
{ id: 'panel', kind: 'shape', frame: { x: 0, y: 150, w: 420, h: 60 }, locked: true },
|
||||
{ id: 'free', kind: 'photo', frame: { x: 230, y: 20, w: 60, h: 60 }, photoId: 8 },
|
||||
{ id: 'kept', kind: 'photo', frame: { x: 10, y: 20, w: 60, h: 60 }, photoId: 9, locked: true },
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
useStudioStore.getState().load(locked);
|
||||
useStudioStore.getState().setActiveSpread(1);
|
||||
panel();
|
||||
fireEvent.click(screen.getByText('journey.studio.tpl.grid4'));
|
||||
const after = spreadOf(1)?.elements ?? [];
|
||||
expect(after[0]).toEqual(locked.spreads[1]?.elements[0]);
|
||||
expect(after.find((e) => e.id === 'kept')).toEqual(locked.spreads[1]?.elements[2]);
|
||||
const poured = after.filter((e) => e.kind === 'photo' && !e.locked);
|
||||
expect(poured).toHaveLength(4);
|
||||
expect(poured.map((e) => (e.kind === 'photo' ? e.photoId : null))).toContain(8);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ import type { BookDecoratedTemplate, BookPageSetup, BookSpread, BookTemplate, Jo
|
||||
import {
|
||||
applyBookTemplate as applyTemplate,
|
||||
BOOK_COVER_TEMPLATES as COVER_TEMPLATES,
|
||||
layoutAroundLocks,
|
||||
BOOK_TEMPLATES as TEMPLATES,
|
||||
} from '@trek/shared';
|
||||
import { memo, useDeferredValue, useMemo, useState } from 'react';
|
||||
@@ -208,8 +209,11 @@ export function StudioTemplatesPanel({
|
||||
? layTemplate(sp, tpl, page, { ...ctx, words: studioTemplateWords(title, sp, source, locale) })
|
||||
: null
|
||||
);
|
||||
// A built-in layout arranges what is not locked, as the assistant's does; a decorated one keeps locks itself.
|
||||
const pickBuiltIn = (tpl: BookTemplate) =>
|
||||
lay((sp) => (pageKind(sp) === (tpl.role ?? 'inner') ? applyTemplate(sp, tpl, page) : null));
|
||||
lay((sp) =>
|
||||
pageKind(sp) === (tpl.role ?? 'inner') ? layoutAroundLocks(sp, (free) => applyTemplate(free, tpl, page)) : null
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
Reference in New Issue
Block a user