editor

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: 37 Imported by: 2

Documentation

Overview

templ: version: v0.3.1020

Index

Constants

View Source
const (
	ROUTE_PATH = "/__go-editorjs__"

	APPVAR_WRAP_RENDERED_BLOCKS = "APPVAR_WRAP_RENDERED_BLOCKS"

	APPVAR_ENABLE_INLINE_TOOLBAR = "APPVAR_ENABLE_INLINE_TOOLBAR"
)

Variables

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

Functions

func EditorComparison added in v1.7.2

func EditorComparison(ctx context.Context, label func(context.Context) string, fieldName string, modelMeta attrs.ModelMeta, old, new attrs.Definer) (compare.Comparison, error)

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)

func NewAppConfig added in v1.6.9

func NewAppConfig() django.AppConfig

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{}

	// OnRegister is called when the feature is registered.
	//
	// It is allowed to add custom routes or do other setup here.
	OnRegister(mux.Multiplexer) error

	// OnValidate is called when the feature is validated.
	OnValidate(BlockData) error

	// 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:"-"`
}

The main datatype to use in structs.

This will automatically assign the appropriate form widget for the field.

It will also allow for simple rendering of the field's data by calling the `Render()` method.

If the struct which the field belongs to defines a `Get<FieldName>Features() []string` method, then these features will be used to build the editorjs widget.

func JSONUnmarshalEditorData added in v1.6.6

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

func (*EditorJSBlockData) DBType added in v1.7.2

func (e *EditorJSBlockData) DBType() dbtype.Type

func (*EditorJSBlockData) HTML added in v1.7.2

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

func (*EditorJSBlockData) MarshalJSON added in v1.7.2

func (e *EditorJSBlockData) MarshalJSON() ([]byte, error)

func (*EditorJSBlockData) MustRender added in v1.7.0

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

func (*EditorJSBlockData) Render

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

func (*EditorJSBlockData) Scan added in v1.7.0

func (e *EditorJSBlockData) Scan(src interface{}) error

func (*EditorJSBlockData) String

func (e *EditorJSBlockData) String() string

func (*EditorJSBlockData) UnmarshalJSON added in v1.7.2

func (e *EditorJSBlockData) UnmarshalJSON(data []byte) error

func (*EditorJSBlockData) Value added in v1.7.0

func (e *EditorJSBlockData) Value() (driver.Value, error)

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) Validate added in v1.7.2

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

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(ctx context.Context, 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(ctx context.Context, w io.Writer, id, name string, value interface{}, attrs map[string]string) error

func (*EditorJSWidget) RenderWithErrors

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

func (*EditorJSWidget) Validate added in v1.7.2

func (b *EditorJSWidget) Validate(ctx context.Context, value interface{}) []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{}
	Class(key string)
	ClassName() string
	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 Field added in v1.7.2

type Field struct {
	// contains filtered or unexported fields
}

func NewField added in v1.7.2

func NewField(forModel attrs.Definer, name string, cnf ...FieldConfig) *Field

func (*Field) AllowBlank added in v1.7.2

func (e *Field) AllowBlank() bool

func (*Field) AllowDBEdit added in v1.7.2

func (e *Field) AllowDBEdit() bool

func (*Field) AllowEdit added in v1.7.2

func (e *Field) AllowEdit() bool

func (*Field) AllowNull added in v1.7.2

func (e *Field) AllowNull() bool

func (*Field) Attrs added in v1.7.2

func (e *Field) Attrs() map[string]any

func (*Field) BindToDefinitions added in v1.7.2

func (f *Field) BindToDefinitions(defs attrs.Definitions)

func (*Field) ColumnName added in v1.7.2

func (e *Field) ColumnName() string

no real column, special case for virtual fields

func (*Field) FieldDefinitions added in v1.7.2

func (f *Field) FieldDefinitions() attrs.Definitions

func (*Field) FormField added in v1.7.2

func (e *Field) FormField() fields.Field

func (*Field) GetDefault added in v1.7.2

func (e *Field) GetDefault() interface{}

func (*Field) GetValue added in v1.7.2

func (e *Field) GetValue() interface{}

func (*Field) HelpText added in v1.7.2

func (e *Field) HelpText(ctx context.Context) string

func (*Field) Instance added in v1.7.2

func (e *Field) Instance() attrs.Definer

func (*Field) IsPrimary added in v1.7.2

func (e *Field) IsPrimary() bool

func (*Field) Label added in v1.7.2

func (e *Field) Label(ctx context.Context) string

func (*Field) Name added in v1.7.2

func (f *Field) Name() string

func (*Field) Rel added in v1.7.2

func (e *Field) Rel() attrs.Relation

func (*Field) Scan added in v1.7.2

func (e *Field) Scan(src interface{}) error

func (*Field) SetValue added in v1.7.2

func (e *Field) SetValue(v interface{}, force bool) error

func (*Field) Tag added in v1.7.2

func (e *Field) Tag(s string) string

func (*Field) ToString added in v1.7.2

func (e *Field) ToString() string

func (*Field) Type added in v1.7.2

func (e *Field) Type() reflect.Type

func (*Field) Validate added in v1.7.2

func (e *Field) Validate() error

func (*Field) Value added in v1.7.2

func (e *Field) Value() (driver.Value, error)

type FieldConfig added in v1.7.2

type FieldConfig struct {
	// Label is the label for the field.
	Label func(ctx context.Context) string

	// HelpText is the help text for the field.
	HelpText func(ctx context.Context) string

	// Features is a list of features to enable for the editor.
	Features []string

	// Default is the default value for the field.
	Default *EditorJSBlockData

	// ReadOnly indicates if the field is read-only.
	ReadOnly bool

	// Blank indicates if the field can be blank.
	Blank bool

	// Nullable indicates if the field can be null.
	Nullable bool

	// Column is the name of the column in the database.
	Column string

	// Attributes are additional attributes for the field.
	Attributes map[string]any

	// Options for the form field.
	FormFieldOpts []func(fields.Field)
}

type InlineFeature

type InlineFeature interface {
	BaseFeature
	ParseInlineData(soup *goquery.Selection) error
}

type JSONTelepathAdapter added in v1.7.2

type JSONTelepathAdapter struct{}

func JSONAdapter added in v1.7.2

func JSONAdapter() *JSONTelepathAdapter

func (*JSONTelepathAdapter) BuildNode added in v1.7.2

func (m *JSONTelepathAdapter) BuildNode(ctx context.Context, value any, c telepath.Context) (telepath.Node, error)

type PrefetchableFeature added in v1.7.2

type PrefetchableFeature interface {
	BaseFeature
	Render(BlockData) FeatureBlock // actually should implement [PrefetchableFeatureBlock]
	PrefetchData(ctx context.Context, data []BlockData) (map[string]BlockData, error)
}

type PrefetchableFeatureBlock added in v1.7.2

type PrefetchableFeatureBlock interface {
	FeatureBlock
	WithData(ctx context.Context, data BlockData)
}

Directories

Path Synopsis
templ: version: v0.3.1020
templ: version: v0.3.1020

Jump to

Keyboard shortcuts

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