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 1 commit
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| /* The split between the Pages list and the Layers tree in the canvas rail. | ||
| It is kept as a percentage of the rail's height, so one split fits any | ||
| window. `pagesHeightCss` clamps it again in CSS, so a window that shrinks | ||
| below the size the split was dragged in still shows both lists. */ | ||
| import { useEffect, useState } from 'react' | ||
|
|
||
| /** the least the Pages section gets: its heading and one row */ | ||
| export const PAGES_MIN_PX = 54 | ||
|
baekjosh marked this conversation as resolved.
Resolved
|
||
| /** what the Layers tree always keeps: the rail's header, the Layers heading | ||
| * and search footer, and room for a few rows */ | ||
| export const LAYERS_MIN_PX = 240 | ||
| /** how far one arrow press moves the split */ | ||
| export const PAGES_KEY_STEP_PX = 10 | ||
|
|
||
| const STORAGE_KEY = 'doop:layers-pages-split' | ||
|
|
||
| /** a Pages height, held between its minimum and the room the Layers tree keeps */ | ||
| export function clampPagesPx(px: number, railPx: number): number { | ||
| const max = Math.max(PAGES_MIN_PX, railPx - LAYERS_MIN_PX) | ||
| return Math.min(max, Math.max(PAGES_MIN_PX, px)) | ||
| } | ||
|
|
||
| /** a Pages height as a percentage of the rail */ | ||
| export function pagesPctOf(px: number, railPx: number): number { | ||
| return (px / railPx) * 100 | ||
| } | ||
|
|
||
| /** the CSS height of the Pages section for a stored percentage, with the limits `clampPagesPx` applies */ | ||
| export function pagesHeightCss(pct: number): string { | ||
| return `clamp(${PAGES_MIN_PX}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): number | undefined { | ||
| switch (key) { | ||
| case 'ArrowUp': | ||
| return clampPagesPx(pagesPx - PAGES_KEY_STEP_PX, railPx) | ||
| case 'ArrowDown': | ||
| return clampPagesPx(pagesPx + PAGES_KEY_STEP_PX, railPx) | ||
| case 'Home': | ||
| return clampPagesPx(-Infinity, railPx) | ||
| case 'End': | ||
| return clampPagesPx(Infinity, railPx) | ||
| 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 the user last left it, kept per browser; null until it is dragged. */ | ||
| export function usePagesPct(): [number | null, (pct: number | null) => void] { | ||
| const [pct, setPct] = useState<number | null>(readStoredPct) | ||
| useEffect(() => { | ||
| try { | ||
| if (pct === null) localStorage.removeItem(STORAGE_KEY) | ||
| else localStorage.setItem(STORAGE_KEY, String(pct)) | ||
| } catch { | ||
| /* the split still works when it cannot be saved */ | ||
| } | ||
| }, [pct]) | ||
| return [pct, setPct] | ||
| } | ||
|
|
||
| function readStoredPct(): number | null { | ||
| try { | ||
| return readPagesPct(localStorage.getItem(STORAGE_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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
| import { LAYERS_MIN_PX, PAGES_MIN_PX, clampPagesPx, pagesPxAfterKey, readPagesPct } from '../src/lib/pagesSplit' | ||
|
|
||
| describe('clampPagesPx', () => { | ||
| it('holds the Pages section between its minimum and the room the Layers tree keeps', () => { | ||
| expect(clampPagesPx(-500, 800)).toBe(PAGES_MIN_PX) | ||
| expect(clampPagesPx(10_000, 800)).toBe(800 - LAYERS_MIN_PX) | ||
| expect(clampPagesPx(300, 800)).toBe(300) | ||
| }) | ||
|
|
||
| it('keeps one row of Pages in a rail too short to hold both lists', () => { | ||
| expect(clampPagesPx(400, 200)).toBe(PAGES_MIN_PX) | ||
| }) | ||
| }) | ||
|
|
||
| describe('pagesPxAfterKey', () => { | ||
| it('moves the split one step per arrow press and stops at its limits', () => { | ||
| expect(pagesPxAfterKey('ArrowDown', 300, 800)).toBe(310) | ||
| expect(pagesPxAfterKey('ArrowUp', 300, 800)).toBe(290) | ||
| expect(pagesPxAfterKey('ArrowUp', PAGES_MIN_PX, 800)).toBe(PAGES_MIN_PX) | ||
| }) | ||
|
|
||
| it('takes Home and End to the two limits', () => { | ||
| expect(pagesPxAfterKey('Home', 300, 800)).toBe(PAGES_MIN_PX) | ||
| expect(pagesPxAfterKey('End', 300, 800)).toBe(800 - LAYERS_MIN_PX) | ||
| }) | ||
|
|
||
| it('leaves every other key to the page', () => { | ||
| expect(pagesPxAfterKey('a', 300, 800)).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.