Documentation
¶
Overview ¶
Package vdom provides the Virtual DOM implementation for Vango.
The Virtual DOM (VDOM) provides an in-memory representation of the UI that can be efficiently diffed to produce minimal DOM updates. In Vango's server-driven architecture, the VDOM lives on the server and diffs produce binary patches sent to the client.
Core Types ¶
VNode is the fundamental building block representing elements, text, fragments, components, and raw HTML. Props holds attributes and event handlers. Attr and EventHandler are used to build Props.
Element API ¶
Elements are created using variadic factory functions:
Div(Class("card"), ID("main"),
H1(Text("Title")),
P(Text("Content")),
OnClick(handler),
)
Diffing ¶
The Diff function compares two VNode trees and returns a slice of Patch operations. Keyed reconciliation is used when children have Key attributes.
Hydration ¶
AssignHIDs walks the tree and assigns hydration IDs to interactive elements (those with event handlers). These IDs link server VNodes to client DOM.
Index ¶
- func AssignAllHIDs(node *VNode, gen *HIDGenerator)
- func AssignHIDs(node *VNode, gen *HIDGenerator)
- func ClearHIDs(node *VNode)
- func CollectHIDs(node *VNode) map[string]*VNode
- func CopyHIDs(src, dst *VNode) bool
- func CountInteractive(node *VNode) int
- func EffectiveAttrs(node *VNode) map[string]string
- func EffectiveAttrsWithPolicy(node *VNode, policy URLPolicy) map[string]string
- func EnableDevWarnings(enabled bool)
- func IsIsland(node *VNode) bool
- func IsIslandWithPolicy(node *VNode, policy URLPolicy) bool
- func IsOpaque(node *VNode) bool
- func IsOpaqueWithPolicy(node *VNode, policy URLPolicy) bool
- func IsVoidElement(tag string) bool
- func IsWasm(node *VNode) bool
- func IsWasmWithPolicy(node *VNode, policy URLPolicy) bool
- func IslandID(node *VNode) (string, bool)
- func IslandIDWithPolicy(node *VNode, policy URLPolicy) (string, bool)
- func IslandModule(node *VNode) (string, bool)
- func IslandModuleWithPolicy(node *VNode, policy URLPolicy) (string, bool)
- func IslandProps(node *VNode) (string, bool)
- func IslandPropsWithPolicy(node *VNode, policy URLPolicy) (string, bool)
- func OpaqueKind(node *VNode) string
- func OpaqueKindWithPolicy(node *VNode, policy URLPolicy) string
- func SanitizeAttrValue(key, raw string) (string, bool)
- func SanitizeAttrValueWithPolicy(policy URLPolicy, key, raw string) (string, bool)
- func ValidateRuntimeUnsafeBootstrap(cfg bootstrap.Config, perms RuntimeUnsafePermissions) error
- func WasmID(node *VNode) (string, bool)
- func WasmIDWithPolicy(node *VNode, policy URLPolicy) (string, bool)
- func WasmModule(node *VNode) (string, bool)
- func WasmModuleWithPolicy(node *VNode, policy URLPolicy) (string, bool)
- func WasmProps(node *VNode) (string, bool)
- func WasmPropsWithPolicy(node *VNode, policy URLPolicy) (string, bool)
- type Attr
- func Accept(types string) Attr
- func AccessKey(key string) Attr
- func Action(url string) Attr
- func Allow(value string) Attr
- func Allowfullscreen(allowfullscreen ...bool) Attr
- func Alt(text string) Attr
- func AriaAtomic(atomic bool) Attr
- func AriaBusy(busy bool) Attr
- func AriaControls(id string) Attr
- func AriaCurrent(value string) Attr
- func AriaDescribedBy(id string) Attr
- func AriaDisabled(disabled bool) Attr
- func AriaExpanded(expanded bool) Attr
- func AriaHasPopup(value string) Attr
- func AriaHidden(hidden bool) Attr
- func AriaLabel(label string) Attr
- func AriaLabelledBy(id string) Attr
- func AriaLive(mode string) Attr
- func AriaModal(modal bool) Attr
- func AriaPressed(pressed string) Attr
- func AriaSelected(selected bool) Attr
- func AriaValueMax(value float64) Attr
- func AriaValueMin(value float64) Attr
- func AriaValueNow(value float64) Attr
- func Async(async ...bool) Attr
- func AttrIf(condition bool, a Attr) Attr
- func Autocomplete(value string) Attr
- func Autofocus(autofocus ...bool) Attr
- func Autoplay(autoplay ...bool) Attr
- func Capture(mode string) Attr
- func Charset(charset string) Attr
- func Checked(checked ...bool) Attr
- func Class(classes ...string) Attr
- func ClassIf(condition bool, class string) Attr
- func Classes(classes ...any) Attr
- func Cols(n int) Attr
- func Colspan(n int) Attr
- func Content(content string) Attr
- func ContentEditable(editable bool) Attr
- func Controls(controls ...bool) Attr
- func Crossorigin(value string) Attr
- func D(value string) Attr
- func Data(key, value string) Attr
- func DataAttr(key, value string) Attr
- func Decoding(mode string) Attr
- func Defer_(deferAttr ...bool) Attr
- func Dir(dir string) Attr
- func Disabled(disabled ...bool) Attr
- func Download(filename ...string) Attr
- func Draggable() Attr
- func Enctype(enctype string) Attr
- func Enterkeyhint(hint string) Attr
- func Fill(value string) Attr
- func For(id string) Attr
- func FormAttr(id string) Attr
- func Formaction(url string) Attr
- func HeadersAttr(ids string) Attr
- func Height(h int) Attr
- func Hidden(hidden ...bool) Attr
- func Href(url string) Attr
- func Hreflang(lang string) Attr
- func HttpEquiv(value string) Attr
- func ID(id string) Attr
- func Inputmode(mode string) Attr
- func Integrity(value string) Attr
- func Key(key any) Attr
- func Lang(lang string) Attr
- func List(id string) Attr
- func Loading(mode string) Attr
- func Loop(loop ...bool) Attr
- func Max(value string) Attr
- func MaxLength(n int) Attr
- func Method(method string) Attr
- func Min(value string) Attr
- func MinLength(n int) Attr
- func Multiple(multiple ...bool) Attr
- func MutedAttr(muted ...bool) Attr
- func Name(name string) Attr
- func Novalidate(novalidate ...bool) Attr
- func Open(open ...bool) Attr
- func Pattern(pattern string) Attr
- func Placeholder(text string) Attr
- func Playsinline(playsinline ...bool) Attr
- func Poster(url string) Attr
- func Preload(mode string) Attr
- func Readonly(readonly ...bool) Attr
- func Rel(rel string) Attr
- func Required(required ...bool) Attr
- func Role(role string) Attr
- func Rows(n int) Attr
- func Rowspan(n int) Attr
- func Sandbox(value string) Attr
- func Scope(scope string) Attr
- func Selected(selected ...bool) Attr
- func SizesAttr(sizes string) Attr
- func Spellcheck(check bool) Attr
- func Src(url string) Attr
- func Srcset(srcset string) Attr
- func Step(value string) Attr
- func Stroke(value string) Attr
- func StrokeLinecap(value string) Attr
- func StrokeLinejoin(value string) Attr
- func StrokeWidth(value any) Attr
- func StyleAttr(style string) Attr
- func TabIndex(index int) Attr
- func Target(target string) Attr
- func TestID(id string) Attr
- func TitleAttr(title string) Attr
- func Type(t string) Attr
- func Value(value string) Attr
- func ViewBox(value string) Attr
- func Width(w int) Attr
- func Wrap(mode string) Attr
- type Case
- type ChildrenProvider
- type Component
- type EventHandler
- func OnAbort(handler any) EventHandler
- func OnAnimationCancel(handler any) EventHandler
- func OnAnimationEnd(handler any) EventHandler
- func OnAnimationIteration(handler any) EventHandler
- func OnAnimationStart(handler any) EventHandler
- func OnBlur(handler any) EventHandler
- func OnCanPlay(handler any) EventHandler
- func OnCanPlayThrough(handler any) EventHandler
- func OnChange(handler any) EventHandler
- func OnClick(handler any) EventHandler
- func OnContextMenu(handler any) EventHandler
- func OnCopy(handler any) EventHandler
- func OnCut(handler any) EventHandler
- func OnDblClick(handler any) EventHandler
- func OnDrag(handler any) EventHandler
- func OnDragEnd(handler any) EventHandler
- func OnDragEnter(handler any) EventHandler
- func OnDragLeave(handler any) EventHandler
- func OnDragOver(handler any) EventHandler
- func OnDragStart(handler any) EventHandler
- func OnDrop(handler any) EventHandler
- func OnDurationChange(handler any) EventHandler
- func OnEmptied(handler any) EventHandler
- func OnEnded(handler any) EventHandler
- func OnError(handler any) EventHandler
- func OnFocus(handler any) EventHandler
- func OnFocusIn(handler any) EventHandler
- func OnFocusOut(handler any) EventHandler
- func OnInput(handler any) EventHandler
- func OnInvalid(handler any) EventHandler
- func OnKeyDown(handler any) EventHandler
- func OnKeyPress(handler any) EventHandler
- func OnKeyUp(handler any) EventHandler
- func OnLoad(handler any) EventHandler
- func OnLoadStart(handler any) EventHandler
- func OnLoadedData(handler any) EventHandler
- func OnLoadedMetadata(handler any) EventHandler
- func OnMouseDown(handler any) EventHandler
- func OnMouseEnter(handler any) EventHandler
- func OnMouseLeave(handler any) EventHandler
- func OnMouseMove(handler any) EventHandler
- func OnMouseOut(handler any) EventHandler
- func OnMouseOver(handler any) EventHandler
- func OnMouseUp(handler any) EventHandler
- func OnPaste(handler any) EventHandler
- func OnPause(handler any) EventHandler
- func OnPlay(handler any) EventHandler
- func OnPlaying(handler any) EventHandler
- func OnPointerCancel(handler any) EventHandler
- func OnPointerDown(handler any) EventHandler
- func OnPointerEnter(handler any) EventHandler
- func OnPointerLeave(handler any) EventHandler
- func OnPointerMove(handler any) EventHandler
- func OnPointerUp(handler any) EventHandler
- func OnProgress(handler any) EventHandler
- func OnRateChange(handler any) EventHandler
- func OnReset(handler any) EventHandler
- func OnScroll(handler any) EventHandler
- func OnScrollEnd(handler any) EventHandler
- func OnSeeked(handler any) EventHandler
- func OnSeeking(handler any) EventHandler
- func OnSelect(handler any) EventHandler
- func OnStalled(handler any) EventHandler
- func OnSubmit(handler any) EventHandler
- func OnSuspend(handler any) EventHandler
- func OnTimeUpdate(handler any) EventHandler
- func OnToggle(handler any) EventHandler
- func OnTouchCancel(handler any) EventHandler
- func OnTouchEnd(handler any) EventHandler
- func OnTouchMove(handler any) EventHandler
- func OnTouchStart(handler any) EventHandler
- func OnTransitionCancel(handler any) EventHandler
- func OnTransitionEnd(handler any) EventHandler
- func OnTransitionRun(handler any) EventHandler
- func OnTransitionStart(handler any) EventHandler
- func OnVolumeChange(handler any) EventHandler
- func OnWaiting(handler any) EventHandler
- func OnWheel(handler any) EventHandler
- type FuncComponent
- type HIDGenerator
- type Patch
- type PatchOp
- type PathProvider
- type Props
- type RawHTMLSanitizeReport
- type RuntimeUnsafePermissions
- type ScriptsOption
- func WithAllowInsecureModuleOrigins() ScriptsOption
- func WithAllowInsecureModuleOriginsAcknowledged(token string) ScriptsOption
- func WithAllowSrcdoc() ScriptsOption
- func WithAllowUnsafeRawHTML() ScriptsOption
- func WithAllowUnsafeRawHTMLAcknowledged(token string) ScriptsOption
- func WithBootstrapConfig(cfg bootstrap.Config) ScriptsOption
- func WithCSRFToken(token string) ScriptsOption
- func WithDebug() ScriptsOption
- func WithModuleOrigins(origins ...string) ScriptsOption
- func WithRuntimeUnsafePermissions(perms RuntimeUnsafePermissions) ScriptsOption
- func WithScriptPath(path string) ScriptsOption
- func WithoutDefer() ScriptsOption
- type TrustedHTML
- type URLPolicy
- type VKind
- type VNode
- func A(args ...any) *VNode
- func Abbr(args ...any) *VNode
- func Address(args ...any) *VNode
- func Area(args ...any) *VNode
- func Article(args ...any) *VNode
- func Aside(args ...any) *VNode
- func Audio(args ...any) *VNode
- func B(args ...any) *VNode
- func Base(args ...any) *VNode
- func Bdi(args ...any) *VNode
- func Bdo(args ...any) *VNode
- func Blockquote(args ...any) *VNode
- func Body(args ...any) *VNode
- func Br(args ...any) *VNode
- func Button(args ...any) *VNode
- func Canvas(args ...any) *VNode
- func Caption(args ...any) *VNode
- func Circle(args ...any) *VNode
- func Cite(args ...any) *VNode
- func Code(args ...any) *VNode
- func Col(args ...any) *VNode
- func Colgroup(args ...any) *VNode
- func CustomElement(tag string, args ...any) *VNode
- func DangerouslySetInnerHTML(html TrustedHTML) *VNode
- func DataElement(args ...any) *VNode
- func Datalist(args ...any) *VNode
- func Dd(args ...any) *VNode
- func Defs(args ...any) *VNode
- func Details(args ...any) *VNode
- func Dfn(args ...any) *VNode
- func Dialog(args ...any) *VNode
- func Div(args ...any) *VNode
- func Dl(args ...any) *VNode
- func Dt(args ...any) *VNode
- func Either(first, second *VNode) *VNode
- func Ellipse(args ...any) *VNode
- func Em(args ...any) *VNode
- func Embed(args ...any) *VNode
- func Empty() *VNode
- func Fieldset(args ...any) *VNode
- func Figcaption(args ...any) *VNode
- func Figure(args ...any) *VNode
- func FindByHID(node *VNode, hid string) *VNode
- func Footer(args ...any) *VNode
- func Form(args ...any) *VNode
- func Fragment(children ...any) *VNode
- func G(args ...any) *VNode
- func Group(children ...any) *VNode
- func H1(args ...any) *VNode
- func H2(args ...any) *VNode
- func H3(args ...any) *VNode
- func H4(args ...any) *VNode
- func H5(args ...any) *VNode
- func H6(args ...any) *VNode
- func Head(args ...any) *VNode
- func Header(args ...any) *VNode
- func Hgroup(args ...any) *VNode
- func Hide(condition bool, node *VNode) *VNode
- func Hr(args ...any) *VNode
- func Html(args ...any) *VNode
- func I(args ...any) *VNode
- func If(condition bool, node *VNode) *VNode
- func IfElse(condition bool, ifTrue, ifFalse *VNode) *VNode
- func IfLazy(condition bool, fn func() *VNode) *VNode
- func Iframe(args ...any) *VNode
- func Img(args ...any) *VNode
- func Input(args ...any) *VNode
- func Kbd(args ...any) *VNode
- func Label(args ...any) *VNode
- func Legend(args ...any) *VNode
- func Li(args ...any) *VNode
- func Line(args ...any) *VNode
- func Link(path string, children ...any) *VNode
- func LinkEl(args ...any) *VNode
- func LinkPrefetch(path string, children ...any) *VNode
- func Main(args ...any) *VNode
- func Map_(args ...any) *VNode
- func Mark(args ...any) *VNode
- func Math(args ...any) *VNode
- func Maybe(node *VNode) *VNode
- func Menu(args ...any) *VNode
- func Meta(args ...any) *VNode
- func Meter(args ...any) *VNode
- func Nav(args ...any) *VNode
- func NavLink(ctx PathProvider, path string, children ...any) *VNode
- func NavLinkPrefix(ctx PathProvider, path string, children ...any) *VNode
- func Noscript(args ...any) *VNode
- func Nothing() *VNode
- func Null() *VNode
- func Object(args ...any) *VNode
- func Ol(args ...any) *VNode
- func Optgroup(args ...any) *VNode
- func Option(args ...any) *VNode
- func Output(args ...any) *VNode
- func P(args ...any) *VNode
- func Param(args ...any) *VNode
- func Path(args ...any) *VNode
- func Picture(args ...any) *VNode
- func Polygon(args ...any) *VNode
- func Polyline(args ...any) *VNode
- func Pre(args ...any) *VNode
- func Progress(args ...any) *VNode
- func Q(args ...any) *VNode
- func Range[T any](items []T, fn func(item T, index int) *VNode) []*VNode
- func RangeKeyed[T any](items []T, key func(item T) any, fn func(item T) *VNode) []*VNode
- func RangeMap[K comparable, V any](m map[K]V, fn func(key K, value V) *VNode) []*VNode
- func Raw(html TrustedHTML) *VNode
- func Rect(args ...any) *VNode
- func Repeat(n int, fn func(i int) *VNode) []*VNode
- func Rp(args ...any) *VNode
- func Rt(args ...any) *VNode
- func Ruby(args ...any) *VNode
- func S(args ...any) *VNode
- func Samp(args ...any) *VNode
- func Script(args ...any) *VNode
- func Section(args ...any) *VNode
- func Select(args ...any) *VNode
- func Show(condition bool, node *VNode) *VNode
- func ShowWhen(condition bool, fn func() *VNode) *VNode
- func Slot(args ...any) *VNode
- func Small(args ...any) *VNode
- func Source(args ...any) *VNode
- func Span(args ...any) *VNode
- func Strong(args ...any) *VNode
- func Style(args ...any) *VNode
- func Sub(args ...any) *VNode
- func Summary(args ...any) *VNode
- func Sup(args ...any) *VNode
- func Svg(args ...any) *VNode
- func Switch[T comparable](value T, cases ...Case[T]) *VNode
- func Table(args ...any) *VNode
- func Tbody(args ...any) *VNode
- func Td(args ...any) *VNode
- func Template(args ...any) *VNode
- func Text(content string) *VNode
- func Textarea(args ...any) *VNode
- func Textf(format string, args ...any) *VNode
- func Tfoot(args ...any) *VNode
- func Th(args ...any) *VNode
- func Thead(args ...any) *VNode
- func Time_(args ...any) *VNode
- func Title(args ...any) *VNode
- func TitleEl(args ...any) *VNode
- func Tr(args ...any) *VNode
- func Track(args ...any) *VNode
- func U(args ...any) *VNode
- func Ul(args ...any) *VNode
- func Unless(condition bool, node *VNode) *VNode
- func Use(args ...any) *VNode
- func VangoScripts(opts ...ScriptsOption) *VNode
- func Var(args ...any) *VNode
- func Video(args ...any) *VNode
- func Wbr(args ...any) *VNode
- func When(condition bool, fn func() *VNode) *VNode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignAllHIDs ¶
func AssignAllHIDs(node *VNode, gen *HIDGenerator)
AssignAllHIDs assigns HIDs to ALL element nodes, not just interactive ones. This is useful for debugging or when all elements need to be addressable.
func AssignHIDs ¶
func AssignHIDs(node *VNode, gen *HIDGenerator)
AssignHIDs walks the tree and assigns HIDs to interactive elements. An element is interactive if it has event handlers (props starting with "on"). Elements containing text children also get HIDs so text updates can target them.
func CollectHIDs ¶
CollectHIDs returns a map of HID to VNode for all nodes with HIDs.
func CopyHIDs ¶
CopyHIDs copies HIDs from the source tree to the destination tree. This is useful when diffing to preserve HIDs between renders. Returns true if all HIDs were successfully copied.
func CountInteractive ¶
CountInteractive returns the number of interactive elements in the tree.
func EffectiveAttrs ¶
EffectiveAttrs returns the string attributes that should be present on the DOM for the given node.
This includes: - regular attributes (excluding internal props, event handlers, etc.) - derived attributes for event interception (`data-ve` + modifier attrs) - derived attributes for hooks (`data-hook` + `data-hook-config`) - derived attributes for optimistic updates (`data-optimistic`)
It intentionally omits `data-hid`, which is managed separately via node.HID.
It may return nil when there are no effective attributes.
func EffectiveAttrsWithPolicy ¶
EffectiveAttrsWithPolicy returns EffectiveAttrs using the provided URL policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
It may return nil when there are no effective attributes.
func EnableDevWarnings ¶
func EnableDevWarnings(enabled bool)
EnableDevWarnings controls whether vdom emits development warnings for potentially expensive or footgun-prone helpers.
This is intended to be toggled by the server/runtime when DevMode is enabled.
func IsIslandWithPolicy ¶
IsIslandWithPolicy reports whether the node is an island boundary using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
func IsOpaqueWithPolicy ¶
IsOpaqueWithPolicy reports whether the node is an opaque boundary using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
func IsVoidElement ¶
IsVoidElement returns true if the tag is a void element.
func IsWasmWithPolicy ¶
IsWasmWithPolicy reports whether the node is a WASM boundary using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
func IslandIDWithPolicy ¶
IslandIDWithPolicy returns the island identifier if present using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
func IslandModule ¶
IslandModule returns the module path for an island, if present.
func IslandModuleWithPolicy ¶
IslandModuleWithPolicy returns the module path for an island, if present, using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
func IslandProps ¶
IslandProps returns the JSON props string for an island, if present.
func IslandPropsWithPolicy ¶
IslandPropsWithPolicy returns the JSON props string for an island, if present, using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
func OpaqueKind ¶
OpaqueKind returns the opaque boundary kind for a node: "island", "wasm", or "".
func OpaqueKindWithPolicy ¶
OpaqueKindWithPolicy returns the opaque boundary kind for a node using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
func SanitizeAttrValue ¶
SanitizeAttrValue applies URL scheme filtering for URL-bearing attributes and enforces srcdoc policy. Non-URL attributes are returned unchanged. Returns ok=false when the attribute should be omitted.
func SanitizeAttrValueWithPolicy ¶
SanitizeAttrValueWithPolicy applies URL scheme filtering for URL-bearing attributes and enforces srcdoc policy. Non-URL attributes are returned unchanged. Returns ok=false when the attribute should be omitted. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
func ValidateRuntimeUnsafeBootstrap ¶ added in v0.2.0
func ValidateRuntimeUnsafeBootstrap(cfg bootstrap.Config, perms RuntimeUnsafePermissions) error
func WasmIDWithPolicy ¶
WasmIDWithPolicy returns the WASM component identifier if present using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
func WasmModule ¶
WasmModule returns the module path for a WASM component, if present.
func WasmModuleWithPolicy ¶
WasmModuleWithPolicy returns the module path for a WASM component, if present, using the provided policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
Types ¶
type Attr ¶
Attr represents a single attribute.
func Allowfullscreen ¶
Allowfullscreen sets the allowfullscreen attribute.
func AriaControls ¶
AriaControls sets the aria-controls attribute.
func AriaDescribedBy ¶
AriaDescribedBy sets the aria-describedby attribute.
func AriaDisabled ¶
AriaDisabled sets the aria-disabled attribute.
func AriaExpanded ¶
AriaExpanded sets the aria-expanded attribute.
func AriaHasPopup ¶
AriaHasPopup sets the aria-haspopup attribute.
func AriaLabelledBy ¶
AriaLabelledBy sets the aria-labelledby attribute.
func AriaPressed ¶
AriaPressed sets the aria-pressed attribute.
func AriaSelected ¶
AriaSelected sets the aria-selected attribute.
func AriaValueMax ¶
AriaValueMax sets the aria-valuemax attribute.
func AriaValueMin ¶
AriaValueMin sets the aria-valuemin attribute.
func AriaValueNow ¶
AriaValueNow sets the aria-valuenow attribute.
func Autocomplete ¶
Autocomplete sets the autocomplete attribute.
func ContentEditable ¶
ContentEditable sets the contenteditable attribute.
func Data ¶
Data creates a data-* attribute. This is the primary way to add data attributes. Example: Data("id", "123") → data-id="123"
func Disabled ¶
Disabled sets/unsets the disabled boolean attribute. Disabled() and Disabled(true) set it; Disabled(false) omits/removes it.
func Enterkeyhint ¶
Enterkeyhint sets the enterkeyhint attribute.
func Key ¶
Key creates a key attribute for reconciliation. The key is converted to a string using fmt.Sprintf.
func Novalidate ¶
Novalidate sets the novalidate attribute.
func Playsinline ¶
Playsinline sets the playsinline attribute.
func StrokeLinecap ¶ added in v0.2.0
StrokeLinecap sets the SVG stroke-linecap attribute.
func StrokeLinejoin ¶ added in v0.2.0
StrokeLinejoin sets the SVG stroke-linejoin attribute.
func StrokeWidth ¶ added in v0.2.0
StrokeWidth sets the SVG stroke-width attribute.
type Case ¶
type Case[T comparable] struct { Value T Node *VNode IsDefault bool }
Case represents a case in a Switch statement.
func Case_ ¶
func Case_[T comparable](value T, node *VNode) Case[T]
Case_ creates a case for Switch.
func Default ¶
func Default[T comparable](node *VNode) Case[T]
Default creates a default case for Switch.
type ChildrenProvider ¶
type ChildrenProvider interface {
ChildrenNodes() []*VNode
}
ChildrenProvider exposes child VNodes to the VDOM layer. This is intended for framework integration only.
type Component ¶
type Component interface {
Render() *VNode
}
Component is anything that can render to a VNode.
type EventHandler ¶
type EventHandler struct {
Event string // "onclick", "oninput", etc.
Handler any // Function to call
}
EventHandler represents an event handler.
func OnAnimationCancel ¶
func OnAnimationCancel(handler any) EventHandler
OnAnimationCancel handles animationcancel events.
func OnAnimationEnd ¶
func OnAnimationEnd(handler any) EventHandler
OnAnimationEnd handles animationend events.
func OnAnimationIteration ¶
func OnAnimationIteration(handler any) EventHandler
OnAnimationIteration handles animationiteration events.
func OnAnimationStart ¶
func OnAnimationStart(handler any) EventHandler
OnAnimationStart handles animationstart events.
func OnCanPlay ¶
func OnCanPlay(handler any) EventHandler
OnCanPlay handles canplay events (can begin playback).
func OnCanPlayThrough ¶
func OnCanPlayThrough(handler any) EventHandler
OnCanPlayThrough handles canplaythrough events (can play without buffering).
func OnChange ¶
func OnChange(handler any) EventHandler
OnChange handles change events (fired when value is committed).
func OnContextMenu ¶
func OnContextMenu(handler any) EventHandler
OnContextMenu handles contextmenu (right-click) events.
func OnDurationChange ¶
func OnDurationChange(handler any) EventHandler
OnDurationChange handles durationchange events.
func OnEmptied ¶
func OnEmptied(handler any) EventHandler
OnEmptied handles emptied events (media emptied).
func OnEnded ¶
func OnEnded(handler any) EventHandler
OnEnded handles ended events (media playback finished).
func OnFocusIn ¶
func OnFocusIn(handler any) EventHandler
OnFocusIn handles focusin events (bubbles, unlike focus).
func OnFocusOut ¶
func OnFocusOut(handler any) EventHandler
OnFocusOut handles focusout events (bubbles, unlike blur).
func OnInput ¶
func OnInput(handler any) EventHandler
OnInput handles input events (fired when value changes).
func OnInvalid ¶
func OnInvalid(handler any) EventHandler
OnInvalid handles invalid events (form validation).
func OnKeyPress ¶
func OnKeyPress(handler any) EventHandler
OnKeyPress handles keypress events (deprecated, but still supported).
func OnLoadStart ¶
func OnLoadStart(handler any) EventHandler
OnLoadStart handles loadstart events (loading begins).
func OnLoadedData ¶
func OnLoadedData(handler any) EventHandler
OnLoadedData handles loadeddata events (first frame loaded).
func OnLoadedMetadata ¶
func OnLoadedMetadata(handler any) EventHandler
OnLoadedMetadata handles loadedmetadata events (metadata loaded).
func OnMouseEnter ¶
func OnMouseEnter(handler any) EventHandler
OnMouseEnter handles mouseenter events.
func OnMouseLeave ¶
func OnMouseLeave(handler any) EventHandler
OnMouseLeave handles mouseleave events.
func OnPause ¶
func OnPause(handler any) EventHandler
OnPause handles pause events (media is paused).
func OnPlay ¶
func OnPlay(handler any) EventHandler
OnPlay handles play events (media starts playing).
func OnPlaying ¶
func OnPlaying(handler any) EventHandler
OnPlaying handles playing events (playback resumed after pausing/buffering).
func OnPointerCancel ¶
func OnPointerCancel(handler any) EventHandler
OnPointerCancel handles pointercancel events.
func OnPointerDown ¶
func OnPointerDown(handler any) EventHandler
OnPointerDown handles pointerdown events.
func OnPointerEnter ¶
func OnPointerEnter(handler any) EventHandler
OnPointerEnter handles pointerenter events.
func OnPointerLeave ¶
func OnPointerLeave(handler any) EventHandler
OnPointerLeave handles pointerleave events.
func OnPointerMove ¶
func OnPointerMove(handler any) EventHandler
OnPointerMove handles pointermove events.
func OnProgress ¶
func OnProgress(handler any) EventHandler
OnProgress handles progress events (loading progress).
func OnRateChange ¶
func OnRateChange(handler any) EventHandler
OnRateChange handles ratechange events (playback rate changed).
func OnSeeked ¶
func OnSeeked(handler any) EventHandler
OnSeeked handles seeked events (seek operation completed).
func OnSeeking ¶
func OnSeeking(handler any) EventHandler
OnSeeking handles seeking events (seek operation started).
func OnSelect ¶
func OnSelect(handler any) EventHandler
OnSelect handles select events (text selection).
func OnStalled ¶
func OnStalled(handler any) EventHandler
OnStalled handles stalled events (fetching media data stalled).
func OnSuspend ¶
func OnSuspend(handler any) EventHandler
OnSuspend handles suspend events (loading suspended).
func OnTimeUpdate ¶
func OnTimeUpdate(handler any) EventHandler
OnTimeUpdate handles timeupdate events (playback position changed).
func OnToggle ¶
func OnToggle(handler any) EventHandler
OnToggle handles toggle events (for details element).
func OnTouchCancel ¶
func OnTouchCancel(handler any) EventHandler
OnTouchCancel handles touchcancel events.
func OnTouchStart ¶
func OnTouchStart(handler any) EventHandler
OnTouchStart handles touchstart events.
func OnTransitionCancel ¶
func OnTransitionCancel(handler any) EventHandler
OnTransitionCancel handles transitioncancel events.
func OnTransitionEnd ¶
func OnTransitionEnd(handler any) EventHandler
OnTransitionEnd handles transitionend events.
func OnTransitionRun ¶
func OnTransitionRun(handler any) EventHandler
OnTransitionRun handles transitionrun events.
func OnTransitionStart ¶
func OnTransitionStart(handler any) EventHandler
OnTransitionStart handles transitionstart events.
func OnVolumeChange ¶
func OnVolumeChange(handler any) EventHandler
OnVolumeChange handles volumechange events.
func OnWaiting ¶
func OnWaiting(handler any) EventHandler
OnWaiting handles waiting events (playback stopped, waiting for data).
type FuncComponent ¶
type FuncComponent struct {
// contains filtered or unexported fields
}
FuncComponent wraps a render function.
type HIDGenerator ¶
type HIDGenerator struct {
// contains filtered or unexported fields
}
HIDGenerator generates unique hydration IDs for interactive elements.
func NewHIDGenerator ¶
func NewHIDGenerator() *HIDGenerator
NewHIDGenerator creates a new HIDGenerator.
func (*HIDGenerator) Current ¶
func (g *HIDGenerator) Current() uint32
Current returns the current counter value without incrementing.
func (*HIDGenerator) Next ¶
func (g *HIDGenerator) Next() string
Next returns the next hydration ID (e.g., "h1", "h2", ...).
type Patch ¶
type Patch struct {
Op PatchOp // Operation type
HID string // Target element's hydration ID
Key string // Attribute key (for SetAttr/RemoveAttr)
Value string // New value
Node *VNode // For InsertNode/ReplaceNode
Index int // Insert position
ParentID string // Parent for InsertNode
// Unaddressable marks a diff batch that cannot be represented safely as patches.
// The server intercepts these batches and falls back to ResyncFull.
Unaddressable bool
Reason string
}
Patch represents a single DOM operation to apply.
func Diff ¶
Diff compares two VNode trees and returns the patches needed to transform prev into next.
func DiffWithPolicy ¶
DiffWithPolicy compares two VNode trees using the provided URL policy. The policy should be normalized (use NormalizeURLPolicy or URLPolicyFromSchemes).
type PatchOp ¶
type PatchOp uint8
PatchOp is the type of patch operation.
const ( PatchSetText PatchOp = 0x01 // Update text content PatchSetAttr PatchOp = 0x02 // Set/update attribute PatchRemoveAttr PatchOp = 0x03 // Remove attribute PatchInsertNode PatchOp = 0x04 // Insert new node PatchRemoveNode PatchOp = 0x05 // Remove node PatchMoveNode PatchOp = 0x06 // Move node to new position PatchReplaceNode PatchOp = 0x07 // Replace node entirely PatchSetValue PatchOp = 0x08 // Set input value PatchSetChecked PatchOp = 0x09 // Set checkbox checked PatchSetSelected PatchOp = 0x0A // Set select option selected PatchFocus PatchOp = 0x0B // Focus element PatchSetTextAt PatchOp = 0x16 // Set text by parent/index PatchRemoveNodeAt PatchOp = 0x17 // Remove node by parent/index PatchReplaceNodeAt PatchOp = 0x18 // Replace node by parent/index )
type PathProvider ¶
type PathProvider interface {
Path() string
}
PathProvider is the interface for context that provides current path. This is typically satisfied by server.Ctx.
type RawHTMLSanitizeReport ¶
type RawHTMLSanitizeReport struct {
Modified bool
RemovedNodes int
RemovedAttrs int
RewrittenAttr int
ParseError bool
UnsafeBypass bool
}
RawHTMLSanitizeReport describes how raw HTML was transformed.
func SanitizeRawHTML ¶
func SanitizeRawHTML(raw string) (string, RawHTMLSanitizeReport)
SanitizeRawHTML sanitizes raw HTML using the default URL policy.
func SanitizeRawHTMLWithPolicy ¶
func SanitizeRawHTMLWithPolicy(policy URLPolicy, raw string) (string, RawHTMLSanitizeReport)
SanitizeRawHTMLWithPolicy sanitizes raw HTML using the provided URL policy.
Sanitization rules: - Drop all on* event handler attributes. - Sanitize URL-bearing attributes with the same policy used for normal attrs. - Drop blocked attributes (unsafe schemes, srcdoc when disallowed, etc.). - Drop high-risk executable/style tags (<script>, <style>, <base>, <meta>) unless raw unsafe mode is enabled. - Drop style attributes to avoid CSS injection through raw HTML sinks.
type RuntimeUnsafePermissions ¶ added in v0.2.0
type ScriptsOption ¶
type ScriptsOption func(*scriptsOptions)
ScriptsOption is a functional option for VangoScripts.
func WithAllowInsecureModuleOrigins ¶ added in v0.0.2
func WithAllowInsecureModuleOrigins() ScriptsOption
WithAllowInsecureModuleOrigins allows cross-origin http: module imports on https: pages. SECURITY: This is a break-glass option for trusted local/dev environments only.
func WithAllowInsecureModuleOriginsAcknowledged ¶ added in v0.2.0
func WithAllowInsecureModuleOriginsAcknowledged(token string) ScriptsOption
WithAllowInsecureModuleOriginsAcknowledged allows insecure cross-origin http: module origins on https: pages with an explicit acknowledgement token.
func WithAllowSrcdoc ¶
func WithAllowSrcdoc() ScriptsOption
WithAllowSrcdoc enables client-side srcdoc updates. Use this only when cfg.Security.URLPolicy.AllowSrcdoc is true.
func WithAllowUnsafeRawHTML ¶
func WithAllowUnsafeRawHTML() ScriptsOption
WithAllowUnsafeRawHTML disables client-side raw HTML sanitization. SECURITY: Only use when all raw HTML input is fully trusted.
func WithAllowUnsafeRawHTMLAcknowledged ¶ added in v0.2.0
func WithAllowUnsafeRawHTMLAcknowledged(token string) ScriptsOption
WithAllowUnsafeRawHTMLAcknowledged disables client-side raw HTML sanitization with an explicit acknowledgement token.
func WithBootstrapConfig ¶ added in v0.0.3
func WithBootstrapConfig(cfg bootstrap.Config) ScriptsOption
WithBootstrapConfig injects canonical bootstrap JSON alongside the runtime script.
func WithCSRFToken ¶
func WithCSRFToken(token string) ScriptsOption
WithCSRFToken injects a CSRF token for the thin client. The token is used for WebSocket handshake validation.
func WithDebug ¶
func WithDebug() ScriptsOption
WithDebug enables debug mode for the thin client. Debug mode logs events, patches, and WebSocket messages to console.
func WithModuleOrigins ¶
func WithModuleOrigins(origins ...string) ScriptsOption
WithModuleOrigins sets allowed origins for island/wasm module imports. Origins must be full origins (scheme + host + optional port).
func WithRuntimeUnsafePermissions ¶ added in v0.2.0
func WithRuntimeUnsafePermissions(perms RuntimeUnsafePermissions) ScriptsOption
WithRuntimeUnsafePermissions injects validated runtime unsafe permissions.
func WithScriptPath ¶
func WithScriptPath(path string) ScriptsOption
WithScriptPath sets a custom path for the thin client script. Default is "/_vango/client.js".
func WithoutDefer ¶
func WithoutDefer() ScriptsOption
WithoutDefer removes the defer attribute from the script tag. By default, scripts are loaded with defer for non-blocking loading.
type TrustedHTML ¶
type TrustedHTML string
TrustedHTML marks HTML content that is intentionally allowed to bypass text escaping. Construct this type only from trusted/sanitized sources.
func SanitizeTrustedHTML ¶
func SanitizeTrustedHTML(html string) TrustedHTML
SanitizeTrustedHTML sanitizes a raw HTML string using the default URL policy.
func SanitizeTrustedHTMLWithPolicy ¶
func SanitizeTrustedHTMLWithPolicy(policy URLPolicy, html string) TrustedHTML
SanitizeTrustedHTMLWithPolicy sanitizes a raw HTML string using the provided URL policy.
func UnsafeTrustedHTML ¶
func UnsafeTrustedHTML(html string) TrustedHTML
UnsafeTrustedHTML marks a string as trusted HTML without sanitization. Use this only for hardcoded/internal HTML that you fully trust.
type URLPolicy ¶
type URLPolicy struct {
AllowedHrefSchemes map[string]struct{}
AllowedResourceSchemes map[string]struct{}
AllowedActionSchemes map[string]struct{}
AllowSrcdoc bool
// AllowUnsafeRawHTML disables sink sanitization for raw HTML content.
// Default: false.
AllowUnsafeRawHTML bool
}
URLPolicy defines allowed schemes for URL-bearing attributes. Empty scheme lists fall back to secure defaults.
func CloneURLPolicy ¶
CloneURLPolicy returns a deep copy of the policy (maps are cloned).
func DefaultURLPolicy ¶
func DefaultURLPolicy() URLPolicy
DefaultURLPolicy returns the default URL scheme policy.
func NormalizeURLPolicy ¶
NormalizeURLPolicy fills in defaults and normalizes schemes.
func URLPolicyFromSchemes ¶
func URLPolicyFromSchemes(hrefSchemes, resourceSchemes, actionSchemes []string, allowSrcdoc bool) URLPolicy
URLPolicyFromSchemes builds a URLPolicy from scheme lists. Empty slices fall back to the defaults.
type VNode ¶
type VNode struct {
Kind VKind // Node type
Tag string // Element tag name (e.g., "div")
Props Props // Attributes and event handlers
Children []*VNode // Child nodes
Key string // Reconciliation key
Text string // For KindText and KindRaw
Comp Component // For KindComponent
HID string // Hydration ID (assigned during render)
}
VNode is the virtual DOM node.
func Blockquote ¶
func CustomElement ¶
CustomElement creates an element with a custom tag name.
func DangerouslySetInnerHTML ¶
func DangerouslySetInnerHTML(html TrustedHTML) *VNode
DangerouslySetInnerHTML creates a raw HTML node.
SECURITY WARNING: This bypasses all HTML escaping and can cause XSS vulnerabilities if the content includes untrusted user input. Vango applies sink sanitization by default (SSR, patches, ResyncFull), but you must still treat this API as dangerous and feed it trusted/sanitized HTML. Default sink sanitization strips executable/style tags, style attrs, event handler attrs, unsafe URL attrs, and Vango runtime control attrs. Only use with content that is:
- Hardcoded in your source code
- Generated by a trusted sanitizer (e.g., bluemonday)
- From a trusted internal service
NEVER pass user-provided strings directly to DangerouslySetInnerHTML().
Example:
DangerouslySetInnerHTML(SanitizeTrustedHTML("<strong>Bold</strong>"))
func DataElement ¶
DataElement creates a <data> HTML element. Note: For data-* attributes, use Data(key, value) from attributes.go instead.
func Empty ¶
func Empty() *VNode
Empty returns an empty fragment that renders nothing. Unlike Null which returns nil, Empty returns a valid VNode that simply has no children.
Example:
vdom.Empty() // Renders nothing
func Figcaption ¶
func Fragment ¶
Fragment groups children without a wrapper element. It accepts ChildrenProvider implementations like vango.Slot. Any unsupported child type panics with a descriptive error.
func Hide ¶
Hide returns the node if condition is false, otherwise Nothing. Alias for Unless for semantic clarity.
func IfLazy ¶
IfLazy is an alias for When - use when you need lazy evaluation. See When for details on why this is needed for nullable pointer access.
func Link ¶
Link creates an anchor for client-side SPA navigation. When clicked, the thin client intercepts and sends a navigate event to the server instead of performing a full page reload.
Example: Link("/about", Text("About"))
func LinkPrefetch ¶
LinkPrefetch creates an SPA link that prefetches the target on hover. This provides faster navigation by loading the page before click.
Example: LinkPrefetch("/about", Text("About"))
func Maybe ¶
Maybe returns the node if it's not nil. This is a no-op but can make code more readable.
func NavLink ¶
func NavLink(ctx PathProvider, path string, children ...any) *VNode
NavLink creates an SPA link with "active" class when path matches. The active class is applied server-side based on the current route. This is the recommended helper for navigation menus.
Example:
Nav(
NavLink(ctx, "/", Text("Home")),
NavLink(ctx, "/about", Text("About")),
)
func NavLinkPrefix ¶
func NavLinkPrefix(ctx PathProvider, path string, children ...any) *VNode
NavLinkPrefix is like NavLink but matches path prefixes. Use for nav items that should be active for all sub-routes.
Example:
NavLinkPrefix(ctx, "/admin", Text("Admin"))
// Active on /admin, /admin/users, /admin/settings, etc.
func Nothing ¶
func Nothing() *VNode
Nothing is a legacy alias for Null. Prefer Null() for new code to match the spec naming.
func Null ¶
func Null() *VNode
Null returns nil, representing explicit nothing in the component tree. Use this when you want to explicitly render nothing.
Example:
func MaybeShow() *vdom.VNode {
if !shouldShow {
return vdom.Null()
}
return Content()
}
func RangeKeyed ¶
RangeKeyed maps a slice to VNodes and assigns a stable key for each item. The key value is formatted using fmt.Sprintf("%v", key).
func RangeMap ¶
func RangeMap[K comparable, V any](m map[K]V, fn func(key K, value V) *VNode) []*VNode
RangeMap maps a map to VNodes. RangeMap iterates deterministically by sorting keys.
Key ordering rules:
- bool: false < true
- signed ints: numeric ascending
- unsigned ints + uintptr: numeric ascending
- string: lexicographic ascending
- other comparable keys: deterministic ordering by (type, value token)
Float keys are rejected (panic) because they can be unordered (NaN).
func Raw ¶
func Raw(html TrustedHTML) *VNode
Raw is a legacy alias for DangerouslySetInnerHTML. Prefer DangerouslySetInnerHTML for new code as it makes the security implications more explicit.
SECURITY WARNING: This bypasses all HTML escaping. See DangerouslySetInnerHTML.
func Show ¶
Show returns the node if condition is true, otherwise Nothing. Alias for If for semantic clarity.
func ShowWhen ¶
ShowWhen is an alias for When with a UI-focused name. Use when conditionally showing UI elements that depend on nullable data.
func Switch ¶
func Switch[T comparable](value T, cases ...Case[T]) *VNode
Switch returns the node for the matching case value. If no case matches and there's a default, the default node is returned.
func TitleEl ¶
TitleEl is an alias for Title. It exists to match the Vango v1 Developer Guide examples and avoid ambiguity with the TitleAttr helper.
func VangoScripts ¶
func VangoScripts(opts ...ScriptsOption) *VNode
VangoScripts returns the script tag(s) needed to load the Vango thin client. This should be placed in the <head> or at the end of <body> in your layout.
Options can customize behavior:
- WithDebug() - enable console logging
- WithScriptPath(path) - custom script location
- WithCSRFToken(token) - inject CSRF token
- WithoutDefer() - load script synchronously
- WithAllowSrcdoc() - enable client-side srcdoc updates
- WithAllowUnsafeRawHTML() - disable raw HTML sanitization (unsafe)
- WithAllowInsecureModuleOrigins() - allow insecure http: cross-origin module imports on https: pages (unsafe)
Example usage in a layout:
func Layout(ctx vango.Ctx, children ...*vdom.VNode) *vdom.VNode {
return vdom.Html(
vdom.Head(
vdom.Meta(vdom.Charset("utf-8")),
vdom.VangoScripts(vdom.WithCSRFToken(ctx.Session().CSRFToken())),
),
vdom.Body(children...),
)
}
func When ¶
When is like If but with lazy evaluation. The function is only called if condition is true, preventing nil pointer panics.
Use this instead of If when the node contains expressions that depend on the condition being true (e.g., dereferencing a pointer that might be nil).
Example - WRONG (panics when DueDate is nil):
If(card.DueDate != nil,
Span(Text(card.DueDate.Format("Jan 2"))), // Evaluated even when nil!
)
Example - CORRECT (safe with lazy evaluation):
When(card.DueDate != nil, func() *VNode {
return Span(Text(card.DueDate.Format("Jan 2"))) // Only evaluated when not nil
})
func (*VNode) IsInteractive ¶
IsInteractive returns true if this element has at least one event handler prop. Event handler detection is centralized in isEventHandler so interactive counting, diffing, and effective attribute generation stay consistent.
func (*VNode) SuppressesRawHTMLUsageWarning ¶ added in v0.0.3
SuppressesRawHTMLUsageWarning reports whether this raw node was produced by internal framework code that should not trigger the generic "raw HTML API used" warning when sink sanitization makes no changes.