Documentation
¶
Index ¶
- func MarshalAndPatchSignals(sse *ServerSentEventGenerator, data interface{}, opts ...PatchSignalsOption) error
- func ReadFormWithSignals(r *http.Request) (map[string]interface{}, error)
- func ReadSignals(r *http.Request, target interface{}) error
- func ReadSignalsMap(r *http.Request) (map[string]interface{}, error)
- type ExecuteScriptOption
- type ExecuteScriptOptions
- type PatchElementMode
- type PatchElementsOption
- type PatchElementsOptions
- type PatchSignalsOption
- type PatchSignalsOptions
- type ServerSentEventGenerator
- func (s *ServerSentEventGenerator) ExecuteScript(script string, opts ...ExecuteScriptOption) error
- func (s *ServerSentEventGenerator) PatchComponent(ctx context.Context, component templ.Component, opts ...PatchElementsOption) error
- func (s *ServerSentEventGenerator) PatchElements(html string, opts ...PatchElementsOption) error
- func (s *ServerSentEventGenerator) PatchSignals(signals map[string]interface{}, opts ...PatchSignalsOption) error
- func (s *ServerSentEventGenerator) Redirect(url string) error
- func (s *ServerSentEventGenerator) RemoveElement(selector string) error
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 ¶
Helper function to read form data and merge with signals
func ReadSignals ¶
ReadSignals parses incoming signal data from the browser using the official Datastar library
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 ¶
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 ¶
func WithMode(mode PatchElementMode) PatchElementsOption
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