use canvist_model::BlockTree;
use crate::FracKey;
use crate::NodeId;
use crate::NodeTypeId;
use crate::Props;
#[derive(Clone, Debug, PartialEq)]
pub struct Node {
pub(crate) id: NodeId,
pub(crate) kind: NodeTypeId,
pub(crate) parent: NodeId,
pub(crate) key: FracKey,
pub(crate) props: Props,
pub(crate) rev: u64,
}
impl Node {
#[must_use]
pub fn id(&self) -> NodeId {
self.id
}
#[must_use]
pub fn kind(&self) -> NodeTypeId {
self.kind
}
#[must_use]
pub fn parent(&self) -> NodeId {
self.parent
}
#[must_use]
pub fn key(&self) -> &FracKey {
&self.key
}
#[must_use]
pub fn props(&self) -> &Props {
&self.props
}
#[must_use]
pub fn rev(&self) -> u64 {
self.rev
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct NodeRecord {
pub id: NodeId,
pub kind: NodeTypeId,
pub parent: NodeId,
pub key: FracKey,
pub props: Props,
pub text: Option<Vec<BlockTree>>,
}
impl NodeRecord {
#[must_use]
pub fn new(id: NodeId, kind: NodeTypeId, parent: NodeId, key: FracKey) -> Self {
Self {
id,
kind,
parent,
key,
props: Props::default(),
text: None,
}
}
#[must_use]
pub fn with_props(mut self, props: Props) -> Self {
self.props = props;
self
}
#[must_use]
pub fn with_text(mut self, blocks: Vec<BlockTree>) -> Self {
self.text = Some(blocks);
self
}
}