AI-native design editor. Open-source Figma alternative.
fix: open the properties panel at one width on any window (#1603)
Danila Poyarkov808dc5737afd
diff --git a/src/app/shell/layout-storage.ts b/src/app/shell/layout-storage.tsindex 3a48b3321..91b86c84c 100644--- a/src/app/shell/layout-storage.ts+++ b/src/app/shell/layout-storage.ts@@ -1,10 +1,27 @@+import { clamp } from 'es-toolkit'import * as v from 'valibot'import { IS_BROWSER } from '@open-pencil/core/constants'const EDITOR_LAYOUT_KEY = 'open-pencil:editor-layout'-/** Left panel, canvas, and right panel, in percent; the right one is wider for the AI chat. */-const DEFAULT_EDITOR_LAYOUT = [18, 60, 22]+/** The left panel's share of the window, in percent, when the editor first opens. */+const DEFAULT_LEFT_PANEL = 18+/**+ * How wide the right panel opens, in pixels, whatever the window's width: wide enough for its+ * fields and the AI chat, without growing on a large screen as a share of the window would.+ */+const DEFAULT_RIGHT_PANEL_WIDTH = 256+/** The window width a layout is made for before there is a window, as in tests. */+const NOMINAL_WINDOW_WIDTH = 1280++/** Left panel, canvas, and right panel, in percent of the window, as the splitter takes them. */+function defaultEditorLayout(): number[] {+ const width = IS_BROWSER && window.innerWidth > 0 ? window.innerWidth : NOMINAL_WINDOW_WIDTH+ // Within the right panel's own limits in EditorWorkspace.vue.+ const right = clamp((DEFAULT_RIGHT_PANEL_WIDTH / width) * 100, 10, 30)+ return [DEFAULT_LEFT_PANEL, 100 - DEFAULT_LEFT_PANEL - right, right]+}+const editorLayoutSchema = v.pipe(v.string(),v.parseJson(),@@ -12,12 +29,12 @@ const editorLayoutSchema = v.pipe()export function loadEditorLayout(): number[] {- if (!IS_BROWSER) return DEFAULT_EDITOR_LAYOUT+ if (!IS_BROWSER) return defaultEditorLayout()try {const parsed = v.safeParse(editorLayoutSchema, window.localStorage.getItem(EDITOR_LAYOUT_KEY))- return parsed.success ? parsed.output : DEFAULT_EDITOR_LAYOUT+ return parsed.success ? parsed.output : defaultEditorLayout()} catch {- return DEFAULT_EDITOR_LAYOUT+ return defaultEditorLayout()}}diff --git a/src/components/editor/EditorWorkspace.vue b/src/components/editor/EditorWorkspace.vueindex 69307e7d5..5d31eb90f 100644--- a/src/components/editor/EditorWorkspace.vue+++ b/src/components/editor/EditorWorkspace.vue@@ -40,7 +40,23 @@ const { tab } = defineProps<{ tab: Tab }>()const store = tab.storeprovideTabEditorStore(store)const { isMobile } = useViewportKind()-const initialEditorLayout = loadEditorLayout()+/**+ * The layout the panels have. The splitter opens with it, also when showing the panels again+ * remounts it, so its opening report matches and only a resize differs.+ */+let editorLayout = loadEditorLayout()+/** How far apart two sizes, in percent, still count as one; the splitter rounds sizes finer. */+const LAYOUT_TOLERANCE = 1e-6+/**+ * Saves a layout the panels were resized to. The splitter also reports the layout it opens with,+ * which must not be saved: the right panel's default is a fixed width, and saved as a share of+ * this window it would open wider on a wider one.+ */+function saveResizedLayout(layout: number[]) {+ if (layout.every((size, index) => Math.abs(size - editorLayout[index]) < LAYOUT_TOLERANCE)) return+ editorLayout = layout+ saveEditorLayout(layout)+}const horizontalSplitterStyles = tv(splitterTheme)({ direction: 'horizontal' })/** One canvas previewing takes the whole window, in the canvas-only layout; split view keeps panels. */const playingAlone = computed(() => store.state.play !== null && store.visiblePaneCount.value <= 1)@@ -59,11 +75,11 @@ const { pending: roomPending } = useRoomActions():key="tab.id"direction="horizontal"class="flex-1 overflow-hidden"- @layout="saveEditorLayout"+ @layout="saveResizedLayout"><SplitterPanelid="layers"- :default-size="initialEditorLayout[0]"+ :default-size="editorLayout[0]":min-size="10":max-size="30"class="flex"@@ -76,19 +92,22 @@ const { pending: roomPending } = useRoomActions()><div :class="horizontalSplitterStyles.divider()" /></SplitterResizeHandle>- <SplitterPanel id="canvas" :default-size="initialEditorLayout[1]" :min-size="30" class="flex">+ <SplitterPanel id="canvas" :default-size="editorLayout[1]" :min-size="30" class="flex"><div class="relative flex min-w-0 flex-1"><CanvasSplitRoot /><ActiveRoomOverlay /><EditorToolbar /></div></SplitterPanel>- <SplitterResizeHandle :class="horizontalSplitterStyles.handle()">+ <SplitterResizeHandle+ data-test-id="right-splitter-handle"+ :class="horizontalSplitterStyles.handle()"+ ><div :class="horizontalSplitterStyles.divider()" /></SplitterResizeHandle><SplitterPanelid="properties"- :default-size="initialEditorLayout[2]"+ :default-size="editorLayout[2]":min-size="10":max-size="30"class="flex flex-col"diff --git a/tests/e2e/panels/basic.spec.ts b/tests/e2e/panels/basic.spec.tsindex b715bf715..92d7f00ef 100644--- a/tests/e2e/panels/basic.spec.ts+++ b/tests/e2e/panels/basic.spec.ts@@ -62,3 +62,65 @@ test('Cmd+Backslash shows panels again', async () => {await expect(editor.page.getByTestId('layers-panel')).toBeVisible()editor.canvas.assertNoErrors()})++// The right panel opens at one width on any window, rather than as a share that grows with it.+test('the properties panel reopens at one width on a narrow and a wide window', async ({+ browser,+ baseURL+}) => {+ const context = await browser.newContext({ baseURL, viewport: { width: 1280, height: 900 } })+ try {+ const page = await context.newPage()+ const panel = page.getByTestId('properties-panel')+ const panelWidth = async () =>+ expectDefined(await panel.boundingBox(), 'properties panel bounds').width++ await page.goto('/?test')+ await expect(panel).toBeVisible()+ const narrow = await panelWidth()+ expect(narrow).toBeGreaterThan(240)+ expect(narrow).toBeLessThan(270)++ // Neither pressing a handle without moving it nor hiding and showing the panels resizes them.+ const handle = expectDefined(+ await page.getByTestId('right-splitter-handle').boundingBox(),+ 'right splitter handle bounds'+ )+ await page.mouse.click(handle.x + handle.width / 2, handle.y + handle.height / 2)+ await page.keyboard.press('Meta+\\')+ await page.keyboard.press('Meta+\\')+ await expect(panel).toBeVisible()++ // A fixed width is a repeating share of 1920 px; saved, it would reopen narrower at 1280 px.+ for (const width of [1920, 1280]) {+ await page.setViewportSize({ width, height: 900 })+ await page.reload()+ await expect(panel).toBeVisible()+ expect(Math.abs((await panelWidth()) - narrow)).toBeLessThanOrEqual(1)+ }+ } finally {+ await context.close()+ }+})++test('a keyboard resize survives a reload and hiding the panels', async () => {+ const panel = editor.page.getByTestId('layers-panel')+ const panelWidth = async () =>+ expectDefined(await panel.boundingBox(), 'layers panel bounds').width+ const before = await panelWidth()++ await editor.page.getByTestId('left-splitter-handle').focus()+ await editor.page.keyboard.press('ArrowRight')+ const resized = await panelWidth()+ expect(resized).toBeGreaterThan(before + 2)++ await editor.page.reload()+ await editor.canvas.waitForInit()+ expect(Math.abs((await panelWidth()) - resized)).toBeLessThanOrEqual(1)++ await editor.page.keyboard.press('Meta+\\')+ await editor.page.keyboard.press('Meta+\\')+ await expect(panel).toBeVisible()+ expect(Math.abs((await panelWidth()) - resized)).toBeLessThanOrEqual(1)+ editor.canvas.assertNoErrors()+})diff --git a/tests/e2e/properties/blend-modes.spec.ts-snapshots/effect-blend-mode-openpencil-darwin.png b/tests/e2e/properties/blend-modes.spec.ts-snapshots/effect-blend-mode-openpencil-darwin.pngindex 0818a98c1..362ecef0d 100644Binary files a/tests/e2e/properties/blend-modes.spec.ts-snapshots/effect-blend-mode-openpencil-darwin.png and b/tests/e2e/properties/blend-modes.spec.ts-snapshots/effect-blend-mode-openpencil-darwin.png differdiff --git a/tests/e2e/properties/component-properties.spec.ts-snapshots/component-properties-controls-openpencil-darwin.png b/tests/e2e/properties/component-properties.spec.ts-snapshots/component-properties-controls-openpencil-darwin.pngindex 37ded6791..86bfd501a 100644Binary files a/tests/e2e/properties/component-properties.spec.ts-snapshots/component-properties-controls-openpencil-darwin.png and b/tests/e2e/properties/component-properties.spec.ts-snapshots/component-properties-controls-openpencil-darwin.png differdiff --git a/tests/e2e/properties/corner/bindings.spec.ts-snapshots/shared-corner-token-openpencil-darwin.png b/tests/e2e/properties/corner/bindings.spec.ts-snapshots/shared-corner-token-openpencil-darwin.pngindex 9c090d822..304ad59c1 100644Binary files a/tests/e2e/properties/corner/bindings.spec.ts-snapshots/shared-corner-token-openpencil-darwin.png and b/tests/e2e/properties/corner/bindings.spec.ts-snapshots/shared-corner-token-openpencil-darwin.png differdiff --git a/tests/e2e/properties/dimensions.spec.ts-snapshots/dimensions-bound-light-openpencil-darwin.png b/tests/e2e/properties/dimensions.spec.ts-snapshots/dimensions-bound-light-openpencil-darwin.pngindex d80cc873d..0cd63927c 100644Binary files a/tests/e2e/properties/dimensions.spec.ts-snapshots/dimensions-bound-light-openpencil-darwin.png and b/tests/e2e/properties/dimensions.spec.ts-snapshots/dimensions-bound-light-openpencil-darwin.png differdiff --git a/tests/e2e/properties/effect-panel.spec.ts-snapshots/inline-shadow-light-openpencil-darwin.png b/tests/e2e/properties/effect-panel.spec.ts-snapshots/inline-shadow-light-openpencil-darwin.pngindex 5ef8bbcc4..2523dbfd0 100644Binary files a/tests/e2e/properties/effect-panel.spec.ts-snapshots/inline-shadow-light-openpencil-darwin.png and b/tests/e2e/properties/effect-panel.spec.ts-snapshots/inline-shadow-light-openpencil-darwin.png differdiff --git a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/fill-missing-style-openpencil-darwin.png b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/fill-missing-style-openpencil-darwin.pngindex 7a5785170..4f4dc6378 100644Binary files a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/fill-missing-style-openpencil-darwin.png and b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/fill-missing-style-openpencil-darwin.png differdiff --git a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.png b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.pngindex 08a7df129..9c666314d 100644Binary files a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.png and b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-frame-openpencil-darwin.png differdiff --git a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.png b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.pngindex 00f9f687f..25ad84119 100644Binary files a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.png and b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-rectangle-openpencil-darwin.png differdiff --git a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.png b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.pngindex 69a80d44d..d6ed4910a 100644Binary files a/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.png and b/tests/e2e/properties/panel/hierarchy.spec.ts-snapshots/layout-text-openpencil-darwin.png differdiff --git a/tests/e2e/properties/shared-styles.spec.ts-snapshots/effects-applied-style-openpencil-darwin.png b/tests/e2e/properties/shared-styles.spec.ts-snapshots/effects-applied-style-openpencil-darwin.pngindex b476d45a1..878135ef8 100644Binary files a/tests/e2e/properties/shared-styles.spec.ts-snapshots/effects-applied-style-openpencil-darwin.png and b/tests/e2e/properties/shared-styles.spec.ts-snapshots/effects-applied-style-openpencil-darwin.png differdiff --git a/tests/e2e/properties/shared-styles.spec.ts-snapshots/effects-unbound-style-openpencil-darwin.png b/tests/e2e/properties/shared-styles.spec.ts-snapshots/effects-unbound-style-openpencil-darwin.pngindex 58a61dbd1..3bf8b44eb 100644Binary files a/tests/e2e/properties/shared-styles.spec.ts-snapshots/effects-unbound-style-openpencil-darwin.png and b/tests/e2e/properties/shared-styles.spec.ts-snapshots/effects-unbound-style-openpencil-darwin.png differdiff --git a/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-applied-style-openpencil-darwin.png b/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-applied-style-openpencil-darwin.pngindex f29d1431c..775289bc1 100644Binary files a/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-applied-style-openpencil-darwin.png and b/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-applied-style-openpencil-darwin.png differdiff --git a/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-unbound-style-openpencil-darwin.png b/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-unbound-style-openpencil-darwin.pngindex 6d92626ae..94f05d3ed 100644Binary files a/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-unbound-style-openpencil-darwin.png and b/tests/e2e/properties/shared-styles.spec.ts-snapshots/fill-unbound-style-openpencil-darwin.png differdiff --git a/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-unbound-style-openpencil-darwin.png b/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-unbound-style-openpencil-darwin.pngindex 06d8b2490..3f79bfe7c 100644Binary files a/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-unbound-style-openpencil-darwin.png and b/tests/e2e/properties/shared-styles.spec.ts-snapshots/stroke-unbound-style-openpencil-darwin.png differdiff --git a/tests/e2e/properties/stroke-settings.spec.ts-snapshots/stroke-main-dark-openpencil-darwin.png b/tests/e2e/properties/stroke-settings.spec.ts-snapshots/stroke-main-dark-openpencil-darwin.pngindex 8156e6728..6ee571382 100644Binary files a/tests/e2e/properties/stroke-settings.spec.ts-snapshots/stroke-main-dark-openpencil-darwin.png and b/tests/e2e/properties/stroke-settings.spec.ts-snapshots/stroke-main-dark-openpencil-darwin.png differdiff --git a/tests/e2e/properties/stroke-settings.spec.ts-snapshots/stroke-main-light-openpencil-darwin.png b/tests/e2e/properties/stroke-settings.spec.ts-snapshots/stroke-main-light-openpencil-darwin.pngindex 5fdcf42df..eaead0b23 100644Binary files a/tests/e2e/properties/stroke-settings.spec.ts-snapshots/stroke-main-light-openpencil-darwin.png and b/tests/e2e/properties/stroke-settings.spec.ts-snapshots/stroke-main-light-openpencil-darwin.png differdiff --git a/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-dark-openpencil-darwin.png b/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-dark-openpencil-darwin.pngindex 61a366469..114f3f726 100644Binary files a/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-dark-openpencil-darwin.png and b/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-dark-openpencil-darwin.png differdiff --git a/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-light-openpencil-darwin.png b/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-light-openpencil-darwin.pngindex 823197ebe..26e6badbd 100644Binary files a/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-light-openpencil-darwin.png and b/tests/e2e/properties/typography-panel.spec.ts-snapshots/typography-groups-light-openpencil-darwin.png differdiff --git a/tests/e2e/properties/unresolved-binding.spec.ts-snapshots/unresolved-fill-dark-openpencil-darwin.png b/tests/e2e/properties/unresolved-binding.spec.ts-snapshots/unresolved-fill-dark-openpencil-darwin.pngindex 7df8488d0..4a900ffc1 100644Binary files a/tests/e2e/properties/unresolved-binding.spec.ts-snapshots/unresolved-fill-dark-openpencil-darwin.png and b/tests/e2e/properties/unresolved-binding.spec.ts-snapshots/unresolved-fill-dark-openpencil-darwin.png differdiff --git a/tests/e2e/text/formatting.spec.ts-snapshots/typography-panel-openpencil-darwin.png b/tests/e2e/text/formatting.spec.ts-snapshots/typography-panel-openpencil-darwin.pngindex e2dfca9c0..0584e95ae 100644Binary files a/tests/e2e/text/formatting.spec.ts-snapshots/typography-panel-openpencil-darwin.png and b/tests/e2e/text/formatting.spec.ts-snapshots/typography-panel-openpencil-darwin.png differ