Canvix — Free & open-source graphic design tool. A community-built Canva alternative with a drag-and-drop editor, templates, shapes, text, images & one-click export. Works on desktop, tablet & mobile.
TypeScript canva-alternativecanvasdesigndesign-tooldrag-and-dropeditorgraphic-designkonvanextjsopen-sourcereactself-hostedtemplatestypescript
fix(v0.11.6): panel state hygiene — Photos search-mode exit + one editing-mode source (#5)
Ashiq Hussain Mir724a05cf8fdb
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 8c7a68a..b46918d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -3,6 +3,45 @@All notable changes to Canvix will be documented in this file.The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).+## [0.11.6] — 2026-11-01++Two QA-pass findings in panel state hygiene (§5.2 of+`research/V0114-QA-PASS.md`): the Photos panel kept a stale search+filtering its grid after a category switch, and the top-bar mode control+could disagree with the Tools-panel Draw toggle.++### Fixed+- **F2 — Photos panel search state sticks.** After a web search, clicking+ a category tab left the query filtering the bundled library, so "All+ photos" showed the stale 6-of-42 result set until the panel was closed+ and reopened. A category click now exits results mode: the query, the+ visible search box (the `PanelShell` search input is optionally+ controlled now), the web results and any error all clear together.+- **F2b — web search on a provider-less server reads as broken.** With no+ AI provider configured, `/api/photos/search` answers 503+ `NO_PROVIDER`; the panel used to render that as "No web photos+ matched". It now says web search needs an AI provider configured on+ the server (pointing at `ZAI_BASE_URL` / `ZAI_API_KEY`) and that the+ free library below still works. Other API errors surface their message.+- **F3 — editing-mode toggles can disagree.** The top-bar "Editing mode"+ control (`editingMode`) and the Tools-panel Select/Draw toggle (`tool`)+ were separate states: the panel could show "Draw" pressed over a+ read-only canvas, and only the panel toggle reliably started drawing.+ Both controls now label the same derivation+ (`interactionMode()` in `lib/editor-utils`: viewing / draw / editing —+ viewing wins, then the active tool), the top-bar menu offers Draw+ directly, and `setTool` leaves read-only viewing so either control+ activates drawing from any state. The Tools panel explains itself in+ viewing mode ("picking a tool resumes editing").++### Added+- `src/lib/editor-utils.ts` → `interactionMode()` + 4 unit tests pinning+ the truth table (`src/lib/editor-utils.test.ts`).+- Playwright `panel-state.spec.ts` (3 tests): category-tab exit of search+ mode, the NO_PROVIDER configuration hint (503 mocked via `page.route`+ so it is deterministic on any machine), and the F3 top-bar ↔ Tools+ panel agreement across all four toggle paths.+## [0.11.5] — 2026-11-01A newly joined collaborator took **60–90 s to appear** for clients thatdiff --git a/README.md b/README.mdindex ef799c8..64d1518 100644--- a/README.md+++ b/README.md@@ -745,6 +745,10 @@ tool descriptions so agents pick the right format.- [x] Presence join latency fix — per-tick presence diff + announce-on-join:a new collaborator shows up for idle clients in ≤ 3.2 s (was 60–90 s),remote cursors included *(v0.11.5)*+- [x] Panel state hygiene — Photos category tabs exit search mode (no more+ stale 6-of-42 grid), web search without an AI provider says so, and+ the top-bar mode control + Tools-panel Draw toggle always agree+ *(v0.11.6)*- [ ] Plugin system (external, installable apps) — sandboxed-iframe MVPper `research/PLUGIN-SYSTEM.md`: manifest + permission model, iframesandbox with postMessage bridge, an “Apps” panel store, and 2–3diff --git a/package-lock.json b/package-lock.jsonindex 1ffe370..ca01595 100644--- a/package-lock.json+++ b/package-lock.json@@ -1,12 +1,12 @@{"name": "canvix",- "version": "0.11.5",+ "version": "0.11.6","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "canvix",- "version": "0.11.5",+ "version": "0.11.6","hasInstallScript": true,"dependencies": {"@imgly/background-removal": "^1.7.0",diff --git a/package.json b/package.jsonindex 05fb2c9..6f4caf1 100644--- a/package.json+++ b/package.json@@ -1,6 +1,6 @@{"name": "canvix",- "version": "0.11.5",+ "version": "0.11.6","private": false,"description": "Canvix — free & open-source graphic design tool. A community-built Canva alternative.","scripts": {diff --git a/research/V0114-QA-PASS.md b/research/V0114-QA-PASS.mdindex bcadbb8..a46b04c 100644--- a/research/V0114-QA-PASS.md+++ b/research/V0114-QA-PASS.md@@ -19,7 +19,7 @@ share → auth → collaboration → comments → versions → mobile.| Editor · shapes | add circle/square, drag, resize 320→506px, rotate to 81°, z-order (To front) | ✅ || Editor · colour | Fill menu: brand palette, gradients picker opens, fill applied (#7630D7) | ✅ || Photos | 42 bundled photos render, add to canvas (756×432) | ✅ |-| Photos | web search without an AI provider key | ⚠️ see F2 |+| Photos | web search without an AI provider key | ⚠️ see F2 (→ fixed v0.11.6) || Uploads | file input → data-URL image lands on canvas | ✅ || Draw | brush colour + stroke created (12-pt line) | ✅ || Export | PNG 2160×2160 RGBA, SVG true vector (clipPaths), PDF 1 page 1440×1440pt | ✅ |@@ -31,7 +31,7 @@ share → auth → collaboration → comments → versions → mobile.| Share | dialog generates canonical `/design/<id>` link | ✅ || Deep links | `/?design=`, `/?d=`, `/design/<id>` all open the editor | ✅ || Collab · stream | SSE replay from `?since=0` (21 events, HLC-stamped), keepalives, presence snapshot | ✅ |-| Collab · presence | second session joins, both eventually see 2 | ⚠️ see F4 |+| Collab · presence | second session joins, both eventually see 2 | ⚠️ see F4 (→ fixed v0.11.5) || Comments | canvas pin drop, post with author identity, DB row, cross-session sync | ✅ || MCP | disabled without `CANVIX_MCP_TOKEN` — clear JSON-RPC error, no auth bypass | ✅ || Health | `/api/health` → ok, db kind/host, template count | ✅ |@@ -51,11 +51,17 @@ share → auth → collaboration → comments → versions → mobile.the results-mode flag. Also: no hint that web results need an AIprovider key — a one-line “configure an AI provider to search the web”note would prevent the “search is broken” impression.+ **→ FIXED in v0.11.6** (category clicks exit results mode — query, box+ text, web results and errors clear together; 503 NO_PROVIDER renders a+ configuration hint; `research/V0116-PANEL-STATE-HYGIENE.md`).- **F3 — editing-mode toggles can disagree.** The top-bar “Editing mode”control and the Tools-panel Select/Draw toggle are separate states:the top bar can read “Draw” while the canvas behaves as Select. Onlythe Tools-panel toggle reliably activates drawing. Either drive bothfrom one store field or make the top-bar control the single source.+ **→ FIXED in v0.11.6** (one `interactionMode()` derivation labels both+ controls, the top-bar menu offers Draw, and `setTool` leaves viewing —+ `research/V0116-PANEL-STATE-HYGIENE.md`).- **F4 — presence latency for idle clients (most impactful).** Thestream pump sends a frame only when events exist or every 20th tick;with the quiet-mode backoff (800ms → 3.2s) a newly joined participantdiff --git a/research/V0116-PANEL-STATE-HYGIENE.md b/research/V0116-PANEL-STATE-HYGIENE.mdnew file mode 100644index 0000000..a0eb680--- /dev/null+++ b/research/V0116-PANEL-STATE-HYGIENE.md@@ -0,0 +1,88 @@+# v0.11.6 — Panel state hygiene (F2 + F3) analysis & fix++Follow-up to `V0114-QA-PASS.md` §5.2 — the two "panel state hygiene"+findings, both reproduced on the v0.11.5 code before fixing.++## F2 — Photos panel search state sticks++**Reproduced** (two real browsers + scripted): search "food" → the bundled+grid narrows to the 6 food photos and the web-results section appears;+click "All photos" → the chip is pressed but the grid STAYS at 6 tiles and+the search box still reads "food". Only closing and reopening the panel+restores the 42-photo library.++**Root cause.** `PhotosPanel` holds `query` (the filter) and `cat` (the+category) as independent states, and `PanelShell`'s search input keeps+its own *local* text state. A category click only set `cat` — the query+kept filtering the grid (`photos` memo applies `cat` AND `query`), and+nothing could clear the visible input from outside the shell.++**Fix.**+- A category click now **exits results mode**: `pickCategory()` sets the+ category, clears the query, and drops the web results + any error.+- `PanelShell` accepts optional `searchValue` / `onSearchValueChange`+ (controlled input, backward compatible — ProjectsPanel keeps local+ state), so clearing the query clears the visible box too.+- Leaving results mode (query < 2 chars) resets the web results AND the+ error state — a stale hint beside the full library would be the same+ bug one frame later.++## F2b — web search on a provider-less server reads as broken++`withProvider` answers 503 `{code: 'NO_PROVIDER'}` when no AI provider is+configured (`ZAI_BASE_URL` / `ZAI_API_KEY` env or a `.z-ai-config` file).+The panel mapped every non-OK response to `[]` and rendered "No web+photos matched — try other keywords" — the exact "search is broken"+impression the QA pass warned about.++**Fix.** The fetch handler classifies the response: 503 `NO_PROVIDER` →+a configuration hint naming both env vars and noting the free library+still works; other errors → the API's own message; otherwise results as+before. The e2e spec mocks the 503 with `page.route`, so the branch is+pinned deterministically even on machines that DO have a provider.++## F3 — editing-mode toggles can disagree++**Reproduced** (v0.11.5): Tools-panel "Draw" pressed + crosshair cursor+while the top bar read just "Editing"; and after switching the top bar to+Viewing, the panel's Draw button stayed pressed over a read-only canvas.+Per the QA pass: "the top-bar control and the Tools-panel toggle hold+separate state; driving both from a single store field resolves it."++**Root cause.** `editingMode` ('editing' | 'viewing') and `tool`+('select' | 'draw') are two orthogonal store fields rendered by two+different controls, each telling half the truth.++**Fix — one derivation, three writes:**+- `interactionMode(editingMode, tool)` (`src/lib/editor-utils.ts`) —+ viewing wins, then the active tool → 'viewing' | 'draw' | 'editing'.+ The top-bar trigger labels and icons that derivation; 4 unit tests pin+ the truth table.+- The top-bar menu now offers **Draw — freehand brush** (and Editing+ resets to the select tool), so drawing is reliably activatable from the+ top bar — previously "only the panel toggle reliably starts drawing".+- `setTool` also leaves read-only viewing (`editingMode: 'editing'` in+ the same store write): the panel toggle can never again show Draw+ pressed over a read-only canvas, because pressing it resumes editing.+- The Tools panel explains the remaining honest edge case: in viewing+ mode it shows "Viewing mode is read-only — picking a tool resumes+ editing." (the pressed tool indicates what resumes, the mode says+ whether the canvas is editable).++`CanvasStage` needed no change — its handlers already key off both+fields (`editingMode !== 'editing'` gates everything; draw paths check+`tool === 'draw'`), which is why the mismatch was purely a display/+control problem.++## Verification++- Reproduced both findings on the pre-fix code in a real browser+ (screenshots `f2-repro-*` in the QA archive).+- Post-fix human pass: search "food" → 6 tiles → "All photos" → 42 tiles,+ box cleared, web section gone; "Textures" → 6 texture photos; top bar+ reads Draw/Editing/Viewing in lockstep with the panel and the canvas+ cursor; a real stroke drawn after activating Draw from the TOP BAR+ (Konva `Line` node verified); zero console errors (the remaining+ setstate-in-render warning is F5, pre-existing, out of scope here).+- Gates: `tsc --noEmit` clean · eslint clean · vitest **302/302**+ (4 new) · Playwright **23/23** (3 new, `panel-state.spec.ts`).diff --git a/src/components/editor/TopBar.tsx b/src/components/editor/TopBar.tsxindex 2c1ff68..6b24c1b 100644--- a/src/components/editor/TopBar.tsx+++ b/src/components/editor/TopBar.tsx@@ -1,9 +1,10 @@'use client'import { useState } from 'react'-import { Home, MessageCircle, Play, Share2, ChevronDown, Undo2, Redo2, Download, Github, Cloud, Check, Loader2, Ruler, History, Languages, Wand2, Zap } from 'lucide-react'+import { Home, MessageCircle, Play, Share2, ChevronDown, Undo2, Redo2, Download, Github, Cloud, Check, Loader2, Ruler, History, Languages, Wand2, Zap, MousePointer2, Brush, Eye } from 'lucide-react'import { useAppStore } from '@/store/app-store'import { useEditorStore } from '@/store/editor-store'+import { interactionMode } from '@/lib/editor-utils'import { Button } from '@/components/ui/button'import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'import { cn } from '@/lib/utils'@@ -32,6 +33,11 @@ export function TopBar({ onSave, onShortcuts }: { onSave: () => Promise<void>; oconst savedAt = useEditorStore((s) => s.savedAt)const editingMode = useEditorStore((s) => s.editingMode)const setEditingMode = useEditorStore((s) => s.setEditingMode)+ // v0.11.6 (F3): the mode control also needs the active tool — both derive+ // from the same store via interactionMode(), so the top bar can never+ // read "Editing" while the canvas is in Draw mode again+ const tool = useEditorStore((s) => s.tool)+ const setTool = useEditorStore((s) => s.setTool)const setPreviewOpen = useEditorStore((s) => s.setPreviewOpen)const setPanel = useEditorStore((s) => s.setPanel)const selectedIds = useEditorStore((s) => s.selectedIds)@@ -53,6 +59,10 @@ export function TopBar({ onSave, onShortcuts }: { onSave: () => Promise<void>; oconst item = 'h-10 px-3 rounded-xl text-white/95 hover:bg-white/15 transition-colors text-sm font-semibold flex items-center gap-1.5 select-none'+ // v0.11.6 (F3): one derivation drives the label — the top bar and the+ // Tools panel can no longer disagree about the canvas mode+ const mode = interactionMode(editingMode, tool)+// canva behaviour: an element selection replaces the topbar middle section with the context toolbarconst hasSelection = selectedIds.length > 0@@ -125,16 +135,26 @@ export function TopBar({ onSave, onShortcuts }: { onSave: () => Promise<void>; oMagic Resize</button>- {/* Editing / Viewing mode */}+ {/* Editing / Draw / Viewing mode — v0.11.6 (F3): ONE derivation+ (interactionMode) drives this label, and the menu can activate+ drawing directly, where previously only the Tools panel could */}<DropdownMenu><DropdownMenuTrigger asChild><button className={item} aria-label="Editing mode">- {editingMode === 'editing' ? 'Editing' : 'Viewing'} <ChevronDown size={12} className="opacity-70" />+ {mode === 'viewing' ? <Eye size={13} className="text-white/80" /> : mode === 'draw' ? <Brush size={13} className="text-white/80" /> : <MousePointer2 size={13} className="text-white/80" />}+ {mode === 'viewing' ? 'Viewing' : mode === 'draw' ? 'Draw' : 'Editing'} <ChevronDown size={12} className="opacity-70" /></button></DropdownMenuTrigger><DropdownMenuContent align="start" className="w-44 bg-[#16181D] border-white/10 text-white">- <DropdownMenuItem onClick={() => setEditingMode('editing')}>✏️ Editing — make changes</DropdownMenuItem>- <DropdownMenuItem onClick={() => setEditingMode('viewing')}>👁 Viewing — read only</DropdownMenuItem>+ <DropdownMenuItem className="gap-2" onClick={() => { setEditingMode('editing'); setTool('select') }}>+ <MousePointer2 size={15} /> Editing — select & edit+ </DropdownMenuItem>+ <DropdownMenuItem className="gap-2" onClick={() => { setEditingMode('editing'); setTool('draw') }}>+ <Brush size={15} /> Draw — freehand brush+ </DropdownMenuItem>+ <DropdownMenuItem className="gap-2" onClick={() => setEditingMode('viewing')}>+ <Eye size={15} /> Viewing — read only+ </DropdownMenuItem></DropdownMenuContent></DropdownMenu>diff --git a/src/components/editor/panels/PhotosPanel.tsx b/src/components/editor/panels/PhotosPanel.tsxindex f8e1827..b8cfa79 100644--- a/src/components/editor/panels/PhotosPanel.tsx+++ b/src/components/editor/panels/PhotosPanel.tsx@@ -23,6 +23,10 @@ interface WebPhoto {height: number}+/** v0.11.6 (F2): why a web search came back empty — surfaced in the panel+ * so an unconfigured server says so instead of looking "broken" */+type WebError = { kind: 'no-provider' } | { kind: 'service'; message: string }+const CATEGORIES = [{ id: 'all', label: 'All photos' },{ id: 'nature', label: 'Nature' },@@ -60,24 +64,46 @@ export function PhotosPanel() {// v0.4: live web search (debounced)const [webResults, setWebResults] = useState<WebPhoto[] | null>(null)const [webBusy, setWebBusy] = useState(false)+ // v0.11.6 (F2): last search's failure mode, if any — 'no-provider' gets+ // a configuration hint, anything else keeps the plain empty message+ const [webError, setWebError] = useState<WebError | null>(null)const lastQuery = useRef('')useEffect(() => {const q = query.trim()const run = async () => {if (q.length < 2) {+ // v0.11.6 (F2): leaving results mode must clear BOTH the results and+ // any error — a stale hint next to the full library is exactly the+ // sticky-state bug the QA pass reportedsetWebResults(null)+ setWebError(null)return}setWebBusy(true)+ setWebError(null)try {const res = await fetch('/api/photos/search', {method: 'POST',headers: { 'Content-Type': 'application/json' },body: JSON.stringify({ query: q, count: 24 }),})- const data = (await res.json()) as { results?: WebPhoto[] }- setWebResults(res.ok && Array.isArray(data.results) ? data.results : [])+ const data = (await res.json().catch(() => ({}))) as {+ results?: WebPhoto[]+ error?: string+ code?: string+ }+ // v0.11.6 (F2): 503 NO_PROVIDER means the server has no AI provider+ // configured — say that, not "no photos matched"+ if (res.status === 503 && data.code === 'NO_PROVIDER') {+ setWebError({ kind: 'no-provider' })+ setWebResults([])+ } else if (!res.ok) {+ setWebError(data.error ? { kind: 'service', message: data.error } : null)+ setWebResults([])+ } else {+ setWebResults(Array.isArray(data.results) ? data.results : [])+ }} catch {setWebResults([])} finally {@@ -119,18 +145,32 @@ export function PhotosPanel() {const showWeb = query.trim().length >= 2 && (webResults !== null || webBusy)+ // v0.11.6 (F2): clicking a category tab EXITS results mode — clears the+ // query (and with it the visible search box, now controlled), the web+ // results and any error. Before, the query kept filtering the bundled+ // grid, so "All photos" showed the stale 6-photo result set instead of+ // the 42-photo library until the panel was closed and reopened.+ const pickCategory = (id: string) => {+ setCat(id)+ setQuery('')+ setWebResults(null)+ setWebError(null)+ }+return (<PanelShelltitle="Photos"subtitle="Search millions of photos or browse the free library"searchPlaceholder="Search photos (e.g. mountain, coffee, beach)"+ searchValue={query}+ onSearchValueChange={setQuery}onSearch={setQuery}belowSearch={<div className="cv-tabscroll -mx-4 mt-2.5 flex gap-1.5 overflow-x-auto px-4">{CATEGORIES.map((c) => (<buttonkey={c.id}- onClick={() => setCat(c.id)}+ onClick={() => pickCategory(c.id)}className={cn('h-7 shrink-0 whitespace-nowrap rounded-full px-3 text-[11.5px] font-semibold transition-colors border',cat === c.id@@ -155,7 +195,16 @@ export function PhotosPanel() {</span>{webBusy && <Loader2 size={11} className="animate-spin text-white/40 ml-1" />}</div>- {webResults && webResults.length === 0 && !webBusy ? (+ {webError?.kind === 'no-provider' ? (+ <p className="text-[11.5px] text-white/40 py-2 leading-relaxed">+ Web search needs an AI provider configured on the server — set+ the <code className="text-white/55">ZAI_BASE_URL</code> and{' '}+ <code className="text-white/55">ZAI_API_KEY</code> environment+ variables. The free library below still works.+ </p>+ ) : webError?.kind === 'service' ? (+ <p className="text-[11.5px] text-white/40 py-2">{webError.message}</p>+ ) : webResults && webResults.length === 0 && !webBusy ? (<p className="text-[11.5px] text-white/40 py-2">No web photos matched — try other keywords.</p>) : (<div className="grid grid-cols-2 gap-2.5">diff --git a/src/components/editor/panels/ToolsPanel.tsx b/src/components/editor/panels/ToolsPanel.tsxindex 2654024..bd4a7e4 100644--- a/src/components/editor/panels/ToolsPanel.tsx+++ b/src/components/editor/panels/ToolsPanel.tsx@@ -55,6 +55,7 @@ export function ToolsPanel() {function DrawTab() {const tool = useEditorStore((s) => s.tool)const setTool = useEditorStore((s) => s.setTool)+ const editingMode = useEditorStore((s) => s.editingMode)const drawColor = useEditorStore((s) => s.drawColor)const setDrawColor = useEditorStore((s) => s.setDrawColor)const drawSize = useEditorStore((s) => s.drawSize)@@ -64,6 +65,14 @@ function DrawTab() {return (<div className="p-4 space-y-4">+ {/* v0.11.6 (F3): setTool now leaves read-only viewing too, so the+ toggle always works — say so instead of showing Draw "pressed"+ over a read-only canvas with no explanation */}+ {editingMode === 'viewing' && (+ <p className="rounded-xl border border-white/10 bg-white/[0.03] px-3 py-2 text-[11.5px] leading-relaxed text-white/60">+ Viewing mode is read-only — picking a tool resumes editing.+ </p>+ )}<div className="flex gap-2"><buttononClick={() => setTool('draw')}diff --git a/src/components/editor/panels/panel-shell.tsx b/src/components/editor/panels/panel-shell.tsxindex b77c156..8bc7164 100644--- a/src/components/editor/panels/panel-shell.tsx+++ b/src/components/editor/panels/panel-shell.tsx@@ -10,6 +10,11 @@ interface PanelShellProps {/** canva-style AI prompt + Generate/Search row */searchPlaceholder?: stringonSearch?: (q: string) => void+ /** v0.11.6 (F2): optional controlled search text — lets a panel reset the+ * visible input (e.g. Photos clears the box when a category tab exits+ * results mode). Unset → the input keeps its own local state. */+ searchValue?: string+ onSearchValueChange?: (q: string) => voidchildren: ReactNode/** extra row under the search bar (e.g. filter chips) */belowSearch?: ReactNode@@ -17,8 +22,12 @@ interface PanelShellProps {}/** Dark side-panel shell matching canva.com 2026: header, AI prompt row, purple Search button. */-export function PanelShell({ title, subtitle, searchPlaceholder, onSearch, children, belowSearch, onClose }: PanelShellProps) {- const [q, setQ] = useState('')+export function PanelShell({ title, subtitle, searchPlaceholder, onSearch, searchValue, onSearchValueChange, children, belowSearch, onClose }: PanelShellProps) {+ const [localQ, setLocalQ] = useState('')+ // controlled when the panel passes a value+change pair; local otherwise+ const isControlled = searchValue !== undefined && onSearchValueChange !== undefined+ const q = isControlled ? searchValue : localQ+ const setQ = isControlled ? onSearchValueChange : setLocalQconst submit = () => onSearch?.(q.trim())return (diff --git a/src/lib/editor-utils.test.ts b/src/lib/editor-utils.test.tsnew file mode 100644index 0000000..06ce7d0--- /dev/null+++ b/src/lib/editor-utils.test.ts@@ -0,0 +1,33 @@+import { describe, expect, it } from 'vitest'+import { interactionMode } from './editor-utils'++/**+ * v0.11.6 (QA finding F3): the top-bar "Editing mode" control and the+ * Tools-panel Select/Draw toggle held separate state and could disagree —+ * "Draw" pressed while the canvas behaved as read-only Select. Both now+ * label the SAME derivation (interactionMode), so these truth-table rows+ * pin the contract the two controls can no longer violate.+ */+describe('interactionMode', () => {+ it('editing + select → editing (the default canvas mode)', () => {+ expect(interactionMode('editing', 'select')).toBe('editing')+ })++ it('editing + draw → draw (brush active — the top bar must say so)', () => {+ expect(interactionMode('editing', 'draw')).toBe('draw')+ })++ it('viewing wins over any tool — read-only is read-only', () => {+ expect(interactionMode('viewing', 'select')).toBe('viewing')+ expect(interactionMode('viewing', 'draw')).toBe('viewing')+ })++ it('covers exactly three modes (no hidden fourth state)', () => {+ const modes = new Set(+ (['editing', 'viewing'] as const).flatMap((m) =>+ (['select', 'draw'] as const).map((t) => interactionMode(m, t)),+ ),+ )+ expect([...modes].sort()).toEqual(['draw', 'editing', 'viewing'])+ })+})diff --git a/src/lib/editor-utils.ts b/src/lib/editor-utils.tsindex 436f628..35894dc 100644--- a/src/lib/editor-utils.ts+++ b/src/lib/editor-utils.ts@@ -429,3 +429,27 @@ export const PRESET_SIZES = [{ name: 'Facebook cover', width: 1640, height: 856, hint: '1640 × 856 px' },{ name: 'Business card', width: 1050, height: 600, hint: '1.75 × 1 in' },] as const++// ── Interaction mode (v0.11.6 — QA finding F3) ──────────────++/**+ * The single derived interaction mode shown by BOTH the top-bar control and+ * the Tools panel. The two controls used to display separate store fields+ * (`editingMode` vs `tool`), so the UI could show "Draw" pressed while the+ * canvas behaved as read-only Select — the QA pass called it "editing-mode+ * toggles can disagree". One derivation can't disagree with itself:+ *+ * viewing — read-only, always wins over the active tool+ * draw — editing + the freehand brush tool+ * editing — editing + the select tool (move / resize / marquee)+ */+export type InteractionMode = 'editing' | 'draw' | 'viewing'++/** Combine the read-only toggle with the active tool into one visible mode. */+export function interactionMode(+ editingMode: 'editing' | 'viewing',+ tool: 'select' | 'draw',+): InteractionMode {+ if (editingMode === 'viewing') return 'viewing'+ return tool === 'draw' ? 'draw' : 'editing'+}diff --git a/src/store/editor-store.ts b/src/store/editor-store.tsindex 8e5d32a..6445e78 100644--- a/src/store/editor-store.ts+++ b/src/store/editor-store.ts@@ -101,9 +101,13 @@ interface EditorState {version: number// canva-2026 chrome+ /** read-only toggle (top bar) — viewing wins over any tool. v0.11.6:+ * the top bar now labels the COMBINED mode (see interactionMode() in+ * lib/editor-utils) so this field and `tool` can no longer be read as+ * disagreeing controls (QA finding F3). */editingMode: 'editing' | 'viewing'previewOpen: boolean- /** freehand draw tool */+ /** freehand draw tool — activating one also leaves viewing mode (F3) */tool: 'select' | 'draw'drawColor: stringdrawSize: number@@ -760,7 +764,11 @@ export const useEditorStore = create<EditorState>((set, get) => ({setEditingMode: (m) => set({ editingMode: m }),setPreviewOpen: (open) => set({ previewOpen: open }),- setTool: (t) => set({ tool: t, selectedIds: [] }),+ // v0.11.6 (F3): activating a tool also leaves read-only viewing — the+ // Tools-panel toggle used to show "Draw" pressed while the canvas stayed+ // read-only, because editingMode and tool were set from separate controls+ // that never reconciled. One store write now covers both.+ setTool: (t) => set({ tool: t, selectedIds: [], editingMode: 'editing' }),setDrawColor: (c) => set({ drawColor: c }),setDrawSize: (n) => set({ drawSize: Math.min(64, Math.max(1, n)) }),setBrand: (b) => set({ brand: b }),diff --git a/tests/e2e/panel-state.spec.ts b/tests/e2e/panel-state.spec.tsnew file mode 100644index 0000000..678451d--- /dev/null+++ b/tests/e2e/panel-state.spec.ts@@ -0,0 +1,147 @@+import { test, expect, type Page } from '@playwright/test'++/**+ * v0.11.6 — panel state hygiene (QA findings F2 + F3,+ * research/V0114-QA-PASS.md §5.2).+ *+ * F2: the Photos panel kept filtering the bundled library by a search query+ * after a category tab was clicked, so "All photos" showed the stale+ * 6-photo result set instead of the 42-photo library until the panel+ * was closed and reopened; and a server with no AI provider configured+ * answered web search with 503 NO_PROVIDER, which the panel rendered+ * as "No web photos matched" — reading like broken search.+ * Fix: a category click exits results mode (query, box text, web+ * results and errors all clear), and the 503 gets a configuration hint.+ *+ * F3: the top-bar "Editing mode" control (editingMode) and the Tools-panel+ * Select/Draw toggle (tool) held separate state, so the panel could+ * show "Draw" pressed over a read-only canvas, and only the panel+ * toggle reliably started drawing. Fix: one derivation+ * (lib/editor-utils interactionMode) labels both controls, the top-bar+ * menu can activate Draw directly, and activating a tool leaves+ * read-only viewing.+ *+ * Needs a database (design creation) — see playwright.config.ts.+ */+test.setTimeout(120_000)++async function openEditorPanel(page: Page, panel: string) {+ await page.goto('/')+ // Next.js dev tools indicator overlays the first rail button in dev mode+ await page.addStyleTag({ content: 'nextjs-portal { display: none !important; }' })+ await page.getByRole('button', { name: /start designing/i }).first().click()+ await page+ .locator('section:has(h2:text("Start a new design")) [aria-label^="Create "]')+ .first()+ .click()+ await expect(page.getByLabel('Design canvas')).toBeVisible({ timeout: 30_000 })+ await page.getByRole('button', { name: panel }).click()+}++const BUNDLED_TOTAL = 42 // 7 categories × 6 bundled photos++// ── F2 ────────────────────────────────────────────────────────++test('F2: clicking a category tab exits Photos search mode and restores the library', async ({ page }) => {+ await openEditorPanel(page, 'Photos')+ const aside = page.locator('aside')+ const search = page.getByLabel('Photos search')++ // the full library is up before any search+ await expect(aside.locator('img')).toHaveCount(BUNDLED_TOTAL)++ // search "food" — bundled grid narrows to the food category's six photos+ await search.fill('food')+ await page.getByRole('button', { name: 'Search', exact: true }).click()+ await expect(aside.locator('img')).toHaveCount(6)++ // THE BUG: "All photos" used to keep the query filtering — 6 stale tiles+ await page.getByRole('button', { name: 'All photos' }).click()+ await expect(aside.locator('img')).toHaveCount(BUNDLED_TOTAL)+ await expect(search).toHaveValue('')+ // the web-results section is gone entirely, not just emptied (the header+ // counts — "Web results (N)"; the footnote "Web results come from…" stays)+ await expect(aside.getByText(/^Web results \(/)).toBeHidden()++ // a specific category chip exits search mode too (was: same stale filter)+ await search.fill('mountain')+ await page.getByRole('button', { name: 'Search', exact: true }).click()+ await expect(aside.locator('img')).toHaveCount(6)+ await page.getByRole('button', { name: 'Textures' }).click()+ await expect(aside.locator('img')).toHaveCount(6) // the six TEXTURE photos+ await expect(search).toHaveValue('')+ await expect(page.getByRole('button', { name: 'Textures' })).toHaveAttribute('aria-pressed', 'true')+})++test('F2: a server without an AI provider says so instead of "no photos matched"', async ({ page }) => {+ // mock the provider-less server response — deterministic regardless of+ // whether the machine running this spec has ZAI_* configured+ await page.route('**/api/photos/search', (route) =>+ route.fulfill({+ status: 503,+ contentType: 'application/json',+ body: JSON.stringify({+ error: 'This feature requires an AI provider configured on the server.',+ code: 'NO_PROVIDER',+ }),+ }),+ )+ await openEditorPanel(page, 'Photos')+ const aside = page.locator('aside')++ await page.getByLabel('Photos search').fill('mountain')+ await page.getByRole('button', { name: 'Search', exact: true }).click()++ // the configuration hint, not the misleading empty-result message+ await expect(aside.getByText('Web search needs an AI provider configured on the server')).toBeVisible()+ await expect(aside.getByText(/ZAI_BASE_URL/)).toBeVisible()+ await expect(aside.getByText('No web photos matched')).toBeHidden()+})++// ── F3 ────────────────────────────────────────────────────────++test('F3: top-bar mode and Tools-panel tool toggle always agree', async ({ page }) => {+ await openEditorPanel(page, 'Tools')+ const modeButton = page.locator('button[aria-label="Editing mode"]')+ // the cursor style lives on the canvas container INSIDE the main editing+ // area — the page navigator below renders its own mini .konvajs-content+ const canvas = page+ .getByLabel('Design canvas')+ .locator('.konvajs-content')+ .first()+ .locator('xpath=..')++ const drawToggle = page.locator('aside .p-4 button[aria-pressed]', { hasText: 'Draw' })+ const selectToggle = page.locator('aside .p-4 button[aria-pressed]', { hasText: 'Select' })++ // initial: top bar reads Editing, canvas is a normal select cursor+ await expect(modeButton).toContainText('Editing')++ // panel toggle activates drawing — and the TOP BAR must say so (was: it+ // kept reading "Editing" over a crosshair cursor)+ await drawToggle.click()+ await expect(modeButton).toContainText('Draw')+ await expect(drawToggle).toHaveAttribute('aria-pressed', 'true')+ await expect(canvas).toHaveCSS('cursor', 'crosshair')++ // top-bar menu: three coherent options; Viewing makes the canvas read-only+ await modeButton.click()+ await page.getByRole('menuitem', { name: 'Viewing — read only' }).click()+ await expect(modeButton).toContainText('Viewing')+ await expect(canvas).toHaveCSS('cursor', 'default')+ // the panel explains itself instead of showing Draw "pressed" silently+ await expect(page.getByText('Viewing mode is read-only — picking a tool resumes editing.')).toBeVisible()++ // activating a tool from the PANEL leaves read-only viewing (was: Draw+ // stayed pressed over a read-only canvas forever)+ await selectToggle.click()+ await expect(modeButton).toContainText('Editing')++ // activating Draw from the TOP BAR works too — previously only the+ // panel toggle reliably started drawing+ await modeButton.click()+ await page.getByRole('menuitem', { name: 'Draw — freehand brush' }).click()+ await expect(modeButton).toContainText('Draw')+ await expect(drawToggle).toHaveAttribute('aria-pressed', 'true')+ await expect(canvas).toHaveCSS('cursor', 'crosshair')+})