refactor: extract block dnd element helpers
This commit is contained in:
@@ -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::*;
|
||||
|
||||
Reference in New Issue
Block a user