Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Attributes of Any Type in XML Objects #189

Open
carlosleandr opened this issue Oct 31, 2024 · 1 comment
Open

Support for Attributes of Any Type in XML Objects #189

carlosleandr opened this issue Oct 31, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@carlosleandr
Copy link

Problem

Would it be possible to implement the storage of attributes of any type similar to what the Yjs package does? For example, you can see Yjs's implementation here:

https://github.com/yjs/yjs/blob/8dc1296a0bd15e70c573160593c2617e0d772f01/src/types/YText.js#L1235-L1268

Currently, more complex attributes from the Yjs package are arriving in the pycrdt package as strings, making it impossible to retrieve them properly. Check the details in the following references:

def attributes(self, txn: Transaction) -> list[tuple[str, str]]:
"""Gets all attributes, as a list of `(key, value)` tuples."""
def attribute(self, txn: Transaction, name: str) -> str | None:
"""Gets an attribute, or `None` if the attribute does not exist."""
def insert_attribute(self, txn: Transaction, name: str, value: str) -> None:
"""Inserts or overwrites an attribute."""

pycrdt/src/xml.rs

Lines 76 to 94 in 2518513

fn attributes(&self, txn: &mut Transaction) -> Vec<(String, String)> {
let mut t0 = txn.transaction();
let t1 = t0.as_mut().unwrap();
let t = t1.as_ref();
self.$xinner.attributes(t).map(|(k,v)| (String::from(k), v)).collect()
}
fn attribute(&self, txn: &mut Transaction, name: &str) -> Option<String> {
let mut t0 = txn.transaction();
let t1 = t0.as_mut().unwrap();
let t = t1.as_ref();
self.$xinner.get_attribute(t, name)
}
fn insert_attribute(&self, txn: &mut Transaction, name: &str, value: &str) {
let mut _t = txn.transaction();
let mut t = _t.as_mut().unwrap().as_mut();
self.$xinner.insert_attribute(&mut t, name, value);
}

Additional context

Here is an example of an attribute that I find difficult to retrieve properly due to the various possibilities of values and data organization:

tokens = "[{text: welcome, start: 55, end: 56.4567498}, {start: 56.4567498, text: feature:, end: 60.11}, {start: 60.11, end: 65.0001, text: 12.4564}]"```
@carlosleandr carlosleandr added the enhancement New feature or request label Oct 31, 2024
@davidbrochart
Copy link
Collaborator

I would have to look into it, but maybe @ColonelThirtyTwo has ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants