use wasm_bindgen::prelude::*;
use crate::utils::*;
use crate::*;
#[wasm_bindgen]
pub struct PerspectiveDebugPluginElement {
elem: web_sys::HtmlElement,
}
impl CustomElementMetadata for PerspectiveDebugPluginElement {
const CUSTOM_ELEMENT_NAME: &'static str = "perspective-viewer-plugin";
}
#[wasm_bindgen]
impl PerspectiveDebugPluginElement {
#[wasm_bindgen(constructor)]
pub fn new(elem: web_sys::HtmlElement) -> Self {
Self { elem }
}
#[wasm_bindgen(getter)]
pub fn name(&self) -> String {
"Debug".to_owned()
}
#[wasm_bindgen(getter)]
pub fn select_mode(&self) -> String {
"select".to_owned()
}
#[wasm_bindgen(getter)]
pub fn min_config_columns(&self) -> JsValue {
JsValue::UNDEFINED
}
#[wasm_bindgen(getter)]
pub fn config_column_names(&self) -> JsValue {
JsValue::UNDEFINED
}
pub fn update(&self, view: &perspective_js::View) -> ApiFuture<()> {
self.draw(view)
}
pub fn draw(&self, view: &perspective_js::View) -> ApiFuture<()> {
let css = "margin:0;overflow:scroll;position:absolute;width:100%;height:100%";
clone!(self.elem, view);
ApiFuture::new(async move {
let csv = view.to_csv(None).await?;
elem.style().set_property("background-color", "#fff")?;
elem.set_inner_html(&format!("<pre style='{css}'>{csv}</pre>"));
Ok(())
})
}
pub fn clear(&self) -> ApiFuture<()> {
ApiFuture::default()
}
pub fn resize(&self) -> ApiFuture<()> {
ApiFuture::default()
}
pub fn restyle(&self) -> ApiFuture<()> {
ApiFuture::default()
}
pub fn save(&self) -> ApiResult<JsValue> {
Ok(JsValue::null())
}
pub fn restore(&self, _config: Option<JsValue>) -> ApiResult<()> {
Ok(())
}
pub fn delete(&self) -> ApiFuture<()> {
ApiFuture::default()
}
#[wasm_bindgen(js_name = "connectedCallback")]
pub fn connected_callback(&self) {}
}