diff --git a/README.md b/README.md index e492ae2b2..f09c6062e 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,9 @@ layers of that frame, so agents read and edit them like any other markup. - **Zoom** — 8% to 1600%. Wheel pans, ⌘/Ctrl + wheel or a pinch zooms; a 1px pixel grid fades in from 300%. The zoom menu has 50/100/200% presets and the rulers toggle. - **Panels** — the right side panel has **Agents**, **Comments**, **Activity** and **Memory** tabs; - Layers and the side panel can be resized, and ⌘. hides all UI. + Layers and the side panel can be resized. Drag the divider between Pages and Layers to change + their split; arrow keys move it, Home and End reach its limits, and Doop remembers it per canvas. + Pages starts compact until you resize it. ⌘. hides all UI. - **Themes** — Light, Dark or System under Settings → Appearance. - **Phones** — the canvas works on a phone: one-finger pan, pinch zoom, tap to comment, and bottom sheets for canvas actions, Layers and the Inspector. diff --git a/src/components/LayersPanel.tsx b/src/components/LayersPanel.tsx index 5e55c5284..21a95a3f2 100644 --- a/src/components/LayersPanel.tsx +++ b/src/components/LayersPanel.tsx @@ -603,7 +603,7 @@ export function LayersPanel({ <> {/* Figma's order: the pages at the top, the frames of the active page under them, the search at the bottom within thumb's reach */} - + {pageCanvas && }
{t('panels.layersTitle')} diff --git a/src/components/PagesPanel.tsx b/src/components/PagesPanel.tsx index 4e0876dba..630ca8596 100644 --- a/src/components/PagesPanel.tsx +++ b/src/components/PagesPanel.tsx @@ -9,6 +9,15 @@ import { ApiError } from '../lib/api' import { Button } from './ui/button' import { PageIcon, PlusIcon } from './ui/icons' import { cn } from '../lib/utils' +import { + clampPagesPx, + pagesHeightCss, + pagesMaxPx, + pagesMinPx, + pagesPctOf, + pagesPxAfterKey, + usePagesPct, +} from '../lib/pagesSplit' import { ContextMenu, ContextMenuTrigger, ContextMenuContent, ContextMenuItem } from './ui/context-menu' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from './ui/select' import { useT } from '@/lib/i18n' @@ -19,7 +28,8 @@ import { useT } from '@/lib/i18n' export const sectionHeading = 'text-[11px] font-normal text-ink-faint' const sectionBtn = 'size-5 rounded-[5px] text-ink-faint hover:bg-paper-deep hover:text-ink' -export function PagesPanel({ fill = false }: { fill?: boolean }) { +export function PagesPanel({ canvasId }: { canvasId: string }) { + const [pagesPct, setPagesPct] = usePagesPct(canvasId) const canvas = useStore((s) => s.canvas) const activePageId = useStore((s) => s.activePageId) const selectedIds = useStore((s) => s.selectedIds) @@ -41,6 +51,9 @@ export function PagesPanel({ fill = false }: { fill?: boolean }) { if (!canvas) return null const pages = canvasPages(canvas) const movableIds = canvas.frames.filter((f) => selectedIds.includes(f.id) && !f.locked).map((f) => f.id) + /* the picker is there to move the selection somewhere else, so it needs a second page */ + const showMovePicker = !readOnly && selectedIds.length > 0 && pages.length > 1 + const minPx = pagesMinPx(showMovePicker) async function moveSelection(pageId: string) { if (!canvas || busy || !movableIds.length) return @@ -312,20 +325,26 @@ export function PagesPanel({ fill = false }: { fill?: boolean }) { ) return ( -
+
{t('panels.pagesTitle')} {!readOnly && addPage}
-
{list}
- {!readOnly && selectedIds.length > 0 && pages.length > 1 && ( +
{list}
+ {showMovePicker && ( /* the canvas shortcuts listen on window: ⌫ would delete the frames being moved and typed letters would switch tools, so the picker's keys stop here; React bubbles the portalled list's keys through this div too, before the native event reaches window */ -
e.stopPropagation()}> +
e.stopPropagation()}>
)} +
) } + +/** The Pages section's bottom edge: dragged, or moved with the arrow keys, Home and End. Each step measures the + * section and its rail again, so it starts from what is on screen. The separator's value and range are those + * measures too: the section also changes height when its content or the window does, not only on a drag. The + * browser releases the pointer's capture when the drag ends, which resets the drag. */ +function PagesSplitHandle({ minPx, onChange }: { minPx: number; onChange: (pct: number) => void }) { + const t = useT() + const handle = useRef(null) + const drag = useRef<{ y: number; pagesPx: number; railPx: number } | null>(null) + const [sizes, setSizes] = useState({ pagesPx: 0, railPx: 0 }) + useEffect(() => { + const el = handle.current + if (!el) return + const measure = () => { + const next = measurePages(el) + setSizes((prev) => (prev.pagesPx === next.pagesPx && prev.railPx === next.railPx ? prev : next)) + } + const observer = new ResizeObserver(measure) + observer.observe(el.closest('[data-slot="pages-panel"]')!) + observer.observe(el.closest('[data-slot="panel"]')!) + return () => observer.disconnect() + }, []) + return ( +
{ + if (e.button !== 0) return + e.preventDefault() + e.stopPropagation() + drag.current = { y: e.clientY, ...measurePages(e.currentTarget) } + e.currentTarget.setPointerCapture(e.pointerId) + }} + onPointerMove={(e) => { + const start = drag.current + if (!start) return + e.stopPropagation() + const px = clampPagesPx(start.pagesPx + e.clientY - start.y, start.railPx, minPx) + onChange(pagesPctOf(px, start.railPx)) + }} + onLostPointerCapture={() => { + drag.current = null + }} + onKeyDown={(e) => { + const { pagesPx, railPx } = measurePages(e.currentTarget) + const px = pagesPxAfterKey(e.key, pagesPx, railPx, minPx) + if (px === undefined) return + e.preventDefault() + e.stopPropagation() + onChange(pagesPctOf(px, railPx)) + }} + /> + ) +} + +/** The Pages section and the rail it sits in, both in px. */ +function measurePages(handle: HTMLElement) { + const pages = handle.closest('[data-slot="pages-panel"]')! + const rail = handle.closest('[data-slot="panel"]')! + return { pagesPx: pages.getBoundingClientRect().height, railPx: rail.getBoundingClientRect().height } +} diff --git a/src/lib/i18n/en/panels.ts b/src/lib/i18n/en/panels.ts index d52751785..bc972af42 100644 --- a/src/lib/i18n/en/panels.ts +++ b/src/lib/i18n/en/panels.ts @@ -38,6 +38,7 @@ export const panels = { pagesMoveFailed: 'Could not move all selected frames to the page', pagesSaveFailed: 'Could not save pages', pagesDuplicateFailed: 'Could not duplicate the page', + pagesResize: 'Resize pages', memoryIntro: 'Memory is how this canvas remembers your taste — and how every agent designs with it.', memoryReferences: 'References', diff --git a/src/lib/i18n/pt-BR/panels.ts b/src/lib/i18n/pt-BR/panels.ts index ea642c005..b7e7606a6 100644 --- a/src/lib/i18n/pt-BR/panels.ts +++ b/src/lib/i18n/pt-BR/panels.ts @@ -38,6 +38,7 @@ export const panels: Catalog['panels'] = { pagesMoveFailed: 'Não foi possível mover todos os frames selecionados para a página', pagesSaveFailed: 'Não foi possível salvar as páginas', pagesDuplicateFailed: 'Não foi possível duplicar a página', + pagesResize: 'Redimensionar páginas', memoryIntro: 'A Memória é como este canvas lembra do seu gosto — e como cada agente cria designs com ele.', memoryReferences: 'Referências', diff --git a/src/lib/pagesSplit.ts b/src/lib/pagesSplit.ts new file mode 100644 index 000000000..0b4e8a3c4 --- /dev/null +++ b/src/lib/pagesSplit.ts @@ -0,0 +1,88 @@ +/* The split between the Pages list and the Layers tree in the canvas rail. + A canvas starts with a content-sized Pages section. After a resize its + height is a share of the rail, clamped to keep both lists usable. */ +import { useEffect, useState } from 'react' + +/** the least the Pages section gets with no move picker: its heading, one page row, + * the list's bottom padding and the 1px divider (30 + 27 + 4 + 1px); + * PagesPanel's classes set those sizes */ +export const PAGES_BASE_MIN_PX = 62 +/** what the move picker adds while it is shown (its 32px trigger and 8px of padding) */ +export const PAGES_MOVE_PICKER_PX = 40 +/** Room for the rail header, Layers heading, one row and the search footer. */ +export const LAYERS_MIN_PX = 144 +/** how far one arrow press moves the split */ +export const PAGES_KEY_STEP_PX = 10 + +const STORAGE_KEY = 'doop:layers-pages-split' + +/** the least the Pages section gets: one page row, plus the move picker while it is shown */ +export function pagesMinPx(withMovePicker: boolean): number { + return withMovePicker ? PAGES_BASE_MIN_PX + PAGES_MOVE_PICKER_PX : PAGES_BASE_MIN_PX +} + +/** the most the Pages section gets: the room the Layers tree leaves, never below `minPx` */ +export function pagesMaxPx(railPx: number, minPx: number): number { + return Math.max(minPx, railPx - LAYERS_MIN_PX) +} + +/** a Pages height, held between `minPx` and the room the Layers tree keeps */ +export function clampPagesPx(px: number, railPx: number, minPx: number): number { + return Math.min(pagesMaxPx(railPx, minPx), Math.max(minPx, px)) +} + +/** a Pages height as a percentage of the rail */ +export function pagesPctOf(px: number, railPx: number): number { + return (px / railPx) * 100 +} + +/** The same height bounds as `clampPagesPx`, applied during layout. */ +export function pagesHeightCss(pct: number, minPx: number): string { + return `clamp(${minPx}px, ${pct}%, calc(100% - ${LAYERS_MIN_PX}px))` +} + +/** the Pages height an arrow key, Home or End asks for; undefined for any other key. + * Home and End clamp infinity, so they stop at the same limits as a drag. */ +export function pagesPxAfterKey(key: string, pagesPx: number, railPx: number, minPx: number): number | undefined { + switch (key) { + case 'ArrowUp': + return clampPagesPx(pagesPx - PAGES_KEY_STEP_PX, railPx, minPx) + case 'ArrowDown': + return clampPagesPx(pagesPx + PAGES_KEY_STEP_PX, railPx, minPx) + case 'Home': + return clampPagesPx(-Infinity, railPx, minPx) + case 'End': + return clampPagesPx(Infinity, railPx, minPx) + default: + return undefined + } +} + +/** a stored split, or null when it is missing or not a percentage of the rail */ +export function readPagesPct(raw: string | null): number | null { + if (raw === null) return null + const pct = Number(raw) + return Number.isFinite(pct) && pct > 0 && pct < 100 ? pct : null +} + +/** The split as last set for this canvas. The caller is keyed by canvas ID. */ +export function usePagesPct(canvasId: string): [number | null, (pct: number) => void] { + const key = `${STORAGE_KEY}:${canvasId}` + const [pct, setPct] = useState(() => readStoredPct(key)) + useEffect(() => { + try { + if (pct !== null) localStorage.setItem(key, String(pct)) + } catch { + /* the split still works when it cannot be saved */ + } + }, [key, pct]) + return [pct, setPct] +} + +function readStoredPct(key: string): number | null { + try { + return readPagesPct(localStorage.getItem(key)) + } catch { + return null + } +} diff --git a/tests/canvasPageFixture.ts b/tests/canvasPageFixture.ts index 7100cb98f..fc79bf487 100644 --- a/tests/canvasPageFixture.ts +++ b/tests/canvasPageFixture.ts @@ -70,5 +70,6 @@ export async function showCanvasPage( await page.goto(fixtureUrl(`canvasPage.html${search}`)) await page.waitForFunction(() => !!window.canvasPageHarness && !!document.querySelector('.stage')) await page.evaluate((frames, canvas) => window.canvasPageHarness.seed(frames, canvas), frames, canvas) - await page.waitForSelector('[data-frame-title]') + /* an empty canvas has no frame title to wait for: its Layers rail is what shows */ + await page.waitForSelector(frames.length ? '[data-frame-title]' : '[data-slot="pages-panel"]') } diff --git a/tests/fixtures/canvasPage.html b/tests/fixtures/canvasPage.html index 28d8dc434..54fc99699 100644 --- a/tests/fixtures/canvasPage.html +++ b/tests/fixtures/canvasPage.html @@ -13,17 +13,19 @@ import { useStore } from '/src/lib/store.ts' import '/src/styles.css' + const canvasId = new URLSearchParams(location.search).get('fixtureCanvasId') ?? 'c' + /* the canvas page as an editor has it open, with all its chrome; the test hands it the canvas the room would have sent */ window.canvasPageHarness = { seed: (frames, canvas) => useStore .getState() - .setCanvas({ id: 'c', name: 'Canvas', frames, role: 'edit', createdAt: 0, updatedAt: 0, ...canvas }), - setPages: (pages) => useStore.getState().setPages(pages, 'c'), + .setCanvas({ id: canvasId, name: 'Canvas', frames, role: 'edit', createdAt: 0, updatedAt: 0, ...canvas }), + setPages: (pages) => useStore.getState().setPages(pages, canvasId), } createRoot(document.getElementById('root')).render( - React.createElement(TooltipProvider, null, React.createElement(CanvasPage, { canvasId: 'c' })), + React.createElement(TooltipProvider, null, React.createElement(CanvasPage, { canvasId })), ) diff --git a/tests/pagesRename.test.tsx b/tests/pagesRename.test.tsx index 8a830a9f2..7d1089a45 100644 --- a/tests/pagesRename.test.tsx +++ b/tests/pagesRename.test.tsx @@ -94,7 +94,13 @@ describe('PagesPanel rename', () => { container = document.createElement('div') document.body.appendChild(container) root = createRoot(container) - act(() => root.render()) + act(() => + root.render( +
+ +
, + ), + ) }) afterEach(() => { diff --git a/tests/pagesSplit.test.ts b/tests/pagesSplit.test.ts new file mode 100644 index 000000000..888ef1ba4 --- /dev/null +++ b/tests/pagesSplit.test.ts @@ -0,0 +1,70 @@ +import { describe, expect, it } from 'vitest' +import { + LAYERS_MIN_PX, + PAGES_BASE_MIN_PX, + PAGES_MOVE_PICKER_PX, + clampPagesPx, + pagesMaxPx, + pagesMinPx, + pagesPxAfterKey, + readPagesPct, +} from '../src/lib/pagesSplit' + +describe('pagesMinPx', () => { + it('reserves room for the move picker only while it is shown', () => { + expect(pagesMinPx(false)).toBe(PAGES_BASE_MIN_PX) + expect(pagesMinPx(true)).toBe(PAGES_BASE_MIN_PX + PAGES_MOVE_PICKER_PX) + }) +}) + +describe('clampPagesPx', () => { + const min = pagesMinPx(false) + + it('holds the Pages section between its minimum and the room the Layers tree keeps', () => { + expect(clampPagesPx(-500, 800, min)).toBe(min) + expect(clampPagesPx(10_000, 800, min)).toBe(800 - LAYERS_MIN_PX) + expect(clampPagesPx(300, 800, min)).toBe(300) + }) + + it('keeps the Pages minimum in a rail too short to hold both lists', () => { + expect(clampPagesPx(400, 200, min)).toBe(min) + expect(pagesMaxPx(200, min)).toBe(min) + }) + + it('lets a section without the picker go lower than one with it', () => { + expect(clampPagesPx(0, 800, pagesMinPx(false))).toBeLessThan(clampPagesPx(0, 800, pagesMinPx(true))) + }) +}) + +describe('pagesPxAfterKey', () => { + const min = pagesMinPx(true) + + it('moves the split one step per arrow press and stops at its limits', () => { + expect(pagesPxAfterKey('ArrowDown', 300, 800, min)).toBe(310) + expect(pagesPxAfterKey('ArrowUp', 300, 800, min)).toBe(290) + expect(pagesPxAfterKey('ArrowUp', min, 800, min)).toBe(min) + }) + + it('takes Home and End to the two limits', () => { + expect(pagesPxAfterKey('Home', 300, 800, min)).toBe(min) + expect(pagesPxAfterKey('End', 300, 800, min)).toBe(800 - LAYERS_MIN_PX) + }) + + it('leaves every other key to the page', () => { + expect(pagesPxAfterKey('a', 300, 800, min)).toBeUndefined() + }) +}) + +describe('readPagesPct', () => { + it('keeps a stored split', () => { + expect(readPagesPct('37.5')).toBe(37.5) + }) + + it('drops anything that is not a split of the rail, so a bad value falls back to the default', () => { + expect(readPagesPct(null)).toBeNull() + expect(readPagesPct('')).toBeNull() + expect(readPagesPct('tall')).toBeNull() + expect(readPagesPct('0')).toBeNull() + expect(readPagesPct('100')).toBeNull() + }) +}) diff --git a/tests/pagesSplitBrowser.test.ts b/tests/pagesSplitBrowser.test.ts new file mode 100644 index 000000000..4a0e14169 --- /dev/null +++ b/tests/pagesSplitBrowser.test.ts @@ -0,0 +1,280 @@ +import type { Page } from 'puppeteer-core' +import { beforeEach, describe, expect, it } from 'vitest' +import { findBrowserPath } from '../server/screenshot' +import { LAYERS_MIN_PX, PAGES_BASE_MIN_PX, PAGES_MOVE_PICKER_PX, pagesMinPx } from '../src/lib/pagesSplit' +import { pagePerTest } from './browser' +import { canvasFrame, openCanvasPage, showCanvasPage } from './canvasPageFixture' + +/* enough pages to outgrow both the Pages list's 30vh default and the largest split an 800px window allows */ +const PAGES = Array.from({ length: 30 }, (_, i) => ({ id: `p${i + 1}`, name: `Page ${i + 1}` })) +const FRAMES = [canvasFrame({ id: 'f1', name: 'Home', x: 0, y: 0, width: 100, height: 100 })] +const FRAME_ROW = '[role="treeitem"][data-row-key="f1"]' +const MOVE_PICKER = '[data-slot="pages-panel"] [data-slot="select-trigger"]' + +/** the separator reports whole pixels, so it may differ from the laid-out size by one */ +const withinPx = (reported: number, laidOut: number) => expect(Math.abs(reported - laidOut)).toBeLessThanOrEqual(1) + +describe.skipIf(!findBrowserPath())('the Pages and Layers split', () => { + const pages = pagePerTest() + let page: Page + + beforeEach(async () => { + page = await pages.open() + await page.setViewport({ width: 1280, height: 800 }) + await openCanvasPage(page, FRAMES, '', { pages: PAGES }) + }) + + /** the Pages section, the Layers tree and the rail they share, in px */ + const sizes = () => + page.evaluate(() => { + const pagesEl = document.querySelector('[data-slot="pages-panel"]')! + const rail = pagesEl.closest('[data-slot="panel"]')! + const tree = rail.querySelector('[role="tree"]')! + return { + pages: pagesEl.getBoundingClientRect().height, + tree: tree.getBoundingClientRect().height, + rail: rail.getBoundingClientRect().height, + } + }) + + /** what the separator reports */ + const separator = () => + page.evaluate(() => { + const el = document.querySelector('[data-slot="pages-split"]')! + const value = (name: string) => Number(el.getAttribute(name)) + return { now: value('aria-valuenow'), min: value('aria-valuemin'), max: value('aria-valuemax') } + }) + + /** the separator's values once they have caught up with the layout on screen */ + async function liveSeparator() { + await page.waitForFunction( + (layersMin) => { + const el = document.querySelector('[data-slot="pages-split"]')! + const pagesEl = document.querySelector('[data-slot="pages-panel"]')! + const rail = pagesEl.closest('[data-slot="panel"]')! + return ( + Math.abs(Number(el.getAttribute('aria-valuenow')) - pagesEl.getBoundingClientRect().height) <= 1 && + Math.abs(Number(el.getAttribute('aria-valuemax')) - (rail.getBoundingClientRect().height - layersMin)) <= 1 + ) + }, + {}, + LAYERS_MIN_PX, + ) + return separator() + } + + const focusSplit = async () => (await page.$('[data-slot="pages-split"]'))!.focus() + + /** press the split and drag it `dy` px, in steps the way a hand moves */ + async function dragSplit(dy: number) { + const box = await (await page.$('[data-slot="pages-split"]'))!.boundingBox() + const x = box!.x + box!.width / 2 + const y = box!.y + box!.height / 2 + await page.mouse.move(x, y) + await page.mouse.down() + await page.mouse.move(x, y + dy, { steps: 8 }) + await page.mouse.up() + } + + /** Leave a large split on the current canvas, then open a different canvas. */ + async function openAnotherCanvas(frames: typeof FRAMES, canvas: Parameters[3]) { + await focusSplit() + await page.keyboard.press('End') + await showCanvasPage( + page, + frames.map((frame) => ({ ...frame, canvasId: 'small' })), + '?fixtureCanvasId=small', + canvas, + ) + } + + /** the edges of a section's parts, for what must stay inside it */ + const fit = () => + page.evaluate((pickerSelector) => { + const edges = (el: Element | null) => { + if (!el) return null + const { top, bottom, height } = el.getBoundingClientRect() + return { top, bottom, height } + } + const pagesEl = document.querySelector('[data-slot="pages-panel"]')! + const rows = [...pagesEl.querySelectorAll('[data-page-id]')] + return { + pages: edges(pagesEl)!, + list: edges(rows[0]!.parentElement)!, + firstRow: edges(rows[0]!)!, + lastRow: edges(rows.at(-1)!)!, + picker: edges(pagesEl.querySelector(pickerSelector)), + } + }, MOVE_PICKER) + + it('dragging the split up gives the Layers tree the room the Pages list gives up', async () => { + const before = await sizes() + await dragSplit(-120) + const after = await sizes() + expect(before.pages - after.pages).toBeCloseTo(120, 0) + expect(after.tree - before.tree).toBeCloseTo(120, 0) + }) + + it('stops the split where the Layers tree keeps its minimum room', async () => { + await dragSplit(2000) + const { pages: pagesPx, rail } = await sizes() + expect(pagesPx).toBeCloseTo(rail - LAYERS_MIN_PX, 0) + }) + + it('moves the split 10px an arrow press, and Home and End take it to its limits', async () => { + const start = await sizes() + await focusSplit() + await page.keyboard.press('ArrowUp') + expect((await sizes()).pages).toBeCloseTo(start.pages - 10, 0) + await page.keyboard.press('Home') + expect((await sizes()).pages).toBeCloseTo(pagesMinPx(false), 0) + await page.keyboard.press('End') + const end = await sizes() + expect(end.pages).toBeCloseTo(end.rail - LAYERS_MIN_PX, 0) + }) + + it('keeps the split when the page loads again', async () => { + await dragSplit(-120) + const dragged = await sizes() + await showCanvasPage(page, FRAMES, '', { pages: PAGES }) + expect((await sizes()).pages).toBeCloseTo(dragged.pages, 0) + }) + + it('drags past the last page row and still leaves a visible Layers row at the bottom', async () => { + await showCanvasPage(page, FRAMES, '', { pages: PAGES.slice(0, 12) }) + const before = await fit() + await dragSplit(500) + const after = await sizes() + expect(after.pages).toBeGreaterThanOrEqual(after.rail - 150) + expect((await fit()).pages.bottom - before.lastRow.bottom).toBeGreaterThan(100) + const rowVisible = await page.$eval(FRAME_ROW, (row) => { + const tree = row.closest('[role="tree"]')! + return row.getBoundingClientRect().bottom <= tree.getBoundingClientRect().bottom + }) + expect(rowVisible).toBe(true) + await showCanvasPage(page, FRAMES, '', { pages: PAGES.slice(0, 12) }) + expect((await sizes()).pages).toBeCloseTo(after.pages, 0) + }) + + it('reports where the split is and the range it can move in, as the keys, a drag and the window move it', async () => { + const start = await liveSeparator() + expect(start.min).toBe(pagesMinPx(false)) + const layout = await sizes() + withinPx(start.now, layout.pages) + withinPx(start.max, layout.rail - LAYERS_MIN_PX) + + await focusSplit() + await page.keyboard.press('ArrowUp') + withinPx((await liveSeparator()).now, start.now - 10) + await page.keyboard.press('Home') + expect((await liveSeparator()).now).toBe(start.min) + await page.keyboard.press('End') + withinPx((await liveSeparator()).now, start.max) + + await dragSplit(-120) + const dragged = await liveSeparator() + withinPx(dragged.now, start.max - 120) + + await page.setViewport({ width: 1280, height: 600 }) + const shrunk = await liveSeparator() + const shrunkLayout = await sizes() + expect(shrunk.max).toBeLessThan(start.max) + withinPx(shrunk.now, shrunkLayout.pages) + expect(shrunk.now).toBeLessThanOrEqual(shrunk.max + 1) + expect(shrunk.now).toBeGreaterThanOrEqual(shrunk.min) + }) + + it('keeps one page row and the move picker inside the Pages section while a frame is selected', async () => { + await focusSplit() + await page.keyboard.press('Home') + const bare = await liveSeparator() + expect(bare.min).toBe(pagesMinPx(false)) + const unselected = await fit() + expect(unselected.picker).toBeNull() + expect(unselected.pages.height).toBeCloseTo(pagesMinPx(false), 0) + expect(unselected.firstRow.bottom).toBeLessThanOrEqual(unselected.list.bottom + 0.5) + + await page.click(FRAME_ROW) + await page.waitForSelector(MOVE_PICKER) + const selected = await liveSeparator() + expect(selected.min).toBe(pagesMinPx(true)) + withinPx(selected.now, pagesMinPx(true)) + const withPicker = await fit() + expect(withPicker.pages.height).toBeCloseTo(pagesMinPx(true), 0) + expect(withPicker.firstRow.bottom).toBeLessThanOrEqual(withPicker.list.bottom + 0.5) + expect(withPicker.picker!.bottom).toBeLessThanOrEqual(withPicker.pages.bottom + 0.5) + }) + + describe('on another canvas after a large split was saved', () => { + /** the divider as the section draws it, the panel's own outline color, and the room under it */ + const divider = () => + page.evaluate(() => { + const pagesEl = document.querySelector('[data-slot="pages-panel"]')! + const rail = pagesEl.closest('[data-slot="panel"]')! + const probe = document.createElement('div') + probe.className = 'border-t border-line-soft' + document.body.append(probe) + const panelOutline = getComputedStyle(probe).borderTopColor + probe.remove() + const style = getComputedStyle(pagesEl) + const layersHeading = document.querySelector('[data-slot="frame-section-heading"]')!.parentElement! + return { + width: pagesEl.getBoundingClientRect().width, + railWidth: rail.clientWidth, + thickness: style.borderBottomWidth, + line: style.borderBottomStyle, + color: style.borderBottomColor, + panelOutline, + gapToLayers: layersHeading.getBoundingClientRect().top - pagesEl.getBoundingClientRect().bottom, + } + }) + + it('sizes a single page to its row on an empty canvas, with a full-width divider in the panel outline color', async () => { + await openAnotherCanvas([], { pages: [PAGES[0]!] }) + const section = await fit() + /* the list's bottom padding and the divider are all that is left under the row */ + expect(section.pages.bottom - section.firstRow.bottom).toBeLessThanOrEqual(6) + expect(section.pages.height).toBeCloseTo(PAGES_BASE_MIN_PX, 0) + const sep = await liveSeparator() + expect(sep.now).toBe(sep.min) + expect(sep.max).toBeGreaterThan(sep.min) + + const line = await divider() + expect(line.thickness).toBe('1px') + expect(line.line).toBe('solid') + expect(line.color).toBe(line.panelOutline) + expect(line.width).toBeCloseTo(line.railWidth, 0) + expect(line.gapToLayers).toBeLessThanOrEqual(8) + }) + + it('grows by the move picker while a frame is selected, keeping the row and the picker inside', async () => { + await openAnotherCanvas(FRAMES, { pages: PAGES.slice(0, 2) }) + const before = await fit() + expect(before.picker).toBeNull() + expect(before.pages.bottom - before.lastRow.bottom).toBeLessThanOrEqual(6) + + await page.click(FRAME_ROW) + await page.waitForSelector(MOVE_PICKER) + const after = await fit() + expect(after.pages.height - before.pages.height).toBeCloseTo(PAGES_MOVE_PICKER_PX, 0) + expect(after.lastRow.bottom).toBeLessThanOrEqual(after.list.bottom + 0.5) + expect(after.picker!.bottom).toBeLessThanOrEqual(after.pages.bottom + 0.5) + const sep = await liveSeparator() + expect(sep.min).toBe(pagesMinPx(true)) + withinPx(sep.now, after.pages.height) + }) + + it('keeps the divider and the resize for a viewer, who gets no move picker', async () => { + await showCanvasPage(page, FRAMES, '', { pages: PAGES, role: 'view' }) + await page.click(FRAME_ROW) + await page.waitForSelector(`${FRAME_ROW}[aria-selected="true"]`) + expect(await page.$(MOVE_PICKER)).toBeNull() + expect((await divider()).thickness).toBe('1px') + await focusSplit() + await page.keyboard.press('Home') + const sep = await liveSeparator() + expect(sep.min).toBe(pagesMinPx(false)) + expect(sep.now).toBe(pagesMinPx(false)) + }) + }) +})