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