Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .context/TECHSTACK.md
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,12 @@ data-doop-webfonts>` for the roster families the frame names and does not load i
400 `ledger_page`, the Archive 400 `archive_page`, unknown page 404, view role 403. A page-list save (REST and
`set_canvas_pages`, MCP and resident) that renames or drops a Finished page is refused 400 `page_finished`; a plain
`{ id, name }` save keeps the flags. Tests: `pageFinished.test.ts` (including the restore-race cases FP-01 and FP-03).
The client side (CHE-9470, L8): a Finished page opens read only. `canEditActivePage` (`src/lib/store.ts`) is
`canEditOpenCanvas` and the active page not Finished, and every frame-edit entry point reads it (frame press and drag,
Layers rows and menus, delete, paste, drop, rename, ⌘K and shortcut actions, version restore, and the Inspector, element
and Page panels). Lock and Unlock and Restore keep `canEditOpenCanvas` (the server leaves them open). `req()` shows the
notice "Finished pages are read only. Restore the page to edit it." on a 409 `page_finished`. The ledger page shows
`LedgerCaption` (a floating bar on desktop, a box at the top of the phone Layers sheet). Tests: `ledgerCanvasUi.test.tsx`.
- Frame write keys (`frame_write_keys`, migration 0045; `actions.writeFrameHtmlOnce`): MCP `set_frame_html` /
`edit_frame_html` / `append_frame_html` and REST `PATCH /api/frames/:id` (html only) and
`POST /api/frames/:id/append` take `idempotency_key` and an optional `version_name`. The key row,
Expand Down
43 changes: 43 additions & 0 deletions docs/ux/CHE-9470.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
issue: CHE-9470
design: design/lifecycle-ui/approved/A5-project-ledger.html @ 572cc77
# L8 (CHE-9398 plan r5): the ledger caption, the read-only Finished canvas and the phone 390 A5
# column. Every row of "What the lock asks for" that is not marked CHE-9448 is named once below:
# under `keep` when this slice leaves it as it is (it belongs to L5 or L7), under `change` when
# this slice draws it. The two landing rows are delivered by CHE-9448 and are not drawn here.
# The phone state rows cite U0 (CHE-9390, docs/ux/CHE-9390.yml), the shared PanelState, which L7
# already mounts in the Pages list: this slice draws the same four states inside the phone sheet.
pages:
- id: a5-ledger-canvas-desktop
design: design/lifecycle-ui/approved/A5-project-ledger.html @ 572cc77
url: doop page che-5478, the canvas stage with the ledger page and a Finished page open (reference frame), 1440 and 390
keep:
- pages-list: 'the Pages list, its Ledger tag, Finished group, row menus and Restore button are L7 (CHE-9469) and are not touched here'
- activity-row-finished: '"CHE-5162 · checkout moved to Finished" is written by the server (L5); the Activity feed is not touched here'
- lock-toggle: 'Lock and Unlock on a frame stay allowed on a Finished page; the server keeps them open and the client keeps its own rule (canEditOpenCanvas)'
- restore-page: 'Restore on a Finished page works from the Pages list; the canvas read-only rule does not cover it'
- copy-frame: 'Copy stays in the frame menu on a Finished page; it reads the frame and writes nothing'
- viewer-rules: 'a view-role visitor is read only as before; the guest and role rules are unchanged'
change:
- ledger-caption: 'a white pill under the top bar, left of the stage, with a brand book icon and the line "Ledger page. The latest approved designs. It changes only when a locked proposal lands."; the lead "Ledger page." is bold; shown on the ledger page only'
- finished-read-only: 'a Finished page opens read only: frame press and drag, the move gesture, delete, paste, drop, rename, hide, duplicate, mark ready and version restore are off, on the canvas, in the Layers panel and in the ⌘K and shortcut actions; the Inspector, the element panel and the Page panel are not offered'
- finished-layers: 'on a Finished page the Layers panel drops the New frame button, the Hide eye and the edit items of the frame menu; the Lock button and Copy stay'
- finished-notice: 'a 409 page_finished refusal shows the notice "Finished pages are read only. Restore the page to edit it." once, then the call still fails as before'
- activity-row-landing: 'delivered by CHE-9448'
- phone-landing-line: 'delivered by CHE-9448'
remove:
- finished-frame-edits: 'every frame edit entry point on a Finished page (listed under finished-read-only); the server already refuses them, the client no longer offers them'
- id: a5-ledger-phone-390
design: design/lifecycle-ui/approved/A-phone-390-all-five.html @ 572cc77
url: doop page che-5478, the Layers sheet on a phone (reference frame), 390
keep:
- phone-tabs: 'the Layers, Tokens, Components and Comments tabs of the sheet are not touched'
- pages-list-phone: 'the Pages list inside the sheet is L7; its rows, Finished group and menus are as shipped there'
- state-loading: 'PanelState loading, "Reading pages…" (U0 state-loading), drawn by L7 and shown here in the phone sheet'
- state-empty: 'PanelState empty, "No ledger page", the hint and its action (U0 state-empty), drawn by L7'
- state-error: 'PanelState error with one retry, "Could not move to Finished (409). The page changed." and Reload pages (U0 state-error), drawn by L7'
- state-offline: 'PanelState offline banner, "Offline. Pages are read only until it reconnects." (U0 state-offline), drawn by L7'
change:
- phone-ledger-caption: 'a grey box at the top of the Layers sheet, above Pages, with the same line as the desktop pill; shown only while the ledger page is open'
- phone-finished-read-only: 'the sheet lists a Finished page read only, as on the desktop'
- phone-landing-line: 'delivered by CHE-9448'
remove: []
16 changes: 13 additions & 3 deletions src/components/FrameContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { writeCanvasClipboard } from '../lib/canvasClipboard'
import { copyFramePng } from '../lib/frameExport'
import { deleteFramesTracked } from '../lib/history'
import { isStackLocked, setFramesHidden, setFramesLocked } from '../lib/layerEdits'
import { canEditOpenCanvas, useStore } from '../lib/store'
import { canEditActivePage, canEditOpenCanvas, useStore } from '../lib/store'
import { setFramesApproval } from '../lib/frameApproval'
import { useFrameSaves } from '../lib/frameSaves'
import { MOD_KEY } from '../lib/keys'
Expand Down Expand Up @@ -46,8 +46,10 @@ export function FrameContextMenu({
const [savingApproval, setSavingApproval] = useState(false)
/* a right-click inside a multi-selection acts on the whole group */
const selectedIds = useStore((s) => s.selectedIds)
/* a view or comment link keeps the items that only read the frame */
const readOnly = useStore((s) => !canEditOpenCanvas(s))
/* a view or comment link keeps the items that only read the frame; so does a Finished page, which
also keeps Lock (the server lets a lock through) */
const readOnly = useStore((s) => !canEditActivePage(s))
const canLock = useStore(canEditOpenCanvas)
const groupIds = selectedIds.includes(frame.id) ? selectedIds : [frame.id]
const groupSize = groupIds.length
const pendingSave = useFrameSaves((s) => groupIds.some((id) => !!s.pending[id]))
Expand Down Expand Up @@ -162,13 +164,21 @@ export function FrameContextMenu({
{allReady ? t('stage.moveToDraft') : t('stage.markReadyForDev')}
{groupSize > 1 && <MenuHint>{t('stage.framesCount', { count: groupSize })}</MenuHint>}
</ContextMenuItem>
</>
)}
{canLock && (
<>
<ContextMenuSeparator />
<ContextMenuItem onSelect={() => setFramesLocked(groupFrames(), !allLocked)}>
{groupSize > 1
? t(allLocked ? 'stage.unlockFrames' : 'stage.lockFrames', { count: groupSize })
: t(allLocked ? 'stage.unlock' : 'stage.lock')}
<MenuHint>{MOD_KEY}⇧L</MenuHint>
</ContextMenuItem>
</>
)}
{!readOnly && (
<>
<ContextMenuSeparator />
<ContextMenuItem tone="danger" disabled={allLocked} onSelect={deleteSelection}>
{groupSize > 1 ? t('stage.deleteFrames', { count: groupSize }) : t('stage.deleteFrame')}
Expand Down
6 changes: 3 additions & 3 deletions src/components/FrameHistoryModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useState } from 'react'
import type { Frame, FrameVersion, FrameVersionInfo } from '../../shared/types'
import { api, errorMessage } from '../lib/api'
import { recordUpdate } from '../lib/history'
import { canEditOpenCanvas, useStore } from '../lib/store'
import { canEditActivePage, useStore } from '../lib/store'
import { timeAgo } from '../lib/time'
import { AgentIcon } from './AgentIcon'
import { Badge } from './ui/badge'
Expand All @@ -25,8 +25,8 @@ type Shown = Pick<FrameVersion, 'html' | 'width' | 'height'>
export function FrameHistoryModal({ frame, onClose }: { frame: Frame; onClose: () => void }) {
/* the live frame: the prop is a snapshot from the menu that opened us */
const live = useStore((s) => s.canvas?.frames.find((f) => f.id === frame.id)) ?? frame
/* a view or comment link may browse the history, not restore from it */
const readOnly = useStore((s) => !canEditOpenCanvas(s))
/* a view or comment link, or a Finished page, may browse the history, not restore from it */
const readOnly = useStore((s) => !canEditActivePage(s))
const [versions, setVersions] = useState<FrameVersionInfo[] | null>(null)
const [selected, setSelected] = useState<FrameVersionInfo | 'current' | null>(null)
const [loaded, setLoaded] = useState<FrameVersion | null>(null)
Expand Down
10 changes: 5 additions & 5 deletions src/components/FrameView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react'
import { createPortal } from 'react-dom'
import type { ElementComment, Frame } from '../../shared/types'
import { canEditOpenCanvas, pickedSelectors, useStore } from '../lib/store'
import { canEditActivePage, pickedSelectors, useStore } from '../lib/store'
import { isCanvasElement } from '../lib/drawing'
import { isLayerLocked, standaloneSelector } from '../lib/layerEdits'
import { documentRect } from '../lib/frameBleed'
Expand Down Expand Up @@ -291,9 +291,9 @@ export const FrameView = memo(function FrameView({
/* the canvas tool: Hand lets presses fall through to the Stage, Comment
turns a click on the surface into a comment on the element under it */
const tool = useStore((s) => s.tool)
/* a view or comment link: the frame can be selected and looked at, never
/* a view or comment link, or a Finished page: the frame can be selected and looked at, never
moved, resized or edited — the server refuses those writes anyway */
const readOnly = useStore((s) => !canEditOpenCanvas(s))
const readOnly = useStore((s) => !canEditActivePage(s))
const select = useStore((s) => s.select)
const flash = useStore((s) => s.flashes[frame.id])
const stream = useStore((s) => s.streams[frame.id])
Expand Down Expand Up @@ -389,7 +389,7 @@ export const FrameView = memo(function FrameView({
/* a locked frame is not the stage's to select, move or resize: the press
falls through to the Stage, which treats it as empty canvas */
if (action !== 'frame-drag' || frame.locked) return
if (!canEditOpenCanvas(s)) {
if (!canEditActivePage(s)) {
e.stopPropagation()
if (!s.selectedIds.includes(frame.id)) select(frame.id)
return
Expand Down Expand Up @@ -723,7 +723,7 @@ export const FrameView = memo(function FrameView({
pointerType: e.pointerType,
spaceHeld: s.panMode,
})
if (action !== 'frame-drag' || frame.locked || !canEditOpenCanvas(s)) return
if (action !== 'frame-drag' || frame.locked || !canEditActivePage(s)) return
e.stopPropagation()
e.preventDefault()
if (!s.selectedIds.includes(frame.id)) select(frame.id)
Expand Down
18 changes: 11 additions & 7 deletions src/components/LayersPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import {
} from 'react'
import type { Frame } from '../../shared/types'
import type { ComponentDef } from '../../shared/components'
import { canEditOpenCanvas, pickedSelectors, useStore } from '../lib/store'
import { canEditActivePage, canEditOpenCanvas, pickedSelectors, useStore } from '../lib/store'
import { layerPlacement } from '../lib/frameBridge'
import { currentPageCanvas, usePageCanvas } from '../lib/pages'
import { PagesPanel, sectionHeading } from './PagesPanel'
import { LedgerCaption } from './LedgerCaption'
import { getIdentity } from '../lib/identity'
import { deleteFramesTracked } from '../lib/history'
import { renameComponent, rootPartKey } from '../lib/components'
Expand Down Expand Up @@ -242,7 +243,7 @@ export function LayersPanel({
const tab = useStore((s) => s.layersTab)
const setTab = useStore((s) => s.setLayersTab)
/* view and comment links browse the tree; nothing in it moves or changes */
const readOnly = useStore((s) => !canEditOpenCanvas(s))
const readOnly = useStore((s) => !canEditActivePage(s))
/* the Components tab wears a dot while its library waits on someone: changes
not yet published, or published updates not yet taken */
const libraryStatus = useLibraryStatus(useStore((s) => s.canvas?.id))
Expand Down Expand Up @@ -603,6 +604,7 @@ export function LayersPanel({
<>
{/* Figma's order: the pages at the top, the frames of the active page
under them, the search at the bottom within thumb's reach */}
{surface === 'inline' && <LedgerCaption variant="box" />}
<PagesPanel />
<div className={cn('mt-1.5 flex h-6 flex-none items-center justify-between pr-2.5 pl-3.5', sectionHeading)}>
<span data-slot="frame-section-heading" className={sectionHeading}>
Expand Down Expand Up @@ -830,7 +832,9 @@ function FrameRow({
onPointerDown: (e: ReactPointerEvent<HTMLDivElement>) => void
}) {
const { frame } = row
const readOnly = useStore((s) => !canEditOpenCanvas(s))
const readOnly = useStore((s) => !canEditActivePage(s))
/* a Finished page keeps the lock: the server lets it through, and so does its menu */
const canLock = useStore(canEditOpenCanvas)
const { label, startRename } = useItemRename(frame.name, !readOnly && !frame.locked, (value) =>
renameFrame(frame.id, value),
)
Expand All @@ -846,8 +850,8 @@ function FrameRow({
return (
<>
<ContextMenu>
{/* every item in the frame menu is an edit */}
<ContextMenuTrigger asChild disabled={readOnly}>
{/* a viewer has no item in the frame menu worth opening; a Finished page keeps the reading items and Lock */}
<ContextMenuTrigger asChild disabled={!canLock}>
<Row
data-row-key={row.key}
depth={0}
Expand All @@ -864,7 +868,7 @@ function FrameRow({
dimmed={!!frame.hidden}
onToggleHidden={readOnly ? undefined : () => setFrameHidden(frame, !frame.hidden)}
locked={!!frame.locked}
onToggleLocked={readOnly ? undefined : () => setFramesLocked([frame], !frame.locked)}
onToggleLocked={canLock ? () => setFramesLocked([frame], !frame.locked) : undefined}
onClick={onActivate}
onDoubleClick={startRename}
onContextMenu={() => {
Expand Down Expand Up @@ -935,7 +939,7 @@ function NodeRow({
onPointerDown: (e: ReactPointerEvent<HTMLDivElement>) => 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,
Expand Down
41 changes: 41 additions & 0 deletions src/components/LedgerCaption.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<p
role="status"
data-slot="ledger-caption"
style={style}
className={cn(
'text-label text-ink-soft',
variant === 'bar'
? 'pointer-events-none absolute z-20 flex max-w-[min(560px,50vw)] items-center gap-2 rounded-panel bg-surface px-3 py-2 shadow-float'
: 'mx-2 mt-2 rounded-card bg-sub px-3 py-2 text-caption',
className,
)}
>
{variant === 'bar' && <BookOpenIcon className="size-3.5 flex-none text-brand" />}
<span>
<strong className="font-medium text-ink">{t('panels.ledgerCaptionLead')}</strong>{' '}
{t('panels.ledgerCaptionRest')}
</span>
</p>
)
}
5 changes: 3 additions & 2 deletions src/lib/actions/edits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 ---- */
Expand Down
9 changes: 6 additions & 3 deletions src/lib/actions/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -749,6 +751,7 @@ export const ACTIONS: readonly CanvasAction[] = [
section: 4,
keys: [mod('l', { shift: true })],
edit: true,
onFinished: true,
enabled: hasSelection,
run: () => toggleLockSelection(),
},
Expand Down Expand Up @@ -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
}

Expand Down
Loading
Loading