json

package
v0.4.28 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2024 License: Apache-2.0 Imports: 10 Imported by: 1

Documentation

Overview

Package json provides the JSON document implementation.

Index

Constants

View Source
const (
	// DefaultRootNodeType is the default type of root node.
	DefaultRootNodeType = "root"
)

Variables

View Source
var (
	// ErrEmptyTextNode is returned when there's empty string value in text node
	ErrEmptyTextNode = errors.New("text node cannot have empty value")
	// ErrMixedNodeType is returned when there're element node and text node inside contents array
	ErrMixedNodeType = errors.New("element node and text node cannot be passed together")
	// ErrIndexBoundary is returned when from index is bigger than to index
	ErrIndexBoundary = errors.New("from should be less than or equal to to")
	// ErrPathLenDiff is returned when two paths have different length
	ErrPathLenDiff = errors.New("both paths should have same length")
	// ErrEmptyPath is returned when there's empty path
	ErrEmptyPath = errors.New("path should not be empty")
)

Functions

This section is empty.

Types

type Array

type Array struct {
	*crdt.Array
	// contains filtered or unexported fields
}

Array represents an array in the document. As a proxy for the CRDT array, it is used when the user manipulate the array from the outside.

func NewArray

func NewArray(ctx *change.Context, array *crdt.Array) *Array

NewArray creates a new instance of Array.

func (*Array) AddBool added in v0.2.16

func (p *Array) AddBool(values ...bool) *Array

AddBool adds the given boolean at the last.

func (*Array) AddBytes added in v0.2.16

func (p *Array) AddBytes(values ...[]byte) *Array

AddBytes adds the given bytes at the last.

func (*Array) AddDate added in v0.2.16

func (p *Array) AddDate(values ...gotime.Time) *Array

AddDate adds the given date at the last.

func (*Array) AddDouble added in v0.2.16

func (p *Array) AddDouble(values ...float64) *Array

AddDouble adds the given double at the last.

func (*Array) AddInteger added in v0.2.16

func (p *Array) AddInteger(values ...int) *Array

AddInteger adds the given integer at the last.

func (*Array) AddLong added in v0.2.16

func (p *Array) AddLong(values ...int64) *Array

AddLong adds the given long at the last.

func (*Array) AddNewArray added in v0.2.16

func (p *Array) AddNewArray() *Array

AddNewArray adds a new array at the last.

func (*Array) AddNull added in v0.2.16

func (p *Array) AddNull() *Array

AddNull adds the null at the last.

func (*Array) AddString added in v0.2.16

func (p *Array) AddString(values ...string) *Array

AddString adds the given string at the last.

func (*Array) Delete

func (p *Array) Delete(idx int) crdt.Element

Delete deletes the element of the given index.

func (*Array) Get

func (p *Array) Get(idx int) crdt.Element

Get element of the given index.

func (*Array) GetArray added in v0.4.14

func (p *Array) GetArray(idx int) *Array

GetArray returns Array of the given index.

func (*Array) GetCounter added in v0.4.14

func (p *Array) GetCounter(idx int) *Counter

GetCounter returns Counter of the given index.

func (*Array) GetObject added in v0.4.14

func (p *Array) GetObject(idx int) *Object

GetObject returns Object of the given index.

func (*Array) GetText added in v0.4.14

func (p *Array) GetText(idx int) *Text

GetText returns Text of the given index.

func (*Array) GetTree added in v0.4.14

func (p *Array) GetTree(idx int) *Tree

GetTree returns Tree of the given index.

func (*Array) InsertIntegerAfter added in v0.2.16

func (p *Array) InsertIntegerAfter(index int, v int) *Array

InsertIntegerAfter inserts the given integer after the given previous element.

func (*Array) Len

func (p *Array) Len() int

Len returns length of this Array.

func (*Array) MoveBefore added in v0.2.16

func (p *Array) MoveBefore(nextCreatedAt, createdAt *time.Ticket)

MoveBefore moves the given element to its new position before the given next element.

type Counter

type Counter struct {
	*crdt.Counter
	// contains filtered or unexported fields
}

Counter represents a counter in the document. As a proxy for the CRDT counter, it is used when the user manipulates the counter from the outside.

func NewCounter

func NewCounter(n interface{}, t crdt.CounterType) *Counter

NewCounter creates a new instance of Counter.

func (*Counter) Increase

func (p *Counter) Increase(v interface{}) *Counter

Increase adds an increase operations. Only numeric types are allowed as operand values, excluding uint64 and uintptr.

func (*Counter) Initialize added in v0.4.13

func (p *Counter) Initialize(ctx *change.Context, counter *crdt.Counter) *Counter

Initialize initializes the Counter by the given context and counter.

type Object

type Object struct {
	*crdt.Object
	// contains filtered or unexported fields
}

Object represents an object in the document. As a proxy for the CRDT object, it is used when the user manipulates the object from the outside.

func NewObject

func NewObject(ctx *change.Context, root *crdt.Object) *Object

NewObject creates a new instance of Object.

func (*Object) Delete

func (p *Object) Delete(k string) crdt.Element

Delete deletes the value of the given key.

func (*Object) GetArray added in v0.2.16

func (p *Object) GetArray(k string) *Array

GetArray returns Array of the given key.

func (*Object) GetCounter added in v0.2.16

func (p *Object) GetCounter(k string) *Counter

GetCounter returns Counter of the given key.

func (*Object) GetObject added in v0.2.16

func (p *Object) GetObject(k string) *Object

GetObject returns Object of the given key.

func (*Object) GetText added in v0.2.16

func (p *Object) GetText(k string) *Text

GetText returns Text of the given key.

func (*Object) GetTree added in v0.4.0

func (p *Object) GetTree(k string) *Tree

GetTree returns Tree of the given key.

func (*Object) SetBool added in v0.2.16

func (p *Object) SetBool(k string, v bool) *Object

SetBool sets the given boolean for the given key.

func (*Object) SetBytes added in v0.2.16

func (p *Object) SetBytes(k string, v []byte) *Object

SetBytes sets the given bytes for the given key.

func (*Object) SetDate added in v0.2.16

func (p *Object) SetDate(k string, v gotime.Time) *Object

SetDate sets the given date for the given key.

func (*Object) SetDouble added in v0.2.16

func (p *Object) SetDouble(k string, v float64) *Object

SetDouble sets the given double for the given key.

func (*Object) SetInteger added in v0.2.16

func (p *Object) SetInteger(k string, v int) *Object

SetInteger sets the given integer for the given key.

func (*Object) SetLong added in v0.2.16

func (p *Object) SetLong(k string, v int64) *Object

SetLong sets the given long for the given key.

func (*Object) SetNewArray added in v0.2.16

func (p *Object) SetNewArray(k string, v ...any) *Array

SetNewArray sets a new Array for the given key.

func (*Object) SetNewCounter added in v0.2.16

func (p *Object) SetNewCounter(k string, t crdt.CounterType, n any) *Counter

SetNewCounter sets a new NewCounter for the given key.

func (*Object) SetNewObject added in v0.2.16

func (p *Object) SetNewObject(k string, v ...any) *Object

SetNewObject sets a new Object for the given key.

func (*Object) SetNewText added in v0.2.16

func (p *Object) SetNewText(k string) *Text

SetNewText sets a new Text for the given key.

func (*Object) SetNewTree added in v0.4.0

func (p *Object) SetNewTree(k string, initialRoot ...*TreeNode) *Tree

SetNewTree sets a new Tree for the given key.

func (*Object) SetNull added in v0.2.16

func (p *Object) SetNull(k string) *Object

SetNull sets the null for the given key.

func (*Object) SetString added in v0.2.16

func (p *Object) SetString(k, v string) *Object

SetString sets the given string for the given key.

type Text

type Text struct {
	*crdt.Text
	// contains filtered or unexported fields
}

Text represents a text in the document. As a proxy for the CRDT text, it is used when the user manipulates the rich text from the outside.

func NewText

func NewText() *Text

NewText creates a new instance of Text.

func (*Text) CreateRange

func (p *Text) CreateRange(from, to int) (*crdt.RGATreeSplitNodePos, *crdt.RGATreeSplitNodePos)

CreateRange creates a range from the given positions.

func (*Text) Edit

func (p *Text) Edit(
	from,
	to int,
	content string,
	attributes ...map[string]string,
) *Text

Edit edits the given range with the given content and attributes.

func (*Text) Initialize added in v0.4.13

func (p *Text) Initialize(ctx *change.Context, text *crdt.Text) *Text

Initialize initializes the Text by the given context and text.

func (*Text) Style added in v0.3.0

func (p *Text) Style(from, to int, attributes map[string]string) *Text

Style applies the style of the given range.

type Tree added in v0.4.0

type Tree struct {
	*crdt.Tree
	// contains filtered or unexported fields
}

Tree is a CRDT-based tree structure that is used to represent the document tree of text-based editor such as ProseMirror.

func NewTree added in v0.4.0

func NewTree(root ...*TreeNode) *Tree

NewTree creates a new instance of Tree.

func (*Tree) Edit added in v0.4.0

func (t *Tree) Edit(fromIdx, toIdx int, content *TreeNode, splitLevel int) bool

Edit edits this tree with the given node.

func (*Tree) EditBulk added in v0.4.10

func (t *Tree) EditBulk(fromIdx, toIdx int, contents []*TreeNode, splitLevel int) bool

EditBulk edits this tree with the given nodes.

func (*Tree) EditBulkByPath added in v0.4.10

func (t *Tree) EditBulkByPath(fromPath []int, toPath []int, contents []*TreeNode, splitLevel int) bool

EditBulkByPath edits this tree with the given path and nodes.

func (*Tree) EditByPath added in v0.4.0

func (t *Tree) EditByPath(fromPath []int, toPath []int, content *TreeNode, splitLevel int) bool

EditByPath edits this tree with the given path and nodes.

func (*Tree) Initialize added in v0.4.13

func (t *Tree) Initialize(ctx *change.Context, tree *crdt.Tree) *Tree

Initialize initializes the Tree by the given context and tree.

func (*Tree) Len added in v0.4.0

func (t *Tree) Len() int

Len returns the length of this tree.

func (*Tree) RemoveStyle added in v0.4.13

func (t *Tree) RemoveStyle(fromIdx, toIdx int, attributesToRemove []string) bool

RemoveStyle sets the attributes to the elements of the given range.

func (*Tree) Style added in v0.4.2

func (t *Tree) Style(fromIdx, toIdx int, attributes map[string]string) bool

Style sets the attributes to the elements of the given range.

type TreeNode added in v0.4.0

type TreeNode struct {
	// Type is the type of this node. It is used to distinguish between text
	// nodes and element nodes.
	Type string

	// Children is the children of this node. It is used to represent the
	// descendants of this node. If this node is a text node, it is nil.
	Children []TreeNode

	// Value is the value of text node. If this node is an element node, it is
	// empty string.
	Value string

	// Attributes is the attributes of this node.
	Attributes map[string]string
}

TreeNode is a node of Tree.

Jump to

Keyboard shortcuts

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