#![recursion_limit = "1024"]
#![feature(const_type_name)]
#![feature(macro_metavar_expr)]
#![feature(anonymous_lifetime_in_impl_trait)]
#![warn(
clippy::all,
clippy::panic_in_result_fn,
clippy::await_holding_refcell_ref
)]
mod components;
pub mod config;
pub mod custom_elements;
mod custom_events;
mod dragdrop;
mod exprtk;
mod js;
mod model;
mod presentation;
mod renderer;
mod session;
pub mod utils;
#[cfg(feature = "define_custom_elements_async")]
pub use components::{LocalStyle, StyleProvider};
use utils::JsValueSerdeExt;
use wasm_bindgen::prelude::*;
use crate::custom_elements::copy_dropdown::CopyDropDownMenuElement;
use crate::custom_elements::date_column_style::PerspectiveDateColumnStyleElement;
use crate::custom_elements::datetime_column_style::PerspectiveDatetimeColumnStyleElement;
use crate::custom_elements::debug_plugin::PerspectiveDebugPluginElement;
use crate::custom_elements::export_dropdown::ExportDropDownMenuElement;
use crate::custom_elements::number_column_style::PerspectiveNumberColumnStyleElement;
use crate::custom_elements::string_column_style::PerspectiveStringColumnStyleElement;
use crate::custom_elements::viewer::PerspectiveViewerElement;
use crate::utils::{define_web_component, ApiResult};
#[wasm_bindgen(js_name = "registerPlugin")]
pub fn register_plugin(name: &str) {
use crate::renderer::*;
PLUGIN_REGISTRY.register_plugin(name);
}
#[wasm_bindgen(js_name = "getExprTKCommands")]
pub fn get_exprtk_commands() -> ApiResult<Box<[JsValue]>> {
crate::exprtk::COMPLETIONS.with(|x| {
Ok(x.iter()
.map(<JsValue as JsValueSerdeExt>::from_serde_ext)
.collect::<Result<Box<[_]>, serde_wasm_bindgen::Error>>()?)
})
}
#[cfg(not(test))]
#[cfg(not(feature = "define_custom_elements_async"))]
#[wasm_bindgen(js_name = "defineWebComponents")]
pub fn js_define_web_components() {
tracing_wasm::set_as_global_default();
define_web_components!("export * as psp from '../../perspective.js'");
}
pub fn bootstrap_web_components(psp: &JsValue) {
if cfg!(feature = "define_custom_elements_async") {
define_web_component::<PerspectiveViewerElement>(psp);
define_web_component::<PerspectiveDebugPluginElement>(psp);
}
define_web_component::<PerspectiveDateColumnStyleElement>(psp);
define_web_component::<PerspectiveDatetimeColumnStyleElement>(psp);
define_web_component::<PerspectiveStringColumnStyleElement>(psp);
define_web_component::<PerspectiveNumberColumnStyleElement>(psp);
define_web_component::<ExportDropDownMenuElement>(psp);
define_web_component::<CopyDropDownMenuElement>(psp);
}
#[macro_export]
macro_rules! define_web_components {
(@prelude $x:expr) => {{
#[wasm_bindgen::prelude::wasm_bindgen(inline_js = $x)]
extern "C" {
#[wasm_bindgen::prelude::wasm_bindgen(js_name = "psp")]
pub static PSP: wasm_bindgen::prelude::JsValue;
}
&PSP
}};
(@custom_elements $psp:expr) => {{
$crate::bootstrap_web_components($psp);
}};
($x:expr) => {{
let psp = $crate::define_web_components!(@prelude $x);
$crate::define_web_components!(@custom_elements psp);
}};
}