ui/client/features/live-preview/services/PreviewSource
The preview transport behind a small interface, so the iframe + postMessage implementation can be swapped (e.g.
Cockpit client (features), next. Source: ui/client/features/live-preview/services/PreviewSource.ts.
Interfaces#
PreviewSource#
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:18
Properties#
url
readonlyurl:string
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:20
Page being previewed.
Methods#
onSelect()
onSelect(
handler): () =>void
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:22
Subscribe to element selections (a raw data-cx-src value). Returns an unsubscribe.
Parameters
handler
(src) => void
Returns
() => void
onSignal()
onSignal(
handler): () =>void
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:24
Subscribe to the plugin's ready and the app's error messages. Returns an unsubscribe.
Parameters
handler
(signal) => void
Returns
() => void
requestRects()
requestRects(
queries):Promise<Record<string,PreviewRect|null>>
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:31
-- ask the bridge for the rects of a batch of nodes; resolves with one entry per query key,
null for a query with nothing currently rendered. Resolves to {} if the bridge never answers
(not installed, or the frame navigated away) rather than hanging forever.
Parameters
queries
Returns
Promise<Record<string, PreviewRect | null>>
setPicking()
setPicking(
on):void
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:27
-- tell the bridge whether Pick is on: off by default, an un-modified click reaches the app untouched (Alt+Click always selects regardless, handled entirely on the bridge's side).
Parameters
on
boolean
Returns
void
Type Aliases#
PreviewRect#
PreviewRect =
object
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:12
-- one element's bounding box, in the iframe's own viewport coordinates (the caller offsets by the frame's position on the page).
Properties#
height
height:
number
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:12
left
left:
number
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:12
top
top:
number
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:12
width
width:
number
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:12
PreviewRectQuery#
PreviewRectQuery =
object
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:16
A request for the rect of the element nearest file:line (the bridge matches by line distance within
the file, not an exact column -- see previewBridge.mjs's elementAt). key is the caller's own id,
echoed back; this bridge knows nothing about the Cockpit's tree or node ids.
Properties#
file
file:
string
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:16
key
key:
string
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:16
line
line:
number
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:16
PreviewSignal#
PreviewSignal = {
type:"ready"; } | {message:string;src:string|null;type:"error"; }
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:8
What the previewed app tells the Cockpit besides a selection: the preview plugin is loaded (ready),
or the app threw an uncaught error (error). src is the stack's top project frame as a
data-cx-src-shaped "file:line:col" string, or null when the stack has no project frame (a library-only
stack shows no "Show in source" button). Nothing else crosses.
Functions#
createIframePreviewSource()#
createIframePreviewSource(
url,getFrameWindow):PreviewSource
Defined in: ui/client/features/live-preview/services/PreviewSource.ts:36
iframe transport: accepts construct:* messages only from the given
iframe's window AND only from the previewed URL's origin.
Parameters#
url
string
getFrameWindow
() => Window | null | undefined