53 lines
1.2 KiB
Rust
Raw Normal View History

2022-08-18 17:49:20 +08:00
use crate::core::{NodeAttributes, TextDelta};
2022-09-09 15:05:41 +08:00
use serde::{Deserialize, Serialize};
2022-08-16 16:25:52 +08:00
2022-09-09 15:05:41 +08:00
#[derive(Clone, Eq, PartialEq, Debug)]
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
2022-09-09 15:05:41 +08:00
#[derive(Clone, Serialize, Deserialize, Eq, PartialEq)]
2022-09-10 08:42:53 +08:00
pub struct Node {
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-10 08:42:53 +08:00
pub children: Vec<Node>,
2022-08-23 11:15:11 +08:00
}
2022-09-10 08:42:53 +08:00
impl Node {
pub fn new(node_type: &str) -> Node {
Node {
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(),
}
}
}