Documentation
¶
Overview ¶
Package gomobile is the bytes-in/bytes-out subset of the ygo API designed to survive `gomobile bind`. The full public API at github.com/Deln0r/ygo exposes Go types that gomobile cannot bind (the `any` interface, callbacks, generic maps), so iOS / Android consumers import this package instead and exchange state with their UI layer via byte arrays.
What gomobile filters out and we work around:
- Function parameters of `any` / `map[K]V` / `chan T` / `func(...)` are silently skipped from the generated binding. ygo.Map.Set takes `value any`; gomobile produces a Map type with no Set.
- Slices of non-byte types (e.g. `[]any`, `[]string`) are skipped. ygo.Array.ToSlice() returns `[]any`.
- Generics break the bind step entirely.
- Callback registration (Sub, OnUpdate, OnChange) is skipped.
What survives:
- Opaque struct pointers (Doc, this package's wrapper types).
- Methods that take/return `string`, `int*`/`uint*`, `bool`, `float*`, `[]byte`, and `error`.
- Bytes-in/bytes-out wire-format operations: this package exposes those plus a tiny Doc wrapper.
The package exposes two API levels:
App level (types.go, client.go): Text (insert / delete / cursors), Map (string keys and values), UndoManager, and Client — a complete background sync provider (WebSocket, handshake, reconnect) so a Swift / Kotlin app only renders UI and edits the Doc. Reads run under internal read transactions, safe against the background client.
Wire level (this file): bytes-in/bytes-out y-protocols flow — encode local state to bytes, apply remote bytes, bring your own transport.
gomobile bind verification: actual `gomobile bind -target=ios` or `-target=android` requires the corresponding toolchain (Xcode / Android NDK) and is not run in CI. The package compiles under pure Go to guarantee no inadvertent CGO leak via dependencies.
Index ¶
- type Array
- func (a *Array) DeleteAt(index, length int) error
- func (a *Array) GetArray(index int) *Array
- func (a *Array) GetJSON(index int) []byte
- func (a *Array) GetMap(index int) *Map
- func (a *Array) GetText(index int) *Text
- func (a *Array) InsertArray(index int) *Array
- func (a *Array) InsertJSON(index int, valueJSON []byte) error
- func (a *Array) InsertMap(index int) *Map
- func (a *Array) InsertText(index int) *Text
- func (a *Array) Length() int
- func (a *Array) ObserveChanges(l ArrayChangeListener)
- func (a *Array) PushJSON(valueJSON []byte) error
- func (a *Array) ToJSON() []byte
- type ArrayChangeListener
- type Awareness
- type Client
- func (c *Client) ClientID() uint64
- func (c *Client) Close() error
- func (c *Client) Connect() error
- func (c *Client) EnableOfflineStore(dbPath string)
- func (c *Client) ObservePresence(l PresenceListener)
- func (c *Client) PresenceStates() []byte
- func (c *Client) RemoveAwarenessState()
- func (c *Client) SetAwarenessState(jsonState []byte)
- func (c *Client) SetListener(l Listener)
- func (c *Client) Synced() bool
- type Doc
- func (d *Doc) ApplyUpdate(rawBytes []byte) error
- func (d *Doc) Array(name string) *Array
- func (d *Doc) ClientID() uint64
- func (d *Doc) EncodeDiff(remoteSV []byte) ([]byte, error)
- func (d *Doc) EncodeStateAsUpdate() []byte
- func (d *Doc) EncodeStateVector() []byte
- func (d *Doc) HasPending() bool
- func (d *Doc) Map(name string) *Map
- func (d *Doc) MissingSV() []byte
- func (d *Doc) NewMapUndoManager(name string) *UndoManager
- func (d *Doc) NewTextUndoManager(name string) *UndoManager
- func (d *Doc) Text(name string) *Text
- func (d *Doc) XmlFragment(name string) *XmlFragment
- type Listener
- type Map
- func (m *Map) Clear()
- func (m *Map) DeleteKey(key string)
- func (m *Map) GetArray(key string) *Array
- func (m *Map) GetJSON(key string) []byte
- func (m *Map) GetMap(key string) *Map
- func (m *Map) GetString(key string) string
- func (m *Map) GetText(key string) *Text
- func (m *Map) Has(key string) bool
- func (m *Map) KeysJSON() []byte
- func (m *Map) Len() int
- func (m *Map) ObserveChanges(l MapChangeListener)
- func (m *Map) SetArray(key string) *Array
- func (m *Map) SetJSON(key string, valueJSON []byte) error
- func (m *Map) SetMap(key string) *Map
- func (m *Map) SetString(key, value string)
- func (m *Map) SetText(key string) *Text
- type MapChangeListener
- type PresenceListener
- type Text
- func (t *Text) ApplyDelta(deltaJSON []byte) error
- func (t *Text) DeleteAt(index, length int) error
- func (t *Text) EncodeCursor(index, assoc int) ([]byte, error)
- func (t *Text) Format(index, length int, attributesJSON []byte) error
- func (t *Text) InsertAt(index int, s string) error
- func (t *Text) InsertEmbed(index int, embedJSON []byte) error
- func (t *Text) InsertWithAttributes(index int, s string, attributesJSON []byte) error
- func (t *Text) Length() int
- func (t *Text) ObserveChanges(l TextChangeListener)
- func (t *Text) ResolveCursor(encoded []byte) int
- func (t *Text) String() string
- type TextChangeListener
- type UndoManager
- type XmlElement
- func (e *XmlElement) AttributesJSON() []byte
- func (e *XmlElement) DeleteAt(index, length int)
- func (e *XmlElement) GetAttribute(name string) string
- func (e *XmlElement) GetElement(index int) *XmlElement
- func (e *XmlElement) GetText(index int) *XmlText
- func (e *XmlElement) HasAttribute(name string) bool
- func (e *XmlElement) InsertElement(index int, nodeName string) *XmlElement
- func (e *XmlElement) InsertText(index int) *XmlText
- func (e *XmlElement) Length() int
- func (e *XmlElement) NodeName() string
- func (e *XmlElement) RemoveAttribute(name string)
- func (e *XmlElement) SetAttribute(name, value string)
- func (e *XmlElement) ToString() string
- type XmlFragment
- func (f *XmlFragment) DeleteAt(index, length int)
- func (f *XmlFragment) GetElement(index int) *XmlElement
- func (f *XmlFragment) GetText(index int) *XmlText
- func (f *XmlFragment) InsertElement(index int, nodeName string) *XmlElement
- func (f *XmlFragment) InsertText(index int) *XmlText
- func (f *XmlFragment) Length() int
- func (f *XmlFragment) ToString() string
- type XmlText
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Array ¶ added in v1.8.0
type Array struct {
// contains filtered or unexported fields
}
Array is the bindable shared Array (ordered sequence) CRDT. Elements are scalar JSON values or nested Text / Map / Array types.
func (*Array) GetArray ¶ added in v1.8.0
GetArray returns the nested Array at index, or nil if not an Array.
func (*Array) GetJSON ¶ added in v1.8.0
GetJSON returns the element at index as JSON, or "null" when the index is out of range or holds a nested type (use GetMap / GetArray / GetText for those).
func (*Array) GetText ¶ added in v1.8.0
GetText returns the nested Text at index, or nil if the element is not a Text.
func (*Array) InsertArray ¶ added in v1.8.0
InsertArray inserts a new nested Array at index and returns it.
func (*Array) InsertJSON ¶ added in v1.8.0
InsertJSON inserts a scalar JSON value at the given index.
func (*Array) InsertMap ¶ added in v1.8.0
InsertMap inserts a new nested Map at index and returns it.
func (*Array) InsertText ¶ added in v1.8.0
InsertText inserts a new nested Text at index and returns it.
func (*Array) ObserveChanges ¶ added in v1.8.0
func (a *Array) ObserveChanges(l ArrayChangeListener)
ObserveChanges registers a listener that fires after every transaction changing this array, delivering the change as a delta. Replaces any previously registered listener on this array.
type ArrayChangeListener ¶ added in v1.8.0
type ArrayChangeListener interface {
OnArrayChange(deltaJSON []byte)
}
ArrayChangeListener receives array change deltas. deltaJSON is a Quill-style delta whose inserts are arrays of values, the shape a collaborative list view applies directly:
[{"retain":2},{"insert":[42,true]},{"delete":1}]
type Awareness ¶
type Awareness struct {
// contains filtered or unexported fields
}
Awareness is the gomobile-bindable handle for the y-protocols Awareness presence layer. Independent of any Doc; the local clientID is passed at construction. Embedders typically pair an Awareness with a Doc and use d.ClientID() as the awareness clientID.
All state is exchanged as raw JSON bytes. Mobile UIs that need typed access (cursor positions, user names) JSON-parse on the caller side after pulling via States.
func NewAwareness ¶
NewAwareness returns a fresh Awareness for the given clientID.
func (*Awareness) Apply ¶
Apply integrates a wire-encoded awareness update. The origin string is forwarded to subscribers — but since callback registration is not gomobile-bindable, mobile callers typically pass an empty string.
Returns an error only for malformed wire bytes.
func (*Awareness) EncodeAll ¶
Encode returns the V1 wire bytes for the awareness states of the given clientIDs. Pass an empty clientIDs slice to encode every known client.
Note: gomobile-bound callers cannot pass `[]uint64` directly (slices of non-byte types are skipped). Use EncodeAll for the common "send everything" case; for per-client encoding adopters must wrap one ID at a time or extend this package.
func (*Awareness) LocalState ¶
LocalState returns the local client's current state JSON bytes, or nil if the state has not been set / has been removed.
func (*Awareness) RemoveLocalState ¶
func (a *Awareness) RemoveLocalState()
RemoveLocalState marks the local client offline. The wire- format representation is an entry with JSON "null"; the local entry is kept (with state cleared) so the clock survives subsequent revival races.
func (*Awareness) SetLocalState ¶
SetLocalState replaces the local client's awareness state with the given raw JSON bytes. Nil clears the state (equivalent to RemoveLocalState). The clock bumps on every call — even no-op equal sets — per the y-protocols 15-second heartbeat invariant.
type Client ¶ added in v1.2.0
type Client struct {
// contains filtered or unexported fields
}
Client is the gomobile-bindable sync provider: a live WebSocket session syncing one Doc with a yserve / Hocuspocus / y-websocket server. Construct with NewClient, optionally SetListener, start with Connect, stop with Close. The native app edits the Doc through Text / Map wrappers; sync happens in the background.
func NewClient ¶ added in v1.2.0
NewClient prepares a sync client for the document. url is the server base ("wss://collab.example.com"); docName addresses the document on it.
func (*Client) ClientID ¶ added in v1.6.0
ClientID returns this client's awareness/document clientID, the key of its own entry in the presence snapshot. Use it to skip yourself when rendering peer cursors.
func (*Client) Close ¶ added in v1.2.0
Close stops the connection loop and releases the listener hooks. Safe to call more than once.
func (*Client) Connect ¶ added in v1.2.0
Connect starts the background connection loop (handshake, update relay, reconnect with exponential backoff). Returns an error when already connected or the configuration is invalid.
func (*Client) EnableOfflineStore ¶ added in v1.3.0
EnableOfflineStore makes the client offline-first, persisting the document to a pure-Go on-device SQLite database at dbPath. On the next Connect the document loads from that file (usable with no network), every change is persisted, and edits made offline sync up when a connection is next established. Call before Connect; a no-op after. Pass the app's document path, e.g. FileManager applicationSupportDirectory on iOS.
func (*Client) ObservePresence ¶ added in v1.6.0
func (c *Client) ObservePresence(l PresenceListener)
ObservePresence registers a listener fired whenever the room's presence changes — a peer's cursor or identity updates, or a peer joins or leaves. It delivers the full current snapshot each time, ready to render. Replaces any previously registered presence listener. May be called before or after Connect; pass nil to stop observing.
Publish your own presence with SetAwarenessState, typically a small JSON object carrying your name and an encoded cursor:
cur, _ := text.EncodeCursor(index, 0)
state, _ := json.Marshal(map[string]any{
"name": "ian",
"cursor": base64.StdEncoding.EncodeToString(cur),
})
client.SetAwarenessState(state)
A peer reading that entry decodes the cursor bytes and calls text.ResolveCursor to map it to its own local index.
func (*Client) PresenceStates ¶ added in v1.6.0
PresenceStates returns the current presence snapshot — the same JSON shape ObservePresence delivers — or "{}" when not connected. Use it for the initial render before the first change arrives.
func (*Client) RemoveAwarenessState ¶ added in v1.2.0
func (c *Client) RemoveAwarenessState()
RemoveAwarenessState clears the local awareness entry (peers see this client leave).
func (*Client) SetAwarenessState ¶ added in v1.2.0
SetAwarenessState sets and broadcasts the local awareness state (JSON bytes, e.g. {"name":"ian","cursor":"<base64 rpos>"}).
func (*Client) SetListener ¶ added in v1.2.0
SetListener registers the event listener. Call before Connect; calls after Connect are ignored.
type Doc ¶
type Doc struct {
// contains filtered or unexported fields
}
Doc is the gomobile-bindable opaque handle for a ygo CRDT replica. Construct via NewDoc / NewDocWithClientID. All shared-type operations route through wire-format bytes — push updates in via ApplyUpdate, pull state out via EncodeStateAsUpdate.
Concurrency: safe for use from multiple goroutines / gomobile-bound callers. Each method opens its own transaction internally; gomobile callers do not see Transaction or TransactionMut directly.
func NewDocWithClientID ¶
NewDocWithClientID returns a fresh Doc with the given ClientID. Use this when the calling application wants deterministic per-device IDs (typical mobile pattern: derive from a stable device identifier).
func (*Doc) ApplyUpdate ¶
ApplyUpdate decodes raw V1 wire bytes and integrates them into the doc. Items whose dependencies the local store has not yet seen queue in the per-doc pending buffer and integrate automatically on subsequent ApplyUpdate calls that satisfy them.
Returns an error only for malformed wire bytes; missing- dependency cases queue silently and are queryable via HasPending / MissingSV.
func (*Doc) Array ¶ added in v1.8.0
Array returns the shared array registered under name, creating the root type on first access.
func (*Doc) EncodeDiff ¶
EncodeDiff returns the wire-encoded V1 update carrying blocks this doc has that the remote (per remoteSV bytes) does not. A nil remoteSV is treated as the empty state vector — emit everything.
remoteSV is the V1 wire-encoded form of the remote's state vector (same shape EncodeStateVector produces). Pass straight from a sync-protocol message; the function decodes internally.
func (*Doc) EncodeStateAsUpdate ¶
EncodeStateAsUpdate returns wire-encoded V1 bytes carrying the doc's full state. Apply to a peer doc to bring it up to speed. Interoperates with JS Yjs Y.encodeStateAsUpdate output.
func (*Doc) EncodeStateVector ¶
EncodeStateVector returns wire-encoded V1 state vector — what the y-sync protocol's SyncStep1 sends. The peer replies with the diff.
func (*Doc) HasPending ¶
HasPending reports whether the doc has any queued items awaiting causal dependencies (items that arrived via ApplyUpdate before their Origin / RightOrigin / Parent ID was visible locally).
func (*Doc) Map ¶ added in v1.2.0
Map returns the shared map registered under name, creating the root type on first access.
func (*Doc) MissingSV ¶
MissingSV returns the wire-encoded V1 state vector identifying the clocks this doc needs to receive in order to drain its pending buffer. Send to a peer as a re-fetch request.
An empty return ([]byte{0x00}, the encoded-empty-SV) means the pending buffer is empty.
func (*Doc) NewMapUndoManager ¶ added in v1.2.0
func (d *Doc) NewMapUndoManager(name string) *UndoManager
NewMapUndoManager returns an UndoManager watching the shared map registered under name.
func (*Doc) NewTextUndoManager ¶ added in v1.2.0
func (d *Doc) NewTextUndoManager(name string) *UndoManager
NewTextUndoManager returns an UndoManager watching the shared text registered under name.
func (*Doc) Text ¶ added in v1.2.0
Text returns the shared text registered under name, creating the root type on first access.
func (*Doc) XmlFragment ¶ added in v1.8.0
func (d *Doc) XmlFragment(name string) *XmlFragment
XmlFragment returns the shared XML fragment registered under name, creating the root type on first access.
type Listener ¶ added in v1.2.0
type Listener interface {
// OnSynced fires on synced-state transitions: true after each
// completed handshake, false on every disconnect.
OnSynced(synced bool)
// OnDocChanged fires after any transaction commits on the local
// doc, local or remote — the "refresh your views" signal.
OnDocChanged()
// OnError reports non-fatal connection errors (the client keeps
// reconnecting).
OnError(message string)
}
Listener receives connection and document events from a Client. Implement it in Swift / Kotlin and pass to Client.SetListener; all methods are called from background goroutines, so dispatch to the main thread before touching UI.
type Map ¶ added in v1.2.0
type Map struct {
// contains filtered or unexported fields
}
Map is the gomobile-bindable handle for a shared map restricted to string keys and string values (the subset that crosses the bridge without an `any` in sight). Other value kinds written by JS peers read back as empty strings; use the bytes-level Doc API for those.
func (*Map) GetArray ¶ added in v1.8.0
GetArray returns the nested Array at key, or nil if not an Array.
func (*Map) GetJSON ¶ added in v1.8.0
GetJSON returns the value at key as JSON, or "null" when the key is absent or holds a nested type (use GetMap / GetArray / GetText).
func (*Map) GetMap ¶ added in v1.8.0
GetMap returns the nested Map at key, or nil if the value is not a Map.
func (*Map) GetString ¶ added in v1.2.0
GetString returns the string value under key, or "" when the key is absent or holds a non-string value. Safe against a concurrent background Client: the read runs under a read transaction.
func (*Map) KeysJSON ¶ added in v1.8.0
KeysJSON returns the map's live keys as a JSON array of strings.
func (*Map) ObserveChanges ¶ added in v1.2.0
func (m *Map) ObserveChanges(l MapChangeListener)
ObserveChanges registers a listener that fires after every transaction changing this map, delivering the changed keys. Replaces any previously registered listener on this map.
func (*Map) SetJSON ¶ added in v1.8.0
SetJSON sets key to a scalar JSON value (string, number, bool, null, or a plain array / object) — the typed-value counterpart to SetString. Syncs byte-compatibly with JS Yjs.
type MapChangeListener ¶ added in v1.2.0
type MapChangeListener interface {
OnMapChange(keysJSON []byte)
}
MapChangeListener receives map change summaries. keysJSON maps each changed key to {"action":"add|update|delete","oldValue":...}:
{"title":{"action":"update","oldValue":"draft"}}
type PresenceListener ¶ added in v1.6.0
type PresenceListener interface {
OnPresenceChange(statesJSON []byte)
}
PresenceListener receives the room's presence (awareness) snapshot whenever any peer's ephemeral state changes — a cursor moves, a user joins, or a user leaves. statesJSON is a JSON object mapping each online peer's clientID (as a decimal string) to that peer's raw state JSON:
{"42":{"name":"ian","cursor":"BASE64..."},"77":{"name":"sam"}}
Render every collaborator's cursor and identity from it. Your own entry is included; filter it with Client.ClientID() if you only want peers. Called from a background goroutine; dispatch to the main thread before touching UI and do not call back into the client synchronously.
type Text ¶ added in v1.2.0
type Text struct {
// contains filtered or unexported fields
}
Text is the gomobile-bindable handle for a shared text type: the editable surface a native note-taking / editor UI binds to. All indices and lengths are UTF-16 code units, matching JS Yjs (and NSString / Java String length semantics, which is what makes the mobile bridge clean).
func (*Text) ApplyDelta ¶ added in v1.7.0
ApplyDelta applies a Quill-style delta to the text in one transaction — the write side of the rich-text round trip, symmetric with ObserveChanges. A native editor (Quill / ProseMirror / a custom view) produces a delta on user input and hands it straight here:
[{"retain":3},{"insert":"hi","attributes":{"bold":true}},{"delete":2}]
An insert value is either a string (text) or a JSON object (an embed, e.g. an image). Indices and retain / delete counts are UTF-16 units, matching ObserveChanges and JS Yjs.
func (*Text) EncodeCursor ¶ added in v1.2.0
EncodeCursor anchors the given index as a relative position and returns its binary form (byte-compatible with Y.encodeRelativePosition), suitable for sharing with JS peers via awareness. assoc >= 0 sticks to the character after the position, assoc < 0 to the character before it.
func (*Text) Format ¶ added in v1.7.0
Format applies attributes (e.g. {"bold":true}) to length UTF-16 units starting at index — the action a toolbar fires when the user bolds a selection. A nil-valued attribute ({"bold":null}) clears that key.
func (*Text) InsertEmbed ¶ added in v1.7.0
InsertEmbed inserts a single embedded value (an image, mention, or other non-text node) at the UTF-16 index. embedJSON is any JSON value, typically an object: {"image":"https://..."}.
func (*Text) InsertWithAttributes ¶ added in v1.7.0
InsertWithAttributes inserts s at the UTF-16 index with formatting already applied (attributesJSON is an object like {"italic":true}).
func (*Text) ObserveChanges ¶ added in v1.2.0
func (t *Text) ObserveChanges(l TextChangeListener)
ObserveChanges registers a listener that fires after every transaction changing this text, delivering the change as a Quill delta. This is the fine-grained signal a native editor needs to update only what changed, instead of re-rendering the whole document. Replaces any previously registered listener on this text.
func (*Text) ResolveCursor ¶ added in v1.2.0
ResolveCursor resolves an encoded relative position back to a current index in this text. Returns -1 when the anchor is unknown to this replica, garbage-collected, or belongs to another type.
type TextChangeListener ¶ added in v1.2.0
type TextChangeListener interface {
OnTextChange(deltaJSON []byte)
}
TextChangeListener receives text change deltas. Implement it in Swift / Kotlin and pass to Text.ObserveChanges. deltaJSON is a Quill-style delta array, the same shape Quill / ProseMirror / a JS Yjs binding consumes, so a native editor can apply it directly:
[{"retain":3},{"insert":"hi","attributes":{"bold":true}},{"delete":2}]
Called from a background goroutine while the document lock is held; dispatch to the main thread before touching UI and do not call back into the document synchronously.
type UndoManager ¶ added in v1.2.0
type UndoManager struct {
// contains filtered or unexported fields
}
UndoManager is the gomobile-bindable scoped undo/redo handle. Construct via Doc.NewTextUndoManager / Doc.NewMapUndoManager.
func (*UndoManager) CanRedo ¶ added in v1.2.0
func (u *UndoManager) CanRedo() bool
CanRedo reports whether the redo stack is non-empty.
func (*UndoManager) CanUndo ¶ added in v1.2.0
func (u *UndoManager) CanUndo() bool
CanUndo reports whether the undo stack is non-empty.
func (*UndoManager) Close ¶ added in v1.2.0
func (u *UndoManager) Close()
Close detaches the UndoManager from the document.
func (*UndoManager) Redo ¶ added in v1.2.0
func (u *UndoManager) Redo() bool
Redo re-applies the most recently undone change. Returns false when there is nothing to redo.
func (*UndoManager) StopCapturing ¶ added in v1.2.0
func (u *UndoManager) StopCapturing()
StopCapturing forces the next edit to start a new undo group.
func (*UndoManager) Undo ¶ added in v1.2.0
func (u *UndoManager) Undo() bool
Undo reverts the most recent captured local change. Returns false when there is nothing to undo.
type XmlElement ¶ added in v1.8.0
type XmlElement struct {
// contains filtered or unexported fields
}
XmlElement is a named node with string attributes and ordered children (elements or text).
func (*XmlElement) AttributesJSON ¶ added in v1.8.0
func (e *XmlElement) AttributesJSON() []byte
AttributesJSON returns all attributes as a JSON object of strings.
func (*XmlElement) DeleteAt ¶ added in v1.8.0
func (e *XmlElement) DeleteAt(index, length int)
DeleteAt removes length children starting at index.
func (*XmlElement) GetAttribute ¶ added in v1.8.0
func (e *XmlElement) GetAttribute(name string) string
GetAttribute returns the attribute value, or "" when absent (use HasAttribute to distinguish an empty value from an absent one).
func (*XmlElement) GetElement ¶ added in v1.8.0
func (e *XmlElement) GetElement(index int) *XmlElement
GetElement returns the child element at index, or nil if not an element.
func (*XmlElement) GetText ¶ added in v1.8.0
func (e *XmlElement) GetText(index int) *XmlText
GetText returns the child text node at index, or nil if not text.
func (*XmlElement) HasAttribute ¶ added in v1.8.0
func (e *XmlElement) HasAttribute(name string) bool
HasAttribute reports whether name is set.
func (*XmlElement) InsertElement ¶ added in v1.8.0
func (e *XmlElement) InsertElement(index int, nodeName string) *XmlElement
InsertElement inserts a child <nodeName> element at index.
func (*XmlElement) InsertText ¶ added in v1.8.0
func (e *XmlElement) InsertText(index int) *XmlText
InsertText inserts a child text node at index.
func (*XmlElement) Length ¶ added in v1.8.0
func (e *XmlElement) Length() int
Length returns the number of children.
func (*XmlElement) NodeName ¶ added in v1.8.0
func (e *XmlElement) NodeName() string
NodeName returns the element's tag name.
func (*XmlElement) RemoveAttribute ¶ added in v1.8.0
func (e *XmlElement) RemoveAttribute(name string)
RemoveAttribute deletes the attribute.
func (*XmlElement) SetAttribute ¶ added in v1.8.0
func (e *XmlElement) SetAttribute(name, value string)
SetAttribute sets a string attribute.
func (*XmlElement) ToString ¶ added in v1.8.0
func (e *XmlElement) ToString() string
ToString renders the element and its subtree as HTML-like markup.
type XmlFragment ¶ added in v1.8.0
type XmlFragment struct {
// contains filtered or unexported fields
}
XmlFragment is the bindable root of an XML document tree — the shape a ProseMirror / Tiptap model maps onto. It holds an ordered list of XmlElement and XmlText children.
func (*XmlFragment) DeleteAt ¶ added in v1.8.0
func (f *XmlFragment) DeleteAt(index, length int)
DeleteAt removes length children starting at index.
func (*XmlFragment) GetElement ¶ added in v1.8.0
func (f *XmlFragment) GetElement(index int) *XmlElement
GetElement returns the child element at index, or nil if it is not an element.
func (*XmlFragment) GetText ¶ added in v1.8.0
func (f *XmlFragment) GetText(index int) *XmlText
GetText returns the child text node at index, or nil if not text.
func (*XmlFragment) InsertElement ¶ added in v1.8.0
func (f *XmlFragment) InsertElement(index int, nodeName string) *XmlElement
InsertElement inserts a new <nodeName> element at index and returns it.
func (*XmlFragment) InsertText ¶ added in v1.8.0
func (f *XmlFragment) InsertText(index int) *XmlText
InsertText inserts a new text node at index and returns it.
func (*XmlFragment) Length ¶ added in v1.8.0
func (f *XmlFragment) Length() int
Length returns the number of children.
func (*XmlFragment) ToString ¶ added in v1.8.0
func (f *XmlFragment) ToString() string
ToString renders the fragment and its subtree as HTML-like markup.