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