Documentation
¶
Index ¶
- func Append(parentID string, component Component) error
- func GetHash() string
- func Hydrate(parentID string, component Component) error
- func Log(v ...any)
- func OnHashChange(handler func(hash string))
- func Render(parentID string, component Component) error
- func SetHash(hash string)
- func SetLog(log func(v ...any))
- func Unmount(component Component)
- func Update(component Component) error
- type BaseComponent
- func (c *BaseComponent) Children() []Component
- func (c *BaseComponent) GetID() string
- func (c *BaseComponent) Mount(parentID string) *BaseComponent
- func (c *BaseComponent) Render() *BaseComponent
- func (c *BaseComponent) RenderHTML() string
- func (c *BaseComponent) SetID(id string)
- func (c *BaseComponent) Unmount()
- func (c *BaseComponent) Update() error
- type CSSProvider
- type Component
- type DOM
- type Element
- func (b *Element) Add(children ...any) *Element
- func (b *Element) Append(child any) *Element
- func (b *Element) Attr(key, val string) *Element
- func (b *Element) Children() []Component
- func (b *Element) Class(class ...string) *Element
- func (b *Element) GetID() string
- func (b *Element) ID(id string) *Element
- func (b *Element) Mount(parentID string) error
- func (b *Element) OnChange(handler func(Event)) *Element
- func (b *Element) OnClick(handler func(Event)) *Element
- func (b *Element) OnInput(handler func(Event)) *Element
- func (b *Element) Render(parentID string) error
- func (b *Element) RenderHTML() string
- func (b *Element) SetID(id string)
- func (b *Element) Text(text string) *Element
- func (b *Element) ToNode() Node
- type Event
- type EventHandler
- type IconSvgProvider
- type JSProvider
- type Mountable
- type Node
- type Reference
- type Unmountable
- type Updatable
- type ViewRenderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Append ¶ added in v0.2.0
Append injects a component AFTER the last child of the parent element.
func OnHashChange ¶ added in v0.0.11
func OnHashChange(handler func(hash string))
OnHashChange registers a hash change listener.
Types ¶
type BaseComponent ¶ added in v0.0.13
type BaseComponent struct {
// contains filtered or unexported fields
}
BaseComponent is a helper struct that implements the Identifiable interface. Users can embed this in their components to automatically handle ID management.
func (*BaseComponent) Children ¶ added in v0.1.0
func (c *BaseComponent) Children() []Component
Children returns the component's children (nil by default).
func (*BaseComponent) GetID ¶ added in v0.2.0
func (c *BaseComponent) GetID() string
GetID returns the component's unique identifier.
func (*BaseComponent) Mount ¶ added in v0.2.0
func (c *BaseComponent) Mount(parentID string) *BaseComponent
Mount injects the component into a parent element.
func (*BaseComponent) Render ¶ added in v0.2.0
func (c *BaseComponent) Render() *BaseComponent
Render re-renders the component in place. This is used for chaining, e.g., component.SetState(...).Render()
func (*BaseComponent) RenderHTML ¶ added in v0.2.0
func (c *BaseComponent) RenderHTML() string
RenderHTML returns an empty string by default, satisfying the HTMLRenderer interface.
func (*BaseComponent) SetID ¶ added in v0.0.13
func (c *BaseComponent) SetID(id string)
SetID sets the component's unique identifier.
func (*BaseComponent) Unmount ¶ added in v0.2.0
func (c *BaseComponent) Unmount()
Unmount removes the component from the DOM.
func (*BaseComponent) Update ¶ added in v0.2.0
func (c *BaseComponent) Update() error
Update triggers a re-render of the component.
type CSSProvider ¶ added in v0.0.13
type CSSProvider interface {
RenderCSS() string
}
CSSProvider is an optional interface for components that need to inject CSS.
type Component ¶
type Component interface {
GetID() string
SetID(id string)
RenderHTML() string
Children() []Component
}
Component is the minimal interface for components. All components must implement this for both SSR (backend) and WASM (frontend).
type DOM ¶
type DOM interface {
// Get retrieves an element by its ID.
// It uses an internal cache to avoid repeated DOM lookups.
// Returns the element and a boolean indicating if it was found.
Get(id string) (Reference, bool)
// Render injects a component into a parent element.
// 1. It calls component.Render() (if ViewRenderer) or component.RenderHTML()
// 2. It sets the content of the parent element (found by parentID)
// 3. It calls component.OnMount() to bind events
Render(parentID string, component Component) error
// Append injects a component AFTER the last child of the parent element.
// Useful for dynamic lists.
Append(parentID string, component Component) error
// Hydrate attaches event listeners to existing HTML without re-rendering it.
Hydrate(parentID string, component Component) error
// OnHashChange registers a listener for URL hash changes.
OnHashChange(handler func(hash string))
// GetHash returns the current URL hash (e.g., "#help").
GetHash() string
// SetHash updates the URL hash.
SetHash(hash string)
// QueryAll finds all elements matching a CSS selector.
QueryAll(selector string) []Reference
// Unmount removes a component from the DOM (by clearing the parent's HTML or removing the node)
// and cleans up any event listeners registered via the Element interface.
Unmount(component Component)
// Update re-renders the component in its current position in the DOM.
Update(component Component) error
// Log provides logging functionality using the log function passed to New.
Log(v ...any)
}
DOM is the main entry point for interacting with the browser. It is designed to be injected into your components.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents a DOM element in the fluent Element API.
func (*Element) Add ¶ added in v0.2.3
Add adds one or more children to the element. Children can be *Element, Node, Component, or string.
func (*Element) Append ¶ added in v0.2.3
Append adds a child to the element. Deprecated: use Add instead.
func (*Element) Children ¶ added in v0.2.3
Children returns the component's children (components only).
func (*Element) Render ¶ added in v0.2.3
Render renders the element to the parent. This is a terminal operation.
func (*Element) RenderHTML ¶ added in v0.2.3
RenderHTML renders the element to HTML string.
type Event ¶
type Event interface {
// PreventDefault prevents the default action of the event.
PreventDefault()
// StopPropagation stops the event from bubbling up the DOM tree.
StopPropagation()
// TargetValue returns the value of the event's target element.
// Useful for input, textarea, and select elements.
TargetValue() string
// TargetID returns the ID of the event's target element.
TargetID() string
}
Event represents a DOM event.
type EventHandler ¶ added in v0.2.0
EventHandler represents a DOM event handler in the declarative builder.
type IconSvgProvider ¶ added in v0.0.13
IconSvgProvider is an optional interface for components that provide SVG icons.
type JSProvider ¶ added in v0.0.13
type JSProvider interface {
RenderJS() string
}
JSProvider is an optional interface for components that need to inject JS.
type Mountable ¶ added in v0.2.0
type Mountable interface {
OnMount()
}
Mountable is an optional interface for components that need initialization logic.
type Node ¶ added in v0.2.0
type Node struct {
Tag string
Attrs []fmt.KeyValue
Events []EventHandler
Children []any // Can be Node, string, or Component
}
Node represents a DOM node in the declarative builder.
type Reference ¶ added in v0.2.3
type Reference interface {
// GetAttr retrieves an attribute value.
GetAttr(key string) string
// Value returns the current value of an input/textarea/select.
Value() string
// Checked returns the current checked state of a checkbox or radio button.
Checked() bool
// On registers a generic event handler (e.g., "click", "change", "input", "keydown").
On(eventType string, handler func(event Event))
// Focus sets focus to the element.
Focus()
}
Reference represents a reference to a DOM node. It provides methods for reading and interaction.
type Unmountable ¶ added in v0.2.0
type Unmountable interface {
OnUnmount()
}
Unmountable is an optional interface for components that need cleanup logic.
type Updatable ¶ added in v0.2.0
type Updatable interface {
OnUpdate()
}
Updatable is an optional interface for components that need update logic.
type ViewRenderer ¶ added in v0.2.0
type ViewRenderer interface {
Render() Node
}
ViewRenderer returns a Node tree for declarative UI.