use dioxus::prelude::*;
use crate::core::types::{Point, TouchSense};
pub(crate) const HOLD_DELAY_MS: f64 = 250.0;
pub(crate) fn touch_style(touch: TouchSense) -> &'static str {
match touch {
TouchSense::Auto => {
"touch-action: pan-y pinch-zoom; user-select: none; \
-webkit-user-select: none; -webkit-touch-callout: none;"
}
TouchSense::Immediate => {
"touch-action: none; user-select: none; -webkit-user-select: none; \
-webkit-touch-callout: none;"
}
}
}
#[component]
pub(crate) fn HoldTimer(
pointer_id: i32,
#[props(default = HOLD_DELAY_MS)] delay_ms: f64,
on_hold: EventHandler<i32>,
) -> Element {
rsx! {
style { style: "display: none;",
"@keyframes dnd-hold-timer {{ from {{ opacity: 0.99; }} to {{ opacity: 1; }} }}"
}
div {
style: "position: absolute; width: 0; height: 0; overflow: hidden; \
animation: dnd-hold-timer {delay_ms.max(0.0)}ms linear forwards;",
aria_hidden: true,
onanimationend: move |_| on_hold.call(pointer_id),
}
}
}
pub(super) fn pointer_client(evt: &PointerEvent) -> Point {
let c = evt.client_coordinates();
Point::new(c.x, c.y)
}
pub(crate) fn primary_press(evt: &PointerEvent) -> bool {
if evt.pointer_type() == "mouse" {
evt.trigger_button() == Some(dioxus::html::input_data::MouseButton::Primary)
} else {
evt.is_primary()
}
}