perspective_viewer/
lib.rs1#![recursion_limit = "1024"]
18#![feature(const_type_name)]
19#![feature(iter_intersperse)]
20#![feature(stmt_expr_attributes)]
21#![feature(try_blocks)]
22#![allow(async_fn_in_trait)]
23#![feature(more_qualified_paths)]
24#![warn(
25 clippy::all,
26 clippy::panic_in_result_fn,
27 clippy::await_holding_refcell_ref,
28 clippy::fallible_impl_from,
29 clippy::unneeded_field_pattern
30)]
31
32pub mod components;
33pub mod config;
34pub mod custom_elements;
35mod custom_events;
36mod dragdrop;
37pub mod exprtk;
38mod js;
39mod root;
40
41pub mod engines;
42mod presentation;
43mod renderer;
44mod session;
45#[doc(hidden)]
46pub mod tasks;
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 JoinOptions,
71 UpdateOptions,
72 DeleteOptions,
73 ViewConfigUpdate,
74 SystemInfo,
75} from "@perspective-dev/client";
76"#;
77
78#[wasm_bindgen]
80#[allow(non_snake_case)]
81pub fn registerPlugin(name: &str) {
82 use crate::renderer::*;
83 PLUGIN_REGISTRY.register_plugin(name);
84}
85
86#[cfg(not(feature = "external-bootstrap"))]
93#[wasm_bindgen(js_name = "init")]
94pub fn js_init() {
95 console_error_panic_hook::set_once();
96 perspective_js::utils::set_global_logging();
97 define_web_components!("export * as psp from '../../perspective-viewer.js'");
98 tracing::info!("Perspective initialized.");
99}
100
101pub fn bootstrap_web_components(psp: &JsValue) {
108 define_web_component::<PerspectiveViewerElement>(psp);
109 define_web_component::<PerspectiveDebugPluginElement>(psp);
110 define_web_component::<CopyDropDownMenuElement>(psp);
111 define_web_component::<ExportDropDownMenuElement>(psp);
112}
113
114#[macro_export]
119macro_rules! define_web_components {
120 ($x:expr) => {{
121 #[wasm_bindgen::prelude::wasm_bindgen(inline_js = $x)]
122 extern "C" {
123 #[wasm_bindgen::prelude::wasm_bindgen(js_name = "psp")]
124 #[wasm_bindgen::prelude::wasm_bindgen(thread_local_v2)]
125 pub static PSP: wasm_bindgen::prelude::JsValue;
126 }
127
128 PSP.with(|x| $crate::bootstrap_web_components(x));
129 }};
130}