ReorderController
A Reorder group on the DOM: the group, its items' drags, its keyboard and its announcements, one
controller a group. make builds one over the context's Projection system and Announcer, for items
that are layout nodes; makePlaced one over the Announcer alone, for a Batch Reorder group's items,
placed from their index and never measured. A binding attaches its group element, gets a driver for
each item, and closing the Scope ends the controller. A server render gets inert.
import * as ReorderController from "@wardic/dom/ReorderController"
const controller = yield* ReorderController.make({ values: () => items, onReorder: (next) => (items = next) })
controller.attach(list)
const driver = controller.item(item, () => Option.some(element))
// Items placed from their index: placed() once they're laid out in a new order.
const placedGroup = yield* ReorderController.makePlaced({ values: () => items, onReorder: (next) => (items = next) })
placedGroup.placed()Its exports also name types the module doesn't export: its internal types.
Interfaces
End
A user's reorder that changed the order, at its end: a pointer drag released, or a keyboard lift dropped, with the item at another index than at its start. What an app saves: the whole order, or the one item that moved and where.
Extended by
Type Parameters
V
V
Properties
from
readonly from: number;Its index at the gesture's start.
to
readonly to: number;Its index at the end.
value
readonly value: V;The item the user moved: the one dragged, or lifted.
values
readonly values: V[];The order at the end.
HoldEnd
A Reorder hold's end, whatever ended it, once: the order then, the item, its index at the start
and now (-1 once it's out of the values), and how. After onReorderEnd, in the same task, when the
order changed.
Extends
End<V>
Type Parameters
V
V
Properties
from
readonly from: number;Its index at the gesture's start.
Inherited from
how
readonly how: HoldHow;How it ended.
to
readonly to: number;Its index at the end.
Inherited from
value
readonly value: V;The item the user moved: the one dragged, or lifted.
Inherited from
values
readonly values: V[];The order at the end.
Inherited from
HoldStart
A Reorder hold's start: the item taken in hand, by its drag's start or a keyboard lift, and its index then.
Type Parameters
V
V
Properties
from
readonly from: number;Its index at the start.
value
readonly value: V;The item taken in hand.
ItemDriver
One item of a ReorderController: its binding feeds it the item's handle, drag samples, keys, focus and presses.
Properties
dispose
readonly dispose: () => void;The item is going away: end a gesture or a lift still in progress.
Returns
void
dragAxis
readonly dragAxis: () => Axis;The axis the item's drag takes, read at each gesture's start.
Returns
Axis
onBlur
readonly onBlur: () => void;Focus left the item: a lift drops where it is, unless focus is back on the item.
Returns
void
onKey
readonly onKey: (event) => void;A key at the item or inside it, inside its dispatch: a keyboard reorder's.
Parameters
event
KeyboardLikeEvent
Returns
void
onPress
readonly onPress: () => void;A press on the item: a lift drops where it is, before any drag.
Returns
void
onSample
readonly onSample: (sample) => void;The item's drag samples, as the drag delivers them.
Parameters
sample
Sample
Returns
void
register
readonly register: (handle) => () => void;Register the item's handle, a projection node's or a placed item's, with the group; returns the unregister.
Parameters
handle
Returns
() => void
ItemHandle
What an item registers with its group: core's ItemSource (its box, its drag offset, its box's
version), how to raise it over the rest while it's lifted, and, for an item placed rather than
measured, its place on screen, for a keyboard step's reveal. A projection handle is one.
Extends
Properties
placeOnScreen?
readonly placeOnScreen?: () => Rect;Its place on screen, in client coordinates, which a keyboard step reveals once the items are laid out. Left out, its painted box with its own transform undone, a layout node's.
Returns
setLifted
readonly setLifted: (lifted) => void;Raise the item over the rest, or let it down: a keyboard lift's.
Parameters
lifted
boolean
Returns
void
Placed
A Batch Reorder group's controller, whose items are placed from their index, never measured: placed
tells it the binding has laid its items out in a new order, as a Measure pass's end tells make's.
Extends
Type Parameters
V
V
Properties
attach
readonly attach: (element) => void;The group's element: its direction, and the scroller Auto-scroll looks for from it.
Parameters
element
Element
Returns
void
Inherited from
ReorderController.attach
axis
readonly axis: () => Axis;The app's axis, else the last detected one ("y" before the first).
Returns
Axis
Inherited from
ReorderController.axis
detect
readonly detect: () => Axis;The axis now: the app's, else detected from the items' boxes as they are, reporting nothing. A binding derives its axis with it when the app's is cleared.
Returns
Axis
Inherited from
ReorderController.detect
group
readonly group: Group<V>;Core's Reorder group (Reorder.move(group, value, toIndex) reorders in code).
Inherited from
item
readonly item: (value, element, onLift?) => ItemDriver;The driver for the item with value; element is its element (for Auto-scroll, its label, its
focus and its reveal), and onLift hears its keyboard lift start and end (the binding's whileDrag).
Parameters
value
V
element
() => Option<Element>
onLift?
(lifted) => void
Returns
Inherited from
ReorderController.item
move
readonly move: (value, toIndex) => void;Move value to toIndex in code (Reorder.move), and announce it.
Parameters
value
V
toIndex
number
Returns
void
Inherited from
ReorderController.move
placed
readonly placed: () => void;The binding has placed its items in the new order: their layout's turn, a stepped item revealed.
Returns
void
valuesChanged
readonly valuesChanged: () => void;The app's values changed: its items laid out in them (a Measure pass), so they animate to their new places.
Returns
void
Inherited from
ReorderController.valuesChanged
Type Aliases
HoldHow
type HoldHow = "drop" | "cancel" | "unmount";How a Reorder hold ended: "drop", released or dropped where it is (a pointer's release or
cancel, a drop key, focus leaving, a press, the app's values, another hold); "cancel", Escape, the
order put back; "unmount", its item went away.
Options
type Options<V> = ReorderControllerOptions<V>;What a binding hands its group: the app's values, its axis, its keyboard and its announcements.
Type Parameters
V
V
ReorderController
type ReorderController<V> = Omit<ReorderController<V>, "dispose">;A Reorder group on the DOM: what a binding attaches its group element and items to.
Type Parameters
V
V
Services
type Services =
| ProjectionSystem
| PassEnds
| Announcer.Announcer;The services a controller takes from its context: the projection system its items are nodes of,
with what tells it each Measure pass's end (DomProjectionSystem's Layer provides both), and the
Environment's Announcer.
Variables
DEFAULT_INSTRUCTIONS
const DEFAULT_INSTRUCTIONS: string;A Reorder item's default instructions on the web: core's keys, and focus mode. A screen reader in browse mode (NVDA's, JAWS's) keeps Space and the arrows for itself until its user switches to focus mode, and it doesn't switch by itself on a list item.
GROUP_STYLE
const GROUP_STYLE: Readonly<{
"overflow-anchor": "none";
}>;The group element's style: no scroll anchoring, so the browser doesn't shift the page as items move (Motion's Group.tsx:187-195 at 16c6122). The user's style goes over it.
inert
const inert: ReorderController<never> = internal.INERT_REORDER_CONTROLLER;The controller a server render gets: its group has no values, so every operation on it does nothing,
its axis is "y", and an item's driver does nothing too.
itemDragAxis
const itemDragAxis: (axis) => true | "x" | "y";An item's drag axis for its gesture's axis, the group's: a grid's "xy" is a free drag. Built once, at module load.
Parameters
axis
Reorder.Axis
Returns
true | "x" | "y"
make
const make: <V>(options) => Effect.Effect<ReorderController<V>, never, Services | Scope.Scope>;Build a group's controller over the context's projection system, announcing through its
Announcer, in the current Scope: closing it ends the controller.
Type Parameters
V
V
Parameters
options
Options<V>
Returns
Effect.Effect<ReorderController<V>, never, Services | Scope.Scope>
makePlaced
const makePlaced: <V>(options) => Effect.Effect<Placed<V>, never, Announcer.Announcer | Scope.Scope>;Build a group's controller for items placed rather than measured, a Batch Reorder group's, announcing
through the context's Announcer, in the current Scope: closing it ends the controller. It needs no
projection system: each item registers a handle whose box is its place, raising its box's version as
it's placed, and the binding calls placed once it has placed a new order.
Type Parameters
V
V
Parameters
options
Options<V>
Returns
Effect.Effect<Placed<V>, never, Announcer.Announcer | Scope.Scope>
sameOrder
const sameOrder: Equivalence.Equivalence<ReadonlyArray<unknown>>;Whether two orders hold the same items in the same order.
Functions
describedByOf()
function describedByOf(own, instructions): string | undefined;An item's aria-describedby: the app's own ids, then the instructions', or none.
Parameters
own
string | undefined
instructions
string | undefined
Returns
string | undefined
instructionsOf()
function instructionsOf(instructions): string;A group's instructions, the English default when it gives none.
Parameters
instructions
string | undefined
Returns
string
keyboardOn()
function keyboardOn(keyboard): boolean;Whether a group's keyboard option turns the Keyboard reorder on: on unless false.
Parameters
keyboard
boolean | undefined
Returns
boolean
tabStopOf()
function tabStopOf(keyboard, pressable): 0 | undefined;An item's tab stop when it gives none of its own: 0 with the keyboard reorder on, or with its items pressable (a Batch Reorder group's).
Parameters
keyboard
boolean
pressable
boolean
Returns
0 | undefined