book: stop layer-creation paths from bouncing book mode to cover

Adding a text layer on a book page kicked templateMode back to
'cover' and rendered the DVD case panels behind the book editor.
Three layer-creation helpers didn't know about book-* targets:

- applyTargetMode(target): the trailing else set templateMode =
  'cover' for anything it didn't recognise. Book targets
  (book-page:<id>, book-master:<id>, book-cover-*, book-spine)
  now keep templateMode = 'book'.
- targetBounds(target): the switch fell through to sheetW/sheetH
  for book targets, returning the wrong rectangle. Added a
  book-* branch that returns the page's trim rect (inset by
  bleed) for pages + masters, and the per-panel slice of the
  spread for cover panels.
- updateLayerTargetOptions(): the #layerTarget <select> had no
  option for the active book page. Book mode now renders a single
  "Current book page" option keyed to the entry-qualified target;
  if no page is open, a "No page open" stub keeps the select from
  appearing broken.

Net effect: hit T, click on the page, type text — the layer lands
on the right page, the canvas stays on the book page, and the
sidebar target dropdown shows the right surface.
This commit is contained in:
thePR0M3TH3AN committed 2026-06-02 14:55:42 -04:00
1 parent 70b270748e
commit 01ecb8a85b
1 file changed
+35 -2
+35 -2
View File
@@ -13553,9 +13553,25 @@
return jewel('front');
case 'jewel-tray':
return jewel('tray');
default:
return { x: 0, y: 0, w: sheetW(), h: sheetH() };
}
// Book-mode targets (entry-id qualified): `book-page:<id>`,
// `book-master:<id>`, `book-cover-{front,back,spine}`. Each
// page is a trim-sized artboard with bleed on all sides; the
// cover panels return their slice of the spread.
if (typeof target === 'string' && target.startsWith('book-')) {
const s = state.book?.spec || defaultBookSpec();
const trimW = Number(s.trimW) || 0;
const trimH = Number(s.trimH) || 0;
const bleed = Number(s.bleed) || 0;
const spineW = bookSpineWidthInches();
if (target.startsWith('book-page:') || target.startsWith('book-master:')) {
return { x: bleed, y: bleed, w: trimW, h: trimH };
}
if (target === 'book-cover-back') return { x: bleed, y: bleed, w: trimW, h: trimH };
if (target === 'book-spine') return { x: bleed + trimW, y: bleed, w: spineW, h: trimH };
if (target === 'book-cover-front') return { x: bleed + trimW + spineW, y: bleed, w: trimW, h: trimH };
}
return { x: 0, y: 0, w: sheetW(), h: sheetH() };
}
function applyTargetMode(target) {
@@ -13568,6 +13584,11 @@
// 'canvas' layers belong to both Custom Art and Slide — don't flip a
// slide back to custom art just because a layer was added.
if (!isCanvasMode(state.templateMode)) state.templateMode = 'customart';
} else if (typeof target === 'string' && target.startsWith('book-')) {
// Book-mode surfaces (`book-page:<id>`, `book-master:<id>`,
// `book-cover-*`, `book-spine`). Stay in book mode; don't
// bounce to cover just because a new layer was added.
state.templateMode = 'book';
} else if (target.startsWith('disc')) {
state.templateMode = 'disc';
} else if (target.startsWith('jewel')) {
@@ -28940,6 +28961,18 @@
`;
} else if (isCanvasMode(state.templateMode)) {
select.innerHTML = `<option value="canvas">Canvas</option>`;
} else if (state.templateMode === 'book') {
// Book mode: the only target a new layer should land on is
// the currently-open page (Phase B). Other surfaces (cover,
// masters) get their own routes in A5/C/D1. If no page is
// open, fall back to a stub so the layers panel doesn't
// appear broken.
const editId = state.book?.editingEntryId;
if (editId) {
select.innerHTML = `<option value="book-page:${editId}">Current book page</option>`;
} else {
select.innerHTML = `<option value="page">No page open</option>`;
}
} else {
select.innerHTML = `
<option value="page">Whole page</option>