@jsvision/ui / Dialog
Class: Dialog
Documented in: Dialog
Defined in: ui/src/dialog/dialog.ts:76
A modal/modeless gray dialog: a Window in the dialog role with a valid() close-gate.
Example
import { Dialog, Input, Label, okButton, cancelButton, createEventLoop, signal, range } from '@jsvision/ui';
import { resolveCapabilities } from '@jsvision/core';
const caps = resolveCapabilities({ env: {}, platform: 'linux' }).profile;
const age = signal('42');
// A width/height with no explicit rect auto-centers the dialog and casts a drop-shadow.
const dialog = new Dialog({ title: ' Person ', width: 34, height: 9 });
const input = new Input({ value: age, validator: range(0, 120) });
const label = new Label('~A~ge (0–120)', input);
label.layout = { position: 'absolute', rect: { x: 1, y: 1, width: 14, height: 1 } };
input.layout = { position: 'absolute', rect: { x: 16, y: 1, width: 14, height: 1 } };
const ok = okButton();
ok.layout = { position: 'absolute', rect: { x: 6, y: 4, width: 10, height: 2 } };
dialog.add(label);
dialog.add(input);
dialog.add(ok);
dialog.add(cancelButton());
const loop = createEventLoop({ width: 40, height: 12 }, { caps });
loop.mount(dialog);
// Resolves to 'ok' only once Age validates; an out-of-range Age keeps the dialog open.
const command = await loop.execView<string>(dialog);Extends
Implements
Constructors
Constructor
new Dialog(
opts?):Dialog
Defined in: ui/src/dialog/dialog.ts:90
Parameters
opts?
DialogOptions = {}
title, plus either an explicit rect or a width/height (which auto-centers).
Returns
Dialog
Overrides
Properties
acceleratorScope
acceleratorScope:
boolean=true
Defined in: ui/src/dialog/dialog.ts:80
Roots the dialog's accelerator scope — its mount-time duplicate check stops at nested scopes.
Overrides
Window.acceleratorScope
active
readonlyactive:Signal<boolean>
Defined in: ui/src/window/window.ts:95
true when this is the active (top-most, focused) window, false when it sits behind another. The desktop keeps it in sync as windows are raised, added, and removed; the frame chrome reads it to switch between the active and inactive look. A standalone window defaults to true.
Inherited from
background?
optionalbackground?: keyof Theme
Defined in: ui/src/view/group.ts:64
Optional background theme role filled before children compose, so overlap never leaks cells.
Inherited from
bounds
bounds:
Rect
Defined in: ui/src/view/view.ts:65
Parent-relative integer rect; written by the layout pass — read it in draw/hit-testing.
Inherited from
castsShadow
castsShadow:
boolean=false
Defined in: ui/src/view/view.ts:78
When true, the renderer paints a drop shadow on the cells just below and to the right of this view, in paint order (a later sibling's shadow falls over an earlier one). Default false. The Desktop sets it per window.
Inherited from
centered
centered:
boolean=false
Defined in: ui/src/view/view.ts:86
When true, the layout pass recentres this view within its parent after layout — origin = (parent - self) / 2 on both axes. Intended for absolutely-placed views (a modal dialog, a message box) whose size is fixed and whose origin would otherwise be placed by the caller. Default false; Dialog sets it when centered.
Inherited from
children
readonlychildren:View[] =[]
Defined in: ui/src/view/group.ts:62
Ordered children; array order is paint order (back-to-front).
Inherited from
closable
closable:
boolean=true
Defined in: ui/src/window/window.ts:105
Whether the window can be closed (shows the close box).
Inherited from
dragging
readonlydragging:Signal<boolean>
Defined in: ui/src/window/window.ts:89
true while the window is being dragged (moved or resized), false otherwise. The desktop flips it around a gesture; bind to it if you want to react to drag start/end. A standalone window (never added to a desktop) stays false.
Inherited from
focusable
focusable:
boolean=true
Defined in: ui/src/window/window.ts:79
A window is a focus target so raising it (and resolving the active window) works.
Inherited from
layout
layout:
LayoutProps
Defined in: ui/src/window/window.ts:81
Absolute placement — the desktop writes layout.rect; padding: 1 insets content past the border.
Inherited from
minHeight
minHeight:
number=3
Defined in: ui/src/window/window.ts:111
Inherited from
minWidth
minWidth:
number=10
Defined in: ui/src/window/window.ts:110
The smallest size a resize gesture will shrink the window to. Raise these in a subclass whose content assumes a fixed minimum (e.g. a dialog whose child rects need at least 49×19).
Inherited from
movable
movable:
boolean=true
Defined in: ui/src/window/window.ts:99
Whether the title bar can be dragged to move the window.
Inherited from
number?
optionalnumber?:number
Defined in: ui/src/window/window.ts:97
An accelerator number 1–9 shown in the frame (Alt+N activates the window); undefined = none.
Inherited from
postProcess
postProcess:
boolean=true
Defined in: ui/src/dialog/dialog.ts:78
Caught after the focused chain so the hosted buttons' command events are seen dialog-wide.
Overrides
preProcess
preProcess:
boolean=false
Defined in: ui/src/view/view.ts:96
Take part in the pre-process sweep (root→down, before the focused view sees the event).
Inherited from
resizable
resizable:
boolean=true
Defined in: ui/src/window/window.ts:101
Whether the window can be resized via the corner grips.
Inherited from
state
readonlystate:ViewState
Defined in: ui/src/view/view.ts:67
Draw-against flags. The object reference is fixed; individual fields mutate (e.g. focused).
Inherited from
title
readonlytitle:Signal<string>
Defined in: ui/src/window/window.ts:83
The window title, centered in the top border. Set it to repaint the frame.
Inherited from
zoomable
zoomable:
boolean=true
Defined in: ui/src/window/window.ts:103
Whether the window can be maximized/restored (shows the zoom box).
Inherited from
Methods
accelerators()
accelerators(): readonly
string[]
Defined in: ui/src/view/view.ts:114
The Alt+hotkey accelerator characters (lowercase) this view claims in its focus scope, for duplicate-accelerator detection. The base returns none; accelerator-bearing widgets (Button/Label/CheckGroup/RadioGroup) override it to report their ~X~ hotkey(s).
Returns
readonly string[]
The claimed accelerator chars, or an empty list when the view claims none.
Inherited from
add()
add(
child):void
Defined in: ui/src/view/group.ts:88
Add a child, appending it on top (later in the array draws in front). If this group is already mounted, the child mounts immediately — its scope nested under this group's — and a reflow is scheduled for the new layout; otherwise the child mounts when this group itself mounts.
Parameters
child
The view to append.
Returns
void
Inherited from
addDynamic()
addDynamic(
build):void
Defined in: ui/src/view/group.ts:135
Add children reactively from a Show/For accessor, so the set of children updates itself as signals change. When the group is mounted, an effect reads the accessor, mounts any newly produced views, unmounts any that disappeared (firing their onCleanup), and schedules a reflow on change. Pass a factory that builds the combinator inside itself, not an already-built accessor — this lets the group own and dispose the combinator's reactive nodes on unmount.
Parameters
build
DynamicBuilder
A factory that constructs the combinator, e.g. () => Show(cond, then) or () => For(each, key, render).
Returns
void
Example
import { Group, signal, Show } from '@jsvision/ui';
const open = signal(false);
const group = new Group();
group.addDynamic(() => Show(() => open(), () => new Panel())); // Panel appears when `open` is trueInherited from
bind()
bind<
T>(reader,apply?,opts?):void
Defined in: ui/src/view/view.ts:228
Bind a reactive value to a redraw. Creates an effect (owned by this view's scope) that reads reader() — subscribing to whatever signals it touches — runs the optional apply(value), then requests a frame: a repaint by default, or a reflow when { relayout: true }. It re-runs automatically whenever those signals change, and is disposed when the view unmounts.
Call it from onMount, not the constructor — the view's scope only exists once mounted, so a pre-mount bind throws rather than silently dropping the binding.
Type Parameters
T
T
Parameters
reader
() => T
Reads the reactive source; the signals it reads become dependencies.
apply?
(v) => void
Optional: apply the read value to the widget (e.g. store it in a field).
opts?
Pass { relayout: true } when the change affects layout, so it reflows instead of just repainting.
relayout?
boolean
Returns
void
Example
import { signal } from '@jsvision/ui';
const count = signal(0);
// `status` is a View whose draw() reads count():
status.onMount(() => {
status.bind(() => count()); // repaint the status line whenever `count` changes
});Inherited from
close()
close():
void
Defined in: ui/src/window/window.ts:212
Close the window, removing it from the desktop (which disposes its scope). No-op if not closable.
Returns
void
Inherited from
commitPlacement()
commitPlacement():
void
Defined in: ui/src/window/window.ts:159
Freeze the current on-screen position into layout.rect and stop auto-centering, if this window is still centered. The desktop calls this at the start of a move/resize gesture: a centered window's real position lives in bounds (computed each reflow) rather than in layout.rect (which stays at the origin), so a gesture that read layout.rect would snap it to the top-left. After this runs once, the window behaves as a normally-placed window. No-op if not centered.
Returns
void
Inherited from
currentRect()
protectedcurrentRect():Rect
Defined in: ui/src/window/window.ts:166
The window's current WM rect (the layout rect, or a degenerate fallback before placement).
Returns
Inherited from
derived()
protectedderived<T>(fn): () =>T
Defined in: ui/src/view/view.ts:261
Create a stable derived accessor owned by this view's scope. The returned () => T keeps the same identity for the life of the view, so it is safe to build in the constructor and hand to child views before this view mounts. The backing computed is created lazily under the view's own scope, so it is always owned and disposed at unmount — unlike a bare computed() in the constructor, which would run before any scope exists, leak, and warn.
Reads behave sensibly across the lifecycle:
- Before mount: evaluates
fn()directly (correct current value, nothing persisted). Good for a pre-mount natural-size measure. - After mount: builds and memoizes a
computed(fn)under the view's scope. - After an unmount→remount: the memo is keyed to the scope it was built under, so a remounted view (which gets a fresh scope) re-derives under the new scope instead of returning the previous mount's disposed, now-frozen computed — keeping a
Show/For-remounted widget reactive.
Type Parameters
T
T
Parameters
fn
() => T
The derivation (pure; the signals it reads become the computed's dependencies).
Returns
A stable accessor; call it to read the derived value.
() => T
Inherited from
desiredCaret()
desiredCaret():
Point|null
Defined in: ui/src/view/view.ts:192
Where this view wants the hardware text cursor, in view-local cells, or null for no cursor (the default — most views never show one). A focused text input overrides this to place the caret at the edit position; the event loop reads it after each frame, converts it to an absolute cell, and moves the terminal cursor there.
Returns
Point | null
The view-local caret point (0-based, relative to this view's origin), or null.
Inherited from
draw()
draw(
ctx):void
Defined in: ui/src/dialog/dialog.ts:139
Paint the frame in the dialog role — close box, no zoom box. A modal dialog always draws active.
Parameters
ctx
Returns
void
Overrides
firstInvalidChild()
protectedfirstInvalidChild(view):View|null
Defined in: ui/src/dialog/dialog.ts:171
Depth-first: the first descendant control whose zero-arg valid() returns false, or null.
Parameters
view
Returns
View | null
focusSignal()
focusSignal():
Signal<void>
Defined in: ui/src/view/view.ts:136
Subscribe to this view's focus changes. Reading the returned signal inside a bind/effect re-runs that effect whenever this view gains or loses focus — including from another view (e.g. a Label repainting when the control it labels is focused). The signal notifies on every poke even without a value change. Lazy: the backing signal is created on first call.
Returns
Signal<void>
A signal that ticks whenever this view gains or loses focus.
Example
// Inside a widget's onMount, repaint whenever `other` view's focus changes:
this.onMount(() => this.bind(() => other.focusSignal()()));Inherited from
handleTerminating()
protectedhandleTerminating(command,ev):void
Defined in: ui/src/dialog/dialog.ts:219
Apply a terminating command: cancel bypasses; ok/yes/no run the valid() gate first.
Parameters
command
string
ev
Returns
void
invalidate()
invalidate():
void
Defined in: ui/src/view/view.ts:197
Request a repaint of this view. A no-op before the view is mounted (the first frame paints everything).
Returns
void
Inherited from
invalidateLayout()
invalidateLayout():
void
Defined in: ui/src/view/view.ts:202
Request a reflow (re-run layout, then repaint). Use this when a change affects size/position, not just pixels.
Returns
void
Inherited from
isZoomed()
isZoomed():
boolean
Defined in: ui/src/window/window.ts:171
Whether the window is currently zoomed (maximized).
Returns
boolean
Inherited from
measure()?
optionalmeasure(available):Size2D
Defined in: ui/src/view/view.ts:71
Optional intrinsic-size hook for auto sizing — return the size this view wants for available.
Parameters
available
Returns
Inherited from
onCleanup()
onCleanup(
fn):void
Defined in: ui/src/view/view.ts:298
Register a teardown callback that runs once when this view unmounts. Requires a mounted view — so call it from within onMount. Use it to release anything the view acquired (a timer, an external subscription).
Parameters
fn
() => void
The teardown callback.
Returns
void
Inherited from
onDesktopResize()
onDesktopResize(
size):void
Defined in: ui/src/window/window.ts:203
Re-fit to a resized desktop: a zoomed window re-maximizes to the new desktop size, and its saved restore rect is clamped so a later un-zoom still lands on-screen. A non-zoomed window is left where it is (a window may overflow the desktop edge).
Parameters
size
The new desktop content size.
Returns
void
Inherited from
onEvent()
onEvent(
ev):void
Defined in: ui/src/dialog/dialog.ts:189
Route events: catch a terminating command → valid() gate → close; and (when modal) route the frame close-box + Esc to the cancel path. Everything else delegates to Window (raise/move for a modeless dialog).
Parameters
ev
The dispatch envelope.
Returns
void
Overrides
onMount()
onMount(
fn):void
Defined in: ui/src/view/view.ts:283
Register a callback to run once when the view becomes live (after its first layout gives it bounds). This is where to call bind, since the view's reactive scope exists by then. Registering after the view is already live runs the callback immediately.
Parameters
fn
() => void
Post-mount setup.
Returns
void
Inherited from
onResized()
onResized():
void
Defined in: ui/src/window/window.ts:148
Called by the desktop right after a resize changed layout.rect, before the next reflow. The base window does nothing — flow-laid content reflows on its own. Override it in a subclass whose absolutely-placed children must be repositioned to track the new size (e.g. anchoring a button to the bottom-right corner).
Returns
void
Inherited from
remove()
remove(
child):void
Defined in: ui/src/view/group.ts:104
Remove a child: dispose its scope (recursively disposing its descendants and running their onCleanup), detach it, and schedule a reflow. Removing a non-child (or removing twice) is a safe no-op.
Parameters
child
The view to remove.
Returns
void
Inherited from
resetZoom()
resetZoom():
void
Defined in: ui/src/window/window.ts:176
Forget the zoom state without restoring the rect (used by cascade/tile, which place the window).
Returns
void
Inherited from
resolveCancel()
protectedresolveCancel(ev):void
Defined in: ui/src/dialog/dialog.ts:233
Resolve the modal to cancel (bypasses valid()), for the frame close-box and Esc.
Parameters
ev
Returns
void
selectByClick()
selectByClick():
void
Defined in: ui/src/window/window.ts:247
Select and raise the window on a mouse-down. The hit-test calls this before the event descends into the window's interior, so the window comes to the front even when an interior child ends up consuming the click. It first records whether the window was already active (so onEvent can make the first click on an inactive window only raise it, not act on a frame button). A standalone window (no desktop) is a safe no-op; re-selecting the already-active window just re-raises it harmlessly.
Returns
void
Inherited from
valid()
valid(
command):boolean
Defined in: ui/src/dialog/dialog.ts:164
The close-gate: cancel always closes; any other terminating command runs a depth-first sweep of the hosted controls, returning false on the first one whose own valid() is false and remembering it in firstInvalid so it can be refocused.
Parameters
command
string
The terminating command being validated.
Returns
boolean
Whether the dialog may close for this command.
zoom()
zoom():
void
Defined in: ui/src/window/window.ts:184
Toggle maximized ↔ restored. Maximizing saves the current rect and fills the desktop; restoring re-applies the exact saved rect. No-op if the window is not zoomable or has no desktop parent.
Returns
void