features

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: GPL-2.0 Imports: 16 Imported by: 1

Documentation

Overview

templ: version: v0.3.833

templ: version: v0.3.833

templ: version: v0.3.833

templ: version: v0.3.833

templ: version: v0.3.833

templ: version: v0.3.833

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",
		CSSFles: []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", func(fb editor.FeatureBlock, data map[string]interface{}) {
		if a, ok := data["stretched"]; ok {
			fb.Class("background-stretched")
			fb.Attribute("data-stretched", a)
		}
	}),
}
View Source
var CheckListBlock = &Block{
	BaseFeature: BaseFeature{
		Type:          "checklist",
		JSConstructor: "Checklist",
		JSFiles: []string{
			"editorjs/js/deps/tools/checklist.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			return fb
		},
	},
	RenderFunc: func(b editor.FeatureBlock, c context.Context, w io.Writer) error {
		var items = make([]checkListItem, 0)
		var checklistItems = b.Data().Data["items"].([]interface{})
		for _, item := range checklistItems {
			item := item.(map[string]interface{})
			items = append(items, checkListItem{
				Text:    item["text"].(string),
				Checked: item["checked"].(bool),
			})
		}
		return renderCheckList(b, items).Render(c, w)
	},
}
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 ListBlock = &Block{
	BaseFeature: BaseFeature{
		Type:          "list",
		JSConstructor: "List",
		JSFiles: []string{
			"editorjs/js/deps/tools/list.js",
		},
		Build: func(fb *FeatureBlock) *FeatureBlock {
			return fb
		},
	},
	RenderFunc: func(b editor.FeatureBlock, c context.Context, w io.Writer) error {
		var items = make([]string, 0)
		for _, item := range b.Data().Data["items"].([]interface{}) {
			items = append(items, item.(string))
		}
		return renderList(b, items).Render(c, w)
	},
}
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 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",
		CSSFles: []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", nil),
}

Functions

This section is empty.

Types

type BaseFeature

type BaseFeature struct {
	Type          string
	Extra         map[string]interface{}
	JSConstructor string
	JSFiles       []string
	CSSFles       []string
	Validate      func(editor.BlockData) error
	Build         func(*FeatureBlock) *FeatureBlock
	Register      func(django.Mux)
}

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 django.Mux) 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.Document) 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 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