AppFlowy/frontend/rust-lib/flowy-document2/src/document_data.rs
Kilu.He c7af04b317
feat: support incremental updates for textblock's delta. (#3216)
* feat: support incremental to update textblock's delta

* fix: update test code

* fix: remove console

* fix: update test

* feat: integrate increamental delta in Flutter

* fix: delete quill editor

* fix: delete quill editor

* feat: add csharp in codeblock (#3371)

* chore: pt-PT & pt-BR translation updated  (#3353)

* chore: Ensure Cargo.lock Is Updated Alongside Changes to Cargo.toml (#3361)

* ci: add cargo check workflow

* ci: test cargo.toml

* fix: update test

* fix: code review

* fix: update cargo.toml and cargo.lock

* fix: code review

* fix: rust format

---------

Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
Co-authored-by: Mayur Mahajan <47064215+MayurSMahajan@users.noreply.github.com>
Co-authored-by: Carlos Silva <mtbf99@gmail.com>
2023-09-12 20:49:03 +08:00

83 lines
1.7 KiB
Rust

use collab_document::blocks::{Block, DocumentData, DocumentMeta};
use crate::entities::{BlockPB, ChildrenPB, DocumentDataPB, MetaPB};
impl From<DocumentData> for DocumentDataPB {
fn from(data: DocumentData) -> 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.into()))
.collect();
let text_map = data.meta.text_map.unwrap_or_default();
let page_id = data.page_id;
Self {
page_id,
blocks,
meta: MetaPB {
children_map,
text_map,
},
}
}
}
impl From<DocumentDataPB> for DocumentData {
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();
let text_map = data.meta.text_map;
let page_id = data.page_id;
DocumentData {
page_id,
blocks,
meta: DocumentMeta {
children_map,
text_map: Some(text_map),
},
}
}
}
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,
external_id: block.external_id,
external_type: block.external_type,
}
}
}
impl From<Vec<String>> for ChildrenPB {
fn from(children: Vec<String>) -> Self {
Self { children }
}
}