perspective_viewer/
lib.rs1#![recursion_limit = "1024"]
18#![feature(const_type_name)]
19#![feature(let_chains)]
20#![feature(macro_metavar_expr)]
21#![feature(iter_intersperse)]
22#![feature(stmt_expr_attributes)]
23#![allow(async_fn_in_trait)]
24#![warn(
25 clippy::all,
26 clippy::panic_in_result_fn,
27 clippy::await_holding_refcell_ref
28)]
29
30pub mod components;
31pub mod config;
32pub mod custom_elements;
33mod custom_events;
34mod dragdrop;
35pub mod exprtk;
36mod js;
37
38#[doc(hidden)]
39pub mod model;
40mod presentation;
41mod renderer;
42mod session;
43pub mod utils;
44
45use perspective_js::utils::*;
46use wasm_bindgen::prelude::*;
47
48use crate::custom_elements::copy_dropdown::CopyDropDownMenuElement;
49use crate::custom_elements::debug_plugin::PerspectiveDebugPluginElement;
50use crate::custom_elements::export_dropdown::ExportDropDownMenuElement;
51use crate::custom_elements::viewer::PerspectiveViewerElement;
52use crate::utils::define_web_component;
53
54#[wasm_bindgen(typescript_custom_section)]
55const TS_APPEND_CONTENT: &'static str = r#"
56import type {
57 TableInitOptions,
58 ColumnWindow,
59 ViewWindow,
60 OnUpdateOptions,
61 UpdateOptions,
62 DeleteOptions,
63 ViewConfigUpdate,
64 SystemInfo,
65} from "@perspective-dev/client";
66"#;
67
68#[wasm_bindgen]
70#[allow(non_snake_case)]
71pub fn registerPlugin(name: &str) {
72 use crate::renderer::*;
73 PLUGIN_REGISTRY.register_plugin(name);
74}
75
76#[cfg(not(feature = "external-bootstrap"))]
83#[wasm_bindgen(js_name = "init")]
84pub fn js_init() {
85 perspective_js::utils::set_global_logging();
86 define_web_components!("export * as psp from '../../perspective-viewer.js'");
87 tracing::info!("Perspective initialized.");
88}
89
90pub fn bootstrap_web_components(psp: &JsValue) {
97 define_web_component::<PerspectiveViewerElement>(psp);
98 define_web_component::<PerspectiveDebugPluginElement>(psp);
99
100 define_web_component::<ExportDropDownMenuElement>(psp);
101 define_web_component::<CopyDropDownMenuElement>(psp);
102}
103
104#[macro_export]
105macro_rules! define_web_components {
106 ($x:expr) => {{
107 #[wasm_bindgen::prelude::wasm_bindgen(inline_js = $x)]
108 extern "C" {
109 #[wasm_bindgen::prelude::wasm_bindgen(js_name = "psp")]
110 #[wasm_bindgen::prelude::wasm_bindgen(thread_local_v2)]
111 pub static PSP: wasm_bindgen::prelude::JsValue;
112 }
113
114 PSP.with(|x| $crate::bootstrap_web_components(x));
115 }};
116}