1use loro::StyleConfig;
2use std::sync::Arc;
3use std::sync::RwLock;
4
5#[derive(Default)]
6pub struct Configure(loro::Configure);
7
8impl Configure {
9 pub fn fork(&self) -> Arc<Self> {
10 Arc::new(Self(self.0.fork()))
11 }
12
13 pub fn record_timestamp(&self) -> bool {
14 self.0.record_timestamp()
15 }
16
17 pub fn set_record_timestamp(&self, record: bool) {
18 self.0.set_record_timestamp(record);
19 }
20
21 pub fn merge_interval(&self) -> i64 {
22 self.0.merge_interval()
23 }
24
25 pub fn set_merge_interval(&self, interval: i64) {
26 self.0.set_merge_interval(interval);
27 }
28
29 pub fn text_style_config(&self) -> Arc<StyleConfigMap> {
30 Arc::new(StyleConfigMap(self.0.text_style_config().clone()))
31 }
32}
33
34#[derive(Default, Debug)]
35pub struct StyleConfigMap(Arc<RwLock<loro::StyleConfigMap>>);
36
37impl StyleConfigMap {
38 pub fn new() -> Self {
39 Self::default()
40 }
41
42 pub fn insert(&self, key: &str, value: StyleConfig) {
43 self.0.write().unwrap().insert(key.into(), value);
44 }
45
46 pub fn get(&self, key: &str) -> Option<StyleConfig> {
47 let m = self.0.read().unwrap();
48 m.get(&(key.into()))
49 }
50
51 pub fn default_rich_text_config() -> Self {
52 Self(Arc::new(RwLock::new(
53 loro::StyleConfigMap::default_rich_text_config(),
54 )))
55 }
56
57 pub(crate) fn to_loro(&self) -> loro::StyleConfigMap {
58 self.0.read().unwrap().clone()
59 }
60}
61
62impl From<loro::Configure> for Configure {
63 fn from(value: loro::Configure) -> Self {
64 Self(value)
65 }
66}