y-rb 0.5.4-x86_64-darwin → 0.5.6-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/yrb/Cargo.toml +6 -7
- data/ext/yrb/src/lib.rs +17 -1
- data/ext/yrb/src/utils.rs +1 -2
- data/ext/yrb/src/yany.rs +5 -5
- data/ext/yrb/src/yarray.rs +2 -3
- data/ext/yrb/src/yattrs.rs +10 -19
- data/ext/yrb/src/yawareness.rs +2 -2
- data/ext/yrb/src/ydiff.rs +19 -0
- data/ext/yrb/src/ydoc.rs +2 -2
- data/ext/yrb/src/ymap.rs +1 -2
- data/ext/yrb/src/ytext.rs +42 -6
- data/ext/yrb/src/yvalue.rs +16 -12
- data/ext/yrb/src/yxml_element.rs +1 -1
- data/ext/yrb/src/yxml_text.rs +1 -2
- data/lib/3.0/yrb.bundle +0 -0
- data/lib/3.1/yrb.bundle +0 -0
- data/lib/3.2/yrb.bundle +0 -0
- data/lib/3.3/yrb.bundle +0 -0
- data/lib/y/array.rb +2 -2
- data/lib/y/diff.rb +38 -0
- data/lib/y/text.rb +15 -0
- data/lib/y/version.rb +1 -1
- data/lib/y-rb.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2e6e419e417b41fedb558e545952b194c693d830aac086e33e84a23b11965a3a
|
4
|
+
data.tar.gz: bfd8ee09e32b42c2006069be6e3511394aa3d9c02c1e8f0a10f1afc86e55f334
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fdd1f1c7f294c4a7c0ca6294ecb6d0dde890349c3f10a8692d6e83074ee43edddf0caca35aea07a219ac714ee353203227812270bdc29e08eddcede2ef09196d
|
7
|
+
data.tar.gz: 1062ef2c900b2e1bb431f254d7421917d28cbc6b8523cba0b89d32d5ed1ca0b62a6f7705634ed1e4e10896ffe143a47f62aa91e96989b7a5cfc826c6e75b2869
|
data/ext/yrb/Cargo.toml
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
[package]
|
2
2
|
name = "yrb"
|
3
|
-
version = "0.5.
|
3
|
+
version = "0.5.6"
|
4
4
|
authors = ["Hannes Moser <box@hannesmoser.at>"]
|
5
5
|
edition = "2021"
|
6
6
|
homepage = "https://github.com/y-crdt/yrb"
|
7
7
|
repository = "https://github.com/y-crdt/yrb"
|
8
8
|
|
9
9
|
[dependencies]
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
rb-sys = "0.9.86"
|
10
|
+
magnus = "=0.6.2"
|
11
|
+
thiserror = "1.0.57"
|
12
|
+
yrs = "=0.17.4"
|
13
|
+
y-sync = "=0.4.0"
|
14
|
+
rb-sys = "0.9.90"
|
16
15
|
|
17
16
|
[dev-dependencies]
|
18
17
|
magnus = { version = "0.6.2", features = ["embed"] }
|
data/ext/yrb/src/lib.rs
CHANGED
@@ -2,6 +2,7 @@ extern crate core;
|
|
2
2
|
|
3
3
|
use crate::yarray::YArray;
|
4
4
|
use crate::yawareness::{YAwareness, YAwarenessEvent};
|
5
|
+
use crate::ydiff::YDiff;
|
5
6
|
use crate::ydoc::YDoc;
|
6
7
|
use crate::ymap::YMap;
|
7
8
|
use crate::ytext::YText;
|
@@ -9,6 +10,7 @@ use crate::ytransaction::YTransaction;
|
|
9
10
|
use crate::yxml_element::YXmlElement;
|
10
11
|
use crate::yxml_fragment::YXmlFragment;
|
11
12
|
use crate::yxml_text::YXmlText;
|
13
|
+
|
12
14
|
use magnus::{class, define_module, function, method, Error, Module, Object};
|
13
15
|
|
14
16
|
mod utils;
|
@@ -16,6 +18,7 @@ mod yany;
|
|
16
18
|
mod yarray;
|
17
19
|
mod yattrs;
|
18
20
|
mod yawareness;
|
21
|
+
mod ydiff;
|
19
22
|
mod ydoc;
|
20
23
|
mod ymap;
|
21
24
|
mod ytext;
|
@@ -224,6 +227,9 @@ fn init() -> Result<(), Error> {
|
|
224
227
|
.define_class("Text", class::object())
|
225
228
|
.expect("cannot define class Y::Text");
|
226
229
|
|
230
|
+
ytext
|
231
|
+
.define_private_method("ytext_diff", method!(YText::ytext_diff, 1))
|
232
|
+
.expect("cannot define private method: ytext_diff");
|
227
233
|
ytext
|
228
234
|
.define_private_method("ytext_format", method!(YText::ytext_format, 4))
|
229
235
|
.expect("cannot define private method: ytext_format");
|
@@ -618,7 +624,7 @@ fn init() -> Result<(), Error> {
|
|
618
624
|
|
619
625
|
let yawareness_event = module
|
620
626
|
.define_class("AwarenessEvent", class::object())
|
621
|
-
.expect("cannot define class Y
|
627
|
+
.expect("cannot define class Y::AwarenessEvent");
|
622
628
|
yawareness_event
|
623
629
|
.define_method("added", method!(YAwarenessEvent::added, 0))
|
624
630
|
.expect("cannot define private method: added");
|
@@ -629,5 +635,15 @@ fn init() -> Result<(), Error> {
|
|
629
635
|
.define_method("removed", method!(YAwarenessEvent::removed, 0))
|
630
636
|
.expect("cannot define private method: removed");
|
631
637
|
|
638
|
+
let ydiff = module
|
639
|
+
.define_class("Diff", class::object())
|
640
|
+
.expect("cannot define class Y::Diff");
|
641
|
+
ydiff
|
642
|
+
.define_private_method("ydiff_insert", method!(YDiff::ydiff_insert, 0))
|
643
|
+
.expect("cannot define private method: insert");
|
644
|
+
ydiff
|
645
|
+
.define_private_method("ydiff_attrs", method!(YDiff::ydiff_attrs, 0))
|
646
|
+
.expect("cannot define private method: attrs");
|
647
|
+
|
632
648
|
Ok(())
|
633
649
|
}
|
data/ext/yrb/src/utils.rs
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
use crate::yvalue::YValue;
|
2
|
-
use lib0::any::Any;
|
3
2
|
use magnus::r_hash::ForEach::Continue;
|
4
3
|
use magnus::{exception, Error, RArray, RHash, RString, Symbol, Value};
|
5
4
|
use std::sync::Arc;
|
6
5
|
use yrs::types::{Attrs, Value as YrsValue};
|
7
|
-
use yrs::{Array, Map, TransactionMut};
|
6
|
+
use yrs::{Any, Array, Map, TransactionMut};
|
8
7
|
|
9
8
|
#[derive(Debug, Clone)]
|
10
9
|
pub(crate) struct TypeConversionError;
|
data/ext/yrb/src/yany.rs
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
use lib0::any::Any;
|
2
1
|
use magnus::r_string::IntoRString;
|
3
2
|
use magnus::value::ReprValue;
|
4
3
|
use magnus::{value, IntoValue, RArray, RHash, RString, Value};
|
5
4
|
use std::borrow::Borrow;
|
6
5
|
use std::ops::{Deref, DerefMut};
|
6
|
+
use yrs::Any;
|
7
7
|
|
8
8
|
pub(crate) struct YAny(pub(crate) Any);
|
9
9
|
|
@@ -35,11 +35,11 @@ impl TryInto<Value> for YAny {
|
|
35
35
|
Ok(hash.as_value())
|
36
36
|
}
|
37
37
|
Any::Null => Ok(value::qnil().as_value()),
|
38
|
-
Any::Undefined => Ok(
|
38
|
+
Any::Undefined => Ok(value::qnil().as_value()),
|
39
39
|
Any::Bool(v) => Ok(v.into_value()),
|
40
|
-
Any::Number(v) => Ok(
|
41
|
-
Any::BigInt(v) => Ok(
|
42
|
-
Any::String(v) => Ok(
|
40
|
+
Any::Number(v) => Ok(v.into_value()),
|
41
|
+
Any::BigInt(v) => Ok(v.into_value()),
|
42
|
+
Any::String(v) => Ok(v.into_r_string().as_value()),
|
43
43
|
Any::Buffer(v) => Ok(RString::from_slice(v.borrow()).as_value()),
|
44
44
|
};
|
45
45
|
}
|
data/ext/yrb/src/yarray.rs
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
use crate::utils::convert_yvalue_to_ruby_value;
|
2
2
|
use crate::ytransaction::YTransaction;
|
3
3
|
use crate::yvalue::YValue;
|
4
|
-
use lib0::any::Any;
|
5
4
|
use magnus::block::Proc;
|
6
5
|
use magnus::value::Qnil;
|
7
6
|
use magnus::{Error, IntoValue, RArray, RHash, Symbol, Value};
|
8
7
|
use std::cell::RefCell;
|
9
8
|
use yrs::types::Change;
|
10
|
-
use yrs::{Array, ArrayRef, Observable};
|
9
|
+
use yrs::{Any, Array, ArrayRef, Observable};
|
11
10
|
|
12
11
|
#[magnus::wrap(class = "Y::Array")]
|
13
12
|
pub(crate) struct YArray(pub(crate) RefCell<ArrayRef>);
|
@@ -175,7 +174,7 @@ impl YArray {
|
|
175
174
|
let r_arr = RArray::new();
|
176
175
|
for item in arr.iter(tx) {
|
177
176
|
let r_val = YValue::from(item);
|
178
|
-
let r_val = r_val.0.borrow()
|
177
|
+
let r_val = *r_val.0.borrow();
|
179
178
|
r_arr.push(r_val).expect("cannot push item event to array");
|
180
179
|
}
|
181
180
|
r_arr
|
data/ext/yrb/src/yattrs.rs
CHANGED
@@ -1,16 +1,21 @@
|
|
1
1
|
use crate::yvalue::YValue;
|
2
|
-
use lib0::any::Any;
|
3
2
|
use magnus::r_hash::ForEach::Continue;
|
4
3
|
use magnus::{RHash, Value};
|
5
|
-
use std::
|
4
|
+
use std::cell::RefCell;
|
6
5
|
use std::sync::Arc;
|
7
6
|
use yrs::types::Attrs;
|
7
|
+
use yrs::Any;
|
8
8
|
|
9
|
-
|
9
|
+
#[magnus::wrap(class = "Y::Attrs")]
|
10
|
+
#[derive(Clone)]
|
11
|
+
pub(crate) struct YAttrs(pub(crate) RefCell<Attrs>);
|
12
|
+
|
13
|
+
/// SAFETY: This is safe because we only access this data when the GVL is held.
|
14
|
+
unsafe impl Send for YAttrs {}
|
10
15
|
|
11
16
|
impl From<Attrs> for YAttrs {
|
12
17
|
fn from(value: Attrs) -> Self {
|
13
|
-
YAttrs(value)
|
18
|
+
YAttrs(RefCell::from(value))
|
14
19
|
}
|
15
20
|
}
|
16
21
|
|
@@ -29,20 +34,6 @@ impl From<RHash> for YAttrs {
|
|
29
34
|
})
|
30
35
|
.expect("cannot iterate attributes hash");
|
31
36
|
|
32
|
-
YAttrs(attrs)
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
impl Deref for YAttrs {
|
37
|
-
type Target = Attrs;
|
38
|
-
|
39
|
-
fn deref(&self) -> &Self::Target {
|
40
|
-
&self.0
|
41
|
-
}
|
42
|
-
}
|
43
|
-
|
44
|
-
impl DerefMut for YAttrs {
|
45
|
-
fn deref_mut(&mut self) -> &mut Self::Target {
|
46
|
-
&mut self.0
|
37
|
+
YAttrs(RefCell::from(attrs))
|
47
38
|
}
|
48
39
|
}
|
data/ext/yrb/src/yawareness.rs
CHANGED
@@ -17,10 +17,10 @@ unsafe impl Send for YAwareness {}
|
|
17
17
|
impl YAwareness {
|
18
18
|
pub(crate) fn yawareness_new() -> Self {
|
19
19
|
let mut options = Options {
|
20
|
-
offset_kind: OffsetKind::
|
20
|
+
offset_kind: OffsetKind::Utf16,
|
21
21
|
..Default::default()
|
22
22
|
};
|
23
|
-
options.offset_kind = OffsetKind::
|
23
|
+
options.offset_kind = OffsetKind::Utf16;
|
24
24
|
|
25
25
|
let doc = Doc::with_options(options);
|
26
26
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
use magnus::{IntoValue, RHash, Value};
|
2
|
+
|
3
|
+
unsafe impl Send for YDiff {}
|
4
|
+
|
5
|
+
#[magnus::wrap(class = "Y::Diff")]
|
6
|
+
pub(crate) struct YDiff {
|
7
|
+
pub(crate) ydiff_insert: Value,
|
8
|
+
pub(crate) ydiff_attrs: Option<RHash>,
|
9
|
+
}
|
10
|
+
|
11
|
+
impl YDiff {
|
12
|
+
pub(crate) fn ydiff_insert(&self) -> Value {
|
13
|
+
self.ydiff_insert
|
14
|
+
}
|
15
|
+
|
16
|
+
pub(crate) fn ydiff_attrs(&self) -> Option<Value> {
|
17
|
+
self.ydiff_attrs.as_ref().map(|value| value.into_value())
|
18
|
+
}
|
19
|
+
}
|
data/ext/yrb/src/ydoc.rs
CHANGED
@@ -25,7 +25,7 @@ impl YDoc {
|
|
25
25
|
let value = client_id.first().unwrap();
|
26
26
|
options.client_id = Integer::from_value(*value).unwrap().to_u64().unwrap();
|
27
27
|
}
|
28
|
-
options.offset_kind = OffsetKind::
|
28
|
+
options.offset_kind = OffsetKind::Utf16;
|
29
29
|
|
30
30
|
let doc = Doc::with_options(options);
|
31
31
|
Self(RefCell::new(doc))
|
@@ -89,7 +89,7 @@ impl YDoc {
|
|
89
89
|
YXmlText::from(xml_text_ref)
|
90
90
|
}
|
91
91
|
|
92
|
-
pub(crate) fn ydoc_transact
|
92
|
+
pub(crate) fn ydoc_transact(&self) -> YTransaction {
|
93
93
|
let doc = self.0.borrow();
|
94
94
|
let transaction = doc.transact_mut();
|
95
95
|
YTransaction::from(transaction)
|
data/ext/yrb/src/ymap.rs
CHANGED
@@ -1,12 +1,11 @@
|
|
1
1
|
use crate::utils::{convert_yvalue_to_ruby_value, indifferent_hash_key};
|
2
2
|
use crate::yvalue::YValue;
|
3
3
|
use crate::YTransaction;
|
4
|
-
use lib0::any::Any;
|
5
4
|
use magnus::block::Proc;
|
6
5
|
use magnus::{exception, Error, RArray, RHash, Symbol, Value};
|
7
6
|
use std::cell::RefCell;
|
8
7
|
use yrs::types::{EntryChange, Value as YrsValue};
|
9
|
-
use yrs::{Map, MapRef, Observable};
|
8
|
+
use yrs::{Any, Map, MapRef, Observable};
|
10
9
|
|
11
10
|
#[magnus::wrap(class = "Y::Map")]
|
12
11
|
pub(crate) struct YMap(pub(crate) RefCell<MapRef>);
|
data/ext/yrb/src/ytext.rs
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
use crate::yattrs::YAttrs;
|
2
|
+
use crate::ydiff::YDiff;
|
2
3
|
use crate::yvalue::YValue;
|
3
4
|
use crate::YTransaction;
|
4
|
-
use lib0::any::Any;
|
5
5
|
use magnus::block::Proc;
|
6
6
|
use magnus::value::Qnil;
|
7
|
-
use magnus::
|
7
|
+
use magnus::RArray;
|
8
|
+
pub(crate) use magnus::{Error, IntoValue, RHash, Symbol, Value};
|
8
9
|
use std::cell::RefCell;
|
10
|
+
use yrs::types::text::YChange;
|
9
11
|
use yrs::types::Delta;
|
10
|
-
use yrs::{GetString, Observable, Text, TextRef};
|
12
|
+
use yrs::{Any, GetString, Observable, Text, TextRef};
|
11
13
|
|
12
14
|
#[magnus::wrap(class = "Y::Text")]
|
13
15
|
pub(crate) struct YText(pub(crate) RefCell<TextRef>);
|
@@ -16,6 +18,38 @@ pub(crate) struct YText(pub(crate) RefCell<TextRef>);
|
|
16
18
|
unsafe impl Send for YText {}
|
17
19
|
|
18
20
|
impl YText {
|
21
|
+
pub(crate) fn ytext_diff(&self, transaction: &YTransaction) -> RArray {
|
22
|
+
let tx = transaction.transaction();
|
23
|
+
let tx = tx.as_ref().unwrap();
|
24
|
+
|
25
|
+
RArray::from_iter(
|
26
|
+
self.0
|
27
|
+
.borrow()
|
28
|
+
.diff(tx, YChange::identity)
|
29
|
+
.iter()
|
30
|
+
.map(move |diff| {
|
31
|
+
let yvalue = YValue::from(diff.insert.clone());
|
32
|
+
let insert = yvalue.0.into_inner();
|
33
|
+
let attributes = diff.attributes.as_ref().map_or_else(
|
34
|
+
|| None,
|
35
|
+
|boxed_attrs| {
|
36
|
+
let attributes = RHash::new();
|
37
|
+
for (key, value) in boxed_attrs.iter() {
|
38
|
+
let key = key.to_string();
|
39
|
+
let value = YValue::from(value.clone()).0.into_inner();
|
40
|
+
attributes.aset(key, value).expect("cannot add value");
|
41
|
+
}
|
42
|
+
Some(attributes)
|
43
|
+
},
|
44
|
+
);
|
45
|
+
YDiff {
|
46
|
+
ydiff_insert: insert,
|
47
|
+
ydiff_attrs: attributes,
|
48
|
+
}
|
49
|
+
.into_value()
|
50
|
+
}),
|
51
|
+
)
|
52
|
+
}
|
19
53
|
pub(crate) fn ytext_format(
|
20
54
|
&self,
|
21
55
|
transaction: &YTransaction,
|
@@ -28,7 +62,9 @@ impl YText {
|
|
28
62
|
|
29
63
|
let a = YAttrs::from(attrs);
|
30
64
|
|
31
|
-
self.0
|
65
|
+
self.0
|
66
|
+
.borrow_mut()
|
67
|
+
.format(tx, index, length, a.0.into_inner())
|
32
68
|
}
|
33
69
|
pub(crate) fn ytext_insert(&self, transaction: &YTransaction, index: u32, chunk: String) {
|
34
70
|
let mut tx = transaction.transaction();
|
@@ -67,7 +103,7 @@ impl YText {
|
|
67
103
|
|
68
104
|
self.0
|
69
105
|
.borrow_mut()
|
70
|
-
.insert_embed_with_attributes(tx, index, avalue, a.0);
|
106
|
+
.insert_embed_with_attributes(tx, index, avalue, a.0.into_inner());
|
71
107
|
}
|
72
108
|
pub(crate) fn ytext_insert_with_attributes(
|
73
109
|
&self,
|
@@ -83,7 +119,7 @@ impl YText {
|
|
83
119
|
|
84
120
|
self.0
|
85
121
|
.borrow_mut()
|
86
|
-
.insert_with_attributes(tx, index, chunk.as_str(), a.0)
|
122
|
+
.insert_with_attributes(tx, index, chunk.as_str(), a.0.into_inner())
|
87
123
|
}
|
88
124
|
pub(crate) fn ytext_length(&self, transaction: &YTransaction) -> u32 {
|
89
125
|
let tx = transaction.transaction();
|
data/ext/yrb/src/yvalue.rs
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
use crate::{YText, YXmlElement, YXmlText};
|
2
|
-
use lib0::any::Any;
|
3
2
|
use magnus::r_hash::ForEach::Continue;
|
4
3
|
use magnus::value::{Qnil, ReprValue};
|
5
4
|
use magnus::{class, value, Float, Integer, IntoValue, RArray, RHash, RString, Symbol, Value};
|
6
5
|
use std::cell::RefCell;
|
7
6
|
use std::collections::HashMap;
|
7
|
+
use std::sync::Arc;
|
8
8
|
use yrs::types::Value as YrsValue;
|
9
9
|
use yrs::{
|
10
|
-
Array, Map, TextRef as YrsText, Transact, XmlElementRef as YrsXmlElement,
|
10
|
+
Any, Array, Map, TextRef as YrsText, Transact, XmlElementRef as YrsXmlElement,
|
11
11
|
XmlTextRef as YrsXmlText,
|
12
12
|
};
|
13
13
|
|
@@ -67,6 +67,12 @@ impl From<RHash> for YValue {
|
|
67
67
|
}
|
68
68
|
}
|
69
69
|
|
70
|
+
impl From<Vec<u8>> for YValue {
|
71
|
+
fn from(value: Vec<u8>) -> Self {
|
72
|
+
YValue(RefCell::from(value.into_value()))
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
70
76
|
impl From<YrsText> for YValue {
|
71
77
|
fn from(value: YrsText) -> Self {
|
72
78
|
YValue(RefCell::from(YText(RefCell::from(value)).into_value()))
|
@@ -113,13 +119,13 @@ impl From<Any> for YValue {
|
|
113
119
|
Any::Bool(v) => YValue::from(v),
|
114
120
|
Any::Number(v) => YValue::from(v),
|
115
121
|
Any::BigInt(v) => YValue::from(v),
|
116
|
-
Any::String(v) => YValue::from(v.
|
117
|
-
Any::Buffer(v) => YValue::from(v.
|
122
|
+
Any::String(v) => YValue::from(v.to_string()),
|
123
|
+
Any::Buffer(v) => YValue::from(v.to_vec()),
|
118
124
|
Any::Array(v) => {
|
119
125
|
let arr = RArray::new();
|
120
126
|
for item in v.iter() {
|
121
127
|
let val = YValue::from(item.clone());
|
122
|
-
let val = val.0.borrow()
|
128
|
+
let val = *val.0.borrow();
|
123
129
|
arr.push(val).expect("cannot push item event to array");
|
124
130
|
}
|
125
131
|
YValue::from(arr)
|
@@ -146,7 +152,6 @@ impl From<YrsValue> for YValue {
|
|
146
152
|
YrsValue::YXmlElement(el) => YValue::from(el),
|
147
153
|
YrsValue::YXmlText(text) => YValue::from(text),
|
148
154
|
YrsValue::YArray(val) => {
|
149
|
-
print!("try to acquire transaction");
|
150
155
|
let tx = val.transact();
|
151
156
|
let arr = RArray::new();
|
152
157
|
for item in val.iter(&tx) {
|
@@ -157,7 +162,6 @@ impl From<YrsValue> for YValue {
|
|
157
162
|
YValue::from(arr)
|
158
163
|
}
|
159
164
|
YrsValue::YMap(val) => {
|
160
|
-
print!("try to acquire transaction");
|
161
165
|
let tx = val.transact();
|
162
166
|
let iter = val.iter(&tx).map(|(key, val)| {
|
163
167
|
let val = YValue::from(val);
|
@@ -184,14 +188,14 @@ impl From<YValue> for Any {
|
|
184
188
|
Any::BigInt(i.to_i64().unwrap())
|
185
189
|
} else if value.is_kind_of(class::symbol()) {
|
186
190
|
let s = Symbol::from_value(value).unwrap();
|
187
|
-
Any::String(
|
191
|
+
Any::String(Arc::from(s.name().unwrap()))
|
188
192
|
} else if value.is_kind_of(class::true_class()) {
|
189
193
|
Any::Bool(true)
|
190
194
|
} else if value.is_kind_of(class::false_class()) {
|
191
195
|
Any::Bool(false)
|
192
196
|
} else if value.is_kind_of(class::string()) {
|
193
197
|
let s = RString::from_value(value).unwrap();
|
194
|
-
unsafe { Any::String(
|
198
|
+
unsafe { Any::String(Arc::from(s.as_str().unwrap().to_string())) }
|
195
199
|
} else if value.is_kind_of(class::array()) {
|
196
200
|
let arr = RArray::from_value(value).unwrap();
|
197
201
|
let items = arr
|
@@ -201,7 +205,7 @@ impl From<YValue> for Any {
|
|
201
205
|
Any::from(yvalue)
|
202
206
|
})
|
203
207
|
.collect::<Vec<Any>>();
|
204
|
-
Any::Array(
|
208
|
+
Any::Array(Arc::from(items))
|
205
209
|
} else if value.is_kind_of(class::hash()) {
|
206
210
|
let map = RHash::from_value(value).unwrap();
|
207
211
|
let mut m: HashMap<String, Any> = HashMap::new();
|
@@ -221,7 +225,7 @@ impl From<YValue> for Any {
|
|
221
225
|
})
|
222
226
|
.expect("cannot map key/value pair");
|
223
227
|
|
224
|
-
Any::Map(
|
228
|
+
Any::Map(Arc::from(m))
|
225
229
|
} else {
|
226
230
|
Any::Undefined
|
227
231
|
}
|
@@ -238,8 +242,8 @@ impl Into<Value> for YValue {
|
|
238
242
|
#[cfg(test)]
|
239
243
|
mod tests {
|
240
244
|
use crate::yvalue::YValue;
|
241
|
-
use lib0::any::Any;
|
242
245
|
use magnus::value::ReprValue;
|
246
|
+
use yrs::Any;
|
243
247
|
|
244
248
|
#[test]
|
245
249
|
fn convert_any_to_yvalue() {
|
data/ext/yrb/src/yxml_element.rs
CHANGED
@@ -116,7 +116,7 @@ impl YXmlElement {
|
|
116
116
|
let values = RArray::new();
|
117
117
|
for value in v.iter() {
|
118
118
|
let value = YValue::from(value.clone());
|
119
|
-
let value = value.0.borrow()
|
119
|
+
let value = *value.0.borrow();
|
120
120
|
values.push(value).expect("cannot push value to array");
|
121
121
|
}
|
122
122
|
|
data/ext/yrb/src/yxml_text.rs
CHANGED
@@ -2,10 +2,9 @@ use crate::utils::map_rhash_to_attrs;
|
|
2
2
|
use crate::yvalue::YValue;
|
3
3
|
use crate::yxml_fragment::YXmlFragment;
|
4
4
|
use crate::{YTransaction, YXmlElement};
|
5
|
-
use lib0::any::Any;
|
6
5
|
use magnus::{Error, IntoValue, RHash, Value};
|
7
6
|
use std::cell::RefCell;
|
8
|
-
use yrs::{GetString, Text, Xml, XmlNode, XmlTextRef};
|
7
|
+
use yrs::{Any, GetString, Text, Xml, XmlNode, XmlTextRef};
|
9
8
|
|
10
9
|
#[magnus::wrap(class = "Y::XMLText")]
|
11
10
|
pub(crate) struct YXmlText(pub(crate) RefCell<XmlTextRef>);
|
data/lib/3.0/yrb.bundle
CHANGED
Binary file
|
data/lib/3.1/yrb.bundle
CHANGED
Binary file
|
data/lib/3.2/yrb.bundle
CHANGED
Binary file
|
data/lib/3.3/yrb.bundle
CHANGED
Binary file
|
data/lib/y/array.rb
CHANGED
@@ -115,8 +115,8 @@ module Y
|
|
115
115
|
end
|
116
116
|
|
117
117
|
# @return [void]
|
118
|
-
def each(
|
119
|
-
document.current_transaction { |tx| yarray_each(tx,
|
118
|
+
def each(...)
|
119
|
+
document.current_transaction { |tx| yarray_each(tx, ...) }
|
120
120
|
end
|
121
121
|
|
122
122
|
# Check if the array is empty
|
data/lib/y/diff.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Y
|
4
|
+
# A representation of an uniformly-formatted chunk of rich context stored by
|
5
|
+
# Text or XmlText. It contains a value (which could be a string, embedded
|
6
|
+
# object or another shared type) with optional formatting attributes wrapping
|
7
|
+
# around this chunk.
|
8
|
+
class Diff
|
9
|
+
# @return [Object]
|
10
|
+
def insert
|
11
|
+
ydiff_insert
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [Hash]
|
15
|
+
def attrs
|
16
|
+
ydiff_attrs
|
17
|
+
end
|
18
|
+
|
19
|
+
# Convert the diff to a Hash representation
|
20
|
+
#
|
21
|
+
# @return [Hash]
|
22
|
+
def to_h
|
23
|
+
{
|
24
|
+
insert: ydiff_insert,
|
25
|
+
attrs: ydiff_attrs
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
# @!method ydiff_insert()
|
30
|
+
# Returns string representation of text
|
31
|
+
#
|
32
|
+
# @return [Object]
|
33
|
+
|
34
|
+
# @!method ydiff_attrs()
|
35
|
+
#
|
36
|
+
# @return [Hash]
|
37
|
+
end
|
38
|
+
end
|
data/lib/y/text.rb
CHANGED
@@ -80,6 +80,15 @@ module Y
|
|
80
80
|
ytext_unobserve(subscription_id)
|
81
81
|
end
|
82
82
|
|
83
|
+
# Diff
|
84
|
+
#
|
85
|
+
# @return[Array<YDiff>]
|
86
|
+
def diff
|
87
|
+
document.current_transaction do |tx|
|
88
|
+
ytext_diff(tx)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
83
92
|
# Checks if text is empty
|
84
93
|
#
|
85
94
|
# @example Check if text is empty
|
@@ -284,6 +293,12 @@ module Y
|
|
284
293
|
value.is_a?(Hash)
|
285
294
|
end
|
286
295
|
|
296
|
+
# @!method ytext_diff(tx)
|
297
|
+
# Returns text changes as list of diffs
|
298
|
+
#
|
299
|
+
# @param transaction [Y::Transaction]
|
300
|
+
# @return [Array<YDiff>]
|
301
|
+
|
287
302
|
# @!method ytext_insert(tx, index, chunk)
|
288
303
|
# Insert into text at position
|
289
304
|
#
|
data/lib/y/version.rb
CHANGED
data/lib/y-rb.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: y-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.6
|
5
5
|
platform: x86_64-darwin
|
6
6
|
authors:
|
7
7
|
- Hannes Moser
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- ext/yrb/src/yarray.rs
|
85
85
|
- ext/yrb/src/yattrs.rs
|
86
86
|
- ext/yrb/src/yawareness.rs
|
87
|
+
- ext/yrb/src/ydiff.rs
|
87
88
|
- ext/yrb/src/ydoc.rs
|
88
89
|
- ext/yrb/src/ymap.rs
|
89
90
|
- ext/yrb/src/ytext.rs
|
@@ -100,6 +101,7 @@ files:
|
|
100
101
|
- lib/y.rb
|
101
102
|
- lib/y/array.rb
|
102
103
|
- lib/y/awareness.rb
|
104
|
+
- lib/y/diff.rb
|
103
105
|
- lib/y/doc.rb
|
104
106
|
- lib/y/map.rb
|
105
107
|
- lib/y/text.rb
|