canonrs_interactions_overlay/
lib.rs1#![deny(warnings)]
2pub mod runtime;
12
13pub mod modal;
14pub mod drawer;
15pub mod sheet;
16pub mod alert_dialog;
17pub mod dialog;
18pub mod confirm_dialog;
19pub mod popover;
20pub mod hover_card;
21pub mod context_menu;
22pub mod dropdown_menu;
23
24use canonrs_interactions_core::runtime::bootstrap;
25
26use wasm_bindgen::prelude::*;
27
28#[wasm_bindgen]
30pub fn init_overlay_all() {
31 if let Some(doc) = web_sys::window().and_then(|w| w.document()) {
32 let Ok(nodes) = doc.query_selector_all("[data-rs-interaction=\"overlay\"]") else { return };
33 for i in 0..nodes.length() {
34 let Some(raw) = nodes.item(i) else { continue };
35 if let Ok(el) = wasm_bindgen::JsCast::dyn_into::<web_sys::Element>(raw) {
36 if !el.has_attribute("data-rs-initialized") {
37 init_overlay(el);
38 }
39 }
40 }
41 }
42}
43
44#[wasm_bindgen]
46pub fn init_overlay_subtree(root: web_sys::Element) {
47 let Ok(nodes) = root.query_selector_all("[data-rs-interaction=\"overlay\"]") else { return };
48 for i in 0..nodes.length() {
49 let Some(raw) = nodes.item(i) else { continue };
50 if let Ok(el) = wasm_bindgen::JsCast::dyn_into::<web_sys::Element>(raw) {
51 if !el.has_attribute("data-rs-initialized") {
52 init_overlay(el);
53 }
54 }
55 }
56 if root.get_attribute("data-rs-interaction").as_deref() == Some("overlay") {
58 if !root.has_attribute("data-rs-initialized") {
59 init_overlay(root);
60 }
61 }
62}
63
64
65pub fn register() {
68 bootstrap::register("overlay", init_overlay);
69}
70
71pub fn init_subtree(root: &web_sys::Element) {
74 bootstrap::init_subtree(root);
75}
76
77pub fn init_overlay(el: web_sys::Element) {
80 if el.has_attribute("data-rs-modal") { modal::init(el.clone()); }
81 if el.has_attribute("data-rs-drawer") { drawer::init(el.clone()); }
82 if el.has_attribute("data-rs-sheet") { sheet::init(el.clone()); }
83 if el.has_attribute("data-rs-alert-dialog") { alert_dialog::init(el.clone()); }
84 if el.has_attribute("data-rs-dialog") { dialog::init(el.clone()); }
85 if el.has_attribute("data-rs-confirm-dialog") { confirm_dialog::init(el.clone()); }
86 if el.has_attribute("data-rs-popover") { popover::init(el.clone()); }
87 if el.has_attribute("data-rs-hover-card") { hover_card::init(el.clone()); }
88 if el.has_attribute("data-rs-context-menu") { context_menu::init(el.clone()); }
89 if el.has_attribute("data-rs-dropdown-menu") { dropdown_menu::init(el.clone()); }
90}