+ {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 */
-
)
}
+
+/** 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 })),
)