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-09-08 20:43:06 +08:00
|
|
|
pub note_type: String,
|
|
|
|
|
2022-08-23 11:15:11 +08:00
|
|
|
pub attributes: NodeAttributes,
|
2022-09-08 20:43:06 +08:00
|
|
|
|
2022-08-23 11:15:11 +08:00
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub delta: Option<TextDelta>,
|
2022-09-08 20:43:06 +08:00
|
|
|
|
2022-08-23 11:15:11 +08:00
|
|
|
#[serde(skip_serializing_if = "Vec::is_empty")]
|
2022-09-08 16:49:09 +08:00
|
|
|
pub children: Vec<NodeSubTree>,
|
2022-08-23 11:15:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl NodeSubTree {
|
|
|
|
pub fn new(node_type: &str) -> NodeSubTree {
|
|
|
|
NodeSubTree {
|
2022-09-08 20:43:06 +08:00
|
|
|
note_type: node_type.into(),
|
2022-08-23 11:15:11 +08:00
|
|
|
attributes: NodeAttributes::new(),
|
|
|
|
delta: None,
|
|
|
|
children: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn to_node_data(&self) -> NodeData {
|
|
|
|
NodeData {
|
2022-09-08 20:43:06 +08:00
|
|
|
node_type: self.note_type.clone(),
|
2022-08-23 11:15:11 +08:00
|
|
|
attributes: self.attributes.clone(),
|
|
|
|
delta: self.delta.clone(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|