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 DeleteOptions,
61 ViewConfigUpdate,
62} from "@finos/perspective";
63"#;
64
65#[wasm_bindgen]
67#[allow(non_snake_case)]
68pub fn registerPlugin(name: &str) {
69 use crate::renderer::*;
70 PLUGIN_REGISTRY.register_plugin(name);
71}
72
73#[cfg(not(feature = "external-bootstrap"))]
80#[wasm_bindgen(js_name = "init")]
81pub fn js_init() {
82 perspective_js::utils::set_global_logging();
83 define_web_components!("export * as psp from '../../perspective-viewer.js'");
84 tracing::info!("Perspective initialized.");
85}
86
87pub fn bootstrap_web_components(psp: &JsValue) {
94 define_web_component::<PerspectiveViewerElement>(psp);
95 define_web_component::<PerspectiveDebugPluginElement>(psp);
96
97 define_web_component::<ExportDropDownMenuElement>(psp);
98 define_web_component::<CopyDropDownMenuElement>(psp);
99}
100
101#[macro_export]
102macro_rules! define_web_components {
103 ($x:expr) => {{
104 #[wasm_bindgen::prelude::wasm_bindgen(inline_js = $x)]
105 extern "C" {
106 #[wasm_bindgen::prelude::wasm_bindgen(js_name = "psp")]
107 #[wasm_bindgen::prelude::wasm_bindgen(thread_local_v2)]
108 pub static PSP: wasm_bindgen::prelude::JsValue;
109 }
110
111 PSP.with(|x| $crate::bootstrap_web_components(x));
112 }};
113}