303 lines
10 KiB
Go
303 lines
10 KiB
Go
// Code generated by templ - DO NOT EDIT.
|
|
|
|
// templ: version: v0.3.960
|
|
// Code generated by wa-generator. DO NOT EDIT.
|
|
|
|
// Source: Web Awesome wa-mutation-observer
|
|
|
|
package wa
|
|
|
|
//lint:file-ignore SA4006 This context is only used if a nested component is present.
|
|
|
|
import "github.com/a-h/templ"
|
|
import templruntime "github.com/a-h/templ/runtime"
|
|
|
|
import (
|
|
"github.com/a-h/templ"
|
|
)
|
|
|
|
// The Mutation Observer component offers a thin, declarative interface to the MutationObserver API.
|
|
//
|
|
// Web Awesome component: <wa-mutation-observer>
|
|
|
|
// MutationObserverProps holds all properties for the wa-mutation-observer component
|
|
type MutationObserverProps struct {
|
|
// Watches for changes to attributes. To watch only specific attributes, separate them by a space, e.g.
|
|
Attr string `attr:"attr"`
|
|
// Indicates whether or not the attribute's previous value should be recorded when monitoring changes.
|
|
AttrOldValue bool `attr:"attr-old-value"`
|
|
// Watches for changes to the character data contained within the node.
|
|
CharData bool `attr:"char-data"`
|
|
// Indicates whether or not the previous value of the node's text should be recorded.
|
|
CharDataOldValue bool `attr:"char-data-old-value"`
|
|
// Watches for the addition or removal of new child nodes.
|
|
ChildList bool `attr:"child-list"`
|
|
// Disables the observer.
|
|
Disabled bool `attr:"disabled"`
|
|
|
|
// Events
|
|
// Emitted when a mutation occurs.
|
|
OnMutation string `attr:"x-on:wa-mutation"`
|
|
|
|
// Slots contains named slot content
|
|
Slots MutationObserverSlots
|
|
|
|
// Attrs contains additional HTML attributes
|
|
Attrs templ.Attributes
|
|
}
|
|
|
|
// MutationObserverBuilder provides a fluent API for constructing MutationObserverProps
|
|
type MutationObserverBuilder struct {
|
|
props MutationObserverProps
|
|
}
|
|
|
|
// NewMutationObserver creates a new builder for wa-mutation-observer
|
|
func NewMutationObserver() *MutationObserverBuilder {
|
|
return &MutationObserverBuilder{}
|
|
}
|
|
|
|
// Attr sets the attr attribute
|
|
// Watches for changes to attributes. To watch only specific attributes, separate them by a space, e.g.
|
|
func (b *MutationObserverBuilder) Attr(v string) *MutationObserverBuilder {
|
|
b.props.Attr = v
|
|
return b
|
|
}
|
|
|
|
// AttrOldValue sets the attr-old-value attribute
|
|
// Indicates whether or not the attribute's previous value should be recorded when monitoring changes.
|
|
func (b *MutationObserverBuilder) AttrOldValue(v bool) *MutationObserverBuilder {
|
|
b.props.AttrOldValue = v
|
|
return b
|
|
}
|
|
|
|
// CharData sets the char-data attribute
|
|
// Watches for changes to the character data contained within the node.
|
|
func (b *MutationObserverBuilder) CharData(v bool) *MutationObserverBuilder {
|
|
b.props.CharData = v
|
|
return b
|
|
}
|
|
|
|
// CharDataOldValue sets the char-data-old-value attribute
|
|
// Indicates whether or not the previous value of the node's text should be recorded.
|
|
func (b *MutationObserverBuilder) CharDataOldValue(v bool) *MutationObserverBuilder {
|
|
b.props.CharDataOldValue = v
|
|
return b
|
|
}
|
|
|
|
// ChildList sets the child-list attribute
|
|
// Watches for the addition or removal of new child nodes.
|
|
func (b *MutationObserverBuilder) ChildList(v bool) *MutationObserverBuilder {
|
|
b.props.ChildList = v
|
|
return b
|
|
}
|
|
|
|
// Disabled sets the disabled attribute
|
|
// Disables the observer.
|
|
func (b *MutationObserverBuilder) Disabled(v bool) *MutationObserverBuilder {
|
|
b.props.Disabled = v
|
|
return b
|
|
}
|
|
|
|
// OnMutation sets the handler for wa-mutation event
|
|
// Emitted when a mutation occurs.
|
|
func (b *MutationObserverBuilder) OnMutation(handler string) *MutationObserverBuilder {
|
|
b.props.OnMutation = handler
|
|
return b
|
|
}
|
|
|
|
// Attr adds a custom HTML attribute
|
|
func (b *MutationObserverBuilder) Attr(name, value string) *MutationObserverBuilder {
|
|
if b.props.Attrs == nil {
|
|
b.props.Attrs = templ.Attributes{}
|
|
}
|
|
b.props.Attrs[name] = value
|
|
return b
|
|
}
|
|
|
|
// Attrs merges multiple attributes
|
|
func (b *MutationObserverBuilder) Attrs(attrs templ.Attributes) *MutationObserverBuilder {
|
|
if b.props.Attrs == nil {
|
|
b.props.Attrs = templ.Attributes{}
|
|
}
|
|
for k, v := range attrs {
|
|
b.props.Attrs[k] = v
|
|
}
|
|
return b
|
|
}
|
|
|
|
// Props returns the built properties
|
|
func (b *MutationObserverBuilder) Props() MutationObserverProps {
|
|
return b.props
|
|
}
|
|
|
|
// Build returns the props (alias for Props for semantic clarity)
|
|
func (b *MutationObserverBuilder) Build() MutationObserverProps {
|
|
return b.props
|
|
}
|
|
|
|
// MutationObserver renders the wa-mutation-observer component
|
|
func MutationObserver(props MutationObserverProps) templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var1 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var1 == nil {
|
|
templ_7745c5c3_Var1 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<wa-mutation-observer")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
if props.Attr != "" {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, " attr=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var2 string
|
|
templ_7745c5c3_Var2, templ_7745c5c3_Err = templ.JoinStringErrs(props.Attr)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/mutation-observer.templ`, Line: 133, Col: 20}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var2))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 3, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
if props.AttrOldValue {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, " attr-old-value")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
if props.CharData {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 5, " char-data")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
if props.CharDataOldValue {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 6, " char-data-old-value")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
if props.ChildList {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 7, " child-list")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
if props.Disabled {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 8, " disabled")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
if props.OnMutation != "" {
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 9, " x-on:wa-mutation=\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
var templ_7745c5c3_Var3 string
|
|
templ_7745c5c3_Var3, templ_7745c5c3_Err = templ.JoinStringErrs(props.OnMutation)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ.Error{Err: templ_7745c5c3_Err, FileName: `pkg/wa/mutation-observer.templ`, Line: 151, Col: 38}
|
|
}
|
|
_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var3))
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 10, "\"")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
}
|
|
templ_7745c5c3_Err = templ.RenderAttributes(ctx, templ_7745c5c3_Buffer, props.Attrs)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 11, ">")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templ_7745c5c3_Var1.Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 12, "</wa-mutation-observer>")
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
// MutationObserverFunc renders with a builder function for inline configuration
|
|
func MutationObserverFunc(fn func(*MutationObserverBuilder)) templ.Component {
|
|
return templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
if templ_7745c5c3_CtxErr := ctx.Err(); templ_7745c5c3_CtxErr != nil {
|
|
return templ_7745c5c3_CtxErr
|
|
}
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Var4 := templ.GetChildren(ctx)
|
|
if templ_7745c5c3_Var4 == nil {
|
|
templ_7745c5c3_Var4 = templ.NopComponent
|
|
}
|
|
ctx = templ.ClearChildren(ctx)
|
|
b := NewMutationObserver()
|
|
fn(b)
|
|
templ_7745c5c3_Var5 := templruntime.GeneratedTemplate(func(templ_7745c5c3_Input templruntime.GeneratedComponentInput) (templ_7745c5c3_Err error) {
|
|
templ_7745c5c3_W, ctx := templ_7745c5c3_Input.Writer, templ_7745c5c3_Input.Context
|
|
templ_7745c5c3_Buffer, templ_7745c5c3_IsBuffer := templruntime.GetBuffer(templ_7745c5c3_W)
|
|
if !templ_7745c5c3_IsBuffer {
|
|
defer func() {
|
|
templ_7745c5c3_BufErr := templruntime.ReleaseBuffer(templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err == nil {
|
|
templ_7745c5c3_Err = templ_7745c5c3_BufErr
|
|
}
|
|
}()
|
|
}
|
|
ctx = templ.InitializeContext(ctx)
|
|
templ_7745c5c3_Err = templ_7745c5c3_Var4.Render(ctx, templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
templ_7745c5c3_Err = MutationObserver(b.Props()).Render(templ.WithChildren(ctx, templ_7745c5c3_Var5), templ_7745c5c3_Buffer)
|
|
if templ_7745c5c3_Err != nil {
|
|
return templ_7745c5c3_Err
|
|
}
|
|
return nil
|
|
})
|
|
}
|
|
|
|
var _ = templruntime.GeneratedTemplate
|