vdom

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BackendUpdate_InitialChunkSize = 50  // Size for initial chunks that contain both TransferElems and StateSync
	BackendUpdate_ChunkSize        = 100 // Size for subsequent chunks
)
View Source
const (
	WorkType_Render = "render"
	WorkType_Effect = "effect"
)
View Source
const BindTag = "#bind"
View Source
const ChildrenPropKey = "children"
View Source
const FragmentTag = "#fragment"
View Source
const Html_BindParamTagName = "bindparam"
View Source
const Html_BindPrefix = "#bind:"
View Source
const Html_BindTagName = "bind"
View Source
const Html_GlobalEventPrefix = "#globalevent"
View Source
const Html_ParamPrefix = "#param:"
View Source
const KeyPropKey = "key"
View Source
const ObjectType_Binding = "binding"
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 Class

func Class(name string) classAttrWrapper

func ClassIf

func ClassIf(cond bool, name string) classAttrWrapper

func ClassIfElse

func ClassIfElse(cond bool, name string, elseName string) classAttrWrapper

func Classes

func Classes(classes ...any) string

func Filter

func Filter[T any](items []T, fn func(T) bool) []T

func FilterIdx

func FilterIdx[T any](items []T, fn func(T, int) bool) []T

func ForEach

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

func ForEachIdx

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

func Fragment

func Fragment(parts ...any) any

func If

func If(cond bool, part any) any

func IfElse

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

func P

func P(propName string, propVal any) any

func PStyle

func PStyle(styleAttr string, propVal any) any

func Props

func Props(props any) map[string]any

func QueueRefOp

func QueueRefOp(ctx context.Context, ref *VDomRef, op VDomRefOperation)

func UseAtom

func UseAtom[T any](ctx context.Context, atomName string) (T, func(T))

func UseEffect

func UseEffect(ctx context.Context, fn func() func(), deps []any)

func UseId

func UseId(ctx context.Context) string

func UseRenderTs

func UseRenderTs(ctx context.Context) int64

func UseState

func UseState[T any](ctx context.Context, initialVal T) (T, func(T))

func UseStateWithFn

func UseStateWithFn[T any](ctx context.Context, initialVal T) (T, func(T), func(func(T) T))

Types

type Atom

type Atom struct {
	Val    any
	Dirty  bool
	UsedBy map[string]bool // component waveid -> true
}

type ChildKey

type ChildKey struct {
	Tag string
	Idx int
	Key string
}

type Component

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

type ComponentImpl

type ComponentImpl struct {
	WaveId  string
	Tag     string
	Key     string
	Elem    *VDomElem
	Mounted bool

	// hooks
	Hooks []*Hook

	// #text component
	Text string

	// base component -- vdom, wave elem, or #fragment
	Children []*ComponentImpl

	// component -> component
	Comp *ComponentImpl
}

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 EffectWorkElem

type EffectWorkElem struct {
	Id          string
	EffectIndex int
}

type Hook

type Hook struct {
	Init      bool          // is initialized
	Idx       int           // index in the hook array
	Fn        func() func() // for useEffect
	UnmountFn func()        // for useEffect
	Val       any           // for useState, useMemo, useRef
	Deps      []any
}

generic hook structure

type RootElem

type RootElem struct {
	OuterCtx        context.Context
	Root            *ComponentImpl
	RenderTs        int64
	CFuncs          map[string]any
	CompMap         map[string]*ComponentImpl // component waveid -> component
	EffectWorkQueue []*EffectWorkElem
	NeedsRenderMap  map[string]bool
	Atoms           map[string]*Atom
	RefOperations   []VDomRefOperation
}

func MakeRoot

func MakeRoot() *RootElem

func (*RootElem) AddEffectWork

func (r *RootElem) AddEffectWork(id string, effectIndex int)

func (*RootElem) AddRenderWork

func (r *RootElem) AddRenderWork(id string)

func (*RootElem) Event

func (r *RootElem) Event(id string, propName string, event VDomEvent)

func (*RootElem) GetAtom

func (r *RootElem) GetAtom(name string) *Atom

func (*RootElem) GetAtomVal

func (r *RootElem) GetAtomVal(name string) any

func (*RootElem) GetRefOperations

func (r *RootElem) GetRefOperations() []VDomRefOperation

func (*RootElem) GetStateSync

func (r *RootElem) GetStateSync(full bool) []VDomStateSync

func (*RootElem) MakeVDom

func (r *RootElem) MakeVDom() *VDomElem

func (*RootElem) QueueRefOp

func (r *RootElem) QueueRefOp(op VDomRefOperation)

func (*RootElem) RegisterComponent

func (r *RootElem) RegisterComponent(name string, cfunc any) error

func (*RootElem) Render

func (r *RootElem) Render(elem *VDomElem)

func (*RootElem) RunWork

func (r *RootElem) RunWork()

this will be called by the frontend to say the DOM has been mounted it will eventually send any updated "refs" to the backend as well

func (*RootElem) SetAtomVal

func (r *RootElem) SetAtomVal(name string, val any, markDirty bool)

func (*RootElem) SetOuterCtx

func (r *RootElem) SetOuterCtx(ctx context.Context)

func (*RootElem) UpdateRef

func (r *RootElem) UpdateRef(updateRef VDomRefUpdate)

type VDomAsyncInitiationRequest

type VDomAsyncInitiationRequest struct {
	Type    string `json:"type" tstype:"\"asyncinitiationrequest\""`
	Ts      int64  `json:"ts"`
	BlockId string `json:"blockid,omitempty"`
}

func MakeAsyncInitiationRequest

func MakeAsyncInitiationRequest(blockId string) VDomAsyncInitiationRequest

type VDomBackendOpts

type VDomBackendOpts struct {
	CloseOnCtrlC         bool `json:"closeonctrlc,omitempty"`
	GlobalKeyboardEvents bool `json:"globalkeyboardevents,omitempty"`
	GlobalStyles         bool `json:"globalstyles,omitempty"`
}

type VDomBackendUpdate

type VDomBackendUpdate struct {
	Type          string             `json:"type" tstype:"\"backendupdate\""`
	Ts            int64              `json:"ts"`
	BlockId       string             `json:"blockid"`
	Opts          *VDomBackendOpts   `json:"opts,omitempty"`
	HasWork       bool               `json:"haswork,omitempty"`
	RenderUpdates []VDomRenderUpdate `json:"renderupdates,omitempty"`
	TransferElems []VDomTransferElem `json:"transferelems,omitempty"`
	StateSync     []VDomStateSync    `json:"statesync,omitempty"`
	RefOperations []VDomRefOperation `json:"refoperations,omitempty"`
	Messages      []VDomMessage      `json:"messages,omitempty"`
}

func SplitBackendUpdate

func SplitBackendUpdate(update *VDomBackendUpdate) []*VDomBackendUpdate

SplitBackendUpdate splits a large VDomBackendUpdate into multiple smaller updates The first update contains all the core fields, while subsequent updates only contain array elements that need to be appended

func (*VDomBackendUpdate) CreateTransferElems

func (beUpdate *VDomBackendUpdate) CreateTransferElems()

type VDomBinding

type VDomBinding struct {
	Type string `json:"type" tstype:"\"binding\""`
	Bind string `json:"bind"`
}

used in props

type VDomContextVal

type VDomContextVal struct {
	Root    *RootElem
	Comp    *ComponentImpl
	HookIdx int
}

type VDomCreateContext

type VDomCreateContext struct {
	Type    string              `json:"type" tstype:"\"createcontext\""`
	Ts      int64               `json:"ts"`
	Meta    waveobj.MetaMapType `json:"meta,omitempty"`
	Target  *VDomTarget         `json:"target,omitempty"`
	Persist bool                `json:"persist,omitempty"`
}

type VDomElem

type VDomElem struct {
	WaveId   string         `json:"waveid,omitempty"` // required, except for #text nodes
	Tag      string         `json:"tag"`
	Props    map[string]any `json:"props,omitempty"`
	Children []VDomElem     `json:"children,omitempty"`
	Text     string         `json:"text,omitempty"`
}

vdom element

func Bind

func Bind(htmlStr string, params map[string]any) *VDomElem

func E

func E(tag string, parts ...any) *VDomElem

func H

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

func TextElem

func TextElem(text string) VDomElem

func (*VDomElem) Key

func (e *VDomElem) Key() string

func (*VDomElem) WithKey

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

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"`
	TargetChecked   bool               `json:"targetchecked,omitempty"`
	TargetName      string             `json:"targetname,omitempty"`
	TargetId        string             `json:"targetid,omitempty"`
	KeyData         *WaveKeyboardEvent `json:"keydata,omitempty"`
	MouseData       *WavePointerData   `json:"mousedata,omitempty"`
}

type VDomFrontendUpdate

type VDomFrontendUpdate struct {
	Type          string            `json:"type" tstype:"\"frontendupdate\""`
	Ts            int64             `json:"ts"`
	BlockId       string            `json:"blockid"`
	CorrelationId string            `json:"correlationid,omitempty"`
	Dispose       bool              `json:"dispose,omitempty"` // the vdom context was closed
	Resync        bool              `json:"resync,omitempty"`  // resync (send all backend data).  useful when the FE reloads
	RenderContext VDomRenderContext `json:"rendercontext,omitempty"`
	Events        []VDomEvent       `json:"events,omitempty"`
	StateSync     []VDomStateSync   `json:"statesync,omitempty"`
	RefUpdates    []VDomRefUpdate   `json:"refupdates,omitempty"`
	Messages      []VDomMessage     `json:"messages,omitempty"`
}

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"`
	PreventDefault  bool     `json:"preventdefault,omitempty"`
	GlobalEvent     string   `json:"globalevent,omitempty"`
	Keys            []string `json:"#keys,omitempty"` // special for keyDown events a list of keys to "capture"
}

used in props

func (*VDomFunc) CallFn

func (vdf *VDomFunc) CallFn(event VDomEvent)

type VDomKeyboardEvent

type VDomKeyboardEvent struct {
	Type     string `json:"type"`
	Key      string `json:"key"`
	Code     string `json:"code"`
	Shift    bool   `json:"shift,omitempty"`
	Control  bool   `json:"ctrl,omitempty"`
	Alt      bool   `json:"alt,omitempty"`
	Meta     bool   `json:"meta,omitempty"`
	Cmd      bool   `json:"cmd,omitempty"`
	Option   bool   `json:"option,omitempty"`
	Repeat   bool   `json:"repeat,omitempty"`
	Location int    `json:"location,omitempty"`
}

matches WaveKeyboardEvent

type VDomMessage

type VDomMessage struct {
	MessageType string `json:"messagetype"`
	Message     string `json:"message"`
	StackTrace  string `json:"stacktrace,omitempty"`
	Params      []any  `json:"params,omitempty"`
}

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

func UseVDomRef

func UseVDomRef(ctx context.Context) *VDomRef

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 VDomRefUpdate

type VDomRefUpdate struct {
	RefId      string           `json:"refid"`
	HasCurrent bool             `json:"hascurrent"`
	Position   *VDomRefPosition `json:"position,omitempty"`
}

type VDomRenderContext

type VDomRenderContext struct {
	BlockId    string `json:"blockid"`
	Focused    bool   `json:"focused"`
	Width      int    `json:"width"`
	Height     int    `json:"height"`
	RootRefId  string `json:"rootrefid"`
	Background bool   `json:"background,omitempty"`
}

type VDomRenderUpdate

type VDomRenderUpdate struct {
	UpdateType string    `json:"updatetype" tstype:"\"root\"|\"append\"|\"replace\"|\"remove\"|\"insert\""`
	WaveId     string    `json:"waveid,omitempty"`
	VDomWaveId string    `json:"vdomwaveid,omitempty"`
	VDom       *VDomElem `json:"vdom,omitempty"` // these get removed for transfer (encoded to transferelems)
	Index      *int      `json:"index,omitempty"`
}

type VDomSimpleRef

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

func UseRef

func UseRef[T any](ctx context.Context, val T) *VDomSimpleRef[T]

type VDomStateSync

type VDomStateSync struct {
	Atom  string `json:"atom"`
	Value any    `json:"value"`
}

type VDomTarget

type VDomTarget struct {
	NewBlock  bool               `json:"newblock,omitempty"`
	Magnified bool               `json:"magnified,omitempty"`
	Toolbar   *VDomTargetToolbar `json:"toolbar,omitempty"`
}

target -- to support new targets in the future, like toolbars, partial blocks, splits, etc. default is vdom context inside of a terminal block

type VDomTargetToolbar

type VDomTargetToolbar struct {
	Toolbar bool   `json:"toolbar"`
	Height  string `json:"height,omitempty"`
}

type VDomTransferElem

type VDomTransferElem struct {
	WaveId   string         `json:"waveid,omitempty"` // required, except for #text nodes
	Tag      string         `json:"tag"`
	Props    map[string]any `json:"props,omitempty"`
	Children []string       `json:"children,omitempty"`
	Text     string         `json:"text,omitempty"`
}

the over the wire format for a vdom element

func ConvertElemsToTransferElems

func ConvertElemsToTransferElems(elems []VDomElem) []VDomTransferElem

func DedupTransferElems

func DedupTransferElems(elems []VDomTransferElem) []VDomTransferElem

type WaveKeyboardEvent

type WaveKeyboardEvent 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 WavePointerData

type WavePointerData 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)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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