Documentation
¶
Overview ¶
Package component defines renderer-independent component definitions and an immutable catalog for kind, variant, and target multi-dispatch.
Index ¶
- Variables
- type Builder
- type Catalog
- type Definition
- type FuncDefinition
- func (definition *FuncDefinition) Defaults() document.Props
- func (definition *FuncDefinition) Key() Key
- func (definition *FuncDefinition) Mode() document.CompositionMode
- func (definition *FuncDefinition) Render(ctx context.Context, renderContext RenderContext, node document.Component) (Output, error)
- func (definition *FuncDefinition) Schema() json.RawMessage
- func (definition *FuncDefinition) Validate(node document.Component) document.Problems
- func (definition *FuncDefinition) Version() string
- type Key
- type Metadata
- type Output
- type RenderContext
- type Renderer
- type Validator
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidKey = errors.New("component key requires kind, variant, and target") ErrInvalidMode = errors.New("component definition has invalid composition mode") ErrNilRenderer = errors.New("component definition renderer must not be nil") ErrDuplicate = errors.New("component definition already registered") ErrCatalogFrozen = errors.New("component catalog builder is frozen") ErrDefinitionAbsent = errors.New("component definition not found") )
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder owns mutable registration. Freeze creates a read-only Catalog and permanently closes the builder against later mutation.
func NewBuilder ¶
func NewBuilder() *Builder
func (*Builder) Register ¶
func (builder *Builder) Register(definition Definition) error
type Catalog ¶
type Catalog struct {
// contains filtered or unexported fields
}
Catalog is immutable after construction and safe for concurrent readers.
func NewCatalog ¶
func NewCatalog(definitions ...Definition) (*Catalog, error)
NewCatalog registers and freezes definitions in one operation.
type Definition ¶
type Definition interface {
Key() Key
Version() string
Mode() document.CompositionMode
Schema() json.RawMessage
Defaults() document.Props
Validate(document.Component) document.Problems
Render(context.Context, RenderContext, document.Component) (Output, error)
}
Definition supplies metadata and behavior for one exact dispatch key.
func Builtins ¶
func Builtins(target string) ([]Definition, error)
Builtins returns minimal target-neutral definitions covering each layout coupling class. Applications can replace or extend them before freezing a catalog.
type FuncDefinition ¶
type FuncDefinition struct {
// contains filtered or unexported fields
}
FuncDefinition is an immutable Definition backed by supplied functions.
func NewDefinition ¶
func NewDefinition( key Key, mode document.CompositionMode, schema json.RawMessage, defaults document.Props, validator Validator, renderer Renderer, ) (*FuncDefinition, error)
NewDefinition validates and defensively owns definition metadata.
func NewVersionedDefinition ¶
func NewVersionedDefinition( key Key, version string, mode document.CompositionMode, schema json.RawMessage, defaults document.Props, validator Validator, renderer Renderer, ) (*FuncDefinition, error)
NewVersionedDefinition includes an explicit renderer/template revision in composition cache keys. Change version whenever rendering semantics change.
func (*FuncDefinition) Defaults ¶
func (definition *FuncDefinition) Defaults() document.Props
func (*FuncDefinition) Key ¶
func (definition *FuncDefinition) Key() Key
func (*FuncDefinition) Mode ¶
func (definition *FuncDefinition) Mode() document.CompositionMode
func (*FuncDefinition) Render ¶
func (definition *FuncDefinition) Render(ctx context.Context, renderContext RenderContext, node document.Component) (Output, error)
func (*FuncDefinition) Schema ¶
func (definition *FuncDefinition) Schema() json.RawMessage
func (*FuncDefinition) Validate ¶
func (definition *FuncDefinition) Validate(node document.Component) document.Problems
func (*FuncDefinition) Version ¶
func (definition *FuncDefinition) Version() string
type Key ¶
type Key struct {
Kind string `json:"kind"`
Variant string `json:"variant"`
Target string `json:"target"`
}
Key selects one component implementation. Dispatch is exact and never falls back silently to another variant or rendering target.
type Metadata ¶
type Metadata struct {
Key Key `json:"key"`
Version string `json:"version"`
Mode string `json:"mode"`
Schema []byte `json:"schema,omitempty"`
Defaults map[string]any `json:"defaults,omitempty"`
}
Metadata is the serializable catalog surface suitable for editor discovery.
type Output ¶
Output is a component definition's target-specific result before the composition pipeline hashes and assembles it.
type RenderContext ¶
RenderContext contains inert values available to pure component renderers.