Skip to content
Merged
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
5 changes: 5 additions & 0 deletions docs/guides/host-ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ props:
`undefined`).
- `details?: 'card' | 'none'` lets you disable the built-in detail card (`none`
turns it off).
- `onRendererStatusChange?: (status: RendererStatus) => void` and
`onPainted?: (painted: Painted) => void` report when the renderer is ready or
failed, and when the frames settle on what is shown, as `useProjection`'s
options of the same names do (see the host core guide), so a host waits on
them rather than on the view's DOM.
- `controllerRef?: Ref<ProjectionController | null>` exposes `selectTarget`,
`resolveTarget`, and `anchorFor` (or use `useProjectionAnchor`).
- `ComparisonExplorer` also supports controlled `before`/`after` props with
Expand Down
2 changes: 2 additions & 0 deletions packages/host/core/src/ui/view/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,7 @@ export function viewOptions(props: ProjectionViewProps, colorMode: ColorMode, th
...(props.controlValues ? {controlValues: props.controlValues} : {}),
...(props.onControlChange ? {onControlChange: props.onControlChange} : {}),
...(props.onAction ? {onAction: props.onAction} : {}),
...(props.onRendererStatusChange ? {onRendererStatusChange: props.onRendererStatusChange} : {}),
...(props.onPainted ? {onPainted: props.onPainted} : {}),
}
}
7 changes: 6 additions & 1 deletion packages/host/core/src/ui/view/props.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type {ReactNode, Ref} from 'react'
import type {Diagnostic} from '@githubnext/projections-schemas'
import type {ColorMode, ControlValue} from '@githubnext/projections-renderer-sdk/protocol'
import type {AnnotationActivation, Highlighting, PresentationDefaults, ProjectionController} from '../../projection.js'
import type {AnnotationActivation, Highlighting, PresentationDefaults, ProjectionController, RendererStatus} from '../../projection.js'
import type {Painted} from '../../projection/paint.js'
import type {Holds} from '../../playback.js'
import type {ProjectionSelection, TargetAnnotation} from '../../targets/target.js'
import type {ComparisonMode} from '../../modes.js'
Expand Down Expand Up @@ -84,6 +85,10 @@ export interface ProjectionViewProps {
onAnnotationActivate?: (activation: AnnotationActivation) => void
/** Embedder content at the end of the detail card (in a `.ph-details-slot` element). */
renderDetails?: (selection: ProjectionSelection, projection: ProjectionController) => ReactNode
/** Called with the renderer status whenever it changes, and with the first (see `ProjectionOptions.onRendererStatusChange`). */
onRendererStatusChange?: (status: RendererStatus) => void
/** Called when the frames settle on what is shown while paused (see `ProjectionOptions.onPainted`). */
onPainted?: (painted: Painted) => void
/** Receives the view's controller, for example to call `selectTarget` or `anchorFor`; `null` once unmounted. */
controllerRef?: Ref<ProjectionController | null>
/**
Expand Down
9 changes: 9 additions & 0 deletions packages/host/core/test/paint.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,12 @@ test('an acknowledgement of an earlier init does not count until the frame catch
assert.equal(paintState(state({mode: 'diff', panes: panes(acknowledged(animated, 0.5)), stage: {init: diff}})), 'painting')
assert.equal(paintState(state({mode: 'diff', panes: panes(acknowledged(diff, 1)), stage: {init: diff}})), 'painted')
})

test('a ProjectionView reports the renderer status and painting to its embedder', async () => {
const {viewOptions} = await import('../dist/ui/view/options.js')
const onRendererStatusChange = () => {}
const onPainted = () => {}
const options = viewOptions({subject: undefined, projection: undefined, onRendererStatusChange, onPainted}, 'light', {})
assert.equal(options.onRendererStatusChange, onRendererStatusChange)
assert.equal(options.onPainted, onPainted)
})