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
77export type * from "../../src/ts/ts-rs/ViewerConfig.d.ts";
78export type * from "../../src/ts/ts-rs/ViewerConfigUpdate.d.ts";
79import type {ViewerConfig} from "../../src/ts/ts-rs/ViewerConfig.d.ts";
80import type {ViewerConfigUpdate} from "../../src/ts/ts-rs/ViewerConfigUpdate.d.ts";
81"#;
82
83#[wasm_bindgen]
85#[allow(non_snake_case)]
86pub fn registerPlugin(name: &str) {
87 use crate::renderer::*;
88 PLUGIN_REGISTRY.register_plugin(name);
89}
90
91#[cfg(not(feature = "external-bootstrap"))]
98#[wasm_bindgen(js_name = "init")]
99pub fn js_init() {
100 console_error_panic_hook::set_once();
101 perspective_js::utils::set_global_logging();
102 define_web_components!("export * as psp from '../../perspective-viewer.js'");
103 tracing::info!("Perspective initialized.");
104}
105
106pub fn bootstrap_web_components(psp: &JsValue) {
113 define_web_component::<PerspectiveViewerElement>(psp);
114 define_web_component::<PerspectiveDebugPluginElement>(psp);
115 define_web_component::<CopyDropDownMenuElement>(psp);
116 define_web_component::<ExportDropDownMenuElement>(psp);
117}
118
119#[macro_export]
124macro_rules! define_web_components {
125 ($x:expr) => {{
126 #[wasm_bindgen::prelude::wasm_bindgen(inline_js = $x)]
127 extern "C" {
128 #[wasm_bindgen::prelude::wasm_bindgen(js_name = "psp")]
129 #[wasm_bindgen::prelude::wasm_bindgen(thread_local_v2)]
130 pub static PSP: wasm_bindgen::prelude::JsValue;
131 }
132
133 PSP.with(|x| $crate::bootstrap_web_components(x));
134 }};
135}