Documentation
¶
Index ¶
- Constants
- func Classes(classes ...any) string
- func ForEach[T any](items []T, fn func(T, int) any) []any
- func If(cond bool, part any) any
- func IfElse(cond bool, part any, elsePart any) any
- func Ternary[T any](cond bool, trueRtn T, falseRtn T) T
- type Component
- type DomRect
- type VDomElem
- type VDomEvent
- type VDomFileData
- type VDomFormData
- type VDomFunc
- type VDomKeyboardEvent
- type VDomPointerData
- type VDomRef
- type VDomRefOperation
- type VDomRefPosition
- type VDomSimpleRef
Constants ¶
const FragmentTag = "#fragment"
const KeyPropKey = "key"
const ObjectType_Func = "func"
const ObjectType_Ref = "ref"
const TextTag = "#text"
const WaveNullTag = "wave:null"
const WaveTextTag = "wave:text"
Variables ¶
This section is empty.
Functions ¶
func Classes ¶
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 ¶
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 ¶
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.
Types ¶
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 ¶
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 ¶
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.
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 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 VDomRefPosition ¶
type VDomSimpleRef ¶
type VDomSimpleRef[T any] struct { Current T `json:"current"` }