yew-full-calendar 0.1.1

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

#[wasm_bindgen]
extern "C" {
    #[derive(Debug, Clone, PartialEq)]
    pub type EventClickInfo;

    #[wasm_bindgen(method, js_name = preventDefault)]
    pub fn prevent_default(this: &EventClickInfo);
}

impl EventClickInfo {
    #[must_use]
    pub fn event(&self) -> Option<CalendarEvent> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("event"))
            .ok()
            .map(web_sys::wasm_bindgen::JsCast::unchecked_into::<CalendarEvent>)
    }
    #[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 html_element(&self) -> Option<web_sys::Element> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("el"))
            .ok()
            .and_then(|v| {
                v.dyn_into::<web_sys::Element>()
                    .inspect_err(|e| web_sys::console::error_1(&format!("{e:#?}").into()))
                    .ok()
            })
    }
}

#[wasm_bindgen]
extern "C" {
    /// A calendar event object
    #[derive(Debug, Clone, PartialEq)]
    pub type CalendarEvent;
    #[wasm_bindgen(method, js_name = remove)]
    pub fn remove(this: &CalendarEvent);
}

///id
/// String. A unique identifier of an event. Useful for getEventById.
///
/// groupId
/// String. Events that share a groupId will be dragged and resized together automatically.
///
/// allDay
/// Boolean (true or false). Determines if the event is shown in the “all-day” section of relevant views. In addition, if true the time text is not displayed with the event.
///
/// start
/// Date object that obeys the current timeZone. When an event begins.
///
/// end
/// Date object that obeys the current timeZone. When an event ends. It could be null if an end wasn’t specified.
///
/// Note: This value is exclusive. For example, an event with the end of 2018-09-03 will appear to span through 2018-09-02 but end before the start of 2018-09-03. See how events are are parsed from a plain object for further details.
///
/// startStr An ISO8601 string representation of the start date. If the event is all-day, there will not be a time part.
/// endStr An ISO8601 string representation of the end date. If the event is all-day, there will not be a time part.
/// title
/// String. The text that will appear on an event.
///
/// url
/// String. A URL that will be visited when this event is clicked by the user. For more information on controlling this behavior, see the eventClick callback.
///
/// classNames
/// An array of strings like [ `myclass1, myclass2` ]. Determines which HTML classNames will be attached to the rendered event.
///
/// editable
/// Boolean (true or false) or null. The value overriding the editable setting for this specific event.
///
/// startEditable
/// Boolean (true or false) or null. The value overriding the eventStartEditable setting for this specific event.
///
/// durationEditable
/// Boolean (true or false) or null. The value overriding the eventDurationEditable setting for this specific event.
///
/// resourceEditable
/// Boolean (true or false) or null. The value overriding the eventResourceEditable setting for this specific event.
///
/// display
/// The rendering type of this event. Can be 'auto', 'block', 'list-item', 'background', 'inverse-background', or 'none'. See eventDisplay.
///
/// overlap
/// The value overriding the eventOverlap setting for this specific event. If false, prevents this event from being dragged/resized over other events. Also prevents other events from being dragged/resized over this event. Does not accept a function.
///
/// constraint
/// The eventConstraint override for this specific event.
///
/// backgroundColor
/// The eventBackgroundColor override for this specific event.
///
/// borderColor
/// The eventBorderColor override for this specific event.
///
/// textColor
/// The eventTextColor override for this specific event.
///
/// extendedProps
/// A plain object holding miscellaneous other properties specified during parsing. Receives properties in the explicitly given extendedProps hash as well as other non-standard properties.
///
/// source
/// A reference to the Event Source this event came from. If the event was added dynamically via addEvent, and the source parameter was not specified, this value will be null.
impl CalendarEvent {
    #[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 group_id(&self) -> Option<String> {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("groupId"))
            .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<Vec<String>> {
        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()
            })
            .and_then(|arr| {
                arr.iter()
                    .map(|v| v.as_string())
                    .collect::<Option<Vec<String>>>()
            })
    }
    #[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
    //pub fn constraint(&self) -> Option<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<T>(&self) -> Option<T>
    where
        T: serde::de::DeserializeOwned,
    {
        web_sys::js_sys::Reflect::get(self, &JsValue::from_str("extendedProps"))
            .ok()
            .and_then(|v| {
                serde_wasm_bindgen::from_value(v)
                    .inspect_err(|e| web_sys::console::error_1(&format!("{e:#?}").into()))
                    .ok()
            })
    }
}