Repository navigation
feat(canvas): resize the Pages and Layers split #516
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kgoedecke
merged 5 commits into
doop-design:main
from
baekjosh:feat/resizable-pages-layers
Nov 18, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
3282009
feat(canvas): resize the Pages and Layers split
baekjosh e5bb208
fix(canvas): keep a page row and the move picker inside Pages
baekjosh 56c860a
fix(pages): finish compact Pages and Layers resizing
baekjosh d13fe97
Merge remote-tracking branch 'origin/main' into feat/resizable-pages-…
baekjosh c86a181
fix(canvas): let Pages take more of the sidebar
baekjosh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<number | null>(() => 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 | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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() | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.