20260513 mindmap优化01

This commit is contained in:
lix-2026
2026-05-13 22:43:16 +08:00
parent 17c003976b
commit b4a452a8b7
89 changed files with 11557 additions and 707 deletions
@@ -150,6 +150,7 @@ fn tiptap_import_preserves_explicit_block_ids_and_marks() {
attrs: TiptapParagraphAttrs {
block_id: Some("p-1".into()),
text_align: None,
..TiptapParagraphAttrs::default()
},
content: vec![TiptapNode::Text {
text: "Hello".into(),
@@ -183,6 +184,7 @@ fn tiptap_import_preserves_explicit_block_ids_and_marks() {
attrs: TiptapParagraphAttrs {
block_id: Some("t-1".into()),
text_align: None,
..TiptapParagraphAttrs::default()
},
content: vec![TiptapNode::Text {
text: "todo".into(),
@@ -335,3 +337,41 @@ fn tiptap_table_round_trip_preserves_table_node() {
Some(&serde_json::json!("A1"))
);
}
#[test]
fn tiptap_mindmap_placeholder_round_trip_preserves_mindmap_attrs() {
let doc: TiptapNode = serde_json::from_value(serde_json::json!({
"type": "doc",
"content": [{
"type": "paragraph",
"attrs": {
"blockId": "mind_1",
"mnoteBlockType": "mindmap",
"mindmapId": "mind_1",
"rootNodeId": "root",
"projectionVersion": 1
}
}]
}))
.expect("mindmap placeholder JSON should parse");
let imported = EditorBlockDocumentTiptapBridge::from_tiptap_doc("doc_mindmap", &doc)
.expect("mindmap placeholder should import");
assert_eq!(imported.blocks[0].block_type, EditorBlockType::Mindmap);
assert_eq!(
imported.blocks[0].props.extra.get("mindmapId"),
Some(&serde_json::json!("mind_1"))
);
let exported =
EditorBlockDocumentTiptapBridge::to_tiptap_doc(&imported).expect("mindmap should export");
let exported_value = serde_json::to_value(exported).expect("exported doc should serialize");
assert_eq!(
exported_value.pointer("/content/0/attrs/mnoteBlockType"),
Some(&serde_json::json!("mindmap"))
);
assert_eq!(
exported_value.pointer("/content/0/attrs/mindmapId"),
Some(&serde_json::json!("mind_1"))
);
}
@@ -0,0 +1,89 @@
use core_protocol::{
KernelBlockAssetRelation, KernelObjectIdentity, KernelObjectKind, KernelProjectionAssetKind,
KernelProjectionResourceKind, KernelProjectionResourceMeta,
};
#[test]
fn object_identity_separates_index_body_from_mindmap_asset() {
let index_identity = KernelObjectIdentity {
object_kind: KernelObjectKind::Index,
document_id: Some("doc_1".into()),
block_id: None,
asset_id: None,
};
let mindmap_identity = KernelObjectIdentity {
object_kind: KernelObjectKind::Mindmap,
document_id: Some("doc_1".into()),
block_id: Some("block_mindmap_1".into()),
asset_id: Some("mind_1".into()),
};
assert_ne!(index_identity, mindmap_identity);
let index_json = serde_json::to_value(&index_identity).expect("index identity 序列化");
let mindmap_json = serde_json::to_value(&mindmap_identity).expect("mindmap identity 序列化");
assert_eq!(index_json["objectKind"], "index");
assert_eq!(index_json["documentId"], "doc_1");
assert_eq!(mindmap_json["objectKind"], "mindmap");
assert_eq!(mindmap_json["assetId"], "mind_1");
}
#[test]
fn resource_meta_can_describe_asset_object_kinds() {
let cases = [
(
KernelObjectKind::Mindmap,
KernelProjectionResourceKind::Mindmap,
KernelProjectionAssetKind::Mindmap,
"mind_1",
),
(
KernelObjectKind::OnlyOffice,
KernelProjectionResourceKind::OnlyOffice,
KernelProjectionAssetKind::File,
"office_1",
),
(
KernelObjectKind::Attachment,
KernelProjectionResourceKind::Attachment,
KernelProjectionAssetKind::Image,
"image_1",
),
(
KernelObjectKind::Code,
KernelProjectionResourceKind::Code,
KernelProjectionAssetKind::File,
"code_1",
),
];
for (object_kind, resource_kind, asset_kind, asset_id) in cases {
let meta = KernelProjectionResourceMeta {
resource_kind: Some(resource_kind),
document_id: Some("doc_1".into()),
asset_id: Some(asset_id.into()),
workspace_id: Some("ws_1".into()),
asset_kind: Some(asset_kind.clone()),
icon_hint: None,
object_identity: Some(KernelObjectIdentity {
object_kind,
document_id: Some("doc_1".into()),
block_id: Some("block_1".into()),
asset_id: Some(asset_id.into()),
}),
block_asset_relation: Some(KernelBlockAssetRelation {
document_id: "doc_1".into(),
block_id: "block_1".into(),
asset_id: asset_id.into(),
asset_kind,
}),
extra: Default::default(),
};
let json = serde_json::to_value(&meta).expect("resource meta 序列化");
assert_eq!(json["objectIdentity"]["documentId"], "doc_1");
assert_eq!(json["blockAssetRelation"]["blockId"], "block_1");
assert_eq!(json["blockAssetRelation"]["assetId"], asset_id);
}
}