refactor: extract block label helper
This commit is contained in:
@@ -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}"),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user