refactor: extract editor dom event helpers
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
//! 编辑器 DOM event target 的窄 helper。
|
||||
//!
|
||||
//! 本模块只做 EventTarget -> Element 归一化和 selector 命中判断,
|
||||
//! 不处理编辑器状态、overlay 或命令分发。
|
||||
|
||||
use wasm_bindgen::JsCast;
|
||||
use web_sys::{Element, EventTarget, Node};
|
||||
|
||||
pub(crate) fn target_element(target: EventTarget) -> Option<Element> {
|
||||
target.clone().dyn_into::<Element>().ok().or_else(|| {
|
||||
target
|
||||
.dyn_into::<Node>()
|
||||
.ok()
|
||||
.and_then(|node| node.parent_element())
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn event_target_matches_selector(target: Option<EventTarget>, selector: &str) -> bool {
|
||||
target
|
||||
.and_then(target_element)
|
||||
.and_then(|element| element.closest(selector).ok().flatten())
|
||||
.is_some()
|
||||
}
|
||||
@@ -6,6 +6,7 @@ pub(crate) mod block_menu_document;
|
||||
pub(crate) mod block_menu_overlay;
|
||||
pub(crate) mod block_menu_legacy_html;
|
||||
pub(crate) mod command_sync;
|
||||
pub(crate) mod dom_events;
|
||||
pub(crate) mod dom_selection;
|
||||
pub(crate) mod editor_focus;
|
||||
pub(crate) mod history_safe_commands;
|
||||
|
||||
Reference in New Issue
Block a user