taino_dnd_leptos/lib.rs
1//! Leptos hooks and components for accessible, pointer-events drag-and-drop.
2//!
3//! This crate is the framework-binding layer; see [`taino_dnd_core`] for the
4//! framework-free primitives that power it.
5//!
6//! # Quick start
7//!
8//! ```no_run
9//! use leptos::prelude::*;
10//! use taino_dnd_core::{DraggableId, DroppableId};
11//! use taino_dnd_leptos::{provide_dnd_context, use_draggable, use_droppable};
12//!
13//! #[component]
14//! fn App() -> impl IntoView {
15//! provide_dnd_context();
16//! let d = use_draggable(DraggableId(1));
17//! let z = use_droppable(DroppableId(2));
18//! view! {
19//! <div
20//! node_ref=d.node_ref
21//! on:pointerdown=move |e| d.on_pointer_down(&e)
22//! on:pointermove=move |e| d.on_pointer_move(&e)
23//! on:pointerup=move |e| d.on_pointer_up(&e)
24//! on:pointercancel=move |e| d.on_pointer_cancel(&e)
25//! style=move || d.style()
26//! >
27//! "Drag me"
28//! </div>
29//! <div node_ref=z.node_ref class:over=move || z.is_over.get()>
30//! "Drop zone"
31//! </div>
32//! }
33//! }
34//! ```
35//!
36//! See [`docs/ROADMAP.md`](https://github.com/juanma-dev/taino-leptos-dnd/blob/main/docs/ROADMAP.md)
37//! for the staged plan; Stage 1 ships the API in this quick-start, Stage 2 adds
38//! keyboard sensors, animations, auto-scroll, and ARIA announcements.
39
40#![doc(html_root_url = "https://docs.rs/taino-dnd-leptos/0.5.1")]
41// Stage 2 acceptance: no `unwrap()` / `expect()` / `panic!` in public-facing
42// paths. See `crates/taino-dnd-core/src/lib.rs` for the rationale; the one
43// remaining `expect()` (in `use_dnd_context`) is `#[allow]`-ed inline because
44// the panic is the documented behavior for "called outside a DndContext".
45#![warn(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
46#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic))]
47
48mod announcer;
49mod autoscroll;
50mod container;
51mod context;
52#[cfg(target_arch = "wasm32")]
53mod dom;
54mod draggable;
55mod droppable;
56mod flip;
57mod overlay;
58
59pub use announcer::DndAnnouncer;
60pub use container::use_drag_container;
61pub use context::{provide_dnd_context, use_dnd_context, DndContext, DropResult};
62pub use draggable::{use_draggable, use_draggable_with, UseDraggable};
63pub use droppable::{use_droppable, use_droppable_with, UseDroppable};
64pub use flip::{use_flip, use_flip_with, FlipConfig};
65pub use overlay::DragOverlay;
66// Re-exports for ergonomics: configuring modifiers and auto-scroll shouldn't
67// require an extra dependency on `taino-dnd-core`.
68pub use taino_dnd_core::{
69 default_announcement, AnnounceEvent, AutoScrollConfig, Axis, Modifier, ModifierContext, Vector,
70};
71
72#[cfg(test)]
73mod tests {
74 #[test]
75 fn crate_compiles() {
76 // Native compilation smoke test. Real browser tests live in `tests/web.rs`.
77 }
78}