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#![warn(
24 clippy::all,
25 clippy::panic_in_result_fn,
26 clippy::fallible_impl_from,
27 clippy::unneeded_field_pattern
28)]
29#![deny(clippy::await_holding_refcell_ref)]
33
34pub mod components;
35pub mod config;
36pub mod custom_elements;
37mod custom_events;
38pub mod exprtk;
39mod js;
40mod presentation;
41mod root;
42
43#[doc(hidden)]
44pub mod queries;
45mod renderer;
46mod session;
47
48#[doc(hidden)]
49pub mod tasks;
50pub mod utils;
51mod workspace;
52
53#[macro_use]
54extern crate macro_rules_attribute;
55extern crate alloc;
56
57use std::cell::RefCell;
58
59use perspective_js::utils::*;
60use wasm_bindgen::prelude::*;
61
62use crate::custom_elements::copy_dropdown::CopyDropDownMenuElement;
63use crate::custom_elements::debug_plugin::PerspectiveDebugPluginElement;
64use crate::custom_elements::export_dropdown::ExportDropDownMenuElement;
65use crate::custom_elements::viewer::PerspectiveViewerElement;
66use crate::utils::define_web_component;
67
68#[wasm_bindgen(typescript_custom_section)]
69const TS_APPEND_CONTENT: &'static str = r#"
70import type {
71 ColumnType,
72 TableInitOptions,
73 ColumnWindow,
74 ViewWindow,
75 TypedArrayWindow,
76 OnUpdateOptions,
77 JoinOptions,
78 UpdateOptions,
79 DeleteOptions,
80 ViewConfigUpdate,
81 SystemInfo,
82} from "@perspective-dev/client";
83
84export type * from "../../src/ts/ts-rs/ViewerConfig.d.ts";
85export type * from "../../src/ts/ts-rs/ViewerConfigUpdate.d.ts";
86export type * from "../../src/ts/ts-rs/PluginStaticConfig.d.ts";
87export type * from "../../src/ts/ts-rs/WorkspaceConfig.d.ts";
88export type * from "../../src/ts/ts-rs/WorkspaceConfigUpdate.d.ts";
89export type * from "../../src/ts/ts-rs/ExportMethod.d.ts";
90export type * from "../../src/ts/ts-rs/PanelOptions.d.ts";
91export type * from "../../src/ts/ts-rs/ClientOptions.d.ts";
92export type * from "../../src/ts/ts-rs/ExportOptions.d.ts";
93export type * from "../../src/ts/ts-rs/GetTableOptions.d.ts";
94export type * from "../../src/ts/ts-rs/GetClientOptions.d.ts";
95import type {GetTableOptions} from "../../src/ts/ts-rs/GetTableOptions.d.ts";
96import type {PanelOptions} from "../../src/ts/ts-rs/PanelOptions.d.ts";
97import type {ExportOptions} from "../../src/ts/ts-rs/ExportOptions.d.ts";
98import type {GetClientOptions} from "../../src/ts/ts-rs/GetClientOptions.d.ts";
99import type {ClientOptions} from "../../src/ts/ts-rs/ClientOptions.d.ts";
100import type {ViewerConfig} from "../../src/ts/ts-rs/ViewerConfig.d.ts";
101import type {ViewerConfigUpdate} from "../../src/ts/ts-rs/ViewerConfigUpdate.d.ts";
102import type {WorkspaceConfig} from "../../src/ts/ts-rs/WorkspaceConfig.d.ts";
103import type {WorkspaceConfigUpdate} from "../../src/ts/ts-rs/WorkspaceConfigUpdate.d.ts";
104"#;
105
106#[wasm_bindgen]
108#[allow(non_snake_case)]
109pub fn registerPlugin(name: &str) {
110 use crate::renderer::*;
111 PLUGIN_REGISTRY.register_plugin(name);
112}
113
114#[cfg(not(feature = "external-bootstrap"))]
121#[wasm_bindgen(js_name = "init")]
122pub fn js_init(module: js_sys::WebAssembly::Module, url: web_sys::Url) {
123 console_error_panic_hook::set_once();
124 perspective_js::utils::set_global_logging();
125 define_web_components!("export * as psp from '../../perspective-viewer.js'");
126 MODULE.with_borrow_mut(|f| {
127 *f = Some((module, url));
128 });
129
130 tracing::info!("Perspective initialized.");
131}
132
133thread_local! {
134 static MODULE: RefCell<Option<(js_sys::WebAssembly::Module, web_sys::Url)>> = RefCell::default();
135}
136
137#[cfg(not(feature = "external-bootstrap"))]
138#[wasm_bindgen(js_name = "get_wasm_module")]
139pub fn js_get_module() -> Result<js_sys::WebAssembly::Module, JsValue> {
140 MODULE
141 .with_borrow(|f| f.clone().map(|x| x.0))
142 .ok_or_else(|| "Uninited module".into())
143}
144
145#[cfg(not(feature = "external-bootstrap"))]
146#[wasm_bindgen(js_name = "get_worker_url")]
147pub fn js_get_worker_url() -> Result<web_sys::Url, JsValue> {
148 MODULE
149 .with_borrow(|f| f.clone().map(|x| x.1))
150 .ok_or_else(|| "Uninited module".into())
151}
152
153pub fn bootstrap_web_components(psp: &JsValue) {
160 define_web_component::<PerspectiveViewerElement>(psp);
161 define_web_component::<PerspectiveDebugPluginElement>(psp);
162 define_web_component::<CopyDropDownMenuElement>(psp);
163 define_web_component::<ExportDropDownMenuElement>(psp);
164}
165
166#[macro_export]
171macro_rules! define_web_components {
172 ($x:expr) => {{
173 #[wasm_bindgen::prelude::wasm_bindgen(inline_js = $x)]
174 extern "C" {
175 #[wasm_bindgen::prelude::wasm_bindgen(js_name = "psp")]
176 #[wasm_bindgen::prelude::wasm_bindgen(thread_local_v2)]
177 pub static PSP: wasm_bindgen::prelude::JsValue;
178 }
179
180 PSP.with(|x| $crate::bootstrap_web_components(x));
181 }};
182}