2023-05-16 06:58:24 +00:00
|
|
|
use collab_document::blocks::{Block, DocumentData, DocumentMeta};
|
|
|
|
|
2023-07-05 12:57:09 +00:00
|
|
|
use crate::entities::{BlockPB, ChildrenPB, DocumentDataPB, MetaPB};
|
|
|
|
|
2023-06-03 05:55:43 +00:00
|
|
|
impl From<DocumentData> for DocumentDataPB {
|
|
|
|
fn from(data: DocumentData) -> Self {
|
2023-05-16 06:58:24 +00:00
|
|
|
let blocks = data
|
|
|
|
.blocks
|
|
|
|
.into_iter()
|
|
|
|
.map(|(id, block)| (id, block.into()))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let children_map = data
|
|
|
|
.meta
|
|
|
|
.children_map
|
|
|
|
.into_iter()
|
|
|
|
.map(|(id, children)| (id, children.into()))
|
|
|
|
.collect();
|
|
|
|
|
2023-09-12 12:49:03 +00:00
|
|
|
let text_map = data.meta.text_map.unwrap_or_default();
|
|
|
|
|
2023-06-03 05:55:43 +00:00
|
|
|
let page_id = data.page_id;
|
2023-05-16 06:58:24 +00:00
|
|
|
|
|
|
|
Self {
|
|
|
|
page_id,
|
|
|
|
blocks,
|
2023-09-12 12:49:03 +00:00
|
|
|
meta: MetaPB {
|
|
|
|
children_map,
|
|
|
|
text_map,
|
|
|
|
},
|
2023-05-16 06:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-03 05:55:43 +00:00
|
|
|
impl From<DocumentDataPB> for DocumentData {
|
2023-05-23 08:13:12 +00:00
|
|
|
fn from(data: DocumentDataPB) -> Self {
|
|
|
|
let blocks = data
|
|
|
|
.blocks
|
|
|
|
.into_iter()
|
|
|
|
.map(|(id, block)| (id, block.into()))
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
let children_map = data
|
|
|
|
.meta
|
|
|
|
.children_map
|
|
|
|
.into_iter()
|
|
|
|
.map(|(id, children)| (id, children.children))
|
|
|
|
.collect();
|
|
|
|
|
2023-09-12 12:49:03 +00:00
|
|
|
let text_map = data.meta.text_map;
|
2023-05-23 08:13:12 +00:00
|
|
|
let page_id = data.page_id;
|
|
|
|
|
2023-06-03 05:55:43 +00:00
|
|
|
DocumentData {
|
2023-05-23 08:13:12 +00:00
|
|
|
page_id,
|
|
|
|
blocks,
|
2023-09-12 12:49:03 +00:00
|
|
|
meta: DocumentMeta {
|
|
|
|
children_map,
|
|
|
|
text_map: Some(text_map),
|
|
|
|
},
|
2023-06-03 05:55:43 +00:00
|
|
|
}
|
2023-05-23 08:13:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-16 06:58:24 +00:00
|
|
|
impl From<Block> for BlockPB {
|
|
|
|
fn from(block: Block) -> Self {
|
|
|
|
Self {
|
|
|
|
id: block.id,
|
|
|
|
ty: block.ty,
|
|
|
|
data: serde_json::to_string(&block.data).unwrap_or_default(),
|
|
|
|
parent_id: block.parent,
|
|
|
|
children_id: block.children,
|
2023-09-12 12:49:03 +00:00
|
|
|
external_id: block.external_id,
|
|
|
|
external_type: block.external_type,
|
2023-05-16 06:58:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<Vec<String>> for ChildrenPB {
|
|
|
|
fn from(children: Vec<String>) -> Self {
|
|
|
|
Self { children }
|
|
|
|
}
|
|
|
|
}
|