Line

You are reading the unreleased docs (next). See latest (v0.9)

ui/client/features/live-preview/hooks/usePreview

Cockpit client (features), next. Source: ui/client/features/live-preview/hooks/usePreview.tsx.

Type Aliases#

PreviewArgs#

PreviewArgs = object

Defined in: ui/client/features/live-preview/hooks/usePreview.tsx:14

Properties#

onShowInSource?

optional onShowInSource?: (src) => void

Defined in: ui/client/features/live-preview/hooks/usePreview.tsx:20

"Show in source" after an app error -- a screen with nowhere to open a file simply omits this.

Parameters
src

string

Returns

void

onSourceSelected?

optional onSourceSelected?: (src) => string | null

Defined in: ui/client/features/live-preview/hooks/usePreview.tsx:18

A raw data-cx-src value ("file:line:col") the framed app posted on click: resolve what it means for the screen hosting this preview (e.g. select a tree node) and return the status message to show, or null for none. Omitted on a screen with nothing to select against -- the message then just echoes the raw value.

Parameters
src

string

Returns

string | null

Functions#

usePreview()#

usePreview(__namedParameters?): object

Defined in: ui/client/features/live-preview/hooks/usePreview.tsx:31

-- live preview state, shared by any screen that frames a dev server (pages-editor was the first and only consumer; this is the extraction so Features/Tests/Git can embed the same thing instead of a second copy): a user-provided URL (input draft + the URL actually framed), click-to-source (a selection posted by the framed app, resolved by the CALLER -- this hook knows nothing about trees or nodes), how big the frame is (device sizes, remembered per project), whether the dev server is actually answering, and full screen.

The URL is set once and left alone: choosing a size or going full screen only changes the box around the iframe, never its src, so the app under development keeps its own state and the selection survives.

Parameters#

__namedParameters?

PreviewArgs = {}

Returns#

connect

connect: () => void

Returns

void

connectTo

connectTo: (target) => void

Point the frame at an address the Cockpit itself was given (the dev server it started, ).

Parameters
target

string

Returns

void

disconnect

disconnect: () => void

Returns

void

draft

draft: string

frameRef

frameRef: RefObject<HTMLIFrameElement | null>

fullScreen

fullScreen: boolean = full.fullScreen

message

message: string | null

release

release: (target) => void

Let go of target only if that is what the frame is showing: a server stopping must not close a URL the person typed.

Parameters
target

string

Returns

void

requestRects

requestRects: (queries) => Promise<Record<string, PreviewRect | null>>

Parameters
queries

PreviewRectQuery[]

Returns

Promise<Record<string, PreviewRect | null>>

setDraft

setDraft: Dispatch<SetStateAction<string>>

url

url: string | null

view

view: LivePreviewView