slate

package
v0.4.5 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 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 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)

Types

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 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) 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