yew-full-calendar 0.1.1

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

/// selectionInfo is a plain object with the following properties:
///
/// start
/// Date. A date indicating the beginning of the selection.
///
/// end
/// Date. A date indicating the end of the selection.
///
/// In line with the discussion about the Event object, it is important to stress that the end date property is exclusive. For example, if the selection is all-day and the last day is a Thursday, end will be Friday.
///
/// startStr
/// String. An ISO8601 string representation of the start date. It will have a timezone offset similar to the calendar’s timeZone e.g. 2018-09-01T12:30:00-05:00. If selecting all-day cells, it won’t have a time nor timezone part e.g. 2018-09-01.
///
/// endStr
/// String. An ISO8601 string representation of the end date. It will have a timezone offset similar to the calendar’s timeZone e.g. 2018-09-02T12:30:00-05:00. If selecting all-day cells, it won’t have a time nor timezone part e.g. 2018-09-02.
///
/// allDay
/// Boolean. true or false whether the selection happened on all-day cells.
///
/// jsEvent
/// The native JavaScript event with low-level information such as click coordinates.
///
/// view
/// View object. The current Calendar view.
///
/// resource
/// Resource object. If the current view is a resource view, this is the Resource object that was selected. This is only available when using one of the resource plugins.

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

impl SelectionInfo {
    #[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 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 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>)
    }
}