49 lines
1.2 KiB
Rust
Raw Normal View History

2022-08-18 17:49:20 +08:00
use crate::core::{NodeAttributes, TextDelta};
2022-08-16 16:25:52 +08:00
2022-08-23 11:15:11 +08:00
#[derive(Clone)]
2022-08-16 16:25:52 +08:00
pub struct NodeData {
pub node_type: String,
2022-08-22 16:46:24 +08:00
pub attributes: NodeAttributes,
pub delta: Option<TextDelta>,
2022-08-16 16:25:52 +08:00
}
impl NodeData {
pub fn new(node_type: &str) -> NodeData {
NodeData {
node_type: node_type.into(),
2022-08-22 16:46:24 +08:00
attributes: NodeAttributes::new(),
delta: None,
2022-08-16 16:25:52 +08:00
}
}
}
2022-08-23 11:15:11 +08:00
#[derive(Clone, serde::Serialize, serde::Deserialize)]
pub struct NodeSubTree {
2022-08-23 19:39:00 +08:00
#[serde(rename = "type")]
2022-08-23 11:15:11 +08:00
pub node_type: String,
pub attributes: NodeAttributes,
#[serde(skip_serializing_if = "Option::is_none")]
pub delta: Option<TextDelta>,
#[serde(skip_serializing_if = "Vec::is_empty")]
pub children: Vec<Box<NodeSubTree>>,
}
impl NodeSubTree {
pub fn new(node_type: &str) -> NodeSubTree {
NodeSubTree {
node_type: node_type.into(),
attributes: NodeAttributes::new(),
delta: None,
children: Vec::new(),
}
}
pub fn to_node_data(&self) -> NodeData {
NodeData {
node_type: self.node_type.clone(),
attributes: self.attributes.clone(),
delta: self.delta.clone(),
}
}
}