blockeditor

package module
v0.21.2 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2024 License: AGPL-3.0 Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

BlockEditor Open in Gitpod

Tests Status Go Report Card PkgGoDev

License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0). You can find a copy of the license at https://www.gnu.org/licenses/agpl-3.0.en.html

For commercial use, please use my contact page to obtain a commercial license.

Status

The status of this project is "work in progress", "multiple changes", "avoid at the minute", "nothing stable".

Introduction

This package allows to build user interfaces based on blocks.

Installation

go get -u github.com/gouniverse/blockeditor

Screenshots

  • simple sequential blocks
  • nested blocks

Documentation

Index

Constants

View Source
const ACTION = "blockeditor_action"
View Source
const ACTION_BLOCKS_SAVE = "blocks_save"
View Source
const ACTION_BLOCK_ADD = "block_add"
View Source
const ACTION_BLOCK_ADD_MODAL = "block_add_modal"
View Source
const ACTION_BLOCK_DELETE = "block_delete"
View Source
const ACTION_BLOCK_DUPLICATE = "block_duplicate"
View Source
const ACTION_BLOCK_MOVE_DOWN = "block_move_down"
View Source
const ACTION_BLOCK_MOVE_INTO = "block_move_into"
View Source
const ACTION_BLOCK_MOVE_OUT = "block_move_out"
View Source
const ACTION_BLOCK_MOVE_UP = "block_move_up"
View Source
const ACTION_BLOCK_SETTINGS = "block_settings"
View Source
const ACTION_BLOCK_SETTINGS_UPDATE = "block_settings_update"
View Source
const BLOCK_ID = "block_id"
View Source
const BLOCK_TYPE = "block_type"
View Source
const EDITOR_HANDLER_ENDPOINT = "editor_handler_endpoint"
View Source
const EDITOR_ID = "editor_id"
View Source
const EDITOR_NAME = "editor_name"
View Source
const SETTINGS_PREFIX = "blockeditor_settings_"

Variables

This section is empty.

Functions

func ApplyAlignmentParameters added in v0.17.0

func ApplyAlignmentParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyAnimationParameters added in v0.17.0

func ApplyAnimationParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyBackgroundParameters added in v0.17.0

func ApplyBackgroundParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyBorderParameters added in v0.17.0

func ApplyBorderParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyDisplayParameters added in v0.19.0

func ApplyDisplayParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyFlexBoxParameters added in v0.17.0

func ApplyFlexBoxParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyFontParameters added in v0.17.0

func ApplyFontParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyHTMLParameters added in v0.17.0

func ApplyHTMLParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyMarginParameters added in v0.17.0

func ApplyMarginParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyPaddingParameters added in v0.17.0

func ApplyPaddingParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyPositionParameters added in v0.17.0

func ApplyPositionParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplySizeParameters added in v0.19.0

func ApplySizeParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyTextParameters added in v0.17.0

func ApplyTextParameters(block ui.BlockInterface, blockTag *hb.Tag)

func ApplyTransitionParameters added in v0.17.0

func ApplyTransitionParameters(block ui.BlockInterface, blockTag *hb.Tag)

func FieldGroupEnd added in v0.17.0

func FieldGroupEnd() form.FieldInterface

func FieldGroupStart added in v0.17.0

func FieldGroupStart(groupId, groupName string, collapsed bool) form.FieldInterface

func FieldsAlign added in v0.7.0

func FieldsAlign() []form.FieldInterface

FieldsAlign is a predefined set of alignment fields - Text Align (text_align) - Vertical Align (vertical_align)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsAnimation added in v0.17.0

func FieldsAnimation() []form.FieldInterface

FieldsAnimation is a predefined set of animation fields

func FieldsBackground added in v0.7.0

func FieldsBackground() []form.FieldInterface

FieldsBackground is a predefined set of background fields - Background Color (background_color) - Background Image URL (background_image_url) - Background Attachment (background_attachment) - Background Position (background_position) - Background Repeat (background_repeat) - Background Size (background_size)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsBorder added in v0.7.0

func FieldsBorder() []form.FieldInterface

FieldsBorder is a predefined set of border fields - Border (border)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsDisplay added in v0.19.0

func FieldsDisplay() []form.FieldInterface

FieldsDisplay is a predefined set of display fields - Display (display) - Visibility (visibility)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsFlexBox added in v0.17.0

func FieldsFlexBox() []form.FieldInterface

func FieldsFont added in v0.7.0

func FieldsFont() []form.FieldInterface

FieldsFont is a predefined set of font fields - Font Family (font_family) - Font Size (font_size) - Font Weight (font_weight) - Font Style (font_style)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsHTML added in v0.8.0

func FieldsHTML() []form.FieldInterface

FieldsHTML is a predefined set of fields common to all HTML elements - HTML ID (html_id) - HTML Class (html_class) - HTML Style (html_style)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsMargin added in v0.7.0

func FieldsMargin() []form.FieldInterface

FieldsMargin is a predefined set of margin fields - Margin Top (margin_top) - Margin Bottom (margin_bottom) - Margin Left (margin_left) - Margin Right (margin_right)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsPadding added in v0.7.0

func FieldsPadding() []form.FieldInterface

FieldsPadding is a predefined set of padding fields - Padding Top (padding_top) - Padding Bottom (padding_bottom) - Padding Left (padding_left) - Padding Right (padding_right)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsPositioning added in v0.17.0

func FieldsPositioning() []form.FieldInterface

FieldsPositioning is a predefined set of positioning fields - Position (position) - Top (top) - Right (right) - Bottom (bottom) - Left (left) - Z-Index (zindex)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsSize added in v0.19.0

func FieldsSize() []form.FieldInterface

FieldsSize is a predefined set of size fields - Width (width) - Height (height)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsText added in v0.7.0

func FieldsText() []form.FieldInterface

FieldsText is a predefined set of text fields - Text Color (text_color) - Line Height (line_height)

Parameters: - none

Returns: - []form.Field - The fields

func FieldsTransition added in v0.17.0

func FieldsTransition() []*form.Field

func Handle

func Handle(w http.ResponseWriter, r *http.Request, blockDefinitions []BlockDefinition) string

Handle handles the block editor

Business logic: - gets the action from the request - gets the editor id, name, content, and handler endpoint from the request - creates a new editor - if an action is provided, executes the action - if no action is provided, renders the editor

Parameters: - w: the http.ResponseWriter - r: the http.Request - blockDefinitions: the block definitions

Returns: - the response string

func NewEditor

func NewEditor(options NewEditorOptions) (*editor, error)

Types

type BlockDefinition

type BlockDefinition struct {
	// Icon is the icon of the block
	Icon hb.TagInterface

	// Type is the type of the block
	Type string

	// Fields are the fields for the paameters of the block which can be edited
	Fields []form.FieldInterface

	// AllowChildren determines if the block can have children
	AllowChildren bool

	// AllowedChildTypes is a list of block types that can be added as children
	AllowedChildTypes []string

	// Wrapper is a function that wraps the block's card in a custom tag
	// suitable for a column that need to apply its width so that the
	// card is displayed with the correct width
	Wrapper func(block ui.BlockInterface) *hb.Tag

	// ToTag is a function that converts a block to a tag to be displayed
	// in the block's card body in the editor
	ToTag func(block ui.BlockInterface) *hb.Tag
}

type FlatBlock added in v0.6.0

type FlatBlock struct {
	ID         string
	Type       string
	ParentID   string
	Sequence   int
	Parameters map[string]string
}

type FlatTree added in v0.1.0

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

func NewFlatTree added in v0.1.0

func NewFlatTree(blocks []ui.BlockInterface) *FlatTree

func (*FlatTree) Add added in v0.6.0

func (tree *FlatTree) Add(parentID string, flatBlock FlatBlock)

func (*FlatTree) AddBlock added in v0.1.0

func (tree *FlatTree) AddBlock(parentID string, block ui.BlockInterface)

AddBlock adds a new ui.BlockInterface to the FlatTree

func (*FlatTree) Children added in v0.1.0

func (tree *FlatTree) Children(parentID string) []FlatBlock

Children returns the children of the FlatBlock with the given parentID

func (*FlatTree) Clone added in v0.6.0

func (tree *FlatTree) Clone(flatBlock FlatBlock) FlatBlock

Clone creates a shallow clone of a FlatBlock (no children)

This is used to create a clone of a FlatBlock, so that the original FlatBlock is not modified, but we can modify the clone safely

Remember to update the ID, Sequence, and ParentID of the copy with new values

func (*FlatTree) Duplicate added in v0.15.0

func (tree *FlatTree) Duplicate(blockID string)

Duplicate creates a deep clone of a FlatBlock (with children) and adds it to the tree, under the same parent

Business Logic: - travserses the tree to find all blocks to be duplicated - makes a map with current IDs as keys, newly generated IDs as values - clones each block, and replaces the ID with the new ID - assignes the correct mapped IDs and ParentIDs - adds the cloned blocks to the tree directly (using list) - moves the duplicated block under the block being duplicated

func (*FlatTree) Exists added in v0.6.0

func (tree *FlatTree) Exists(flatBlockID string) bool

func (*FlatTree) Find added in v0.6.0

func (tree *FlatTree) Find(flatBlockID string) *FlatBlock

func (*FlatTree) FindNextSibling added in v0.6.0

func (tree *FlatTree) FindNextSibling(flatBlockID string) *FlatBlock

func (*FlatTree) FindPreviousSibling added in v0.6.0

func (tree *FlatTree) FindPreviousSibling(flatBlockID string) *FlatBlock

func (*FlatTree) List added in v0.21.2

func (tree *FlatTree) List() []FlatBlock

func (*FlatTree) MoveDown added in v0.6.0

func (tree *FlatTree) MoveDown(flatBlockID string)

func (*FlatTree) MoveToParent added in v0.6.0

func (tree *FlatTree) MoveToParent(flatBlockID, parentID string)

func (*FlatTree) MoveToPosition added in v0.14.0

func (tree *FlatTree) MoveToPosition(flatBlockID, parentID string, position int)

func (*FlatTree) MoveUp added in v0.6.0

func (tree *FlatTree) MoveUp(flatBlockID string)

func (*FlatTree) Parent added in v0.6.0

func (tree *FlatTree) Parent(flatBlockID string) *FlatBlock

func (*FlatTree) RecalculateSequences added in v0.6.0

func (tree *FlatTree) RecalculateSequences(blockID string)

func (*FlatTree) Remove added in v0.6.0

func (tree *FlatTree) Remove(flatBlockID string)

Remove removes the block with the given id

Buisiness Logic: - checks if the block exists, if not, do nothing - removes the block from the list - recalculates the sequences of the parent's children

func (*FlatTree) RemoveOrphans added in v0.15.0

func (tree *FlatTree) RemoveOrphans()

RemoveOrphans removes all orphaned blocks that have no parent

Buisiness Logic: - finds and creates a new list without orphaned blocks - non orphaned blocks are the ones that have a parent or root blocks - updates the list with the new list

Parameters: - none

Returns: - none

func (*FlatTree) ToBlocks added in v0.1.0

func (tree *FlatTree) ToBlocks() []ui.BlockInterface

func (*FlatTree) Traverse added in v0.15.0

func (tree *FlatTree) Traverse(blockID string) []FlatBlock

func (*FlatTree) Update added in v0.6.0

func (tree *FlatTree) Update(flatBlock FlatBlock)

type NewEditorOptions

type NewEditorOptions struct {
	ID               string
	Name             string
	Value            string
	HandleEndpoint   string
	BlockDefinitions []BlockDefinition
}

Jump to

Keyboard shortcuts

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