{"modulePath":"github.com/wavetermdev/waveterm","version":"v0.14.5","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package vdom\n\n## Constants\n\n```go\nconst (\n\tBackendUpdate_InitialChunkSize = 50  // Size for initial chunks that contain both TransferElems and StateSync\n\tBackendUpdate_ChunkSize        = 100 // Size for subsequent chunks\n)\n```\n\n```go\nconst (\n\tWorkType_Render = \"render\"\n\tWorkType_Effect = \"effect\"\n)\n```\n\n```go\nconst BindTag = \"#bind\"\n```\n\n```go\nconst ChildrenPropKey = \"children\"\n```\n\n```go\nconst FragmentTag = \"#fragment\"\n```\n\n```go\nconst Html_BindParamTagName = \"bindparam\"\n```\n\n```go\nconst Html_BindPrefix = \"#bind:\"\n```\n\n```go\nconst Html_BindTagName = \"bind\"\n```\n\n```go\nconst Html_GlobalEventPrefix = \"#globalevent\"\n```\n\n```go\nconst Html_ParamPrefix = \"#param:\"\n```\n\n```go\nconst KeyPropKey = \"key\"\n```\n\n```go\nconst ObjectType_Binding = \"binding\"\n```\n\n```go\nconst ObjectType_Func = \"func\"\n```\n\n```go\nconst ObjectType_Ref = \"ref\"\n```\n\n```go\nconst TextTag = \"#text\"\n```\n\n```go\nconst WaveNullTag = \"wave:null\"\n```\n\n```go\nconst WaveTextTag = \"wave:text\"\n```\n\n## Functions\n\n```go\nfunc Class(name string) classAttrWrapper\n```\n\n```go\nfunc ClassIf(cond bool, name string) classAttrWrapper\n```\n\n```go\nfunc ClassIfElse(cond bool, name string, elseName string) classAttrWrapper\n```\n\n```go\nfunc Classes(classes ...any) string\n```\n\n```go\nfunc Filter[T any](items []T, fn func(T) bool) []T\n```\n\n```go\nfunc FilterIdx[T any](items []T, fn func(T, int) bool) []T\n```\n\n```go\nfunc ForEach[T any](items []T, fn func(T) any) []any\n```\n\n```go\nfunc ForEachIdx[T any](items []T, fn func(T, int) any) []any\n```\n\n```go\nfunc Fragment(parts ...any) any\n```\n\n```go\nfunc If(cond bool, part any) any\n```\n\n```go\nfunc IfElse(cond bool, part any, elsePart any) any\n```\n\n```go\nfunc P(propName string, propVal any) any\n```\n\n```go\nfunc PStyle(styleAttr string, propVal any) any\n```\n\n```go\nfunc Props(props any) map[string]any\n```\n\n```go\nfunc QueueRefOp(ctx context.Context, ref *VDomRef, op VDomRefOperation)\n```\n\n```go\nfunc UseAtom[T any](ctx context.Context, atomName string) (T, func(T))\n```\n\n```go\nfunc UseEffect(ctx context.Context, fn func() func(), deps []any)\n```\n\n```go\nfunc UseId(ctx context.Context) string\n```\n\n```go\nfunc UseRenderTs(ctx context.Context) int64\n```\n\n```go\nfunc UseState[T any](ctx context.Context, initialVal T) (T, func(T))\n```\n\n```go\nfunc UseStateWithFn[T any](ctx context.Context, initialVal T) (T, func(T), func(func(T) T))\n```\n\n## Types\n\n```go\ntype Atom struct {\n\tVal    any\n\tDirty  bool\n\tUsedBy map[string]bool // component waveid -\u003e true\n}\n```\n\n```go\ntype ChildKey struct {\n\tTag string\n\tIdx int\n\tKey string\n}\n```\n\n```go\ntype Component[P any] func(props P) *VDomElem\n```\n\n```go\ntype ComponentImpl struct {\n\tWaveId  string\n\tTag     string\n\tKey     string\n\tElem    *VDomElem\n\tMounted bool\n\n\t// hooks\n\tHooks []*Hook\n\n\t// #text component\n\tText string\n\n\t// base component -- vdom, wave elem, or #fragment\n\tChildren []*ComponentImpl\n\n\t// component -\u003e component\n\tComp *ComponentImpl\n}\n```\n\n```go\ntype DomRect struct {\n\tTop    float64 `json:\"top\"`\n\tLeft   float64 `json:\"left\"`\n\tRight  float64 `json:\"right\"`\n\tBottom float64 `json:\"bottom\"`\n\tWidth  float64 `json:\"width\"`\n\tHeight float64 `json:\"height\"`\n}\n```\n\n```go\ntype EffectWorkElem struct {\n\tId          string\n\tEffectIndex int\n}\n```\n\n```go\ntype Hook struct {\n\tInit      bool          // is initialized\n\tIdx       int           // index in the hook array\n\tFn        func() func() // for useEffect\n\tUnmountFn func()        // for useEffect\n\tVal       any           // for useState, useMemo, useRef\n\tDeps      []any\n}\n```\ngeneric hook structure\n\n```go\ntype RootElem struct {\n\tOuterCtx        context.Context\n\tRoot            *ComponentImpl\n\tRenderTs        int64\n\tCFuncs          map[string]any\n\tCompMap         map[string]*ComponentImpl // component waveid -\u003e component\n\tEffectWorkQueue []*EffectWorkElem\n\tNeedsRenderMap  map[string]bool\n\tAtoms           map[string]*Atom\n\tRefOperations   []VDomRefOperation\n}\n```\n\n```go\nfunc MakeRoot() *RootElem\n```\n\n```go\nfunc (r *RootElem) AddEffectWork(id string, effectIndex int)\n```\n\n```go\nfunc (r *RootElem) AddRenderWork(id string)\n```\n\n```go\nfunc (r *RootElem) Event(id string, propName string, event VDomEvent)\n```\n\n```go\nfunc (r *RootElem) GetAtom(name string) *Atom\n```\n\n```go\nfunc (r *RootElem) GetAtomVal(name string) any\n```\n\n```go\nfunc (r *RootElem) GetRefOperations() []VDomRefOperation\n```\n\n```go\nfunc (r *RootElem) GetStateSync(full bool) []VDomStateSync\n```\n\n```go\nfunc (r *RootElem) MakeVDom() *VDomElem\n```\n\n```go\nfunc (r *RootElem) QueueRefOp(op VDomRefOperation)\n```\n\n```go\nfunc (r *RootElem) RegisterComponent(name string, cfunc any) error\n```\n\n```go\nfunc (r *RootElem) Render(elem *VDomElem)\n```\n\n```go\nfunc (r *RootElem) RunWork()\n```\nthis 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\n\n```go\nfunc (r *RootElem) SetAtomVal(name string, val any, markDirty bool)\n```\n\n```go\nfunc (r *RootElem) SetOuterCtx(ctx context.Context)\n```\n\n```go\nfunc (r *RootElem) UpdateRef(updateRef VDomRefUpdate)\n```\n\n```go\ntype VDomAsyncInitiationRequest struct {\n\tType    string `json:\"type\" tstype:\"\\\"asyncinitiationrequest\\\"\"`\n\tTs      int64  `json:\"ts\"`\n\tBlockId string `json:\"blockid,omitempty\"`\n}\n```\n\n```go\nfunc MakeAsyncInitiationRequest(blockId string) VDomAsyncInitiationRequest\n```\n\n```go\ntype VDomBackendOpts struct {\n\tCloseOnCtrlC         bool `json:\"closeonctrlc,omitempty\"`\n\tGlobalKeyboardEvents bool `json:\"globalkeyboardevents,omitempty\"`\n\tGlobalStyles         bool `json:\"globalstyles,omitempty\"`\n}\n```\n\n```go\ntype VDomBackendUpdate struct {\n\tType          string             `json:\"type\" tstype:\"\\\"backendupdate\\\"\"`\n\tTs            int64              `json:\"ts\"`\n\tBlockId       string             `json:\"blockid\"`\n\tOpts          *VDomBackendOpts   `json:\"opts,omitempty\"`\n\tHasWork       bool               `json:\"haswork,omitempty\"`\n\tRenderUpdates []VDomRenderUpdate `json:\"renderupdates,omitempty\"`\n\tTransferElems []VDomTransferElem `json:\"transferelems,omitempty\"`\n\tStateSync     []VDomStateSync    `json:\"statesync,omitempty\"`\n\tRefOperations []VDomRefOperation `json:\"refoperations,omitempty\"`\n\tMessages      []VDomMessage      `json:\"messages,omitempty\"`\n}\n```\n\n```go\nfunc SplitBackendUpdate(update *VDomBackendUpdate) []*VDomBackendUpdate\n```\nSplitBackendUpdate 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\n\n```go\nfunc (beUpdate *VDomBackendUpdate) CreateTransferElems()\n```\n\n```go\ntype VDomBinding struct {\n\tType string `json:\"type\" tstype:\"\\\"binding\\\"\"`\n\tBind string `json:\"bind\"`\n}\n```\nused in props\n\n```go\ntype VDomContextVal struct {\n\tRoot    *RootElem\n\tComp    *ComponentImpl\n\tHookIdx int\n}\n```\n\n```go\ntype VDomCreateContext struct {\n\tType    string              `json:\"type\" tstype:\"\\\"createcontext\\\"\"`\n\tTs      int64               `json:\"ts\"`\n\tMeta    waveobj.MetaMapType `json:\"meta,omitempty\"`\n\tTarget  *VDomTarget         `json:\"target,omitempty\"`\n\tPersist bool                `json:\"persist,omitempty\"`\n}\n```\n\n```go\ntype VDomElem struct {\n\tWaveId   string         `json:\"waveid,omitempty\"` // required, except for #text nodes\n\tTag      string         `json:\"tag\"`\n\tProps    map[string]any `json:\"props,omitempty\"`\n\tChildren []VDomElem     `json:\"children,omitempty\"`\n\tText     string         `json:\"text,omitempty\"`\n}\n```\nvdom element\n\n```go\nfunc Bind(htmlStr string, params map[string]any) *VDomElem\n```\n\n```go\nfunc E(tag string, parts ...any) *VDomElem\n```\n\n```go\nfunc H(tag string, props map[string]any, children ...any) *VDomElem\n```\n\n```go\nfunc TextElem(text string) VDomElem\n```\n\n```go\nfunc (e *VDomElem) Key() string\n```\n\n```go\nfunc (e *VDomElem) WithKey(key string) *VDomElem\n```\n\n```go\ntype VDomEvent struct {\n\tWaveId          string             `json:\"waveid\"`\n\tEventType       string             `json:\"eventtype\"` // usually the prop name (e.g. onClick, onKeyDown)\n\tGlobalEventType string             `json:\"globaleventtype,omitempty\"`\n\tTargetValue     string             `json:\"targetvalue,omitempty\"`\n\tTargetChecked   bool               `json:\"targetchecked,omitempty\"`\n\tTargetName      string             `json:\"targetname,omitempty\"`\n\tTargetId        string             `json:\"targetid,omitempty\"`\n\tKeyData         *WaveKeyboardEvent `json:\"keydata,omitempty\"`\n\tMouseData       *WavePointerData   `json:\"mousedata,omitempty\"`\n}\n```\n\n```go\ntype VDomFrontendUpdate struct {\n\tType          string            `json:\"type\" tstype:\"\\\"frontendupdate\\\"\"`\n\tTs            int64             `json:\"ts\"`\n\tBlockId       string            `json:\"blockid\"`\n\tCorrelationId string            `json:\"correlationid,omitempty\"`\n\tDispose       bool              `json:\"dispose,omitempty\"` // the vdom context was closed\n\tResync        bool              `json:\"resync,omitempty\"`  // resync (send all backend data).  useful when the FE reloads\n\tRenderContext VDomRenderContext `json:\"rendercontext,omitempty\"`\n\tEvents        []VDomEvent       `json:\"events,omitempty\"`\n\tStateSync     []VDomStateSync   `json:\"statesync,omitempty\"`\n\tRefUpdates    []VDomRefUpdate   `json:\"refupdates,omitempty\"`\n\tMessages      []VDomMessage     `json:\"messages,omitempty\"`\n}\n```\n\n```go\ntype VDomFunc struct {\n\tFn              any      `json:\"-\"` // server side function (called with reflection)\n\tType            string   `json:\"type\" tstype:\"\\\"func\\\"\"`\n\tStopPropagation bool     `json:\"stoppropagation,omitempty\"`\n\tPreventDefault  bool     `json:\"preventdefault,omitempty\"`\n\tGlobalEvent     string   `json:\"globalevent,omitempty\"`\n\tKeys            []string `json:\"#keys,omitempty\"` // special for keyDown events a list of keys to \"capture\"\n}\n```\nused in props\n\n```go\nfunc (vdf *VDomFunc) CallFn(event VDomEvent)\n```\n\n```go\ntype VDomKeyboardEvent struct {\n\tType     string `json:\"type\"`\n\tKey      string `json:\"key\"`\n\tCode     string `json:\"code\"`\n\tShift    bool   `json:\"shift,omitempty\"`\n\tControl  bool   `json:\"ctrl,omitempty\"`\n\tAlt      bool   `json:\"alt,omitempty\"`\n\tMeta     bool   `json:\"meta,omitempty\"`\n\tCmd      bool   `json:\"cmd,omitempty\"`\n\tOption   bool   `json:\"option,omitempty\"`\n\tRepeat   bool   `json:\"repeat,omitempty\"`\n\tLocation int    `json:\"location,omitempty\"`\n}\n```\nmatches WaveKeyboardEvent\n\n```go\ntype VDomMessage struct {\n\tMessageType string `json:\"messagetype\"`\n\tMessage     string `json:\"message\"`\n\tStackTrace  string `json:\"stacktrace,omitempty\"`\n\tParams      []any  `json:\"params,omitempty\"`\n}\n```\n\n```go\ntype VDomRef struct {\n\tType          string           `json:\"type\" tstype:\"\\\"ref\\\"\"`\n\tRefId         string           `json:\"refid\"`\n\tTrackPosition bool             `json:\"trackposition,omitempty\"`\n\tPosition      *VDomRefPosition `json:\"position,omitempty\"`\n\tHasCurrent    bool             `json:\"hascurrent,omitempty\"`\n}\n```\nused in props\n\n```go\nfunc UseVDomRef(ctx context.Context) *VDomRef\n```\n\n```go\ntype VDomRefOperation struct {\n\tRefId     string `json:\"refid\"`\n\tOp        string `json:\"op\"`\n\tParams    []any  `json:\"params,omitempty\"`\n\tOutputRef string `json:\"outputref,omitempty\"`\n}\n```\n\n```go\ntype VDomRefPosition struct {\n\tOffsetHeight       int     `json:\"offsetheight\"`\n\tOffsetWidth        int     `json:\"offsetwidth\"`\n\tScrollHeight       int     `json:\"scrollheight\"`\n\tScrollWidth        int     `json:\"scrollwidth\"`\n\tScrollTop          int     `json:\"scrolltop\"`\n\tBoundingClientRect DomRect `json:\"boundingclientrect\"`\n}\n```\n\n```go\ntype VDomRefUpdate struct {\n\tRefId      string           `json:\"refid\"`\n\tHasCurrent bool             `json:\"hascurrent\"`\n\tPosition   *VDomRefPosition `json:\"position,omitempty\"`\n}\n```\n\n```go\ntype VDomRenderContext struct {\n\tBlockId    string `json:\"blockid\"`\n\tFocused    bool   `json:\"focused\"`\n\tWidth      int    `json:\"width\"`\n\tHeight     int    `json:\"height\"`\n\tRootRefId  string `json:\"rootrefid\"`\n\tBackground bool   `json:\"background,omitempty\"`\n}\n```\n\n```go\ntype VDomRenderUpdate struct {\n\tUpdateType string    `json:\"updatetype\" tstype:\"\\\"root\\\"|\\\"append\\\"|\\\"replace\\\"|\\\"remove\\\"|\\\"insert\\\"\"`\n\tWaveId     string    `json:\"waveid,omitempty\"`\n\tVDomWaveId string    `json:\"vdomwaveid,omitempty\"`\n\tVDom       *VDomElem `json:\"vdom,omitempty\"` // these get removed for transfer (encoded to transferelems)\n\tIndex      *int      `json:\"index,omitempty\"`\n}\n```\n\n```go\ntype VDomSimpleRef[T any] struct {\n\tCurrent T `json:\"current\"`\n}\n```\n\n```go\nfunc UseRef[T any](ctx context.Context, val T) *VDomSimpleRef[T]\n```\n\n```go\ntype VDomStateSync struct {\n\tAtom  string `json:\"atom\"`\n\tValue any    `json:\"value\"`\n}\n```\n\n```go\ntype VDomTarget struct {\n\tNewBlock  bool               `json:\"newblock,omitempty\"`\n\tMagnified bool               `json:\"magnified,omitempty\"`\n\tToolbar   *VDomTargetToolbar `json:\"toolbar,omitempty\"`\n}\n```\ntarget -- to support new targets in the future, like toolbars, partial blocks, splits, etc. default is vdom context inside of a terminal block\n\n```go\ntype VDomTargetToolbar struct {\n\tToolbar bool   `json:\"toolbar\"`\n\tHeight  string `json:\"height,omitempty\"`\n}\n```\n\n```go\ntype VDomTransferElem struct {\n\tWaveId   string         `json:\"waveid,omitempty\"` // required, except for #text nodes\n\tTag      string         `json:\"tag\"`\n\tProps    map[string]any `json:\"props,omitempty\"`\n\tChildren []string       `json:\"children,omitempty\"`\n\tText     string         `json:\"text,omitempty\"`\n}\n```\nthe over the wire format for a vdom element\n\n```go\nfunc ConvertElemsToTransferElems(elems []VDomElem) []VDomTransferElem\n```\n\n```go\nfunc DedupTransferElems(elems []VDomTransferElem) []VDomTransferElem\n```\n\n```go\ntype WaveKeyboardEvent struct {\n\tType     string `json:\"type\" tstype:\"\\\"keydown\\\"|\\\"keyup\\\"|\\\"keypress\\\"|\\\"unknown\\\"\"`\n\tKey      string `json:\"key\"`  // KeyboardEvent.key\n\tCode     string `json:\"code\"` // KeyboardEvent.code\n\tRepeat   bool   `json:\"repeat,omitempty\"`\n\tLocation int    `json:\"location,omitempty\"` // KeyboardEvent.location\n\n\t// modifiers\n\tShift   bool `json:\"shift,omitempty\"`\n\tControl bool `json:\"control,omitempty\"`\n\tAlt     bool `json:\"alt,omitempty\"`\n\tMeta    bool `json:\"meta,omitempty\"`\n\tCmd     bool `json:\"cmd,omitempty\"`    // special (on mac it is meta, on windows/linux it is alt)\n\tOption  bool `json:\"option,omitempty\"` // special (on mac it is alt, on windows/linux it is meta)\n}\n```\n\n```go\ntype WavePointerData struct {\n\tButton  int `json:\"button\"`\n\tButtons int `json:\"buttons\"`\n\n\tClientX   int `json:\"clientx,omitempty\"`\n\tClientY   int `json:\"clienty,omitempty\"`\n\tPageX     int `json:\"pagex,omitempty\"`\n\tPageY     int `json:\"pagey,omitempty\"`\n\tScreenX   int `json:\"screenx,omitempty\"`\n\tScreenY   int `json:\"screeny,omitempty\"`\n\tMovementX int `json:\"movementx,omitempty\"`\n\tMovementY int `json:\"movementy,omitempty\"`\n\n\t// Modifiers\n\tShift   bool `json:\"shift,omitempty\"`\n\tControl bool `json:\"control,omitempty\"`\n\tAlt     bool `json:\"alt,omitempty\"`\n\tMeta    bool `json:\"meta,omitempty\"`\n\tCmd     bool `json:\"cmd,omitempty\"`    // special (on mac it is meta, on windows/linux it is alt)\n\tOption  bool `json:\"option,omitempty\"` // special (on mac it is alt, on windows/linux it is meta)\n}\n```\n\n","path":"github.com/wavetermdev/waveterm/pkg/vdom","name":"vdom","synopsis":"","isRedistributable":true}
