refactor: extract block label helper

This commit is contained in:
lix-2026
2026-05-25 07:52:06 +08:00
parent 5186e0334b
commit 2c3077cb24
6 changed files with 31 additions and 21 deletions
@@ -1284,7 +1284,7 @@ function __wbg_get_imports() {
return ret;
},
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 294, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 839, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf);
return ret;
},
@@ -4,6 +4,8 @@
//! 或 editor command。类型字段使用 `pub(crate)` 以支持跨模块访问,保持结构
//! 和语义同构。
use web_sys::Element;
/// Hovered block 的共享状态:索引、类型标签、位置和高度。
#[derive(Clone, Debug, PartialEq)]
pub(crate) struct HoveredBlockState {
@@ -45,3 +47,22 @@ pub(crate) struct PendingDragState {
pub(crate) start_x: i32,
pub(crate) start_y: i32,
}
pub(crate) fn block_label_for_element(block: &Element) -> String {
match block.get_attribute("data-type").as_deref() {
Some("taskList") => "Todo 列表".to_string(),
Some("taskItem") => "Todo 项".to_string(),
_ => match block.tag_name().as_str() {
"H1" => "一级标题".to_string(),
"H2" => "二级标题".to_string(),
"H3" => "三级标题".to_string(),
"P" => "段落".to_string(),
"UL" => "无序列表".to_string(),
"OL" => "有序列表".to_string(),
"BLOCKQUOTE" => "引用块".to_string(),
"PRE" => "代码块".to_string(),
"HR" => "分割线".to_string(),
other => format!("块节点 {other}"),
},
}
}
+2 -20
View File
@@ -34,7 +34,8 @@ use editor_runtime::block_menu_legacy_html::{
duplicate_top_level_block_html, reorder_top_level_block_html,
};
use editor_runtime::block_hover_state::{
BlockMenuLayout, DropIndicatorState, HoveredBlockState, PendingDragState,
block_label_for_element, BlockMenuLayout, DropIndicatorState, HoveredBlockState,
PendingDragState,
};
use editor_runtime::command_sync::{
read_editor_snapshot, sync_editor_outputs, sync_persisted_editor_command,
@@ -4826,25 +4827,6 @@ fn handle_lane_left(stage_rect_width: f64) -> f64 {
.max(HANDLE_STAGE_PADDING_LEFT)
}
fn block_label_for_element(block: &Element) -> String {
match block.get_attribute("data-type").as_deref() {
Some("taskList") => "Todo 列表".to_string(),
Some("taskItem") => "Todo 项".to_string(),
_ => match block.tag_name().as_str() {
"H1" => "一级标题".to_string(),
"H2" => "二级标题".to_string(),
"H3" => "三级标题".to_string(),
"P" => "段落".to_string(),
"UL" => "无序列表".to_string(),
"OL" => "有序列表".to_string(),
"BLOCKQUOTE" => "引用块".to_string(),
"PRE" => "代码块".to_string(),
"HR" => "分割线".to_string(),
other => format!("块节点 {other}"),
},
}
}
fn current_target_html_element(event: &WheelEvent) -> Option<HtmlElement> {
event.current_target()?.dyn_into::<HtmlElement>().ok()
}