feat(studio): give a book its first and its last page (#2317)

A new book was a cover, a spread and a back cover, so it opened straight
onto pages 2 and 3. A bound book does not: the inside of the cover is
blank, and the first thing facing the reader is a single right-hand page,
page 1. The same at the end, where a single left-hand page sits before the
back cover. Both are laid down now, empty, in a new book and in a laid-out
one, and they are fixed the way the covers are: an inner spread only ever
goes between them.

The page numbers follow. They were counted from a spread's position in the
array, which assumed the spread after the cover was the first, and three
places did that sum on their own. One function now counts along the book,
one page for a single leaf and two for a spread, so the sheet on screen and
the label in the print view and the folio on the page all say the same
number. A book with a first page starts at 1; a book from before the first
page existed has none and keeps the numbers it always had.
This commit is contained in:
Maurice
2026-09-11 11:01:15 +02:00
parent 1128bcd1c5
commit 87c73e50fb
17 changed files with 370 additions and 92 deletions
@@ -311,3 +311,66 @@ describe('turning an element', () => {
expect(rotationOf('one')).toBe(0)
})
})
/*
* The single first and last pages are fixed the way the covers are (#2317):
* a bound book opens onto one right-hand page and closes on one left-hand
* page, and an inner spread may only ever go between them.
*/
describe('a book with a first and a last page', () => {
beforeEach(() => {
useStudioStore.getState().load(book(
spread('cover', 'cover'),
spread('first', 'first'),
spread('a', 'inner'),
spread('last', 'last'),
spread('back', 'back'),
))
})
it('treats them as fixed points, not as inner spreads', () => {
expect(store().canEditSpread(1)).toBe(false)
expect(store().canEditSpread(3)).toBe(false)
expect(store().canEditSpread(2)).toBe(true)
})
it('adds after the first page when asked to add at the cover or the first page', () => {
store().addSpread(0)
expect(roles()).toEqual(['cover', 'first', 'inner', 'inner', 'last', 'back'])
expect(store().activeSpread).toBe(2)
})
it('never lands on or behind the last page', () => {
store().addSpread(3)
expect(roles()).toEqual(['cover', 'first', 'inner', 'inner', 'last', 'back'])
store().addSpread(9)
expect(roles()).toEqual(['cover', 'first', 'inner', 'inner', 'inner', 'last', 'back'])
})
it('inserts a spread inside them too', () => {
store().insertSpread(0, spread('x', 'inner'))
expect(roles()).toEqual(['cover', 'first', 'inner', 'inner', 'last', 'back'])
})
it('will not move an inner spread onto either of them', () => {
store().moveSpread(2, -1)
store().moveSpread(2, 1)
expect(ids()).toEqual(['cover', 'first', 'a', 'last', 'back'])
})
it('will not move, copy or delete them', () => {
store().moveSpread(1, 1)
store().moveSpread(3, -1)
store().duplicateSpread(1)
store().removeSpread(3)
expect(ids()).toEqual(['cover', 'first', 'a', 'last', 'back'])
})
it('adds the first inner spread of an empty book between them', () => {
useStudioStore.getState().load(book(
spread('cover', 'cover'), spread('first', 'first'), spread('last', 'last'), spread('back', 'back'),
))
store().addSpread(-1)
expect(roles()).toEqual(['cover', 'first', 'inner', 'last', 'back'])
})
})