refactor: extract block dnd element helpers

This commit is contained in:
lix-2026
2026-05-25 06:21:02 +08:00
parent 6017a0ad7c
commit 8bcf958fe8
5 changed files with 35 additions and 29 deletions
@@ -1270,7 +1270,7 @@ function __wbg_get_imports() {
},
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 973, ret: Unit, inner_ret: Some(Unit) }, mutable: false }) -> Externref`.
const ret = makeClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__had771ddc65647798);
const ret = makeClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__h19d53c3ed5a90a91);
return ret;
},
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
@@ -1284,8 +1284,8 @@ 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: 886, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf);
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 799, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__ha181c94e3b9968a5);
return ret;
},
__wbindgen_cast_0000000000000007: function(arg0, arg1) {
@@ -1359,8 +1359,8 @@ function wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5(arg0, arg
wasm.wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5(arg0, arg1, arg2);
}
function wasm_bindgen__convert__closures_____invoke__had771ddc65647798(arg0, arg1, arg2) {
wasm.wasm_bindgen__convert__closures_____invoke__had771ddc65647798(arg0, arg1, arg2);
function wasm_bindgen__convert__closures_____invoke__h19d53c3ed5a90a91(arg0, arg1, arg2) {
wasm.wasm_bindgen__convert__closures_____invoke__h19d53c3ed5a90a91(arg0, arg1, arg2);
}
function wasm_bindgen__convert__closures_____invoke__h0abd2b2fe4652e2a(arg0, arg1, arg2) {
@@ -1371,8 +1371,8 @@ function wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5_4(arg0, a
wasm.wasm_bindgen__convert__closures_____invoke__h396914cf76a9e7a5_4(arg0, arg1, arg2);
}
function wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf(arg0, arg1, arg2) {
wasm.wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf(arg0, arg1, arg2);
function wasm_bindgen__convert__closures_____invoke__ha181c94e3b9968a5(arg0, arg1, arg2) {
wasm.wasm_bindgen__convert__closures_____invoke__ha181c94e3b9968a5(arg0, arg1, arg2);
}
function wasm_bindgen__convert__closures_____invoke__h3a3182d847094e12(arg0, arg1, arg2) {
@@ -85,6 +85,26 @@ pub(crate) fn element_within_handle_shell(element: &Element, handle_selector: &s
element.closest(handle_selector).ok().flatten().is_some()
}
pub(crate) fn direct_block_from_element(mut element: Element, root: &Element) -> Option<Element> {
loop {
let parent = element.parent_element()?;
if parent.is_same_node(Some(root)) {
return Some(element);
}
element = parent;
}
}
pub(crate) fn top_level_block_index(root: &Element, block: &Element) -> Option<usize> {
let children = root.children();
(0..children.length()).find_map(|index| {
children
.item(index)
.filter(|child| child.is_same_node(Some(block)))
.map(|_| index as usize)
})
}
#[cfg(test)]
mod tests {
use super::*;
+3 -22
View File
@@ -22,8 +22,9 @@ use web_sys::{
use editor_runtime::attachment_upload::dispatch_editor_upload_request;
use editor_runtime::block_dnd::{
drop_indicator_from_geometry, element_within_handle_shell, event_target_from_point,
pointer_in_handle_corridor_geometry, HandleCorridorGeometry,
direct_block_from_element, drop_indicator_from_geometry, element_within_handle_shell,
event_target_from_point, pointer_in_handle_corridor_geometry, top_level_block_index,
HandleCorridorGeometry,
};
use editor_runtime::block_menu_overlay;
use editor_runtime::block_menu_legacy_html::{
@@ -4837,26 +4838,6 @@ fn handle_lane_left(stage_rect_width: f64) -> f64 {
.max(HANDLE_STAGE_PADDING_LEFT)
}
fn direct_block_from_element(mut element: Element, root: &Element) -> Option<Element> {
loop {
let parent = element.parent_element()?;
if parent.is_same_node(Some(root)) {
return Some(element);
}
element = parent;
}
}
fn top_level_block_index(root: &Element, block: &Element) -> Option<usize> {
let children = root.children();
(0..children.length()).find_map(|index| {
children
.item(index)
.filter(|child| child.is_same_node(Some(block)))
.map(|_| index as usize)
})
}
fn block_label_for_element(block: &Element) -> String {
match block.get_attribute("data-type").as_deref() {
Some("taskList") => "Todo 列表".to_string(),