Documentation
¶
Overview ¶
Package richtext provides Ridu's official versioned rich-text field plugin.
Index ¶
- Constants
- func Field(name string, configs ...Config) field.PluginField
- func New() ridu.Plugin
- func RenderDocument[T any](document Document[T], block func(T) (string, error), ...) (string, error)
- func RenderHTML(value store.Value, renderers map[string]func(store.Values) (string, error)) (string, error)
- type Config
- type Document
- type Feature
- type Node
Constants ¶
const ( Key = "richtext" DocumentVersion = 1 AdminPluginPairingVersion = 1 )
Variables ¶
This section is empty.
Functions ¶
func Field ¶
func Field(name string, configs ...Config) field.PluginField
Field constructs a rich-text field with optional configuration. With no Config, it uses the recommended defaults. A supplied Config with omitted Features also inherits those defaults; an explicitly empty Features slice disables them. Embedded block fields retain their attached behavior and presentation. Field panics if more than one Config is supplied.
func RenderDocument ¶ added in v0.2.0
func RenderDocument[T any](document Document[T], block func(T) (string, error), nodes map[string]func(store.Values) (string, error)) (string, error)
RenderDocument renders a typed document without loading an editor or fetching referenced records. The block callback receives the generated payload codec; applications dispatch its Value union by concrete generated type. Missing callbacks fail explicitly. Use RenderHTML for deliberate raw recovery tooling.
Types ¶
type Config ¶
type Config struct {
// Blocks is the fixed executable schema allowlist. Fields are resolved
// through the public embedded-fields contract, never serialized as settings.
Blocks []field.Block `json:"-"`
// BlockReferences selects Config.Blocks definitions; it is exclusive with Blocks.
BlockReferences []string `json:"-"`
Features []Feature `json:"features"`
UploadCollections []string `json:"uploadCollections,omitempty"`
RelationshipCollections []string `json:"relationshipCollections,omitempty"`
}
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a defensive copy of Ridu's recommended authoring defaults.
type Document ¶
Document is the portable rich-text envelope. T is the generated, field-specific block payload codec. It is not a map: configured variants retain their exact input/output types and discriminator through ordinary generated block codecs.
func MapDocumentBlocks ¶ added in v0.2.0
func MapDocumentBlocks[From, To any](document Document[From], convert func(From) (To, error)) (Document[To], error)
MapDocumentBlocks copies the editor tree while explicitly converting each typed block payload. Pass the generated output payload's Retain method to make an update document: only block identities are retained, so omitted, redacted, localized and populated fields are never copied into a write. Edit returned update payloads and save with the parent document's revision.
func (Document[T]) MarshalJSON ¶ added in v0.2.0
func (*Document[T]) UnmarshalJSON ¶ added in v0.2.0
UnmarshalJSON rejects unsupported documents rather than dropping historical content while decoding. Export/migration tools should retain raw JSON when a typed decoder returns an error.
type Node ¶ added in v0.2.0
type Node[T any] struct { Type string `json:"type"` Version int `json:"version,omitempty"` Children []Node[T] `json:"children,omitempty"` Fields *T `json:"fields,omitempty"` Text string `json:"text,omitempty"` Format json.RawMessage `json:"format,omitempty"` Detail int `json:"detail,omitempty"` Mode string `json:"mode,omitempty"` Style string `json:"style,omitempty"` TextFormat int `json:"textFormat,omitempty"` TextStyle string `json:"textStyle,omitempty"` Direction *string `json:"direction,omitempty"` Indent int `json:"indent,omitempty"` Tag string `json:"tag,omitempty"` URL string `json:"url,omitempty"` Target string `json:"target,omitempty"` Rel string `json:"rel,omitempty"` Title string `json:"title,omitempty"` ListType string `json:"listType,omitempty"` Start int `json:"start,omitempty"` Value int `json:"value,omitempty"` Checked *bool `json:"checked,omitempty"` Language string `json:"language,omitempty"` Theme string `json:"theme,omitempty"` RelationTo string `json:"relationTo,omitempty"` ID string `json:"id,omitempty"` Caption string `json:"caption,omitempty"` }
Node contains portable editor properties. Fields is present only for atomic block nodes and holds the field-specific generated payload union.