Expose merge_text_with_cursors on API

This commit is contained in:
Andras Schmelczer 2025-04-01 20:10:03 +01:00
parent 71ccd7b61d
commit e9e2328f03
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
3 changed files with 79 additions and 5 deletions

View file

@ -8,12 +8,15 @@
//! # Modules
//!
//! - `errors`: Contains error types used in this crate.
use core::str;
use base64::{Engine as _, engine::general_purpose::STANDARD};
use cursor::OwnedTextWithCursors;
use errors::SyncLibError;
use wasm_bindgen::prelude::*;
pub mod cursor;
pub mod errors;
/// Encode binary data for easy transport over HTTP. Inverse of
@ -93,7 +96,7 @@ pub fn merge(parent: &[u8], left: &[u8], right: &[u8]) -> Vec<u8> {
}
}
/// WASM wrapper around `reconcile::reconcile` for text merging.
/// WASM wrapper around `reconcile::reconcile` for merging text.
#[wasm_bindgen(js_name = mergeText)]
#[must_use]
pub fn merge_text(parent: &str, left: &str, right: &str) -> String {
@ -102,6 +105,19 @@ pub fn merge_text(parent: &str, left: &str, right: &str) -> String {
reconcile::reconcile(parent, left, right)
}
/// WASM wrapper around `reconcile::reconcile_with_cursors` for merging text.
#[wasm_bindgen(js_name = mergeText)]
#[must_use]
pub fn merge_text_with_cursors(
parent: &str,
left: OwnedTextWithCursors,
right: OwnedTextWithCursors,
) -> OwnedTextWithCursors {
set_panic_hook();
reconcile::reconcile_with_cursors(parent, left.into(), right.into()).into()
}
/// Heuristically determine if the given data is a binary or a text file's
/// content.
#[wasm_bindgen(js_name = isBinary)]