yew-full-calendar 0.1.1

Yew component for fullcalendar
Documentation
use wasm_bindgen::prelude::*;

/// dateClickInfo is a plain object with the following properties:
///
/// date
/// a Date for the clicked day/time.
///
/// dateStr
/// An ISO8601 string representation of the date. Will have a time zone offset according to the calendar’s timeZone like 2018-09-01T12:30:00-05:00. If clicked on an all-day cell, won’t have a time part nor a time zone part, like 2018-09-01.
///
/// allDay
/// true or false whether the click happened on an all-day cell.
///
/// dayEl
/// An HTML element that represents the whole-day that was clicked on.
///
/// jsEvent
/// The native JavaScript event with low-level information such as click coordinates.
///
/// view
/// The current View Object.
///
/// resource
/// If the current view is a resource-view, the Resource Object that owns this date. Must be using one of the resource plugins.
#[wasm_bindgen]
extern "C" {
    #[derive(Debug, Clone, PartialEq)]
    pub type DateClickInfo;
    #[wasm_bindgen(method, js_name = preventDefault)]
    pub fn prevent_default(this: &DateClickInfo);
}

impl DateClickInfo {
    #[must_use]
    pub fn date(&self) -> Option<web_sys::js_sys::Date> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("date"))
            .ok()
            .and_then(|v| {
                v.dyn_into::<web_sys::js_sys::Date>()
                    .inspect_err(|e| web_sys::console::error_1(&format!("{e:#?}").into()))
                    .ok()
            })
    }
    #[must_use]
    pub fn date_str(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("dateStr"))
            .ok()
            .and_then(|v| v.as_string())
    }
    #[must_use]
    pub fn all_day(&self) -> Option<bool> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("allDay"))
            .ok()
            .and_then(|v| v.as_bool())
    }
    #[must_use]
    pub fn day_el(&self) -> Option<web_sys::Element> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("dayEl"))
            .ok()
            .and_then(|v| {
                v.dyn_into::<web_sys::Element>()
                    .inspect_err(|e| web_sys::console::error_1(&format!("{e:#?}").into()))
                    .ok()
            })
    }
    #[must_use]
    pub fn js_event(&self) -> Option<web_sys::Event> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("jsEvent"))
            .ok()
            .and_then(|v| {
                v.dyn_into::<web_sys::Event>()
                    .inspect_err(|e| web_sys::console::error_1(&format!("{e:#?}").into()))
                    .ok()
            })
    }
    #[must_use]
    pub fn view(&self) -> Option<super::CalendarView> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("view"))
            .ok()
            .map(web_sys::wasm_bindgen::JsCast::unchecked_into::<super::CalendarView>)
    }
    #[must_use]
    pub fn resource(&self) -> Option<crate::ResourceObject> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("resource"))
            .ok()
            .map(web_sys::wasm_bindgen::JsCast::unchecked_into::<crate::ResourceObject>)
    }
}

#[wasm_bindgen]
extern "C" {
    #[derive(Debug, Clone, PartialEq)]
    pub type ResourceObject;
    #[wasm_bindgen(method, js_name = preventDefault)]
    pub fn prevent_default(this: &ResourceObject);
}

impl ResourceObject {
    #[must_use]
    pub fn id(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("id"))
            .ok()
            .and_then(|v| v.as_string())
    }
    #[must_use]
    pub fn all_day(&self) -> Option<bool> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("allDay"))
            .ok()
            .and_then(|v| v.as_bool())
    }
    #[must_use]
    pub fn start(&self) -> Option<web_sys::js_sys::Date> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("start"))
            .ok()
            .and_then(|v| {
                v.dyn_into::<web_sys::js_sys::Date>()
                    .inspect_err(|e| web_sys::console::error_1(&format!("{e:#?}").into()))
                    .ok()
            })
    }
    #[must_use]
    pub fn end(&self) -> Option<web_sys::js_sys::Date> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("end"))
            .ok()
            .and_then(|v| {
                v.dyn_into::<web_sys::js_sys::Date>()
                    .inspect_err(|e| web_sys::console::error_1(&format!("{e:#?}").into()))
                    .ok()
            })
    }
    #[must_use]
    pub fn start_str(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("startStr"))
            .ok()
            .and_then(|v| v.as_string())
    }
    #[must_use]
    pub fn end_str(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("endStr"))
            .ok()
            .and_then(|v| v.as_string())
    }
    #[must_use]
    pub fn title(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("title"))
            .ok()
            .and_then(|v| v.as_string())
    }
    #[must_use]
    pub fn url(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("url"))
            .ok()
            .and_then(|v| v.as_string())
    }
    #[must_use]
    pub fn class_names(&self) -> Option<web_sys::js_sys::Array> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("classNames"))
            .ok()
            .and_then(|v| {
                v.dyn_into::<web_sys::js_sys::Array>()
                    .inspect_err(|e| web_sys::console::error_1(&format!("{e:#?}").into()))
                    .ok()
            })
    }
    #[must_use]
    pub fn editable(&self) -> Option<bool> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("editable"))
            .ok()
            .and_then(|v| v.as_bool())
    }
    #[must_use]
    pub fn start_editable(&self) -> Option<bool> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("startEditable"))
            .ok()
            .and_then(|v| v.as_bool())
    }
    #[must_use]
    pub fn duration_editable(&self) -> Option<bool> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("durationEditable"))
            .ok()
            .and_then(|v| v.as_bool())
    }
    #[must_use]
    pub fn resource_editable(&self) -> Option<bool> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("resourceEditable"))
            .ok()
            .and_then(|v| v.as_bool())
    }
    #[must_use]
    pub fn display(&self) -> Option<crate::EventDisplay> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("display"))
            .ok()
            .and_then(|v| v.as_string())
            .and_then(|s| s.as_str().parse().ok())
    }
    #[must_use]
    pub fn overlap(&self) -> Option<bool> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("overlap"))
            .ok()
            .and_then(|v| v.as_bool())
    }
    // TODO: Constraint
    //#[must_use]
    //pub fn constraint(&self) -> Option<crate::EventConstraint> {
    //    web_sys::js_sys::Reflect::get(self, &JsValue::from_str("constraint"))
    //        .ok()
    //        .and_then(|v| v.as_string())
    //        .and_then(|s| s.as_str().parse().ok())
    //}
    #[must_use]
    pub fn background_color(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("backgroundColor"))
            .ok()
            .and_then(|v| v.as_string())
    }
    #[must_use]
    pub fn border_color(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("borderColor"))
            .ok()
            .and_then(|v| v.as_string())
    }
    #[must_use]
    pub fn text_color(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("textColor"))
            .ok()
            .and_then(|v| v.as_string())
    }
    #[must_use]
    pub fn extended_props(&self) -> Option<web_sys::js_sys::Object> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("extendedProps"))
            .ok()
            .and_then(|v| {
                v.dyn_into::<web_sys::js_sys::Object>()
                    .inspect_err(|e| web_sys::console::error_1(&format!("{e:#?}").into()))
                    .ok()
            })
    }
}