Capability entries
Each capability is its own import, so an app's bundle carries only what it uses. What each entry holds, and what it costs on a production build.
dnd is split by capability, not by layer. Each capability is its own entry, in the React package and in the core, and a capability never imports another one: it imports only the shared core.
@fragiola/dnd-react shared: drag space, collision strategies, events, types,
DragOverlay, useDragMonitor, useDragSpace, autoScroll
├── /draggable Draggable, DragHandle, useDraggable
├── /droppable Droppable, useDroppable
├── /sortable Sortable, SortableGroup, DragHandle, useSortable,
│ useSortableGroup, verticalList, horizontalList, grid,
│ arrayMove, moveBetween
└── /swappable Swappable, DragHandle, useSwappable, swapItems, swapBetweenEach React entry re-exports the core entry of the same name (export *), so the core's
registerDraggable is importable from @fragiola/dnd-react/draggable too. DragHandle is a
shared part, re-exported by each drag source's entry (/draggable, /sortable, /swappable).
What a drag source needs (the pointer and keyboard sensors, the operation, the writer) lives in
the shared core, so sortable and swappable never import draggable. Collision strategies
and autoScroll are separate exports of the shared entry, so an app that does not import one does
not ship it.
What an app ships
pnpm size builds what an app's production build ships for the entries it imports, with the core
they pull, minified and gzipped, with React left out and the development checks dropped:
| imported | min + gzip | over the shared entry | target |
|---|---|---|---|
@fragiola/dnd-react | 3.6 KB | ≤ 4 KB | |
@fragiola/dnd-react + /draggable | 8.6 KB | 5.0 KB | ≤ 2 KB extra |
@fragiola/dnd-react + /droppable | 4.8 KB | 1.1 KB | ≤ 1.5 KB extra |
@fragiola/dnd-react + /sortable | 11.5 KB | 7.9 KB | ≤ 2.5 KB extra |
@fragiola/dnd-react + /swappable | 9.5 KB | 5.8 KB | ≤ 1.5 KB extra |
the shared entry, /draggable, /droppable | 9.2 KB | 5.5 KB | |
those three + /sortable | 12.2 KB | 3.0 KB over those three | |
those three + /swappable | 10.2 KB | 1.0 KB over those three | |
| all five | 13.0 KB | 9.3 KB | |
only Draggable | 7.0 KB | ||
only Droppable | 3.1 KB | ||
only Sortable | 9.2 KB | ||
only Swappable | 7.6 KB |
The drag sources miss their targets: each carries the pointer and keyboard sensors, the drag
operation and the translate writer, shared between them, so an app that both drags and sorts
pays for that machinery once. See bundle size
for what is in each number and how it is measured.
Proved by a test
A bundle test builds a fixture that imports only Draggable and fails when droppable, sortable or
swappable code is in the output, and the same for each capability. A guard test fails when a capability imports
another.
No namespace object
There is no Dnd.* namespace on purpose: one object holding every part would put every
capability in every bundle. This deviates from the Fragiola "one namespace" rule; see
wrappers without HTML.
Wrappers without HTML
A wrapper clones its single child and adds its behaviour there. What the child must do, how props merge and stack, and the render prop.
State attributes
Every state a wrapper has is a data-dnd attribute on your element, present or absent, and the only inline style it writes is structural.