Model pages and blocks as document nodes
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::Value;
|
||||
|
||||
use super::{
|
||||
id::{IdError, validate_id},
|
||||
rich_text::RichText,
|
||||
workspace::WorkspaceId,
|
||||
};
|
||||
|
||||
@@ -32,5 +34,39 @@ pub struct DocumentKey {
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Document {
|
||||
pub key: DocumentKey,
|
||||
pub body: Value,
|
||||
pub parent_id: Option<DocumentId>,
|
||||
pub position: u64,
|
||||
pub content: DocumentContent,
|
||||
}
|
||||
|
||||
impl Document {
|
||||
pub fn new(key: DocumentKey, content: DocumentContent) -> Self {
|
||||
Self {
|
||||
key,
|
||||
parent_id: None,
|
||||
position: 0,
|
||||
content,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
|
||||
#[serde(tag = "kind", content = "data", rename_all = "snake_case")]
|
||||
pub enum DocumentContent {
|
||||
Page {
|
||||
title: String,
|
||||
},
|
||||
Heading(RichText),
|
||||
Paragraph(RichText),
|
||||
ListItem(RichText),
|
||||
Todo {
|
||||
text: RichText,
|
||||
checked: bool,
|
||||
},
|
||||
Code {
|
||||
language: String,
|
||||
source: String,
|
||||
},
|
||||
/// Preserves documents written with the original arbitrary JSON model.
|
||||
Json(Value),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user