features

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: 18 Imported by: 1

Documentation

Overview

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

Index

Constants

This section is empty.

Variables

View Source
var AlertFeature = &Block{
	BaseFeature: BaseFeature{
		Type:          "alert",
		JSConstructor: "Alert",
		JSFiles: []string{
			"editorjs/js/deps/tools/vishaltelangre.editorjs-alert.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string { return d.Data["message"].(string) }
			return fb
		},
		Validate: func(bd editor.BlockData) error {
			var data = bd.Data
			var typ, hasType = data["type"]
			if !hasType {
				return fmt.Errorf("type is required for alert feature")
			}
			if typ == nil || typ == "" {
				return fmt.Errorf("type cannot be empty for alert feature")
			}
			if _, ok := alertTypes[typ.(string)]; !ok {
				return fmt.Errorf("invalid type %s for alert feature", typ)
			}
			return nil
		},
	},
	RenderFunc: templRender(renderAlert),
}
View Source
var AlignmentBlockTune = &BlockTune{
	BaseFeature: BaseFeature{
		Type:          "text-align",
		JSConstructor: "AlignmentBlockTune",
		JSFiles: []string{
			"editorjs/js/deps/tools/text-alignment.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string { return d.Data["text"].(string) }
			return fb
		},
	},
	TuneFunc: tuneBlocks,
}
View Source
var BackgroundColorTune = &BlockTune{
	BaseFeature: BaseFeature{
		Type:          "background-color",
		JSConstructor: "BackgroundColorTune",
		CSSFiles: []string{
			"editorjs/css/color-tune.css",
		},
		JSFiles: []string{
			"editorjs/js/deps/tools/color-tune.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string { return d.Data["text"].(string) }
			return fb
		},
	},
	TuneFunc: colorTune("background-color"),
}
View Source
var DelimiterFeature = &Block{
	BaseFeature: BaseFeature{
		Type:          "delimiter",
		JSConstructor: "Delimiter",
		JSFiles: []string{
			"editorjs/js/deps/tools/delimiter.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(editor.BlockData) string { return "----" }
			return fb
		},
	},
	RenderFunc: renderDelimiter,
}
View Source
var (
	ErrRenderNotImplemented = errors.New("feature does not implement RenderBlock")
)
View Source
var HeadingFeature = &Block{
	BaseFeature: BaseFeature{
		Type:          "header",
		JSConstructor: "Header",
		JSFiles: []string{
			"editorjs/js/deps/tools/header.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string { return d.Data["text"].(string) }
			return fb
		},
	},
	RenderFunc: renderHeading,
}
View Source
var HotkeyFeature = &InlineFeature{
	TagName:    "kbd",
	Class:      "editorjs-inline-hotkey",
	Attributes: []InlineFeatureAttribute{},
	BaseFeature: BaseFeature{
		Type:          "hotkey",
		JSConstructor: "EditorJSInlineHotkey",
		JSFiles: []string{
			"editorjs/js/deps/tools/hotkey.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string {
				return fmt.Sprintf("[%s](%s)", d.Data["text"], d.Data["id"])
			}
			return fb
		},
	},
	RebuildElementsFn: func(li []*InlineFeatureElement) error {
		for _, el := range li {
			el.Node.Attr = []html.Attribute{
				{
					Key: "class",
					Val: "hotkey",
				},
			}
		}

		return nil
	},
}
View Source
var InlineCodeFeature = &InlineFeature{
	TagName:    "span",
	Class:      "inline-code",
	Attributes: []InlineFeatureAttribute{},
	BaseFeature: BaseFeature{
		Type:          "inline-code",
		JSConstructor: "InlineCode",
		JSFiles: []string{
			"editorjs/js/deps/tools/inline-code.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string {
				return fmt.Sprintf("[%s](%s)", d.Data["text"], d.Data["id"])
			}
			return fb
		},
	},
	RebuildElementsFn: func(li []*InlineFeatureElement) error {
		for _, el := range li {
			el.Node.Attr = []html.Attribute{
				{
					Key: "class",
					Val: "inline-code",
				},
			}
		}

		return nil
	},
}
View Source
var ListBlock = &Block{
	BaseFeature: BaseFeature{
		Type:          "list",
		JSConstructor: "EditorjsList",
		JSFiles: []string{
			"editorjs/js/deps/tools/list@2.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			return fb
		},
	},
	RenderFunc: func(b editor.FeatureBlock, c context.Context, w io.Writer) error {
		var data = b.Data().Data
		var out = &listOutput{
			Items: make([]listItem, 0),
		}

		style, ok := data["style"].(string)
		if ok {
			out.Style = style
		}

		meta, ok := data["meta"].(map[string]interface{})
		if ok {
			start, _ := meta["start"].(int)
			counterType, _ := meta["counterType"].(string)
			out.Meta = listItemMeta{
				Start:       start,
				CounterType: counterType,
			}
		}

		items, ok := data["items"].([]interface{})
		if ok {
			out.Items = parseItems(items)
		}

		return renderList(b, out).Render(c, w)
	},
}
View Source
var MarkerFeature = &InlineFeature{
	TagName:    "mark",
	Class:      "cdx-marker",
	Attributes: []InlineFeatureAttribute{},
	BaseFeature: BaseFeature{
		Type:          "marker",
		JSConstructor: "Marker",
		JSFiles: []string{
			"editorjs/js/deps/tools/marker.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string {
				return fmt.Sprintf("[%s](%s)", d.Data["text"], d.Data["id"])
			}
			return fb
		},
	},
	RebuildElementsFn: func(li []*InlineFeatureElement) error {
		for _, el := range li {
			el.Node.Attr = []html.Attribute{
				{
					Key: "class",
					Val: "marker",
				},
			}
		}

		return nil
	},
}
View Source
var ParagraphFeature = &Block{
	BaseFeature: BaseFeature{
		Type:          "paragraph",
		JSConstructor: "Paragraph",
		JSFiles: []string{
			"editorjs/js/deps/tools/paragraph.umd.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string { return d.Data["text"].(string) }
			return fb
		},
	},
	RenderFunc: renderParagraph,
}
View Source
var StrikeThroughFeature = &InlineFeature{
	TagName:    "s",
	Class:      "cdx-strikethrough",
	Attributes: []InlineFeatureAttribute{},
	BaseFeature: BaseFeature{
		Type:          "strikethrough",
		JSConstructor: "Strikethrough",
		JSFiles: []string{
			"editorjs/js/deps/tools/strikethrough.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string {
				return fmt.Sprintf("[%s](%s)", d.Data["text"], d.Data["id"])
			}
			return fb
		},
	},
	RebuildElementsFn: func(li []*InlineFeatureElement) error {
		for _, el := range li {
			el.Node.Attr = []html.Attribute{
				{
					Key: "class",
					Val: "strikethrough",
				},
			}
		}

		return nil
	},
}
View Source
var TableFeature = &Block{
	BaseFeature: BaseFeature{
		Type:          "table",
		JSConstructor: "Table",
		JSFiles: []string{
			"editorjs/js/deps/tools/table.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string { return "Table" }
			return fb
		},
		Validate: func(bd editor.BlockData) error {
			var data = bd.Data
			var content, hasContent = data["content"]
			if !hasContent {
				return fmt.Errorf("content is required for table feature")
			}
			var _, isArray = content.([]interface{})
			if !isArray {
				return fmt.Errorf("content should be an array of arrays")
			}
			return nil
		},
	},
	RenderFunc: templRender(renderTable),
}
View Source
var TextColorTune = &BlockTune{
	BaseFeature: BaseFeature{
		Type:          "text-color",
		JSConstructor: "TextColorTune",
		CSSFiles: []string{
			"editorjs/css/color-tune.css",
		},
		JSFiles: []string{
			"editorjs/js/deps/tools/color-tune.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string { return d.Data["text"].(string) }
			return fb
		},
	},
	TuneFunc: colorTune("text-color"),
}
View Source
var UnderlineFeature = &InlineFeature{
	TagName:    "u",
	Class:      "cdx-underline",
	Attributes: []InlineFeatureAttribute{},
	BaseFeature: BaseFeature{
		Type:          "underline",
		JSConstructor: "Underline",
		JSFiles: []string{
			"editorjs/js/deps/tools/underline.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			fb.GetString = func(d editor.BlockData) string {
				return fmt.Sprintf("[%s](%s)", d.Data["text"], d.Data["id"])
			}
			return fb
		},
	},
	RebuildElementsFn: func(li []*InlineFeatureElement) error {
		for _, el := range li {
			el.Node.Attr = []html.Attribute{
				{
					Key: "class",
					Val: "underline",
				},
			}
		}

		return nil
	},
}

Functions

This section is empty.

Types

type AttributeWrapperBlock added in v1.7.2

type AttributeWrapperBlock struct {
	editor.FeatureBlock
	Attrs   map[string]interface{}
	Classes []string
}

func (*AttributeWrapperBlock) Attribute added in v1.7.2

func (a *AttributeWrapperBlock) Attribute(key string, value interface{})

func (*AttributeWrapperBlock) Attributes added in v1.7.2

func (a *AttributeWrapperBlock) Attributes() map[string]interface{}

func (*AttributeWrapperBlock) Render added in v1.7.2

func (a *AttributeWrapperBlock) Render(ctx context.Context, w io.Writer) error

type BaseFeature

type BaseFeature struct {
	Type          string
	JSConstructor string
	JSFiles       []string
	CSSFiles      []string
	Extra         func(widgetContext ctx.Context) map[string]interface{}
	Validate      func(editor.BlockData) error
	Build         func(*FeatureBlock) *FeatureBlock
	Register      func(mux.Multiplexer)
}

func (*BaseFeature) Config

func (b *BaseFeature) Config(widgetContext ctx.Context) map[string]interface{}

Config returns the configuration of the feature.

func (*BaseFeature) Constructor

func (b *BaseFeature) Constructor() string

Constructor returns the JS class name of the feature.

func (*BaseFeature) Media

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

Media return's the feature's static / media files.

func (*BaseFeature) Name

func (b *BaseFeature) Name() string

Name returns the name of the feature.

func (*BaseFeature) OnRegister added in v1.6.9

func (b *BaseFeature) OnRegister(m mux.Multiplexer) error

OnRegister is called when the feature is registered.

It is allowed to add custom routes or do other setup here.

func (*BaseFeature) OnValidate added in v1.6.9

func (b *BaseFeature) OnValidate(data editor.BlockData) error

OnValidate is called when the feature is validated.

func (*BaseFeature) Render

Render returns the feature block.

type Block

type Block struct {
	BaseFeature
	RenderFunc func(b editor.FeatureBlock, c context.Context, w io.Writer) error
}

func (*Block) Render

func (b *Block) Render(d editor.BlockData) editor.FeatureBlock

func (*Block) RenderBlock

func (b *Block) RenderBlock(fb editor.FeatureBlock, c context.Context, w io.Writer) error

type BlockRenderer

type BlockRenderer interface {
	RenderBlock(fb editor.FeatureBlock, c context.Context, w io.Writer) error
}

type BlockTune

type BlockTune struct {
	BaseFeature
	TuneFunc func(fb editor.FeatureBlock, data interface{}) editor.FeatureBlock
}

func (*BlockTune) Tune

func (b *BlockTune) Tune(fb editor.FeatureBlock, data interface{}) editor.FeatureBlock

type FeatureBlock

type FeatureBlock struct {
	Attrs      map[string]interface{}
	Classes    []string
	Identifier string

	FeatureData   editor.BlockData
	FeatureObject editor.BaseFeature
	FeatureName   string
	GetString     func(editor.BlockData) string
}

func (*FeatureBlock) Attribute

func (b *FeatureBlock) Attribute(key string, value interface{})

func (*FeatureBlock) Attributes

func (b *FeatureBlock) Attributes() map[string]interface{}

func (*FeatureBlock) Class added in v1.7.0

func (b *FeatureBlock) Class(key string)

func (*FeatureBlock) ClassName added in v1.7.0

func (b *FeatureBlock) ClassName() string

func (*FeatureBlock) Data

func (b *FeatureBlock) Data() editor.BlockData

func (*FeatureBlock) Feature

func (b *FeatureBlock) Feature() editor.BaseFeature

func (*FeatureBlock) ID

func (b *FeatureBlock) ID() string

func (*FeatureBlock) Render

func (b *FeatureBlock) Render(ctx context.Context, w io.Writer) error

func (*FeatureBlock) String

func (b *FeatureBlock) String() string

func (*FeatureBlock) Type

func (b *FeatureBlock) Type() string

type InlineFeature added in v1.7.0

type InlineFeature struct {
	BaseFeature
	TagName           string
	Class             string
	Attributes        []InlineFeatureAttribute
	RebuildElementsFn func([]*InlineFeatureElement) error
	RebuildElementFn  func(*InlineFeatureElement) error
}

func (*InlineFeature) ParseInlineData added in v1.7.0

func (b *InlineFeature) ParseInlineData(doc *goquery.Selection) error

func (*InlineFeature) RebuildElements added in v1.7.0

func (b *InlineFeature) RebuildElements(elements []*InlineFeatureElement) error

type InlineFeatureAttribute added in v1.7.0

type InlineFeatureAttribute struct {
	Required bool    // if true, the attribute must be present
	Name     string  // the name of the attribute to search for
	Value    *string // nil means any value is allowed, or that just the presence of the attribute is enough
}

type InlineFeatureElement added in v1.7.0

type InlineFeatureElement struct {
	Node *html.Node
	Data map[string]*string // the data of the element, equivalent to the parsed data of InlineFeatureAttribute
}

type PrefetchableFeature added in v1.7.2

type PrefetchableFeature struct {
	Block
	Prefetch func(ctx context.Context, data []editor.BlockData) (map[string]editor.BlockData, error)
}

func (*PrefetchableFeature) PrefetchData added in v1.7.2

func (f *PrefetchableFeature) PrefetchData(ctx context.Context, data []editor.BlockData) (map[string]editor.BlockData, error)

func (*PrefetchableFeature) Render added in v1.7.2

type PrefetchableFeatureBlock added in v1.7.2

type PrefetchableFeatureBlock struct {
	*FeatureBlock
}

func (*PrefetchableFeatureBlock) WithData added in v1.7.2

func (b *PrefetchableFeatureBlock) WithData(ctx context.Context, data editor.BlockData)

type WrapperBlock

type WrapperBlock struct {
	editor.FeatureBlock
	Wrap func(editor.FeatureBlock) func(context.Context, io.Writer) error
}

func (*WrapperBlock) Render

func (w *WrapperBlock) Render(ctx context.Context, wr io.Writer) error

type WrapperTune

type WrapperTune struct {
	BaseFeature
	Wrap func(editor.FeatureBlock) func(context.Context, io.Writer) error
}

func (*WrapperTune) Render

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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