) => void
}) {
const { frame, node } = row
- const readOnly = useStore((s) => !canEditOpenCanvas(s))
+ const readOnly = useStore((s) => !canEditActivePage(s))
const hasChildren = node.children.length > 0
const component = useStore((s) =>
node.componentId ? s.canvas?.components?.find((def) => def.id === node.componentId) : undefined,
diff --git a/src/components/LedgerCaption.tsx b/src/components/LedgerCaption.tsx
new file mode 100644
index 000000000..d60ae48fb
--- /dev/null
+++ b/src/components/LedgerCaption.tsx
@@ -0,0 +1,41 @@
+import type { CSSProperties } from 'react'
+import { activePageOf, useStore } from '../lib/store'
+import { useT } from '../lib/i18n'
+import { cn } from '../lib/utils'
+import { BookOpenIcon } from './ui/icons'
+
+/** What the ledger page is and when it changes (CHE-9398 L8, A5). Shown only while the ledger page is the
+ * active page. `bar` is the desktop chip floating over the stage, `box` the note on top of the phone sheet. */
+export function LedgerCaption({
+ variant = 'bar',
+ className,
+ style,
+}: {
+ variant?: 'bar' | 'box'
+ className?: string
+ style?: CSSProperties
+}) {
+ const t = useT()
+ const ledger = useStore((s) => !!activePageOf(s)?.ledger)
+ if (!ledger) return null
+ return (
+
+ {variant === 'bar' && }
+
+ {t('panels.ledgerCaptionLead')}{' '}
+ {t('panels.ledgerCaptionRest')}
+
+
+ )
+}
diff --git a/src/lib/actions/edits.ts b/src/lib/actions/edits.ts
index ce33e65aa..06255d48b 100644
--- a/src/lib/actions/edits.ts
+++ b/src/lib/actions/edits.ts
@@ -10,7 +10,7 @@ import { readingOrder } from '../../../shared/frameOrder'
import { normalizeRotation } from '../../../shared/frameRotation'
import { api } from '../api'
import { t } from '../i18n'
-import { canEditOpenCanvas, pickedSelectors, useStore } from '../store'
+import { canEditActivePage, pickedSelectors, useStore } from '../store'
import { currentPageCanvas } from '../pages'
import { LAYER_TEXT_PROPERTIES } from '../richText'
import { recordUpdates, trackSave } from '../history'
@@ -86,7 +86,8 @@ export function selectedFrames(): Frame[] {
return frames.filter((f) => s.selectedIds.includes(f.id))
}
-export const canEdit = () => canEditOpenCanvas(useStore.getState())
+/** Frame edits on the page in view: false for a viewer and on a Finished page. */
+export const canEdit = () => canEditActivePage(useStore.getState())
const notice = (text: string) => useStore.getState().pushNotice(text)
/* ---- frames: moved, turned, rounded as one undo step ---- */
diff --git a/src/lib/actions/registry.ts b/src/lib/actions/registry.ts
index 9bbe3cc67..b0720d504 100644
--- a/src/lib/actions/registry.ts
+++ b/src/lib/actions/registry.ts
@@ -4,7 +4,7 @@
the registry what only it holds (its modals and panels) as the host. */
import type { PlainMessageKey } from '../i18n'
-import { useStore } from '../store'
+import { canEditOpenCanvas, useStore } from '../store'
import { currentMe, offersUpgrade } from '../me'
import { openUpgrade } from '../upgrade'
import { currentPageCanvas } from '../pages'
@@ -125,8 +125,10 @@ export interface CanvasAction {
section: number
/** the first chord bound on this platform is the one menus show */
keys?: readonly Chord[]
- /** changes the canvas: only an editor may run it */
+ /** changes the canvas: only an editor may run it, and not on a Finished page */
edit?: boolean
+ /** with `edit`: still runs on a Finished page, whose frames the server lets an editor lock */
+ onFinished?: boolean
/** the chords are shown, but another handler owns them (⌫ and Esc, which
* the canvas page claims with rules of their own) */
hintOnly?: boolean
@@ -749,6 +751,7 @@ export const ACTIONS: readonly CanvasAction[] = [
section: 4,
keys: [mod('l', { shift: true })],
edit: true,
+ onFinished: true,
enabled: hasSelection,
run: () => toggleLockSelection(),
},
@@ -1085,7 +1088,7 @@ export const ACTIONS: readonly CanvasAction[] = [
* needs to be, and its own test passes. */
export function isEnabled(action: CanvasAction): boolean {
if (!host) return false
- if (action.edit && !canEdit()) return false
+ if (action.edit && !(action.onFinished ? canEditOpenCanvas(useStore.getState()) : canEdit())) return false
return action.enabled ? action.enabled() : true
}
diff --git a/src/lib/api.ts b/src/lib/api.ts
index 5e3cb6b0b..e7096f234 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -1,4 +1,5 @@
import { useStore } from './store'
+import { t } from './i18n'
import type { InstanceSettings, InstanceSettingsPatch } from '../../shared/instanceSettings'
import { beginFrameSave } from './frameSaves'
import type { StackWrite } from '../../shared/frameStack'
@@ -433,7 +434,14 @@ export async function req(url: string, init?: RequestInit): Promise {
headers: { 'Content-Type': 'application/json' },
...init,
})
- if (!res.ok) throw new ApiError(res.status, await res.text())
+ if (!res.ok) {
+ const error = new ApiError(res.status, await res.text())
+ /* a write on a Finished page (CHE-9398 L8): every surface that sent one says why it did not land */
+ if (error.status === 409 && error.body.code === 'page_finished') {
+ useStore.getState().pushNotice(t('panels.pageFinishedReadOnly'))
+ }
+ throw error
+ }
return res.json()
}
diff --git a/src/lib/i18n/en/panels.ts b/src/lib/i18n/en/panels.ts
index 56fe5a114..b043bfb10 100644
--- a/src/lib/i18n/en/panels.ts
+++ b/src/lib/i18n/en/panels.ts
@@ -47,6 +47,9 @@ export const panels = {
pagesFinishedGroup: 'Finished',
pagesFinishedHint: 'Read only. Restore to move one back.',
pagesRestore: 'Restore',
+ ledgerCaptionLead: 'Ledger page.',
+ ledgerCaptionRest: 'The latest approved designs. It changes only when a locked proposal lands.',
+ pageFinishedReadOnly: 'Finished pages are read only. Restore the page to edit it.',
pagesLoading: 'Reading pages…',
pagesNoLedger: 'No ledger page',
pagesNoLedgerHint: 'Mark one page as the ledger. Approved designs land there.',
diff --git a/src/lib/i18n/pt-BR/panels.ts b/src/lib/i18n/pt-BR/panels.ts
index 3ddf75bf1..d46afff1d 100644
--- a/src/lib/i18n/pt-BR/panels.ts
+++ b/src/lib/i18n/pt-BR/panels.ts
@@ -47,6 +47,9 @@ export const panels: Catalog['panels'] = {
pagesFinishedGroup: 'Concluídas',
pagesFinishedHint: 'Somente leitura. Restaure para trazer uma de volta.',
pagesRestore: 'Restaurar',
+ ledgerCaptionLead: 'Página do registro.',
+ ledgerCaptionRest: 'Os designs aprovados mais recentes. Só muda quando uma proposta travada entra.',
+ pageFinishedReadOnly: 'Páginas concluídas são somente leitura. Restaure a página para editá-la.',
pagesLoading: 'Lendo as páginas…',
pagesNoLedger: 'Nenhuma página de registro',
pagesNoLedgerHint: 'Marque uma página como o registro. Os designs aprovados entram nela.',
diff --git a/src/lib/layerEdits.ts b/src/lib/layerEdits.ts
index 325231ae6..70d21bad6 100644
--- a/src/lib/layerEdits.ts
+++ b/src/lib/layerEdits.ts
@@ -3,7 +3,7 @@ import type { Frame } from '../../shared/types'
import { ELEMENT_ID_ATTR } from '../../shared/elementId'
import type { ReorderMove } from './keys'
import { restack, roomAt, stackOf, type StackWrite } from '../../shared/frameStack'
-import { canEditOpenCanvas, pickedSelectors, useStore } from './store'
+import { canEditActivePage, pickedSelectors, useStore } from './store'
import { t } from './i18n'
import { api, ApiError, errorMessage } from './api'
import { formatElementText, inspectElement, nudgeElements, requestFrame } from './frameBridge'
@@ -61,7 +61,7 @@ function queueRename(frameId: string, edit: (frame: Frame) => Promise) {
const started = historyEpoch()
const run = async () => {
const s = useStore.getState()
- if (s.canvas?.id !== canvasId || historyEpoch() !== started || !canEditOpenCanvas(s)) return
+ if (s.canvas?.id !== canvasId || historyEpoch() !== started || !canEditActivePage(s)) return
const frame = s.canvas?.frames.find((f) => f.id === frameId)
if (frame) await edit(frame)
}
diff --git a/src/lib/store.ts b/src/lib/store.ts
index 581476db2..ae1c355fb 100644
--- a/src/lib/store.ts
+++ b/src/lib/store.ts
@@ -10,6 +10,7 @@ import type {
AgentTask,
Canvas,
CanvasGuide,
+ CanvasPageInfo,
DesignDecision,
ElementComment,
Frame,
@@ -835,6 +836,20 @@ export function canEditOpenCanvas(s: Pick): boolean {
return roleAllows(roleOf(s), 'edit')
}
+/** The page the caller is on: the saved one, else the first. */
+export function activePageOf(s: Pick): CanvasPageInfo | undefined {
+ if (!s.canvas) return undefined
+ const pages = canvasPages(s.canvas)
+ return pages.find((page) => page.id === s.activePageId) ?? pages[0]
+}
+
+/** May the caller edit the frames on the page they are on? A Finished page is read only (CHE-9398 L8):
+ * the server refuses every frame write on it (409 `page_finished`), so the editor never offers one.
+ * Locking, Restore and the page-agnostic panels keep `canEditOpenCanvas`. */
+export function canEditActivePage(s: Pick): boolean {
+ return canEditOpenCanvas(s) && !activePageOf(s)?.finished
+}
+
/** May the caller comment on the open canvas? */
export function canCommentOpenCanvas(s: Pick): boolean {
return roleAllows(roleOf(s), 'comment')
diff --git a/src/pages/CanvasPage.tsx b/src/pages/CanvasPage.tsx
index c758a7ef8..a08774e50 100644
--- a/src/pages/CanvasPage.tsx
+++ b/src/pages/CanvasPage.tsx
@@ -1,6 +1,6 @@
import { CAPTURE_PREFIX, pasteWebCapture } from '../lib/webCapture'
import { useEffect, useMemo, useRef, useState, type CSSProperties } from 'react'
-import { canEditOpenCanvas, pickedSelectors, roleOf, useStore } from '../lib/store'
+import { canEditActivePage, canEditOpenCanvas, pickedSelectors, roleOf, useStore } from '../lib/store'
import { followPageInUrl } from '../lib/pageUrl'
import { MOD_KEY, PRESENT_SHORTCUT_HINT, isControlTarget, isTypingTarget } from '../lib/keys'
import { enterSelection, exitSelection, selectSibling } from '../lib/selectionKeys'
@@ -128,6 +128,7 @@ import { Note } from '../components/ui/note'
import { Textarea } from '../components/ui/textarea'
import { Modal, ModalActions, ModalEyebrow, ModalLede, ModalTitle } from '../components/ui/modal'
import { createCenteredFrame } from '../lib/framePlacement'
+import { LedgerCaption } from '../components/LedgerCaption'
import { RULER_PX } from '../components/Rulers'
import { NO_CANVAS, onViewCommand, syncViewMenu } from '../lib/viewMenu'
import { AGENTS_MIN, LAYERS_MIN, fitPanelWidths } from '../lib/panelWidths'
@@ -260,6 +261,9 @@ export function CanvasPage({
/* a guest is read-only from the first paint; anyone else until their role
arrives with the canvas (roleOf reads a missing canvas as edit) */
const readOnly = useStore((s) => guest || !canEditOpenCanvas(s))
+ /* a Finished page opens read only: no Inspector, element panel or Page panel to edit it with (the server
+ refuses those writes too) */
+ const pageEditable = useStore((s) => !guest && canEditActivePage(s))
const editorReady = useStore((s) => !guest && s.canvas?.id === canvasId && canEditOpenCanvas(s))
const isMobile = useIsMobile()
const prototypeMode = useStore((s) => s.prototypeMode)
@@ -415,7 +419,7 @@ export function CanvasPage({
always claimed, deleted something or not: an unhandled Backspace is
"back" to some engines (WebKitGTK, the Linux desktop app), and a
canvas must never leave the page for it. */
- const canEdit = canEditOpenCanvas(useStore.getState())
+ const canEdit = canEditActivePage(useStore.getState())
if (e.key === 'Delete' || e.key === 'Backspace') {
e.preventDefault()
if (canEdit && !e.repeat) deleteSelection()
@@ -472,7 +476,7 @@ export function CanvasPage({
function onPaste(e: ClipboardEvent) {
if (isTypingTarget(e.target)) return
/* every paste lands a frame or a layer */
- if (!canEditOpenCanvas(useStore.getState())) return
+ if (!canEditActivePage(useStore.getState())) return
const captureText = e.clipboardData?.getData('text/plain') ?? ''
if (captureText.startsWith(CAPTURE_PREFIX)) {
e.preventDefault()
@@ -541,13 +545,13 @@ export function CanvasPage({
function onDragOver(e: DragEvent) {
if (!carriesFiles(e) || e.defaultPrevented) return
e.preventDefault()
- if (e.dataTransfer) e.dataTransfer.dropEffect = canEditOpenCanvas(useStore.getState()) ? 'copy' : 'none'
+ if (e.dataTransfer) e.dataTransfer.dropEffect = canEditActivePage(useStore.getState()) ? 'copy' : 'none'
}
function onDrop(e: DragEvent) {
endDrag()
if (!carriesFiles(e) || e.defaultPrevented) return
e.preventDefault()
- if (!canEditOpenCanvas(useStore.getState())) return
+ if (!canEditActivePage(useStore.getState())) return
const componentId = e.dataTransfer?.getData(COMPONENT_DRAG_TYPE)
if (componentId) {
void dropComponent(componentId, { x: e.clientX, y: e.clientY })
@@ -727,10 +731,10 @@ export function CanvasPage({
/* with nothing selected the slot is the page's own settings, once opened
from the rail, until closed */
const pagePanelOpen = useStore((s) => s.pagePanelOpen)
- const pageShown = !readOnly && !selectedFrame && pagePanelOpen && !deferPanel
+ const pageShown = pageEditable && !selectedFrame && pagePanelOpen && !deferPanel
/* the frame Inspector, the element panel or the Page panel, whichever has the slot */
const propertiesShown =
- (!readOnly && !!selectedFrame && !deferPanel && (!!panelElement || inspectorOpen)) || pageShown
+ (pageEditable && !!selectedFrame && !deferPanel && (!!panelElement || inspectorOpen)) || pageShown
/* ⇧R docks the rulers on the canvas's top and left edges; the bar and the
floating chrome step in past them (the same test Stage draws them by) */
const rulers = useStore((s) => s.rulers)
@@ -1071,6 +1075,9 @@ export function CanvasPage({
{/* the presence pill in the bar already carries each agent's status
line; this per-agent stack is only for windows too narrow for it */}
+ {!isMobile && !uiHidden && (
+
+ )}
{!readOnly && }
@@ -1102,7 +1109,7 @@ export function CanvasPage({
}}
/>
)}
- {!isMobile && !readOnly && selectedFrame && panelElement && !deferPanel && (
+ {!isMobile && pageEditable && selectedFrame && panelElement && !deferPanel && (
)}
- {!isMobile && !readOnly && selectedFrame && inspectorOpen && !panelElement && !deferPanel && (
+ {!isMobile && pageEditable && selectedFrame && inspectorOpen && !panelElement && !deferPanel && (
)}
{!isMobile && pageShown && }
@@ -1140,7 +1147,7 @@ export function CanvasPage({
agentsOpen={showActivity}
onToggleAgents={() => setShowActivity((open) => !open)}
inspectorOpen={propertiesShown}
- inspectorAvailable={!readOnly}
+ inspectorAvailable={pageEditable}
inspectTarget={selectedFrame ? 'frame' : 'page'}
onToggleInspector={() => {
const s = useStore.getState()
@@ -1256,7 +1263,7 @@ export function CanvasPage({
the open state they read from is untouched, so they are back
as they were when ⌘. restores the chrome */}
{
if (!open) select(null)
}}
diff --git a/tests/ledgerCanvasUi.test.tsx b/tests/ledgerCanvasUi.test.tsx
new file mode 100644
index 000000000..36c6c5413
--- /dev/null
+++ b/tests/ledgerCanvasUi.test.tsx
@@ -0,0 +1,267 @@
+// @vitest-environment happy-dom
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { act } from 'react'
+import { createRoot, type Root } from 'react-dom/client'
+import type { Canvas, CanvasPageInfo, Frame } from '../shared/types'
+
+/* The canvas side of the A5 ledger (CHE-9398 L8): the ledger caption, the read-only Finished page, and the
+ notice a `page_finished` refusal shows. Design: design/lifecycle-ui/approved/A5-project-ledger.html and
+ A-phone-390-all-five.html @ 572cc77. */
+
+const updateFrame = vi.fn(() => Promise.resolve())
+const deleteFrame = vi.fn(() => Promise.resolve())
+const restackFrames = vi.fn(() => Promise.resolve([]))
+const setPageFinished = vi.fn()
+const getCanvas = vi.fn()
+vi.mock('../src/lib/api', async (original) => {
+ const actual = await original()
+ return {
+ ...actual,
+ api: {
+ ...actual.api,
+ /* the Components tab's dot asks; nothing waits in these tests */
+ canvasLibrary: () => new Promise(() => {}),
+ updateFrame: () => updateFrame(),
+ deleteFrame: () => deleteFrame(),
+ restackFrames: () => restackFrames(),
+ setPageFinished: (...args: unknown[]) => setPageFinished(...args),
+ getCanvas: (...args: unknown[]) => getCanvas(...args),
+ },
+ }
+})
+vi.mock('../src/lib/posthog', () => ({ posthog: { capture: vi.fn() } }))
+
+const storeModule = await import('../src/lib/store')
+const { useStore } = storeModule
+const { ApiError, req } = await import('../src/lib/api')
+const { LayersPanel } = await import('../src/components/LayersPanel')
+const { TooltipProvider } = await import('../src/components/ui/tooltip')
+
+;(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true
+globalThis.ResizeObserver ??= class {
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+} as unknown as typeof ResizeObserver
+
+const AT = { at: 1, by: 'user' }
+const PAGES: CanvasPageInfo[] = [
+ { id: 'base', name: 'Baseline', ledger: true },
+ { id: 'flows', name: 'Flows' },
+ { id: 'fin1', name: 'CHE-5162 · checkout', finished: AT },
+]
+const CAPTION = 'Ledger page. The latest approved designs. It changes only when a locked proposal lands.'
+
+const frame = (id: string, pageId: string, createdAt: number): Frame => ({
+ id,
+ canvasId: 'c1',
+ pageId,
+ name: `Frame ${id}`,
+ x: 0,
+ y: 0,
+ width: 100,
+ height: 100,
+ html: '',
+ createdAt,
+ updatedAt: 0,
+ updatedBy: 'me',
+})
+const canvasOf = (over: Partial