Documentation ¶
Overview ¶
Package json provides the JSON document implementation.
Index ¶
- Constants
- Variables
- type Array
- func (p *Array) AddBool(values ...bool) *Array
- func (p *Array) AddBytes(values ...[]byte) *Array
- func (p *Array) AddDate(values ...gotime.Time) *Array
- func (p *Array) AddDouble(values ...float64) *Array
- func (p *Array) AddInteger(values ...int) *Array
- func (p *Array) AddLong(values ...int64) *Array
- func (p *Array) AddNewArray() *Array
- func (p *Array) AddNull() *Array
- func (p *Array) AddString(values ...string) *Array
- func (p *Array) Delete(idx int) crdt.Element
- func (p *Array) Get(idx int) crdt.Element
- func (p *Array) GetArray(idx int) *Array
- func (p *Array) GetCounter(idx int) *Counter
- func (p *Array) GetObject(idx int) *Object
- func (p *Array) GetText(idx int) *Text
- func (p *Array) GetTree(idx int) *Tree
- func (p *Array) InsertIntegerAfter(index int, v int) *Array
- func (p *Array) Len() int
- func (p *Array) MoveBefore(nextCreatedAt, createdAt *time.Ticket)
- type Counter
- type Object
- func (p *Object) Delete(k string) crdt.Element
- func (p *Object) GetArray(k string) *Array
- func (p *Object) GetCounter(k string) *Counter
- func (p *Object) GetObject(k string) *Object
- func (p *Object) GetText(k string) *Text
- func (p *Object) GetTree(k string) *Tree
- func (p *Object) SetBool(k string, v bool) *Object
- func (p *Object) SetBytes(k string, v []byte) *Object
- func (p *Object) SetDate(k string, v gotime.Time) *Object
- func (p *Object) SetDouble(k string, v float64) *Object
- func (p *Object) SetInteger(k string, v int) *Object
- func (p *Object) SetLong(k string, v int64) *Object
- func (p *Object) SetNewArray(k string, v ...any) *Array
- func (p *Object) SetNewCounter(k string, t crdt.CounterType, n any) *Counter
- func (p *Object) SetNewObject(k string, v ...any) *Object
- func (p *Object) SetNewText(k string) *Text
- func (p *Object) SetNewTree(k string, initialRoot ...*TreeNode) *Tree
- func (p *Object) SetNull(k string) *Object
- func (p *Object) SetString(k, v string) *Object
- type Text
- func (p *Text) CreateRange(from, to int) (*crdt.RGATreeSplitNodePos, *crdt.RGATreeSplitNodePos)
- func (p *Text) Edit(from, to int, content string, attributes ...map[string]string) *Text
- func (p *Text) Initialize(ctx *change.Context, text *crdt.Text) *Text
- func (p *Text) Style(from, to int, attributes map[string]string) *Text
- type Tree
- func (t *Tree) Edit(fromIdx, toIdx int, content *TreeNode, splitLevel int) bool
- func (t *Tree) EditBulk(fromIdx, toIdx int, contents []*TreeNode, splitLevel int) bool
- func (t *Tree) EditBulkByPath(fromPath []int, toPath []int, contents []*TreeNode, splitLevel int) bool
- func (t *Tree) EditByPath(fromPath []int, toPath []int, content *TreeNode, splitLevel int) bool
- func (t *Tree) Initialize(ctx *change.Context, tree *crdt.Tree) *Tree
- func (t *Tree) Len() int
- func (t *Tree) RemoveStyle(fromIdx, toIdx int, attributesToRemove []string) bool
- func (t *Tree) Style(fromIdx, toIdx int, attributes map[string]string) bool
- type TreeNode
Constants ¶
const (
// DefaultRootNodeType is the default type of root node.
DefaultRootNodeType = "root"
)
Variables ¶
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 ¶
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 (*Array) AddInteger ¶ added in v0.2.16
AddInteger adds the given integer at the last.
func (*Array) AddNewArray ¶ added in v0.2.16
AddNewArray adds a new array at the last.
func (*Array) GetCounter ¶ added in v0.4.14
GetCounter returns Counter of the given index.
func (*Array) InsertIntegerAfter ¶ added in v0.2.16
InsertIntegerAfter inserts the given integer after the given previous element.
func (*Array) MoveBefore ¶ added in v0.2.16
MoveBefore moves the given element to its new position before the given next element.
type Counter ¶
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.
type Object ¶
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 (*Object) GetCounter ¶ added in v0.2.16
GetCounter returns Counter of the given key.
func (*Object) SetInteger ¶ added in v0.2.16
SetInteger sets the given integer for the given key.
func (*Object) SetNewArray ¶ added in v0.2.16
SetNewArray sets a new Array for the given key.
func (*Object) SetNewCounter ¶ added in v0.2.16
SetNewCounter sets a new NewCounter for the given key.
func (*Object) SetNewObject ¶ added in v0.2.16
SetNewObject sets a new Object for the given key.
func (*Object) SetNewText ¶ added in v0.2.16
SetNewText sets a new Text for the given key.
func (*Object) SetNewTree ¶ added in v0.4.0
SetNewTree sets a new Tree for the given key.
type Text ¶
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 (*Text) CreateRange ¶
func (p *Text) CreateRange(from, to int) (*crdt.RGATreeSplitNodePos, *crdt.RGATreeSplitNodePos)
CreateRange creates a range from the given positions.
func (*Text) Initialize ¶ added in v0.4.13
Initialize initializes the Text by the given context and text.
type Tree ¶ added in v0.4.0
Tree is a CRDT-based tree structure that is used to represent the document tree of text-based editor such as ProseMirror.
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
EditByPath edits this tree with the given path and nodes.
func (*Tree) Initialize ¶ added in v0.4.13
Initialize initializes the Tree by the given context and tree.
func (*Tree) RemoveStyle ¶ added in v0.4.13
RemoveStyle 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.