Documentation
¶
Overview ¶
templ: version: v0.3.1020
Index ¶
- Constants
- Variables
- func EditorComparison(ctx context.Context, label func(context.Context) string, fieldName string, ...) (compare.Comparison, error)
- func EditorJSField(features []string, opts ...func(fields.Field)) fields.Field
- func FeatureNames(f ...BaseFeature) []string
- func JSONMarshalEditorData(d *EditorJSBlockData) ([]byte, error)
- func NewAppConfig() django.AppConfig
- type BaseFeature
- type BlockData
- type BlockTuneFeature
- type EditorJSBlockData
- func (e *EditorJSBlockData) DBType() dbtype.Type
- func (e *EditorJSBlockData) HTML() template.HTML
- func (e *EditorJSBlockData) MarshalJSON() ([]byte, error)
- func (e *EditorJSBlockData) MustRender() template.HTML
- func (e *EditorJSBlockData) Render() (template.HTML, error)
- func (e *EditorJSBlockData) Scan(src interface{}) error
- func (e *EditorJSBlockData) String() string
- func (e *EditorJSBlockData) UnmarshalJSON(data []byte) error
- func (e *EditorJSBlockData) Value() (driver.Value, error)
- type EditorJSData
- type EditorJSFormField
- func (e *EditorJSFormField) HasChanged(initial, data interface{}) bool
- func (e *EditorJSFormField) SetWidget(widget widgets.Widget)
- func (e *EditorJSFormField) Validate(ctx context.Context, value interface{}) []error
- func (e *EditorJSFormField) ValueToForm(value interface{}) interface{}
- func (e *EditorJSFormField) ValueToGo(value interface{}) (interface{}, error)
- func (e *EditorJSFormField) Widget() widgets.Widget
- type EditorJSWidget
- func (b *EditorJSWidget) Component(id, name, value string, errors []error, attrs map[string]string, ...) templ.Component
- func (b *EditorJSWidget) GetContextData(ctx context.Context, id, name string, value interface{}, ...) ctx.Context
- func (b *EditorJSWidget) Media() media.Media
- func (b *EditorJSWidget) Render(ctx context.Context, w io.Writer, id, name string, value interface{}, ...) error
- func (b *EditorJSWidget) RenderWithErrors(ctx context.Context, w io.Writer, id, name string, value interface{}, ...) error
- func (b *EditorJSWidget) Validate(ctx context.Context, value interface{}) []error
- func (b *EditorJSWidget) ValueToForm(value interface{}) interface{}
- func (b *EditorJSWidget) ValueToGo(value interface{}) (interface{}, error)
- type FeatureBlock
- type FeatureBlockRenderer
- type Field
- func (e *Field) AllowBlank() bool
- func (e *Field) AllowDBEdit() bool
- func (e *Field) AllowEdit() bool
- func (e *Field) AllowNull() bool
- func (e *Field) Attrs() map[string]any
- func (f *Field) BindToDefinitions(defs attrs.Definitions)
- func (e *Field) ColumnName() string
- func (f *Field) FieldDefinitions() attrs.Definitions
- func (e *Field) FormField() fields.Field
- func (e *Field) GetDefault() interface{}
- func (e *Field) GetValue() interface{}
- func (e *Field) HelpText(ctx context.Context) string
- func (e *Field) Instance() attrs.Definer
- func (e *Field) IsPrimary() bool
- func (e *Field) Label(ctx context.Context) string
- func (f *Field) Name() string
- func (e *Field) Rel() attrs.Relation
- func (e *Field) Scan(src interface{}) error
- func (e *Field) SetValue(v interface{}, force bool) error
- func (e *Field) Tag(s string) string
- func (e *Field) ToString() string
- func (e *Field) Type() reflect.Type
- func (e *Field) Validate() error
- func (e *Field) Value() (driver.Value, error)
- type FieldConfig
- type InlineFeature
- type JSONTelepathAdapter
- type PrefetchableFeature
- type PrefetchableFeatureBlock
Constants ¶
const ( ROUTE_PATH = "/__go-editorjs__" APPVAR_WRAP_RENDERED_BLOCKS = "APPVAR_WRAP_RENDERED_BLOCKS" APPVAR_ENABLE_INLINE_TOOLBAR = "APPVAR_ENABLE_INLINE_TOOLBAR" )
Variables ¶
var ( EditorRegistry = newEditorRegistry() ValueToForm = EditorRegistry.ValueToForm ValueToGo = EditorRegistry.ValueToGo Features = EditorRegistry.Features Register = EditorRegistry.Register Unregister = EditorRegistry.Unregister TuneFeature = EditorRegistry.TuneFeature Tune = EditorRegistry.Tune )
var (
RENDER_ERRORS = true
)
Functions ¶
func EditorComparison ¶ added in v1.7.2
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
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 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) 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
type EditorJSData ¶
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) GetContextData ¶
func (*EditorJSWidget) Media ¶
func (b *EditorJSWidget) Media() media.Media
func (*EditorJSWidget) RenderWithErrors ¶
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 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 (*Field) AllowDBEdit ¶ added in v1.7.2
func (*Field) BindToDefinitions ¶ added in v1.7.2
func (f *Field) BindToDefinitions(defs attrs.Definitions)
func (*Field) ColumnName ¶ added in v1.7.2
no real column, special case for virtual fields
func (*Field) FieldDefinitions ¶ added in v1.7.2
func (f *Field) FieldDefinitions() attrs.Definitions
func (*Field) GetDefault ¶ added in v1.7.2
func (e *Field) GetDefault() interface{}
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
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)
}