import type { DesignDocument } from '../document/contracts.js'; /** Navigation state belongs to the workspace, never to document history. */ export type WorkspaceMode = 'view' | 'edit' | 'application'; export interface WorkspaceTarget { screenId: string; sourceRevision: string; } export interface WorkspaceCamera { x: number; y: number; zoom: number; } export interface WorkspaceViewExploration { query: string; flow: string; connectionMode: 'none' | 'selected' | 'all'; collapsedGroups: readonly string[]; navigationScrollTop: number; inspectorScrollTop: number; /** The measured canvas size lets a remounted View restore its camera center. */ viewport: { width: number; height: number; } | null; boardColumns?: number; /** Browser-local board placement, separate from product frame geometry. */ framePositions?: Readonly>; } export interface WorkspaceDesignContext { target: WorkspaceTarget; selection: readonly string[]; camera: WorkspaceCamera; /** One-shot canvas pick carried across the asynchronous View → Edit import. */ pendingPick?: WorkspaceDesignPick; /** Page navigation is view state, separate from the saved design document. */ pageId?: string; pages?: Readonly>; } export interface WorkspaceDesignPick { point: { x: number; y: number; }; /** A source occurrence remains identifiable after the preview has scrolled. */ source?: { attribute: string; value: string; occurrence: number; count: number; }; } export interface WorkspaceApplicationSurface { /** An implementation URL or a built draft URL supplied by the host. */ url: string; /** A built draft must identify the exact document revision it executes. */ documentRevision?: string; /** The artifact must confirm that its declared screen recipe has completed. */ waitForReady?: boolean; /** A run-scoped capability for selection messages from the isolated artifact. */ interactionBridge?: { version: 1; nonce: string; sourceRevision: string; documentRevision: string; }; } /** A fixed CSS viewport width for an executed surface; the host application still owns its own layout. */ export interface WorkspaceRunViewport { width: number; label?: string; } export interface WorkspaceApplicationRun { id: number; target: WorkspaceTarget; kind: 'implementation' | 'built-draft' | 'prototype'; /** Immutable authoring snapshot. It executes only declared prototype interactions. */ prototype?: { document: DesignDocument; fixtureId?: string; startingNodeId?: string; }; documentRevision?: string; viewport?: WorkspaceRunViewport; status: 'preparing' | 'ready' | 'failed'; surface?: WorkspaceApplicationSurface; error?: string; /** Run navigation cannot change the selected storyboard or design target. */ locations: readonly string[]; locationIndex: number; } export interface WorkspaceSnapshot { mode: WorkspaceMode; view: { target: WorkspaceTarget | null; camera: WorkspaceCamera; /** An explicit clear must not be mistaken for the first catalog load. */ selectionInitialized: boolean; exploration: WorkspaceViewExploration; }; design: WorkspaceDesignContext | null; application: WorkspaceApplicationRun | null; returnMode: 'view' | 'edit'; } export interface WorkspaceRunRequest { target: WorkspaceTarget; kind?: WorkspaceApplicationRun['kind']; documentRevision?: string; /** Requested execution width; omitted means the surface fills the workspace. */ viewport?: WorkspaceRunViewport; } export type WorkspaceApplicationPreparer = ( /** Captured run identity; caller mutations cannot retarget preparation. */ request: WorkspaceRunRequest, /** Return, replacement, and disposal abort pending work. */ signal: AbortSignal) => Promise;