editor

package
v1.6.6 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2024 License: GPL-2.0 Imports: 20 Imported by: 0

Documentation

Overview

templ: version: v0.2.707

Index

Constants

This section is empty.

Variables

View Source
var (
	EditorRegistry = newEditorRegistry()
	ValueToForm    = EditorRegistry.ValueToForm
	ValueToGo      = EditorRegistry.ValueToGo
	Features       = EditorRegistry.Features
	Register       = EditorRegistry.Register
	TuneFeature    = EditorRegistry.TuneFeature
	Tune           = EditorRegistry.Tune
)
View Source
var (
	RENDER_ERRORS = true
)

Functions

func EditorJSField

func EditorJSField(features []string, opts ...func(fields.Field)) fields.Field

func FeatureNames added in v1.6.6

func FeatureNames(f ...BaseFeature) []string

func JSONMarshalEditorData added in v1.6.6

func JSONMarshalEditorData(d *EditorJSBlockData) ([]byte, error)

Types

type BaseFeature

type BaseFeature interface {
	// Name returns the name of the feature.
	Name() string

	// Config returns the configuration of the feature.
	Config(widgetContext ctx.Context) map[string]interface{}

	// Constructor returns the JS class name of the feature.
	Constructor() string

	// Media return's the feature's static / media files.
	Media() media.Media
}

type BlockData

type BlockData struct {
	ID    string                 `json:"id"`
	Type  string                 `json:"type"`
	Data  map[string]interface{} `json:"data"`
	Tunes map[string]interface{} `json:"tunes,omitempty"`
}

type BlockTuneFeature

type BlockTuneFeature interface {
	BaseFeature
	Tune(FeatureBlock, interface{}) FeatureBlock
}

BlockTuneFeature is a feature that can tune a block.

This is used to tune the block after it has been converted from JSON to Go.

The tune method should return a new block, or the same block if no changes were made.

The tune object should wrap the provided block or make changes to it.

type EditorJSBlockData

type EditorJSBlockData struct {
	Time     int64          `json:"time"`
	Blocks   []FeatureBlock `json:"blocks"`
	Version  string         `json:"version"`
	Features []BaseFeature  `json:"-"`
}

func JSONUnmarshalEditorData added in v1.6.6

func JSONUnmarshalEditorData(features []string, data []byte) (*EditorJSBlockData, error)

func (*EditorJSBlockData) Render

func (e *EditorJSBlockData) Render() template.HTML

func (*EditorJSBlockData) String

func (e *EditorJSBlockData) String() string

type EditorJSData

type EditorJSData struct {
	Time    int64       `json:"time"`
	Blocks  []BlockData `json:"blocks"`
	Version string      `json:"version"`
}

type EditorJSFormField

type EditorJSFormField struct {
	*fields.JSONFormField[EditorJSData]

	Features []string
	// contains filtered or unexported fields
}

func (*EditorJSFormField) HasChanged

func (e *EditorJSFormField) HasChanged(initial, data interface{}) bool

func (*EditorJSFormField) SetWidget

func (e *EditorJSFormField) SetWidget(widget widgets.Widget)

func (*EditorJSFormField) ValueToForm

func (e *EditorJSFormField) ValueToForm(value interface{}) interface{}

func (*EditorJSFormField) ValueToGo

func (e *EditorJSFormField) ValueToGo(value interface{}) (interface{}, error)

func (*EditorJSFormField) Widget

func (e *EditorJSFormField) Widget() widgets.Widget

type EditorJSWidget

type EditorJSWidget struct {
	widgets.BaseWidget
	Features []string
}

func NewEditorJSWidget

func NewEditorJSWidget(features ...string) *EditorJSWidget

func (*EditorJSWidget) Component

func (b *EditorJSWidget) Component(id, name, value string, errors []error, attrs map[string]string, config map[string]interface{}) templ.Component

func (*EditorJSWidget) GetContextData

func (b *EditorJSWidget) GetContextData(id, name string, value interface{}, attrs map[string]string) ctx.Context

func (*EditorJSWidget) Media

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

func (*EditorJSWidget) Render

func (b *EditorJSWidget) Render(w io.Writer, id, name string, value interface{}, attrs map[string]string) error

func (*EditorJSWidget) RenderWithErrors

func (b *EditorJSWidget) RenderWithErrors(w io.Writer, id, name string, value interface{}, errors []error, attrs map[string]string) error

func (EditorJSWidget) ValueToForm

func (b EditorJSWidget) ValueToForm(value interface{}) interface{}

func (EditorJSWidget) ValueToGo

func (b EditorJSWidget) ValueToGo(value interface{}) (interface{}, error)

type FeatureBlock

type FeatureBlock interface {
	ID() string
	Type() string
	Feature() BaseFeature
	Render(ctx context.Context, w io.Writer) error
	Attribute(key string, value any)
	Attributes() map[string]interface{}
	Data() BlockData
}

type FeatureBlockRenderer

type FeatureBlockRenderer interface {
	BaseFeature
	// Render should return a new block object that can be used to render
	// the HTML.
	Render(BlockData) FeatureBlock
}

FeatureBlockRenderer is a feature that can render a block.

This is used to render the block after it has been converted from JSON to Go.

The render method should return an object based on the provided data. This object will be used to render the HTML.

type InlineFeature

type InlineFeature interface {
	BaseFeature
}

Directories

Path Synopsis
templ: version: v0.2.707
templ: version: v0.2.707

Jump to

Keyboard shortcuts

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