slate

package
v0.5.5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 0 Imported by: 0

Documentation

Overview

Package slate provides types for working with Slate.js editor nodes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CombineProps added in v0.5.0

func CombineProps(props ...map[string]interface{}) map[string]interface{}

CombineProps combines multiple property maps into a single map

func IsElementNode

func IsElementNode(value interface{}) bool

IsElementNode checks if a value is a Slate.js element node

func IsTextNode

func IsTextNode(value interface{}) bool

IsTextNode checks if a value is a Slate.js text node

func MergeElementNodesFromMaps

func MergeElementNodesFromMaps(one, two map[string]interface{}) map[string]interface{}

MergeElementNodesFromMaps merges two Slate element nodes from maps (backward compatibility)

func MergeTextNodesFromMaps

func MergeTextNodesFromMaps(one, two map[string]interface{}) map[string]interface{}

MergeTextNodesFromMaps merges two Slate text nodes from maps (backward compatibility)

func SplitElementNodeFromMap

func SplitElementNodeFromMap(nodeMap map[string]interface{}, pos int, props map[string]interface{}) []map[string]interface{}

SplitElementNodeFromMap splits a Slate element node from map (backward compatibility)

func SplitTextNodeFromMap

func SplitTextNodeFromMap(nodeMap map[string]interface{}, pos int, props map[string]interface{}) []map[string]interface{}

SplitTextNodeFromMap splits a Slate text node from map (backward compatibility)

func WithBold added in v0.5.0

func WithBold(bold bool) map[string]interface{}

WithBold creates a property setter for bold text

func WithCode added in v0.5.0

func WithCode(code bool) map[string]interface{}

WithCode creates a property setter for code text

func WithItalic added in v0.5.0

func WithItalic(italic bool) map[string]interface{}

WithItalic creates a property setter for italic text

func WithStrikethrough added in v0.5.0

func WithStrikethrough(strikethrough bool) map[string]interface{}

WithStrikethrough creates a property setter for strikethrough text

func WithUnderline added in v0.5.0

func WithUnderline(underline bool) map[string]interface{}

WithUnderline creates a property setter for underlined text

Types

type BasicProps added in v0.5.0

type BasicProps map[string]interface{}

BasicProps represents basic Slate.js properties

type ElementNode added in v0.4.3

type ElementNode = Node

ElementNode is a type alias for better API clarity

type Node added in v0.4.3

type Node struct {
	// Text field is present only for text nodes
	Text *string `json:"text,omitempty"`
	// Children field is present only for element nodes
	Children []Node `json:"children,omitempty"`
	// Properties contains additional properties (equivalent to [key: string]: unknown)
	Properties map[string]interface{} `json:",inline"`
}

Node represents a Slate.js node that can be either a text node or an element node. It uses a union-type approach similar to TypeScript's SlateNode.

func FromMap

func FromMap(data map[string]interface{}) *Node

FromMap creates a Node from map[string]interface{} for backward compatibility

func MergeElementNodes

func MergeElementNodes(one, two *Node) *Node

MergeElementNodes merges two Slate element nodes by concatenating their children and merging properties

func MergeTextNodes

func MergeTextNodes(one, two *Node) *Node

MergeTextNodes merges two Slate text nodes by concatenating their text and merging properties

func NewBasicElementNode added in v0.5.0

func NewBasicElementNode(children []TextNode, properties BasicProps) *Node

NewBasicElementNode creates a new Slate element node with basic properties

func NewBasicTextNode added in v0.5.0

func NewBasicTextNode(text string, properties map[string]interface{}) *Node

NewBasicTextNode creates a new Slate text node with basic properties

func NewElementNode

func NewElementNode(children []Node, properties map[string]interface{}) *Node

NewElementNode creates a new Slate element node

func NewTextNode

func NewTextNode(text string, properties map[string]interface{}) *Node

NewTextNode creates a new Slate text node

func SplitElementNode

func SplitElementNode(node *Node, pos int, props map[string]interface{}) []*Node

SplitElementNode splits a Slate element node at the specified position in its children

func SplitTextNode

func SplitTextNode(node *Node, pos int, props map[string]interface{}) []*Node

SplitTextNode splits a Slate text node at the specified position

func (*Node) GetChildren added in v0.4.3

func (n *Node) GetChildren() []Node

GetChildren returns the children (empty slice if not an element node)

func (*Node) GetProperties added in v0.5.0

func (n *Node) GetProperties() map[string]interface{}

GetProperties returns all properties

func (*Node) GetProperty added in v0.4.3

func (n *Node) GetProperty(key string) interface{}

GetProperty returns a property value

func (*Node) GetText added in v0.4.3

func (n *Node) GetText() string

GetText returns the text content (empty string if not a text node)

func (*Node) IsElement added in v0.4.3

func (n *Node) IsElement() bool

IsElement returns true if this is an element node

func (*Node) IsText added in v0.4.3

func (n *Node) IsText() bool

IsText returns true if this is a text node

func (*Node) SetChildren added in v0.4.3

func (n *Node) SetChildren(children []Node)

SetChildren sets the children and converts to element node

func (*Node) SetProperty added in v0.4.3

func (n *Node) SetProperty(key string, value interface{})

SetProperty sets a property value

func (*Node) SetText added in v0.4.3

func (n *Node) SetText(text string)

SetText sets the text content and converts to text node

func (*Node) ToMap added in v0.4.3

func (n *Node) ToMap() map[string]interface{}

ToMap converts the node to map[string]interface{} for backward compatibility

type SlateElementNode

type SlateElementNode = ElementNode //nolint:revive // Backward compatibility alias

type SlateNode

type SlateNode = Node //nolint:revive // Backward compatibility alias

type SlateTextNode

type SlateTextNode = TextNode //nolint:revive // Backward compatibility alias

type TextNode added in v0.4.3

type TextNode = Node

TextNode is a type alias for better API clarity

Jump to

Keyboard shortcuts

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