Checkpoint current workspace

This commit is contained in:
lix-2026
2026-05-02 06:25:26 +08:00
parent 015ad5bedd
commit 98b6360595
88 changed files with 40217 additions and 178 deletions
@@ -149,6 +149,7 @@ fn tiptap_import_preserves_explicit_block_ids_and_marks() {
TiptapNode::Paragraph {
attrs: TiptapParagraphAttrs {
block_id: Some("p-1".into()),
text_align: None,
},
content: vec![TiptapNode::Text {
text: "Hello".into(),
@@ -161,6 +162,8 @@ fn tiptap_import_preserves_explicit_block_ids_and_marks() {
attrs: TiptapHeadingAttrs {
level: 3,
block_id: Some("h-1".into()),
text_align: None,
collapsed: None,
},
content: vec![TiptapNode::Text {
text: "H".into(),
@@ -179,6 +182,7 @@ fn tiptap_import_preserves_explicit_block_ids_and_marks() {
content: vec![TiptapNode::Paragraph {
attrs: TiptapParagraphAttrs {
block_id: Some("t-1".into()),
text_align: None,
},
content: vec![TiptapNode::Text {
text: "todo".into(),
@@ -191,6 +195,7 @@ fn tiptap_import_preserves_explicit_block_ids_and_marks() {
attrs: TiptapCodeBlockAttrs {
language: Some("ts".into()),
block_id: Some("c-1".into()),
text_align: None,
},
content: vec![TiptapNode::Text {
text: "let x = 1;".into(),
@@ -214,3 +219,119 @@ fn tiptap_import_preserves_explicit_block_ids_and_marks() {
other => panic!("unexpected payload: {other:?}"),
}
}
#[test]
fn tiptap_heading_round_trip_preserves_collapsed_attr() {
let doc: TiptapNode = serde_json::from_value(serde_json::json!({
"type": "doc",
"content": [{
"type": "heading",
"attrs": {
"level": 1,
"blockId": "folded-h1",
"collapsed": true
},
"content": [{ "type": "text", "text": "折叠主标题" }]
}]
}))
.expect("heading JSON should parse");
let imported = EditorBlockDocumentTiptapBridge::from_tiptap_doc("doc_folded", &doc)
.expect("heading should import");
assert_eq!(imported.blocks[0].props.heading_level, Some(1));
assert_eq!(imported.blocks[0].props.collapsed, Some(true));
let exported =
EditorBlockDocumentTiptapBridge::to_tiptap_doc(&imported).expect("heading should export");
let exported_value = serde_json::to_value(exported).expect("exported doc should serialize");
assert_eq!(
exported_value.pointer("/content/0/attrs/collapsed"),
Some(&serde_json::json!(true))
);
}
#[test]
fn tiptap_image_round_trip_preserves_image_node() {
let doc: TiptapNode = serde_json::from_value(serde_json::json!({
"type": "doc",
"content": [{
"type": "image",
"attrs": {
"src": "/api/editor/image-placeholder.svg",
"alt": "E24 图片占位",
"title": "E24 图片"
}
}]
}))
.expect("image JSON should parse");
let imported = EditorBlockDocumentTiptapBridge::from_tiptap_doc("doc_image", &doc)
.expect("image should import");
assert_eq!(imported.blocks[0].block_type, EditorBlockType::Image);
let exported =
EditorBlockDocumentTiptapBridge::to_tiptap_doc(&imported).expect("image should export");
let exported_value = serde_json::to_value(exported).expect("exported doc should serialize");
assert_eq!(
exported_value.pointer("/content/0/type"),
Some(&serde_json::json!("image"))
);
assert_eq!(
exported_value.pointer("/content/0/attrs/src"),
Some(&serde_json::json!("/api/editor/image-placeholder.svg"))
);
}
#[test]
fn tiptap_table_round_trip_preserves_table_node() {
let doc: TiptapNode = serde_json::from_value(serde_json::json!({
"type": "doc",
"content": [{
"type": "table",
"attrs": { "blockId": "table-1" },
"content": [{
"type": "tableRow",
"content": [{
"type": "tableCell",
"attrs": { "colspan": 1, "rowspan": 1, "colwidth": null },
"content": [{
"type": "paragraph",
"content": [{ "type": "text", "text": "A1" }]
}]
}, {
"type": "tableCell",
"attrs": { "colspan": 1, "rowspan": 1, "colwidth": null },
"content": [{ "type": "paragraph" }]
}]
}, {
"type": "tableRow",
"content": [{
"type": "tableCell",
"attrs": { "colspan": 1, "rowspan": 1, "colwidth": null },
"content": [{ "type": "paragraph" }]
}, {
"type": "tableCell",
"attrs": { "colspan": 1, "rowspan": 1, "colwidth": null },
"content": [{ "type": "paragraph" }]
}]
}]
}]
}))
.expect("table JSON should parse");
let imported = EditorBlockDocumentTiptapBridge::from_tiptap_doc("doc_table", &doc)
.expect("table should import");
assert_eq!(imported.blocks[0].block_type, EditorBlockType::Table);
let exported =
EditorBlockDocumentTiptapBridge::to_tiptap_doc(&imported).expect("table should export");
let exported_value = serde_json::to_value(exported).expect("exported doc should serialize");
assert_eq!(
exported_value.pointer("/content/0/type"),
Some(&serde_json::json!("table"))
);
assert_eq!(
exported_value.pointer("/content/0/content/0/content/0/content/0/content/0/text"),
Some(&serde_json::json!("A1"))
);
}