blocks

package
v1.7.4 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 42 Imported by: 2

Documentation

Overview

templ: version: v0.3.1020

Index

Constants

This section is empty.

Variables

View Source
var (
	AppConfig *apps.AppConfig
)
View Source
var (
	JSContext = telepath.NewContext()
)

Functions

func NewAppConfig

func NewAppConfig() *apps.AppConfig

func RenderTelepathAdapterHTML added in v1.7.2

func RenderTelepathAdapterHTML(ctx context.Context, obj widgets.Widget) []interface{}

Types

type BaseBlock

type BaseBlock struct {
	Name_      string                                     `json:"-"`
	Template   string                                     `json:"-"`
	FormField  fields.Field                               `json:"-"`
	Validators []func(context.Context, interface{}) error `json:"-"`
	Default    func() interface{}                         `json:"-"`

	DataType        any
	ValueFromDBFunc func(b *BaseBlock, j json.RawMessage) (interface{}, error) `json:"-"`
	LabelFunc       func(ctx context.Context) string                           `json:"-"`
	HelpFunc        func(ctx context.Context) string                           `json:"-"`
}

func NewBaseBlock

func NewBaseBlock(opts ...OptFunc[*BaseBlock]) *BaseBlock

func (*BaseBlock) Adapter

func (b *BaseBlock) Adapter(ctx context.Context) telepath.Adapter

func (*BaseBlock) Clean

func (b *BaseBlock) Clean(ctx context.Context, value interface{}) (interface{}, error)

func (*BaseBlock) Field

func (b *BaseBlock) Field() fields.Field

func (*BaseBlock) FormContext

func (b *BaseBlock) FormContext(name string, value interface{}, context ctx.Context) *BlockContext

func (*BaseBlock) GetDefault

func (b *BaseBlock) GetDefault() interface{}

func (*BaseBlock) HasChanged added in v1.7.2

func (b *BaseBlock) HasChanged(initial, data interface{}) bool

func (*BaseBlock) HelpText

func (b *BaseBlock) HelpText(ctx context.Context) string

func (*BaseBlock) Label

func (b *BaseBlock) Label(ctx context.Context) string

func (*BaseBlock) Media

func (b *BaseBlock) Media() media.Media

func (*BaseBlock) Name

func (b *BaseBlock) Name() string

func (*BaseBlock) Render

func (b *BaseBlock) Render(ctx context.Context, w io.Writer, value interface{}, context ctx.Context) error

func (*BaseBlock) RenderForm

func (b *BaseBlock) RenderForm(ctx context.Context, w io.Writer, id, name string, value interface{}, errors []error, context ctx.Context) error

func (*BaseBlock) SetDefault added in v1.7.2

func (b *BaseBlock) SetDefault(def interface{})

func (*BaseBlock) SetField

func (b *BaseBlock) SetField(field fields.Field)

func (*BaseBlock) SetHelpText added in v1.7.2

func (b *BaseBlock) SetHelpText(helpText any)

func (*BaseBlock) SetLabel added in v1.7.2

func (b *BaseBlock) SetLabel(label any)

func (*BaseBlock) SetName

func (b *BaseBlock) SetName(name string)

func (*BaseBlock) Validate

func (b *BaseBlock) Validate(ctx context.Context, value interface{}) []error

func (*BaseBlock) ValueAtPath added in v1.7.2

func (b *BaseBlock) ValueAtPath(bound BoundBlockValue, parts []string) (interface{}, error)

func (*BaseBlock) ValueFromDB added in v1.7.2

func (b *BaseBlock) ValueFromDB(value json.RawMessage) (interface{}, error)

func (*BaseBlock) ValueFromDataDict

func (b *BaseBlock) ValueFromDataDict(ctx context.Context, data url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)

func (*BaseBlock) ValueOmittedFromData

func (b *BaseBlock) ValueOmittedFromData(ctx context.Context, data url.Values, files map[string][]filesystem.FileHeader, name string) bool

func (*BaseBlock) ValueToForm

func (b *BaseBlock) ValueToForm(value interface{}) interface{}

func (*BaseBlock) ValueToGo

func (b *BaseBlock) ValueToGo(value interface{}) (interface{}, error)

type BaseBlockValidationError

type BaseBlockValidationError[T comparable] struct {
	Errors         map[T][]error
	NonBlockErrors []error
}

func NewBlockErrors

func NewBlockErrors[T comparable](errors ...error) *BaseBlockValidationError[T]

func (*BaseBlockValidationError[T]) AddError

func (m *BaseBlockValidationError[T]) AddError(key T, err ...error) *BaseBlockValidationError[T]

func (*BaseBlockValidationError[T]) AddNonBlockError

func (m *BaseBlockValidationError[T]) AddNonBlockError(err error)

func (*BaseBlockValidationError[T]) Error

func (m *BaseBlockValidationError[T]) Error() string

func (*BaseBlockValidationError[T]) Get

func (m *BaseBlockValidationError[T]) Get(key T) []error

func (*BaseBlockValidationError[T]) HasErrors

func (m *BaseBlockValidationError[T]) HasErrors() bool

func (*BaseBlockValidationError[T]) Len

func (m *BaseBlockValidationError[T]) Len() int

func (*BaseBlockValidationError[T]) MarshalJSON

func (m *BaseBlockValidationError[T]) MarshalJSON() ([]byte, error)

type Block

type Block interface {
	Name() string
	SetName(name string)
	SetLabel(label any)
	SetHelpText(helpText any)
	SetDefault(def interface{})
	Label(ctx context.Context) string
	HelpText(ctx context.Context) string
	Field() fields.Field
	SetField(field fields.Field)
	ValueAtPath(bound BoundBlockValue, parts []string) (interface{}, error)
	ValueFromDB(value json.RawMessage) (interface{}, error)
	RenderForm(ctx context.Context, w io.Writer, id, name string, value interface{}, errors []error, context ctx.Context) error
	Render(ctx context.Context, w io.Writer, value interface{}, context ctx.Context) error
	HasChanged(initial, data interface{}) bool
	GetDefault() interface{}
	telepath.AdapterGetter
	media.MediaDefiner
	widgets.FormValuer
	forms.Validator
	forms.Cleaner
}

type BlockContext

type BlockContext struct {
	Request_  *http.Request
	BlockDef  Block
	ID        string
	Name      string
	BlockHTML template.HTML
	Value     interface{}
	Errors    []error
	Attrs     map[string]string
	Context   ctx.Context
}

func NewBlockContext

func NewBlockContext(b Block, context ctx.Context) *BlockContext

func (*BlockContext) Data added in v1.7.2

func (bc *BlockContext) Data() map[string]interface{}

func (*BlockContext) Get

func (bc *BlockContext) Get(name string) interface{}

func (*BlockContext) Request

func (bc *BlockContext) Request() *http.Request

func (*BlockContext) Set

func (bc *BlockContext) Set(name string, value interface{})

type BlockFormField

type BlockFormField struct {
	*fields.BaseField
	Block Block
}

func BlockField

func BlockField(block Block, opts ...func(fields.Field)) *BlockFormField

func (*BlockFormField) Clean

func (bw *BlockFormField) Clean(ctx context.Context, value interface{}) (interface{}, error)

func (*BlockFormField) Default added in v1.7.2

func (bw *BlockFormField) Default() interface{}

func (*BlockFormField) HasChanged added in v1.7.2

func (bw *BlockFormField) HasChanged(initial, data interface{}) bool

func (*BlockFormField) SetHelpText added in v1.7.2

func (bw *BlockFormField) SetHelpText(helpText func(ctx context.Context) string)

func (*BlockFormField) SetLabel added in v1.7.2

func (bw *BlockFormField) SetLabel(label func(ctx context.Context) string)

func (*BlockFormField) Validate

func (bw *BlockFormField) Validate(ctx context.Context, value interface{}) []error

func (*BlockFormField) ValueToForm

func (bw *BlockFormField) ValueToForm(value interface{}) interface{}

func (*BlockFormField) ValueToGo

func (bw *BlockFormField) ValueToGo(value interface{}) (interface{}, error)

type BlockWidget

type BlockWidget struct {
	BlockDef  Block
	FormField forms.Field
}

func NewBlockWidget

func NewBlockWidget(blockDef Block) *BlockWidget

func (*BlockWidget) BindField added in v1.7.2

func (bw *BlockWidget) BindField(field forms.Field)

func (*BlockWidget) Clean

func (bw *BlockWidget) Clean(ctx context.Context, value interface{}) (interface{}, error)

func (*BlockWidget) Field added in v1.7.2

func (bw *BlockWidget) Field() forms.Field

func (*BlockWidget) FormType added in v1.6.7

func (bw *BlockWidget) FormType() string

func (*BlockWidget) GetContextData

func (bw *BlockWidget) GetContextData(c context.Context, id, name string, value interface{}, attrs map[string]string) ctx.Context

func (*BlockWidget) Hide

func (bw *BlockWidget) Hide(hidden bool)

func (*BlockWidget) IdForLabel

func (bw *BlockWidget) IdForLabel(name string) string

func (*BlockWidget) IsHidden

func (bw *BlockWidget) IsHidden() bool

func (*BlockWidget) Media

func (bw *BlockWidget) Media() media.Media

func (*BlockWidget) Render

func (bw *BlockWidget) Render(ctx context.Context, w io.Writer, id, name string, value interface{}, attrs map[string]string) error

func (*BlockWidget) RenderWithErrors

func (bw *BlockWidget) RenderWithErrors(ctx context.Context, w io.Writer, id, name string, value interface{}, errors []error, attrs map[string]string, ctxData ctx.Context) error

func (*BlockWidget) SetAttrs

func (bw *BlockWidget) SetAttrs(attrs map[string]string)

func (*BlockWidget) Validate

func (bw *BlockWidget) Validate(ctx context.Context, value interface{}) []error

func (*BlockWidget) ValueFromDataDict

func (bw *BlockWidget) ValueFromDataDict(ctx context.Context, data url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)

func (*BlockWidget) ValueOmittedFromData

func (bw *BlockWidget) ValueOmittedFromData(ctx context.Context, data url.Values, files map[string][]filesystem.FileHeader, name string) bool

func (*BlockWidget) ValueToForm

func (bw *BlockWidget) ValueToForm(value interface{}) interface{}

func (*BlockWidget) ValueToGo

func (bw *BlockWidget) ValueToGo(value interface{}) (interface{}, error)

type BoundBlockValue added in v1.7.2

type BoundBlockValue interface {
	Block() Block
	Data() interface{}
}

type BoundValue added in v1.7.2

type BoundValue[T any] struct {
	BlockObject Block `json:"-"`
	V           T     `json:"-"`
	// contains filtered or unexported fields
}

func NewBlockValue added in v1.7.2

func NewBlockValue[T any](block Block, data T) *BoundValue[T]

func (*BoundValue[T]) BindToModel added in v1.7.2

func (l *BoundValue[T]) BindToModel(model attrs.Definer, field attrs.Field) error

func (*BoundValue[T]) Block added in v1.7.2

func (l *BoundValue[T]) Block() Block

func (*BoundValue[T]) DBType added in v1.7.2

func (l *BoundValue[T]) DBType() dbtype.Type

func (*BoundValue[T]) Data added in v1.7.2

func (l *BoundValue[T]) Data() interface{}

func (*BoundValue[T]) GoString added in v1.7.2

func (l *BoundValue[T]) GoString() string

func (*BoundValue[T]) LoadData added in v1.7.2

func (l *BoundValue[T]) LoadData(raw json.RawMessage) error

func (*BoundValue[T]) MarshalJSON added in v1.7.2

func (l *BoundValue[T]) MarshalJSON() ([]byte, error)

func (*BoundValue[T]) Render added in v1.7.2

func (l *BoundValue[T]) Render(c context.Context, w io.Writer, ctxt ctx.Context) error

func (*BoundValue[T]) Scan added in v1.7.2

func (l *BoundValue[T]) Scan(value interface{}) (err error)

func (*BoundValue[T]) String added in v1.7.2

func (l *BoundValue[T]) String() string

func (*BoundValue[T]) UnmarshalJSON added in v1.7.2

func (l *BoundValue[T]) UnmarshalJSON(data []byte) error

func (BoundValue[T]) Value added in v1.7.2

func (l BoundValue[T]) Value() (driver.Value, error)

type FieldBlock

type FieldBlock struct {
	*BaseBlock
}

func CharBlock

func CharBlock(opts ...func(*FieldBlock)) *FieldBlock

func DateBlock

func DateBlock(opts ...func(*FieldBlock)) *FieldBlock

func DateTimeBlock

func DateTimeBlock(opts ...func(*FieldBlock)) *FieldBlock

func EmailBlock

func EmailBlock(opts ...func(*FieldBlock)) *FieldBlock

func FormFieldBlock added in v1.7.2

func FormFieldBlock(field fields.Field, datatype any, opts ...func(*FieldBlock)) *FieldBlock

func NewFieldBlock

func NewFieldBlock(opts ...func(*FieldBlock)) *FieldBlock

func NumberBlock

func NumberBlock(opts ...func(*FieldBlock)) *FieldBlock

func PasswordBlock

func PasswordBlock(opts ...func(*FieldBlock)) *FieldBlock

func TextBlock

func TextBlock(opts ...func(*FieldBlock)) *FieldBlock

func (*FieldBlock) Adapter

func (b *FieldBlock) Adapter(ctx context.Context) telepath.Adapter

func (*FieldBlock) RenderForm

func (b *FieldBlock) RenderForm(ctx context.Context, w io.Writer, id, name string, value interface{}, errors []error, c ctx.Context) error

func (*FieldBlock) RenderTempl

func (b *FieldBlock) RenderTempl(id, name string, value interface{}, telepath string, errors []error, tplCtx ctx.Context) templ.Component

type FieldBlockValue added in v1.7.2

type FieldBlockValue = BoundValue[interface{}]

type JSONListBlockData added in v1.7.2

type JSONListBlockData struct {
	ID    uuid.UUID       `json:"id"`
	Order int             `json:"order"`
	Data  json.RawMessage `json:"data"`
}

type JSONStreamBlockData added in v1.7.2

type JSONStreamBlockData struct {
	ID   uuid.UUID       `json:"id"`
	Type string          `json:"type"`
	Data json.RawMessage `json:"data"`
}

type Length

type Length interface {
	Len() int
}

type ListBlock

type ListBlock struct {
	*BaseBlock
	Child Block
	Min   int
	Max   int
}

func NewListBlock

func NewListBlock(block Block, minMax ...int) *ListBlock

func (*ListBlock) Adapter

func (m *ListBlock) Adapter(ctx context.Context) telepath.Adapter

func (*ListBlock) Clean

func (l *ListBlock) Clean(ctx context.Context, value interface{}) (interface{}, error)

func (*ListBlock) GetDefault

func (l *ListBlock) GetDefault() interface{}

func (*ListBlock) HasChanged added in v1.7.2

func (l *ListBlock) HasChanged(initial, data interface{}) bool

func (*ListBlock) MaxNum

func (l *ListBlock) MaxNum() int

func (*ListBlock) MinNum

func (l *ListBlock) MinNum() int

func (*ListBlock) Render added in v1.7.2

func (b *ListBlock) Render(ctx context.Context, w io.Writer, value interface{}, context ctx.Context) error

func (*ListBlock) RenderForm

func (l *ListBlock) RenderForm(ctx context.Context, w io.Writer, id, name string, value interface{}, errors []error, tplCtx ctx.Context) error

func (*ListBlock) RenderTempl

func (l *ListBlock) RenderTempl(id, name string, valueArr *ListBlockValue, telepath string, listBlockErrors *BaseBlockValidationError[int], tplCtx ctx.Context) templ.Component

func (*ListBlock) Validate

func (l *ListBlock) Validate(ctx context.Context, value interface{}) []error

func (*ListBlock) ValueAtPath added in v1.7.2

func (l *ListBlock) ValueAtPath(bound BoundBlockValue, parts []string) (interface{}, error)

func (*ListBlock) ValueFromDB added in v1.7.2

func (s *ListBlock) ValueFromDB(value json.RawMessage) (interface{}, error)

func (*ListBlock) ValueFromDataDict

func (l *ListBlock) ValueFromDataDict(ctx context.Context, d url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)

func (*ListBlock) ValueOmittedFromData

func (b *ListBlock) ValueOmittedFromData(ctx context.Context, data url.Values, files map[string][]filesystem.FileHeader, name string) bool

func (*ListBlock) ValueToForm

func (l *ListBlock) ValueToForm(value interface{}) interface{}

func (*ListBlock) ValueToGo

func (l *ListBlock) ValueToGo(value interface{}) (interface{}, error)

type ListBlockData added in v1.7.2

type ListBlockData struct {
	ID    uuid.UUID   `json:"id"`
	Order int         `json:"order"`
	Data  interface{} `json:"data"`
}

type ListBlockValue

type ListBlockValue = BoundValue[[]*ListBlockData]

type OptFunc

type OptFunc[T any] func(T)

func WithBlockField added in v1.7.2

func WithBlockField[T Block](name string, block Block) OptFunc[T]

func WithDefault added in v1.7.2

func WithDefault[T Block](def interface{}) OptFunc[T]

func WithHelpText

func WithHelpText[T Block](text any) OptFunc[T]

func WithLabel

func WithLabel[T Block](label any) OptFunc[T]

func WithMax added in v1.7.2

func WithMax[T Block](max int) OptFunc[T]

func WithMin added in v1.7.2

func WithMin[T Block](min int) OptFunc[T]

func WithTemplate added in v1.7.2

func WithTemplate[T Block](template string) OptFunc[T]

func WithValidators

func WithValidators[T any](validators ...func(context.Context, interface{}) error) OptFunc[T]

type RenderableValue added in v1.7.2

type RenderableValue interface {
	Render(c context.Context, w io.Writer, ctxt ctx.Context) error
}

type StreamBlock added in v1.7.2

type StreamBlock struct {
	*BaseBlock `json:"-"`
	Children   *orderedmap.OrderedMap[string, Block] `json:"-"`
	Min        int                                   `json:"-"`
	Max        int                                   `json:"-"`
}

func NewStreamBlock added in v1.7.2

func NewStreamBlock(opts ...func(*StreamBlock)) *StreamBlock

func (*StreamBlock) Adapter added in v1.7.2

func (m *StreamBlock) Adapter(ctx context.Context) telepath.Adapter

func (*StreamBlock) AddField added in v1.7.2

func (l *StreamBlock) AddField(name string, block Block)

func (*StreamBlock) Clean added in v1.7.2

func (l *StreamBlock) Clean(ctx context.Context, value interface{}) (interface{}, error)

func (*StreamBlock) HasChanged added in v1.7.2

func (l *StreamBlock) HasChanged(initial, data interface{}) bool

func (*StreamBlock) MaxNum added in v1.7.2

func (l *StreamBlock) MaxNum() int

func (*StreamBlock) MinNum added in v1.7.2

func (l *StreamBlock) MinNum() int

func (*StreamBlock) Render added in v1.7.2

func (b *StreamBlock) Render(ctx context.Context, w io.Writer, value interface{}, context ctx.Context) error

func (*StreamBlock) RenderForm added in v1.7.2

func (l *StreamBlock) RenderForm(ctx context.Context, w io.Writer, id, name string, value interface{}, errors []error, tplCtx ctx.Context) error

func (*StreamBlock) RenderTempl added in v1.7.2

func (s *StreamBlock) RenderTempl(id, name string, valueArr *StreamBlockValue, telepath string, streamBlockErrors *BaseBlockValidationError[int], tplCtx ctx.Context) templ.Component

func (*StreamBlock) Validate added in v1.7.2

func (l *StreamBlock) Validate(ctx context.Context, value interface{}) []error

func (*StreamBlock) ValueAtPath added in v1.7.2

func (l *StreamBlock) ValueAtPath(bound BoundBlockValue, parts []string) (interface{}, error)

func (*StreamBlock) ValueFromDB added in v1.7.2

func (s *StreamBlock) ValueFromDB(value json.RawMessage) (interface{}, error)

func (*StreamBlock) ValueFromDataDict added in v1.7.2

func (l *StreamBlock) ValueFromDataDict(ctx context.Context, d url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)

func (*StreamBlock) ValueOmittedFromData added in v1.7.2

func (b *StreamBlock) ValueOmittedFromData(ctx context.Context, data url.Values, files map[string][]filesystem.FileHeader, name string) bool

func (*StreamBlock) ValueToForm added in v1.7.2

func (l *StreamBlock) ValueToForm(value interface{}) interface{}

func (*StreamBlock) ValueToGo added in v1.7.2

func (l *StreamBlock) ValueToGo(value interface{}) (interface{}, error)

type StreamBlockData added in v1.7.2

type StreamBlockData struct {
	ID    uuid.UUID   `json:"id"`
	Type  string      `json:"type"`
	Data  interface{} `json:"data"`
	Order int         `json:"-"`
}

type StreamBlockValue added in v1.7.2

type StreamBlockValue = BoundValue[[]*StreamBlockData]

type StructBlock

type StructBlock struct {
	*BaseBlock
	Fields *orderedmap.OrderedMap[string, Block]
}

func NewStructBlock

func NewStructBlock(opts ...func(*StructBlock)) *StructBlock

func (*StructBlock) Adapter

func (m *StructBlock) Adapter(ctx context.Context) telepath.Adapter

func (*StructBlock) AddField

func (m *StructBlock) AddField(name string, block Block)

func (*StructBlock) Clean

func (m *StructBlock) Clean(ctx context.Context, value interface{}) (interface{}, error)

func (*StructBlock) Field

func (m *StructBlock) Field() fields.Field

func (*StructBlock) GetDefault

func (m *StructBlock) GetDefault() interface{}

func (*StructBlock) HasChanged added in v1.7.2

func (m *StructBlock) HasChanged(initial, data interface{}) bool

func (*StructBlock) Name

func (m *StructBlock) Name() string

func (*StructBlock) Render added in v1.7.2

func (b *StructBlock) Render(ctx context.Context, w io.Writer, value interface{}, context ctx.Context) error

func (*StructBlock) RenderForm

func (m *StructBlock) RenderForm(ctx context.Context, w io.Writer, id, name string, value interface{}, errors []error, tplCtx ctx.Context) error

func (*StructBlock) RenderTempl

func (b *StructBlock) RenderTempl(id, name string, valueMap map[string]interface{}, telepath string, errors *BaseBlockValidationError[string], tplCtx ctx.Context) templ.Component

func (*StructBlock) SetName

func (m *StructBlock) SetName(name string)

func (*StructBlock) Validate

func (m *StructBlock) Validate(ctx context.Context, value interface{}) []error

func (*StructBlock) ValueAtPath added in v1.7.2

func (l *StructBlock) ValueAtPath(bound BoundBlockValue, parts []string) (interface{}, error)

func (*StructBlock) ValueFromDB added in v1.7.2

func (s *StructBlock) ValueFromDB(value json.RawMessage) (interface{}, error)

func (*StructBlock) ValueFromDataDict

func (m *StructBlock) ValueFromDataDict(ctx context.Context, d url.Values, files map[string][]filesystem.FileHeader, name string) (interface{}, []error)

func (*StructBlock) ValueOmittedFromData

func (m *StructBlock) ValueOmittedFromData(ctx context.Context, data url.Values, files map[string][]filesystem.FileHeader, name string) bool

func (*StructBlock) ValueToForm

func (m *StructBlock) ValueToForm(value interface{}) interface{}

func (*StructBlock) ValueToGo

func (m *StructBlock) ValueToGo(value interface{}) (interface{}, error)

type StructBlockValue added in v1.7.2

type StructBlockValue = BoundValue[map[string]interface{}]

Jump to

Keyboard shortcuts

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