1use crate::internal_prelude::*;
5
6crate::use_behaviors!(sandbox_member);
7
8pub struct NodeList {
18 pub context: SandboxMemberBehaviorStorage,
20
21 pub(crate) nodelist_storage: NodeListStorage,
23}
24
25impl NodeList {
26 pub(crate) fn new(context: Weak<Sandbox>, nodelist_storage: NodeListStorage) -> Arc<NodeList> {
27 Arc::new(NodeList {
28 context: SandboxMemberBehaviorStorage::new(context),
29 nodelist_storage,
30 })
31 }
32
33 pub(crate) fn new_static(context: Weak<Sandbox>, elements: Vec<AnyNodeArc>) -> Arc<NodeList> {
34 let nodelist_storage = NodeListStorage::Static(elements);
35 NodeList::new(context, nodelist_storage)
36 }
37
38 pub fn length(&self) -> usize {
40 match &self.nodelist_storage {
41 NodeListStorage::Static(list) => list.len(),
42 NodeListStorage::Live(query) => match query {
43 Query::ChildNodes { children_of } => {
44 children_of.common.node_graph.static_child_nodes().len()
45 }
46 },
47 }
48 }
49
50 pub fn item(&self, index: usize) -> Option<AnyNodeArc> {
52 match &self.nodelist_storage {
53 NodeListStorage::Static(list) => list.get(index).cloned(),
54 NodeListStorage::Live(query) => match query {
55 Query::ChildNodes { children_of } => children_of
56 .common
57 .node_graph
58 .static_child_nodes()
59 .get(index)
60 .cloned(),
61 },
62 }
63 }
64
65 pub fn get(&self, index: usize) -> Option<AnyNodeArc> {
67 self.item(index)
68 }
69}
70
71impl_sandbox_member!(NodeList, context);
72
73pub(crate) enum NodeListStorage {
75 Static(Vec<AnyNodeArc>),
77
78 Live(Query),
80}
81
82pub(crate) enum Query {
83 ChildNodes { children_of: AnyNodeArc },
84}