component

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package component defines renderer-independent component definitions and an immutable catalog for kind, variant, and target multi-dispatch.

Index

Constants

This section is empty.

Variables

View Source
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) Freeze

func (builder *Builder) Freeze() (*Catalog, error)

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.

func (*Catalog) Lookup

func (catalog *Catalog) Lookup(key Key) (Definition, error)

Lookup performs exact multi-dispatch.

func (*Catalog) Metadata

func (catalog *Catalog) Metadata() []Metadata

Metadata returns a stable defensive snapshot for web editor discovery.

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.

func (Key) String

func (key Key) String() string

func (Key) Valid

func (key Key) Valid() bool

Valid reports whether all dispatch dimensions are present.

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

type Output struct {
	Content      []byte
	Assets       []document.AssetRef
	Dependencies []string
}

Output is a component definition's target-specific result before the composition pipeline hashes and assembles it.

type RenderContext

type RenderContext struct {
	Theme  string
	Values map[string]any
}

RenderContext contains inert values available to pure component renderers.

type Renderer

Renderer projects one component. Implementations should be calculations; context exists for prompt cancellation, not hidden I/O.

type Validator

type Validator func(document.Component) document.Problems

Validator returns field-addressable domain problems for definition-specific props and style rules.

Jump to

Keyboard shortcuts

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