vdom

package
v0.12.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 22, 2025 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const FragmentTag = "#fragment"
View Source
const KeyPropKey = "key"
View Source
const ObjectType_Func = "func"
View Source
const ObjectType_Ref = "ref"
View Source
const TextTag = "#text"
View Source
const WaveNullTag = "wave:null"
View Source
const WaveTextTag = "wave:text"

Variables

This section is empty.

Functions

func Classes

func Classes(classes ...any) string

Classes combines multiple class values into a single space-separated string. Similar to the JavaScript clsx library, it accepts:

  • strings: added directly if non-empty
  • nil: ignored (useful for vdom.If() statements)
  • []string: all non-empty strings are added
  • map[string]bool: keys with true values are added
  • []any: recursively processed

Returns a space-separated string of all valid class names.

func ForEach

func ForEach[T any](items []T, fn func(T, int) any) []any

ForEach applies a function to each item in a slice and returns a slice of results. The function receives the item and its index, and can return any type for flexible VDOM generation.

func If

func If(cond bool, part any) any

If returns the provided part if the condition is true, otherwise returns nil. This is useful for conditional rendering in VDOM children lists, props, and style attributes.

func IfElse

func IfElse(cond bool, part any, elsePart any) any

IfElse returns part if the condition is true, otherwise returns elsePart. This provides ternary-like conditional logic for VDOM children, props, and attributes. Accepts mixed types - part and elsePart don't need to be the same type, which is especially useful for children.

func Ternary

func Ternary[T any](cond bool, trueRtn T, falseRtn T) T

Ternary returns trueRtn if the condition is true, otherwise returns falseRtn. Unlike IfElse, this enforces type safety by requiring both return values to be the same type T.

Types

type Component

type Component[P any] func(props P) *VDomElem

type DomRect

type DomRect struct {
	Top    float64 `json:"top"`
	Left   float64 `json:"left"`
	Right  float64 `json:"right"`
	Bottom float64 `json:"bottom"`
	Width  float64 `json:"width"`
	Height float64 `json:"height"`
}

type VDomElem

type VDomElem struct {
	Tag      string         `json:"tag"`
	Props    map[string]any `json:"props,omitempty"`
	Children []VDomElem     `json:"children,omitempty"`
	Text     string         `json:"text,omitempty"`
}

vdom element

func H

func H(tag string, props map[string]any, children ...any) *VDomElem

H creates a VDomElem with the specified tag, properties, and children. This is the primary function for creating virtual DOM elements. Children can be strings, VDomElems, *VDomElem, slices, booleans, numeric types, or other types which are converted to strings using fmt.Sprint. nil children are allowed and removed from the final list.

func ToElems

func ToElems(part any) []VDomElem

ToElems converts various types into VDomElem slices for use in VDOM children. It handles strings, booleans, VDomElems, *VDomElem, slices, and other types by converting them to appropriate VDomElem representations. nil values are ignored and removed from the final slice. This is primarily an internal function and not typically called directly by application code.

func (*VDomElem) WithKey

func (e *VDomElem) WithKey(key any) *VDomElem

WithKey sets the key property of the VDomElem and returns the element. This is particularly useful for defined components since their prop types won't include keys. Returns nil if the element is nil, otherwise returns the same element for chaining.

type VDomEvent

type VDomEvent struct {
	WaveId          string             `json:"waveid"`
	EventType       string             `json:"eventtype"` // usually the prop name (e.g. onClick, onKeyDown)
	GlobalEventType string             `json:"globaleventtype,omitempty"`
	TargetValue     string             `json:"targetvalue,omitempty"`   // set for onChange events on input/textarea/select
	TargetChecked   bool               `json:"targetchecked,omitempty"` // set for onChange events on checkbox/radio inputs
	TargetName      string             `json:"targetname,omitempty"`    // target element's name attribute
	TargetId        string             `json:"targetid,omitempty"`      // target element's id attribute
	TargetFiles     []VDomFileData     `json:"targetfiles,omitempty"`   // set for onChange events on file inputs
	KeyData         *VDomKeyboardEvent `json:"keydata,omitempty"`       // set for onKeyDown events
	MouseData       *VDomPointerData   `json:"mousedata,omitempty"`     // set for onClick, onMouseDown, onMouseUp, onDoubleClick events
	FormData        *VDomFormData      `json:"formdata,omitempty"`      // set for onSubmit events on forms
}

type VDomFileData added in v0.12.3

type VDomFileData struct {
	FieldName string `json:"fieldname"`
	Name      string `json:"name"`
	Size      int64  `json:"size"`
	Type      string `json:"type"`
	Data64    []byte `json:"data64,omitempty"`
	Error     string `json:"error,omitempty"`
}

type VDomFormData added in v0.12.3

type VDomFormData struct {
	Action   string                    `json:"action,omitempty"`
	Method   string                    `json:"method"`
	Enctype  string                    `json:"enctype"`
	FormId   string                    `json:"formid,omitempty"`
	FormName string                    `json:"formname,omitempty"`
	Fields   map[string][]string       `json:"fields"`
	Files    map[string][]VDomFileData `json:"files"`
}

func (*VDomFormData) GetField added in v0.12.3

func (f *VDomFormData) GetField(fieldName string) string

type VDomFunc

type VDomFunc struct {
	Fn              any      `json:"-"` // server side function (called with reflection)
	Type            string   `json:"type" tstype:"\"func\""`
	StopPropagation bool     `json:"stoppropagation,omitempty"` // set to call e.stopPropagation() on the client side
	PreventDefault  bool     `json:"preventdefault,omitempty"`  // set to call e.preventDefault() on the client side
	GlobalEvent     string   `json:"globalevent,omitempty"`
	Keys            []string `json:"keys,omitempty"` // special for keyDown events a list of keys to "capture"
}

used in props

type VDomKeyboardEvent

type VDomKeyboardEvent struct {
	Type     string `json:"type" tstype:"\"keydown\"|\"keyup\"|\"keypress\"|\"unknown\""`
	Key      string `json:"key"`  // KeyboardEvent.key
	Code     string `json:"code"` // KeyboardEvent.code
	Repeat   bool   `json:"repeat,omitempty"`
	Location int    `json:"location,omitempty"` // KeyboardEvent.location

	// modifiers
	Shift   bool `json:"shift,omitempty"`
	Control bool `json:"control,omitempty"`
	Alt     bool `json:"alt,omitempty"`
	Meta    bool `json:"meta,omitempty"`
	Cmd     bool `json:"cmd,omitempty"`    // special (on mac it is meta, on windows/linux it is alt)
	Option  bool `json:"option,omitempty"` // special (on mac it is alt, on windows/linux it is meta)
}

type VDomPointerData

type VDomPointerData struct {
	Button  int `json:"button"`
	Buttons int `json:"buttons"`

	ClientX   int `json:"clientx,omitempty"`
	ClientY   int `json:"clienty,omitempty"`
	PageX     int `json:"pagex,omitempty"`
	PageY     int `json:"pagey,omitempty"`
	ScreenX   int `json:"screenx,omitempty"`
	ScreenY   int `json:"screeny,omitempty"`
	MovementX int `json:"movementx,omitempty"`
	MovementY int `json:"movementy,omitempty"`

	// Modifiers
	Shift   bool `json:"shift,omitempty"`
	Control bool `json:"control,omitempty"`
	Alt     bool `json:"alt,omitempty"`
	Meta    bool `json:"meta,omitempty"`
	Cmd     bool `json:"cmd,omitempty"`    // special (on mac it is meta, on windows/linux it is alt)
	Option  bool `json:"option,omitempty"` // special (on mac it is alt, on windows/linux it is meta)
}

type VDomRef

type VDomRef struct {
	Type          string           `json:"type" tstype:"\"ref\""`
	RefId         string           `json:"refid"`
	TrackPosition bool             `json:"trackposition,omitempty"`
	Position      *VDomRefPosition `json:"position,omitempty"`
	HasCurrent    bool             `json:"hascurrent,omitempty"`
}

used in props

type VDomRefOperation

type VDomRefOperation struct {
	RefId     string `json:"refid"`
	Op        string `json:"op"`
	Params    []any  `json:"params,omitempty"`
	OutputRef string `json:"outputref,omitempty"`
}

type VDomRefPosition

type VDomRefPosition struct {
	OffsetHeight       int     `json:"offsetheight"`
	OffsetWidth        int     `json:"offsetwidth"`
	ScrollHeight       int     `json:"scrollheight"`
	ScrollWidth        int     `json:"scrollwidth"`
	ScrollTop          int     `json:"scrolltop"`
	BoundingClientRect DomRect `json:"boundingclientrect"`
}

type VDomSimpleRef

type VDomSimpleRef[T any] struct {
	Current T `json:"current"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL