refactor: extract dnd target and sidebar helpers

This commit is contained in:
lix-2026
2026-05-25 04:16:35 +08:00
parent 32adfb38a1
commit 1e097a9597
9 changed files with 201 additions and 57 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: 883, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("KeyboardEvent")], shim_idx: 736, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
const ret = makeMutClosure(arg0, arg1, wasm_bindgen__convert__closures_____invoke__hd90af689bc3e71bf);
return ret;
},
@@ -1,9 +1,10 @@
//! Block handle 拖拽命中的纯几何 helper。
//! Block handle 拖拽命中的 runtime helper。
//!
//! 本模块不查询 DOM、不处理 Leptos signal,也不分发 editor command
//! 调用方负责传入已经从页面中读取的坐标
//! 本模块只承接拖拽命中所需的窄 helper,不处理 Leptos signal
//! 也不分发 editor command;调用方负责保留编辑器状态编排
use crate::editor_runtime::block_hover_state::DropPlacement;
use web_sys::{window, EventTarget};
pub(crate) struct HandleCorridorGeometry {
pub(crate) stage_left: f64,
@@ -56,6 +57,13 @@ pub(crate) fn drop_indicator_top(
}
}
pub(crate) fn event_target_from_point(client_x: i32, client_y: i32) -> Option<EventTarget> {
window()
.and_then(|win| win.document())
.and_then(|document| document.element_from_point(client_x as f32, client_y as f32))
.map(Into::into)
}
#[cfg(test)]
mod tests {
use super::*;
+3 -6
View File
@@ -22,8 +22,8 @@ use web_sys::{
use editor_runtime::attachment_upload::dispatch_editor_upload_request;
use editor_runtime::block_dnd::{
drop_indicator_top, drop_placement_from_block_point, pointer_in_handle_corridor_geometry,
HandleCorridorGeometry,
drop_indicator_top, drop_placement_from_block_point, event_target_from_point,
pointer_in_handle_corridor_geometry, HandleCorridorGeometry,
};
use editor_runtime::block_menu_overlay;
use editor_runtime::block_menu_legacy_html::{
@@ -5430,10 +5430,7 @@ fn drop_indicator_from_target(
}
fn drop_indicator_from_point(client_x: i32, client_y: i32) -> Option<DropIndicatorState> {
let target = window()
.and_then(|win| win.document())
.and_then(|document| document.element_from_point(client_x as f32, client_y as f32))?;
let target: web_sys::EventTarget = target.into();
let target = event_target_from_point(client_x, client_y)?;
drop_indicator_from_target(target, client_y)
}