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