Documentation
¶
Overview ¶
Package attribution keeps track of who inserted and deleted what in a document, as yjs 14 does: maps from item IDs to attributes (an author, a time, anything of the lib0 Any domain), kept beside the document instead of inside it.
Experimental ¶
Everything in this package is Experimental. It follows yjs 14.0.0-16, a beta (yjs's npm "beta" tag; its "latest" is still 13.6.x), and ContentIds and ContentMap follow yjs's main branch, where they are not published at all. When yjs 14 is final this package changes to match it, in a minor release of ygo: the v1 compatibility promise does not cover it. The wire formats are checked byte for byte against yjs 14.0.0-16 in both directions (testdata/attribution-fixtures.json, and testdata/go-attribution-fixtures.json read by yjs).
Where it departs from yjs 14.0.0-16:
- IDs are JavaScript numbers in yjs: as ygo's update decoder, the decoders refuse a clock, a length or a range end past 2^53 and a client past 2^53-1 (UpdateIdRanges refuses such a client too), and operations on larger IDs are not yjs's (yjs rounds them).
- UpdateIdRanges refuses legacy ContentJSON and a V2 string cut inside a surrogate pair, as ygo's other update utilities do; yjs reads them.
- A "__proto__" key in a decoded object value stays a key; yjs makes it the object's prototype and drops it, so such a value fingerprints and encodes differently.
- A decoded IdMap whose attribute or name ID skips ahead is an error; yjs reads an undefined entry.
Decoding is bounded by its input (counts against the bytes left, each name hashed once). The first read of a decoded map sorts and joins its ranges as yjs does, which for many overlapping ranges with different attributes takes time and memory quadratic in their number: decode only maps from a source you trust, or bound their size.
What is here ¶
- IdSet: item IDs, as ranges of clocks per client (yjs's IdSet), with MergeIdSets, InsertIntoIdSet, DiffIdSet, IntersectIdSets and Equal.
- Attribute and IdMap: IDs with attribute lists (yjs's AttributionItem and IdMap), with IdMapFromIdSet, MergeIdMaps, InsertIntoIdMap, DiffIdMap, IntersectIdMaps and FilterIdMap. Each operation keeps yjs's quirks, which its documentation names.
- Encodings: IdSet.EncodeV1 and EncodeV2, EncodeIdMap (yjs's encodeIdMap), EncodeContentIds and EncodeContentMap, each with its decoder.
- UpdateIdRanges (yjs's readUpdateIdRanges): what an update inserts and deletes, read without a document; InsertSet and DeleteSet of a document.
- Stamp: attributes for what an update adds to a record, for a server that stamps each change with its sender (server.Options.OnChangeFrom).
- Attribute values are held as JavaScript holds them (an integer within 31 bits as an int64, any other number as a float64), so a value reads the same before and after it is encoded.
- Attribution: the JSON form a renderer gives an attributed range.
- Rendering (since 1.61.0): Render is yjs 14's getContent(am, opts) of a shared type, its content as a delta (package delta, lib0's) with each insert, delete and format marked by its attribution; managers NoAttributions, Twoset (two IdMaps), StaticDiff (two documents) and SnapshotDiff (two snapshots); DiffDocsToDelta is yjs's diffDocsToDelta, what changed between two documents. Checked against yjs 14.0.0-16's JSON on 72 editing sessions (testdata/attribution-render-fixtures.json).
A manager renders from several goroutines at once (it sorts its maps when built; do not change them while it is in use). An IdSet or IdMap is not safe for concurrent use, reads included: a read sorts it lazily. Render reads the document under its read lock and gives nested types by their JSON, computed then. Plain values (maps, slices, binary) are the document's own, as values read elsewhere in ygo are: do not change them. Subdocuments are read after the document's lock is released, each under its own lock alone, so a render never holds two documents' locks. A subdocument's roots are rendered by their content (a text when they hold strings, a map when they hold keys only, an array otherwise; an empty one left out): ygo does not record which kind an application asked a root to be, and yjs renders a root nobody asked for as nothing.
Where rendering departs from yjs 14.0.0-16:
- Where yjs throws (a map key with no piece to render: a key whose deleted value the next document collected and the previous never had, in diffDocsToDelta; a key whose current value is past a snapshot), Render leaves the key out. For the snapshot that hides the key's value at the snapshot too, since yjs's renderer looks only at a key's current item. ygo's output for these cases is pinned in testdata/attribution-render-divergent.json.
- yjs's rendering can change a document's item content (after a snapshot rendering, another rendering of the same document repeats values) and its diff manager can change its own ranges while it reads; ygo's rendering writes neither.
- A map value held as string content (which yjs's API does not write) renders its last character; yjs renders its last UTF-16 unit, half a surrogate pair for a character outside the BMP, which a Go string cannot hold.
- StaticDiff is computed once; yjs's DiffAttributionManager follows both documents and supports suggestions (accept, reject), which are not ported.
- A packed run of values renders as one retain or delete per piece in yjs, so its output depends on how yjs split its items; ygo renders from its own items, which split at the same places in every fixture (edits, deletions and attribution boundaries split both stores alike), but a store that squashed a run yjs keeps split would render it with fewer pieces.
Sender is not author ¶
An update carries items its sender did not make: a client that reconnects sends what others wrote while it was away. Stamp attributes only the IDs a record has not seen, so the record says whose change carrying each item was stamped first. For a live edit that is its author; but the server calls OnChangeFrom only after it has broadcast, stored and published an update and called OnChange, so if any of that is slow for one connection, another connection's change carrying the same items can be stamped first. Deleted items keep their IDs after garbage collection, but not their content: to show deleted text with its author later, keep the updates or use a document without GC.
Example ¶
A server stamps each change with its sender and reads back who wrote a range.
package main
import (
"encoding/json"
"fmt"
"github.com/Deln0r/ygo"
"github.com/Deln0r/ygo/attribution"
)
func main() {
alice := ygo.NewDocWithOptions(ygo.Options{ClientID: 1})
text := ygo.NewText(alice, "t")
var update []byte
alice.OnUpdate(func(u []byte, _ any) { update = u })
txn := alice.WriteTxn()
text.Insert(txn, 0, "hi")
txn.Commit()
// On the server, in OnChangeFrom: stamp what the record has not seen.
var record attribution.ContentMap
by := []*attribution.Attribute{attribution.MustAttribute("insert", "alice")}
stamp, err := attribution.Stamp(record, update, by, nil)
if err != nil {
panic(err)
}
record = attribution.MergeContentMaps(record, stamp)
// Store attribution.EncodeContentMap(record); later, read a range.
saved, _ := attribution.DecodeContentMap(attribution.EncodeContentMap(record))
for _, r := range saved.Inserts.Slice(1, 0, 2) {
out, _ := json.Marshal(attribution.Attribution(r.Attrs, false))
fmt.Printf("clocks [%d,%d): %s\n", r.Clock, r.Clock+r.Len, out)
}
}
Output: clocks [0,2): {"insert":["alice"]}
Index ¶
- Variables
- func Attribution(attrs []*Attribute, deleted bool) map[string]any
- func DiffDocsToDelta(prev, next *ygo.Doc, am Manager) (*delta.Delta, error)
- func EncodeContentIds(c ContentIds) ([]byte, error)
- func EncodeContentMap(c ContentMap) []byte
- func EncodeIdMap(m *IdMap) []byte
- func InsertIntoIdMap(dest, src *IdMap)
- func InsertIntoIdSet(dest, src *IdSet)
- func Render(d *ygo.Doc, t Shared, am Manager, opts Options) (*delta.Delta, error)
- type AttrRange
- type Attribute
- type ContentIds
- type ContentMap
- func ContentMapFromContentIds(ids ContentIds, insertAttrs, deleteAttrs []*Attribute) ContentMap
- func DecodeContentMap(data []byte) (ContentMap, error)
- func DiffContentMap(m ContentMap, exclude ContentIds) ContentMap
- func FilterContentMap(m ContentMap, keepInsert, keepDelete func([]*Attribute) bool) ContentMap
- func IntersectContentMaps(a, b ContentMap) ContentMap
- func MergeContentMaps(cs ...ContentMap) ContentMap
- func Stamp(seen ContentMap, update []byte, insertAttrs, deleteAttrs []*Attribute) (ContentMap, error)
- type IdMap
- func DecodeIdMap(data []byte) (*IdMap, error)
- func DiffIdMap(m *IdMap, exclude Ids) *IdMap
- func FilterIdMap(m *IdMap, keep func(attrs []*Attribute) bool) *IdMap
- func IdMapFromIdSet(set *IdSet, attrs []*Attribute) *IdMap
- func IntersectIdMaps(a *IdMap, b Ids) *IdMap
- func MergeIdMaps(maps ...*IdMap) *IdMap
- func NewIdMap() *IdMap
- func (m *IdMap) Add(client, clock, length uint64, attrs []*Attribute)
- func (m *IdMap) Attributes() []*Attribute
- func (m *IdMap) Clients() []uint64
- func (m *IdMap) Delete(client, clock, length uint64)
- func (m *IdMap) ForEach(fn func(client uint64, r AttrRange))
- func (m *IdMap) Has(client, clock uint64) bool
- func (m *IdMap) IsEmpty() bool
- func (m *IdMap) Ranges(client uint64) []AttrRange
- func (m *IdMap) Slice(client, clock, length uint64) []AttrRange
- type IdSet
- func DecodeIdSetV1(data []byte) (*IdSet, error)
- func DecodeIdSetV2(data []byte) (*IdSet, error)
- func DeleteSet(d *ygo.Doc) *IdSet
- func DiffIdSet(set *IdSet, exclude Ids) *IdSet
- func InsertSet(d *ygo.Doc, filterDeleted bool) *IdSet
- func IntersectIdSets(a *IdSet, b Ids) *IdSet
- func MergeIdSets(sets ...*IdSet) *IdSet
- func NewIdSet() *IdSet
- func (s *IdSet) Add(client, clock, length uint64)
- func (s *IdSet) Clients() []uint64
- func (s *IdSet) Delete(client, clock, length uint64)
- func (s *IdSet) EncodeV1() []byte
- func (s *IdSet) EncodeV2() ([]byte, error)
- func (s *IdSet) Equal(o *IdSet) bool
- func (s *IdSet) ForEach(fn func(client uint64, r Range))
- func (s *IdSet) Has(client, clock uint64) bool
- func (s *IdSet) IsEmpty() bool
- func (s *IdSet) Ranges(client uint64) []Range
- func (s *IdSet) Slice(client, clock, length uint64) []MaybeRange
- type Ids
- type Manager
- type MaybeRange
- type Options
- type Range
- type Shared
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrEmptyRange = errors.New("attribution: a zero-length range cannot be written in V2")
ErrEmptyRange is returned by the V2 encoders for a range of length zero, which the V2 format cannot write (yjs throws there). Only an IdSet decoded from V1 bytes can hold one, until it is read.
var ErrMalformed = errors.New("attribution: malformed encoding")
ErrMalformed is returned (wrapped) for bytes that do not decode as the format asked for.
Functions ¶
func Attribution ¶
Attribution is yjs 14's createAttributionFromAttributionItems: the JSON form a renderer gives an attributed range. "insert" and "delete" collect the values of the attributes with those names (with an empty "delete" list for deleted content, else an empty "insert" list, to start from), any other name gives its value (the last one of that name wins), and a name starting with "_" is left out. nil attrs (an unattributed range) give nil. yjs plans to rename these keys.
func DiffDocsToDelta ¶ added in v1.61.0
DiffDocsToDelta is yjs 14's diffDocsToDelta: what changed from prev to next, rendered with attributions. For each root type of next that holds a change, a deep delta of the changed types, retained deletes included, keyed by the root's name. A nil am renders with StaticDiff(prev, next).
func EncodeContentIds ¶
func EncodeContentIds(c ContentIds) ([]byte, error)
EncodeContentIds writes the inserts and then the deletes, each as IdSet.EncodeV2.
func EncodeContentMap ¶
func EncodeContentMap(c ContentMap) []byte
EncodeContentMap writes the inserts and then the deletes, each as EncodeIdMap with its own attribute and name tables.
func EncodeIdMap ¶
EncodeIdMap writes m as yjs 14's encodeIdMap (writeIdMap with IdSetEncoderV2).
func InsertIntoIdMap ¶
func InsertIntoIdMap(dest, src *IdMap)
InsertIntoIdMap is yjs 14's insertIntoIdMap: src's ranges added to dest with src's attribute objects as they are (not registered with dest). A client dest does not have yet takes src's ranges as held, marked sorted.
func InsertIntoIdSet ¶
func InsertIntoIdSet(dest, src *IdSet)
InsertIntoIdSet is yjs 14's insertIntoIdSet: src's ranges added to dest. As in yjs, a client dest does not have yet takes src's ranges as they are held (not sorted or merged first) and marked sorted.
func Render ¶ added in v1.61.0
Render is yjs 14's getContent(am, opts) of a shared type of d: its content as a delta, with each insert and delete marked by its attribution.
Its ItemsToRender and DeletedItems are sorted first (a read of a set sorts it lazily): a set must not be used by another goroutine meanwhile. The delta holds values, not references into the document.
Example ¶
A text rendered with who inserted and deleted what.
package main
import (
"encoding/json"
"fmt"
"github.com/Deln0r/ygo"
"github.com/Deln0r/ygo/attribution"
)
func main() {
d := ygo.NewDocWithOptions(ygo.Options{ClientID: 1, DisableGC: true})
text := ygo.NewText(d, "t")
var updates [][]byte
d.OnUpdate(func(u []byte, _ any) { updates = append(updates, append([]byte(nil), u...)) })
txn := d.WriteTxn()
_ = text.Insert(txn, 0, "hello")
txn.Commit()
txn = d.WriteTxn()
_ = text.Delete(txn, 0, 1)
txn.Commit()
// Stamp each update with its author, as a server does.
var record attribution.ContentMap
for i, u := range updates {
who := []string{"alice", "bob"}[i]
s, _ := attribution.Stamp(record, u,
[]*attribution.Attribute{attribution.MustAttribute("insert", who)},
[]*attribution.Attribute{attribution.MustAttribute("delete", who)})
record = attribution.MergeContentMaps(record, s)
}
out, _ := attribution.Render(d, text, attribution.Twoset(record.Inserts, record.Deletes), attribution.Options{})
b, _ := json.Marshal(out)
fmt.Println(string(b))
}
Output: {"type":"delta","children":[{"type":"insert","insert":"h","attribution":{"delete":["bob"]}},{"type":"insert","insert":"ello","attribution":{"insert":["alice"]}}]}
Types ¶
type AttrRange ¶
AttrRange is a run of clocks of one client with the attributes it has, yjs 14's AttrRange. In IdMap.Slice a part the map does not cover has nil Attrs, which is not the same as an empty list.
type Attribute ¶
Attribute is one fact about the items of a range, yjs 14's AttributionItem: a name (yjs's attribution projection reads "insert", "delete", "insertedAt", "deletedAt" and hides names starting with "_") and a value of the lib0 Any domain.
An Attribute is compared by pointer, as yjs compares attribution objects: an IdMap keeps one Attribute for each distinct name and value it registered (by yjs's fingerprint of the two) and hands out that one. Do not change an Attribute or its value after building it.
func MustAttribute ¶
MustAttribute is NewAttribute that panics on a value outside the Any domain.
func NewAttribute ¶
NewAttribute returns an Attribute with the given name and value. The value must be of the lib0 Any domain: nil, bool, int, int32, int64, float32, float64, string, []byte, []any, map[string]any, ygo.Undefined or ygo.BigInt, nested. Strings and keys that are not valid UTF-8 are fixed as the rest of ygo fixes them.
The value is held as JavaScript holds it, so that it reads the same before and after it is encoded: a number that is an integer within 31 bits as an int64, any other number as a float64 (a float32 widened, an integer past 31 bits rounded as JavaScript rounds it): 3.0 and 3 are the same value. A value nested deeper than 1000 levels is refused: below that depth strings could not be fixed.
func (*Attribute) Fingerprint ¶
Fingerprint is yjs 14's AttributionItem.hash before its base64: the 128-bit Rabin fingerprint (lib0's StandardIrreducible128) of the name as a lib0 string followed by the value as lib0 Any. Attributes with the same fingerprint are the same fact to an IdMap.
type ContentIds ¶
type ContentIds struct {
Inserts, Deletes *IdSet
}
ContentIds is the IDs an update or a document inserts and deletes, as yjs's main branch pairs them (ContentIds); no published yjs has it yet.
Experimental: follows yjs main's composition (see the package documentation).
func ContentIdsOf ¶
func ContentIdsOf(m ContentMap) ContentIds
ContentIdsOf returns the IDs a ContentMap covers.
func DecodeContentIds ¶
func DecodeContentIds(data []byte) (ContentIds, error)
DecodeContentIds reads what EncodeContentIds wrote.
func MergeContentIds ¶
func MergeContentIds(cs ...ContentIds) ContentIds
MergeContentIds merges the inserts and the deletes of each (MergeIdSets on each half).
func UpdateIdRanges ¶
func UpdateIdRanges(update []byte) (ContentIds, error)
UpdateIdRanges is yjs 14's readUpdateIdRanges: the IDs a V1 update inserts and deletes, read without a document. Every struct but a Skip counts as inserted, GC structs included; the deletes are the update's delete set, a client's later section replacing an earlier one.
func UpdateIdRangesV2 ¶
func UpdateIdRangesV2(update []byte) (ContentIds, error)
UpdateIdRangesV2 is UpdateIdRanges for a V2 update (readUpdateIdRangesV2).
type ContentMap ¶
type ContentMap struct {
Inserts, Deletes *IdMap
}
ContentMap is the inserts and deletes of ContentIds with their attributes (yjs main's ContentMap).
Experimental: follows yjs main's composition.
func ContentMapFromContentIds ¶
func ContentMapFromContentIds(ids ContentIds, insertAttrs, deleteAttrs []*Attribute) ContentMap
ContentMapFromContentIds is the ContentMap of ids with insertAttrs on every insert and deleteAttrs on every delete (yjs main's createContentMapFromContentIds, IdMapFromIdSet on each half).
func DecodeContentMap ¶
func DecodeContentMap(data []byte) (ContentMap, error)
DecodeContentMap reads what EncodeContentMap wrote.
func DiffContentMap ¶
func DiffContentMap(m ContentMap, exclude ContentIds) ContentMap
DiffContentMap removes from m's inserts the IDs exclude inserts and from its deletes those it deletes (DiffIdMap on each half).
func FilterContentMap ¶
func FilterContentMap(m ContentMap, keepInsert, keepDelete func([]*Attribute) bool) ContentMap
FilterContentMap keeps the ranges whose attributes the predicates keep (FilterIdMap on each half).
func IntersectContentMaps ¶
func IntersectContentMaps(a, b ContentMap) ContentMap
IntersectContentMaps keeps the inserts both insert and the deletes both delete, with a's attributes followed by b's (IntersectIdMaps on each half).
func MergeContentMaps ¶
func MergeContentMaps(cs ...ContentMap) ContentMap
MergeContentMaps merges the inserts and the deletes of each (MergeIdMaps on each half).
func Stamp ¶
func Stamp(seen ContentMap, update []byte, insertAttrs, deleteAttrs []*Attribute) (ContentMap, error)
Stamp attributes what update adds to what seen has stamped already: the IDs it inserts that seen.Inserts does not cover get insertAttrs, the IDs it deletes that seen.Deletes does not cover get deleteAttrs. Merge the result into seen (MergeContentMaps) to keep the record.
An update names the IDs it carries, not who made them: a client that reconnects sends items others made while it was away, and a replayed update sends them all again. Stamping only what is not stamped yet makes the record "first stamped", and stamping the same update twice changes nothing. Which change is stamped first is the order of the calls (see the package documentation on the server's order). An update with a client past 2^53-1 is refused (UpdateIdRanges).
type IdMap ¶
type IdMap struct {
// contains filtered or unexported fields
}
IdMap maps item IDs to the attributes they have, yjs 14's IdMap: for each client, ranges of clocks with an attribute list. Ranges may be added in any order and may overlap; a read splits overlapping ranges and joins their lists.
Experimental: follows yjs 14.0.0-16 (see the package documentation).
func DecodeIdMap ¶
DecodeIdMap reads a map EncodeIdMap or yjs 14's encodeIdMap wrote, as yjs's decodeIdMap does. Bytes after it are ignored.
func DiffIdMap ¶
DiffIdMap is yjs 14's diffIdMap: a new map with the parts of m's ranges that exclude does not cover, by ID only, sharing m's attribute registry.
func FilterIdMap ¶
FilterIdMap returns a new map with the ranges of m whose attributes keep says to keep. yjs 14.0.0-16 has no such function; reearth/ygo's FilterIDMap does the same.
func IdMapFromIdSet ¶
IdMapFromIdSet is yjs 14's createIdMapFromIdSet: every range of set with attrs, each attribute registered once (a repeated one is dropped from the list).
func IntersectIdMaps ¶
IntersectIdMaps is yjs 14's intersectSets with an IdMap first: a new map with the IDs both cover, each overlap with a's attributes followed by b's (none when b is an IdSet), so intersecting a map with itself doubles every list. As in yjs the new map registers none of them.
func MergeIdMaps ¶
MergeIdMaps is yjs 14's mergeIdMaps: a new map with every range of the maps, each attribute replaced by the one the new map registers for its fingerprint, so equal facts from different maps become one.
func (*IdMap) Add ¶
Add adds the range [clock, clock+length) of client with attrs. Each attribute becomes the one the map holds for its fingerprint; the list keeps its length and order. A zero length adds nothing.
func (*IdMap) Attributes ¶
Attributes returns the attributes the map holds, in the order it took them.
func (*IdMap) Ranges ¶
Ranges returns client's ranges, split, joined and merged, as a copy. The attribute lists are shared: do not change them.
type IdSet ¶
type IdSet struct {
// contains filtered or unexported fields
}
IdSet is a set of item IDs, yjs 14's IdSet: for each client, ranges of clocks. Ranges may be added in any order; a read sorts and merges them.
Experimental: follows yjs 14.0.0-16 (see the package documentation).
func DecodeIdSetV1 ¶
DecodeIdSetV1 reads a set EncodeV1 (or yjs's writeIdSet with IdSetEncoderV1) wrote. Bytes after it are ignored, as in yjs.
func DecodeIdSetV2 ¶
DecodeIdSetV2 reads a set EncodeV2 wrote. Bytes after it are ignored.
func DeleteSet ¶
DeleteSet is yjs 14's createDeleteSetFromStructStore: the IDs of d's deleted items and GC structs.
func DiffIdSet ¶
DiffIdSet is yjs 14's diffIdSet: a new set with the ranges of set that exclude does not hold.
func InsertSet ¶
InsertSet is yjs 14's createInsertSetFromStructStore: the IDs of d's structs, deleted items and GC structs left out when filterDeleted is set.
func IntersectIdSets ¶
IntersectIdSets is yjs 14's intersectSets with an IdSet first: a new set with the IDs both hold.
func MergeIdSets ¶
MergeIdSets is yjs 14's mergeIdSets: a new set with every range of the sets, merged when read.
func (*IdSet) EncodeV1 ¶
EncodeV1 writes the set as yjs 14's writeIdSet with IdSetEncoderV1 (the delete set of a V1 update).
func (*IdSet) EncodeV2 ¶
EncodeV2 writes the set as yjs 14's writeIdSet with IdSetEncoderV2: each clock as the difference from where the previous range ended, each length less one, counted from zero again for each client.
func (*IdSet) Equal ¶
Equal is yjs 14's equalIdSets: the same clients with the same sorted and merged ranges.
func (*IdSet) ForEach ¶
ForEach calls fn for each range, client by client in the order first added, each client's ranges sorted and merged.
func (*IdSet) Slice ¶
func (s *IdSet) Slice(client, clock, length uint64) []MaybeRange
Slice is yjs 14's IdSet.slice: the span [clock, clock+length) of client cut where the set's ranges start and end, each part marked in the set or not. A zero length gives one zero-length part not in the set.
type Ids ¶
type Ids interface {
// contains filtered or unexported methods
}
Ids is an IdSet or an IdMap, as the second operand of Diff and Intersect.
type Manager ¶ added in v1.61.0
type Manager interface {
// contains filtered or unexported methods
}
Manager is an attribution manager (yjs 14's AbstractAttributionManager): it splits an item's content into attributed pieces for the renderer.
Experimental: follows yjs 14.0.0-16.
func NoAttributions ¶ added in v1.61.0
func NoAttributions() Manager
NoAttributions is yjs's noAttributionsManager: content as it is.
func SnapshotDiff ¶ added in v1.61.0
SnapshotDiff is yjs's createAttributionManagerFromSnapshots(prev, next): content in next and not in prev is rendered as inserted, content deleted between them as deleted (with an empty attribution), content past next not at all. The document rendered must keep deleted content (garbage collection off), as snapshots require. Whether an item is deleted comes from next's delete set, not from the item.
func StaticDiff ¶ added in v1.61.0
StaticDiff attributes what next has and prev does not: the IDs next inserted and deleted since prev, each with an empty attribute list, as yjs's DiffAttributionManager computes them. It is computed once: both documents must not change while it is used (yjs's manager follows them through observers, and adds suggestion support, which this does not). Deleted content is read back from prev, so prev must still hold it (garbage collection off, or not yet collected); rendering returns an error for a deleted range prev cannot give back.
func Twoset ¶ added in v1.61.0
Twoset is yjs's TwosetAttributionManager: inserted content attributed by inserts, deleted content by deletes.
It sorts the maps' ranges now (a read sorts them lazily), so that it can then render from several goroutines at once; do not change the maps while it is in use.
type MaybeRange ¶
MaybeRange is a part of a span IdSet.Slice was asked about: in the set or not.
type Options ¶ added in v1.61.0
type Options struct {
// ItemsToRender, when set, renders only these IDs as changes; the
// rest is retained.
ItemsToRender *IdSet
// RetainInserts and RetainDeletes render attributed inserts and
// deletes as retains carrying their attribution.
RetainInserts, RetainDeletes bool
// DeletedItems is used to find a map entry's previous value.
DeletedItems *IdSet
// Deep renders nested types as deltas instead of their JSON.
Deep bool
// contains filtered or unexported fields
}
Options are yjs's getContent options.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package delta is the part of lib0's delta (lib0 0.2.119, delta/delta.js) that yjs 14 renders documents into: a tree-shaped change with a node name, attributes and children, each child an insert, retain, delete or modify with optional formatting and attribution.
|
Package delta is the part of lib0's delta (lib0 0.2.119, delta/delta.js) that yjs 14 renders documents into: a tree-shaped change with a node name, attributes and children, each child an insert, retain, delete or modify with optional formatting and attribution. |