pub struct CollaborativeDocument { /* private fields */ }Expand description
A collaborative rich text document backed by CRDTs.
This is the main entry point for document editing. All operations are conflict-free and can be merged with remote changes.
Implementations§
Source§impl CollaborativeDocument
impl CollaborativeDocument
Sourcepub fn new(doc_id: &str, replica_id: &str) -> Self
pub fn new(doc_id: &str, replica_id: &str) -> Self
Create a new collaborative document.
§Arguments
doc_id- Unique identifier for this documentreplica_id- Unique identifier for this replica/user
Sourcepub fn insert(&mut self, position: usize, text: &str)
pub fn insert(&mut self, position: usize, text: &str)
Insert text at a position.
§Arguments
position- Character index to insert at (0-based)text- Text to insert
Sourcepub fn delete(&mut self, position: usize, length: usize)
pub fn delete(&mut self, position: usize, length: usize)
Delete text at a position.
§Arguments
position- Starting character index (0-based)length- Number of characters to delete
Sourcepub fn apply_bold(&mut self, start: usize, end: usize)
pub fn apply_bold(&mut self, start: usize, end: usize)
Apply bold formatting to a range.
§Arguments
start- Starting character index (inclusive)end- Ending character index (exclusive)
Sourcepub fn apply_italic(&mut self, start: usize, end: usize)
pub fn apply_italic(&mut self, start: usize, end: usize)
Apply italic formatting to a range.
Sourcepub fn apply_underline(&mut self, start: usize, end: usize)
pub fn apply_underline(&mut self, start: usize, end: usize)
Apply underline formatting to a range.
Sourcepub fn apply_strikethrough(&mut self, start: usize, end: usize)
pub fn apply_strikethrough(&mut self, start: usize, end: usize)
Apply strikethrough formatting to a range.
Sourcepub fn apply_code(&mut self, start: usize, end: usize)
pub fn apply_code(&mut self, start: usize, end: usize)
Apply inline code formatting to a range.
Sourcepub fn apply_link(&mut self, start: usize, end: usize, url: &str)
pub fn apply_link(&mut self, start: usize, end: usize, url: &str)
Apply a link to a range.
§Arguments
start- Starting character index (inclusive)end- Ending character index (exclusive)url- The URL to link to
Sourcepub fn apply_highlight(&mut self, start: usize, end: usize, color: &str)
pub fn apply_highlight(&mut self, start: usize, end: usize, color: &str)
Apply a highlight color to a range.
§Arguments
start- Starting character index (inclusive)end- Ending character index (exclusive)color- CSS color string (e.g., “#FFEAA7”)
Sourcepub fn apply_comment(
&mut self,
start: usize,
end: usize,
author: &str,
content: &str,
)
pub fn apply_comment( &mut self, start: usize, end: usize, author: &str, content: &str, )
Apply a comment annotation to a range.
§Arguments
start- Starting character index (inclusive)end- Ending character index (exclusive)author- Comment author name/idcontent- Comment body
Sourcepub fn apply_custom_mark(
&mut self,
start: usize,
end: usize,
name: &str,
value: &str,
)
pub fn apply_custom_mark( &mut self, start: usize, end: usize, name: &str, value: &str, )
Apply a custom formatting mark to a range.
§Arguments
start- Starting character index (inclusive)end- Ending character index (exclusive)name- Custom mark namevalue- Custom mark value
Sourcepub fn version(&self) -> u64
pub fn version(&self) -> u64
Get the current version number.
This increments with each local operation and can be used to track changes for sync purposes.
Sourcepub fn replica_id(&self) -> String
pub fn replica_id(&self) -> String
Get the replica ID.
Sourcepub fn serialize(&self) -> Result<String, JsValue>
pub fn serialize(&self) -> Result<String, JsValue>
Serialize the document state for sync.
Returns a base64-encoded binary string that can be sent to other replicas. Binary format is more efficient and handles complex key types.
Sourcepub fn merge(&mut self, remote_state: &str) -> Result<(), JsValue>
pub fn merge(&mut self, remote_state: &str) -> Result<(), JsValue>
Merge remote state into this document.
This is the core CRDT operation - merging is commutative, associative, and idempotent, so the order of merges doesn’t matter.
§Arguments
remote_state- JSON string from another replica’sserialize()
Trait Implementations§
Source§impl From<CollaborativeDocument> for JsValue
impl From<CollaborativeDocument> for JsValue
Source§fn from(value: CollaborativeDocument) -> Self
fn from(value: CollaborativeDocument) -> Self
Source§impl FromWasmAbi for CollaborativeDocument
impl FromWasmAbi for CollaborativeDocument
Source§impl IntoWasmAbi for CollaborativeDocument
impl IntoWasmAbi for CollaborativeDocument
Source§impl RefFromWasmAbi for CollaborativeDocument
impl RefFromWasmAbi for CollaborativeDocument
Source§type Anchor = RcRef<CollaborativeDocument>
type Anchor = RcRef<CollaborativeDocument>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.Source§impl VectorFromWasmAbi for CollaborativeDocument
impl VectorFromWasmAbi for CollaborativeDocument
type Abi = <Box<[JsValue]> as FromWasmAbi>::Abi
unsafe fn vector_from_abi(js: Self::Abi) -> Box<[CollaborativeDocument]>
Source§impl VectorIntoWasmAbi for CollaborativeDocument
impl VectorIntoWasmAbi for CollaborativeDocument
type Abi = <Box<[JsValue]> as IntoWasmAbi>::Abi
fn vector_into_abi(vector: Box<[CollaborativeDocument]>) -> Self::Abi
Source§impl WasmDescribeVector for CollaborativeDocument
impl WasmDescribeVector for CollaborativeDocument
impl SupportsConstructor for CollaborativeDocument
impl SupportsInstanceProperty for CollaborativeDocument
impl SupportsStaticProperty for CollaborativeDocument
Auto Trait Implementations§
impl Freeze for CollaborativeDocument
impl RefUnwindSafe for CollaborativeDocument
impl Send for CollaborativeDocument
impl Sync for CollaborativeDocument
impl Unpin for CollaborativeDocument
impl UnsafeUnpin for CollaborativeDocument
impl UnwindSafe for CollaborativeDocument
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.