datastar

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalAndPatchSignals

func MarshalAndPatchSignals(sse *ServerSentEventGenerator, data interface{}, opts ...PatchSignalsOption) error

MarshalAndPatchSignals is a convenience wrapper around the official Datastar method

func ReadFormWithSignals

func ReadFormWithSignals(r *http.Request) (map[string]interface{}, error)

Helper function to read form data and merge with signals

func ReadSignals

func ReadSignals(r *http.Request, target interface{}) error

ReadSignals parses incoming signal data from the browser using the official Datastar library

func ReadSignalsMap

func ReadSignalsMap(r *http.Request) (map[string]interface{}, error)

Helper function to read signals as a map

Types

type ExecuteScriptOption

type ExecuteScriptOption func(*ExecuteScriptOptions)

ExecuteScriptOption is a function that configures ExecuteScriptOptions

func WithAttributes

func WithAttributes(attrs map[string]string) ExecuteScriptOption

WithAttributes sets custom attributes for the script tag

func WithAutoRemove

func WithAutoRemove(enable bool) ExecuteScriptOption

WithAutoRemove sets whether the script tag should be auto-removed

type ExecuteScriptOptions

type ExecuteScriptOptions struct {
	AutoRemove bool
	Attributes map[string]string
}

ExecuteScriptOptions contains options for executing scripts

type PatchElementMode

type PatchElementMode string

PatchElementMode defines how elements should be patched

const (
	ElementPatchModeMorph   PatchElementMode = "morph"   // Maps to outer (intelligent morphing)
	ElementPatchModeInner   PatchElementMode = "inner"   // Morphs inner HTML
	ElementPatchModeOuter   PatchElementMode = "outer"   // Intelligent morphing (default)
	ElementPatchModeReplace PatchElementMode = "replace" // Complete replacement (old outer mode)
	ElementPatchModePrepend PatchElementMode = "prepend"
	ElementPatchModeAppend  PatchElementMode = "append"
	ElementPatchModeBefore  PatchElementMode = "before"
	ElementPatchModeAfter   PatchElementMode = "after"
	ElementPatchModeRemove  PatchElementMode = "remove"
)

type PatchElementsOption

type PatchElementsOption func(*PatchElementsOptions)

PatchElementsOption is a function that configures PatchElementsOptions

func WithMode

WithMode sets the patch mode

func WithSelector

func WithSelector(selector string) PatchElementsOption

WithSelector sets the selector for element patching

func WithViewTransition

func WithViewTransition(enable bool) PatchElementsOption

WithViewTransition enables view transitions

type PatchElementsOptions

type PatchElementsOptions struct {
	Selector       string
	Mode           PatchElementMode
	ViewTransition bool
}

PatchElementsOptions contains options for patching elements

type PatchSignalsOption

type PatchSignalsOption func(*PatchSignalsOptions)

PatchSignalsOption is a function that configures PatchSignalsOptions

func WithOnlyIfMissing

func WithOnlyIfMissing(enable bool) PatchSignalsOption

WithOnlyIfMissing sets the onlyIfMissing flag

type PatchSignalsOptions

type PatchSignalsOptions struct {
	OnlyIfMissing bool
}

PatchSignalsOptions contains options for patching signals

type ServerSentEventGenerator

type ServerSentEventGenerator struct {
	// contains filtered or unexported fields
}

ServerSentEventGenerator wraps the official Datastar SSE functionality This wrapper maintains API compatibility while using the official library

func NewServerSentEventGenerator

func NewServerSentEventGenerator(w http.ResponseWriter, r *http.Request) *ServerSentEventGenerator

NewServerSentEventGenerator creates a new SSE generator using the official Datastar library

func (*ServerSentEventGenerator) ExecuteScript

func (s *ServerSentEventGenerator) ExecuteScript(script string, opts ...ExecuteScriptOption) error

ExecuteScript sends JavaScript code to be executed in the browser Note: The official library doesn't have ExecuteScript, so we'll implement it manually

func (*ServerSentEventGenerator) PatchComponent

func (s *ServerSentEventGenerator) PatchComponent(ctx context.Context, component templ.Component, opts ...PatchElementsOption) error

PatchComponent is a convenience method that renders a templ component and patches it

func (*ServerSentEventGenerator) PatchElements

func (s *ServerSentEventGenerator) PatchElements(html string, opts ...PatchElementsOption) error

PatchElements sends HTML elements to the browser for DOM manipulation Uses the official Datastar library under the hood

func (*ServerSentEventGenerator) PatchSignals

func (s *ServerSentEventGenerator) PatchSignals(signals map[string]interface{}, opts ...PatchSignalsOption) error

PatchSignals sends signal updates to the browser using the official Datastar library

func (*ServerSentEventGenerator) Redirect

func (s *ServerSentEventGenerator) Redirect(url string) error

Redirect redirects the client to a new page Note: The official library may not have Redirect, so we'll use ExecuteScript

func (*ServerSentEventGenerator) RemoveElement

func (s *ServerSentEventGenerator) RemoveElement(selector string) error

RemoveElement removes an element from the DOM

Jump to

Keyboard shortcuts

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