use super::{Element, Node, NodeList, Text};
pub struct NonKeyedFor {
node_list: NodeList,
}
#[allow(clippy::new_without_default)]
impl NonKeyedFor {
pub fn with_capacity(capacity: usize) -> Self {
Self {
node_list: NodeList::with_capacity(capacity),
}
}
pub fn node_list_mut(&mut self) -> &mut NodeList {
&mut self.node_list
}
pub fn text(&mut self, index: usize, value: &impl ToString) -> Option<&Text> {
self.node_list.text(index, value)
}
pub fn element(&mut self, index: usize, tag: &str) -> (&mut Element, bool, bool) {
let len = self.node_list.nodes.len();
let (new, need_insert) = if len == 0 {
self.node_list.nodes.push(Node::Element(Element::new(tag)));
(true, true)
} else if index >= len {
match self.node_list.nodes[0] {
Node::Element(ref e) => {
let e = e.start_clone();
self.node_list.nodes.push(Node::Element(e));
}
_ => panic!("For loop not contains an Element"),
}
(
false, true,
)
} else {
(false, false)
};
debug_assert!(index < self.node_list.nodes.len());
match unsafe { self.node_list.nodes.get_unchecked_mut(index) } {
Node::Element(e) => (e, new, need_insert),
_ => panic!("Expect a Node::Element at the given index"),
}
}
pub(crate) fn remove_and_get_next_sibling(
&mut self,
real_parent: &web_sys::Node,
) -> Option<web_sys::Node> {
self.node_list.remove_and_get_next_sibling(real_parent)
}
pub(crate) fn remove_real_node(&mut self, real_parent: &web_sys::Node) {
self.node_list.remove_real_node(real_parent)
}
pub fn get_next_sibling(&self) -> Option<web_sys::Node> {
self.node_list.get_next_sibling()
}
pub fn get_first_real_node(&self) -> Option<&web_sys::Node> {
self.node_list.get_first_real_node()
}
pub(super) fn clone(&self, _real_parent: &web_sys::Node) -> Self {
Self {
node_list: NodeList::new(),
}
}
pub(super) fn start_clone(&self) -> Self {
Self {
node_list: NodeList::new(),
}
}
}