Model pages and blocks as document nodes

This commit is contained in:
2026-11-30 18:36:16 +08:00
parent 365be3870e
commit 455a3580d6
11 changed files with 481 additions and 35 deletions
+37 -1
View File
@@ -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),
}