@mk-drag-and-drop/dom 0.4.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +203 -476
- package/dist/controller/create-drag-controller.d.ts +1 -0
- package/dist/controller/create-drag-controller.js +3 -0
- package/dist/index.d.ts +1 -1
- package/dist/integration/index.d.ts +1 -1
- package/dist/runtime/drag-runtime-scope.d.ts +2 -0
- package/dist/runtime/drag-runtime-scope.js +2 -0
- package/dist/runtime/drag-runtime.d.ts +4 -1
- package/dist/runtime/drag-runtime.js +162 -71
- package/dist/runtime/drop-target-registry.d.ts +3 -10
- package/dist/runtime/drop-target-registry.js +52 -96
- package/dist/runtime/lifecycle.d.ts +15 -0
- package/dist/runtime/sortable-coordinator.d.ts +32 -0
- package/dist/runtime/sortable-coordinator.js +11 -0
- package/dist/runtime/types.d.ts +1 -0
- package/dist/sortable/create-sortable.js +1 -0
- package/dist/sortable/sortable-preview.d.ts +3 -2
- package/dist/sortable/sortable-preview.js +48 -43
- package/dist/sortable/sortable-registry.d.ts +10 -54
- package/dist/sortable/sortable-registry.js +59 -46
- package/package.json +10 -10
package/README.md
CHANGED
|
@@ -1,310 +1,146 @@
|
|
|
1
1
|
# @mk-drag-and-drop/dom
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
Headless DOM drag-and-drop primitives for draggable, droppable, sortable, and
|
|
4
|
+
grouped interactions. The package owns input, target measurement and selection,
|
|
5
|
+
modifiers, overlays, transient sortable DOM preview, normalization, and
|
|
6
|
+
lifecycle sequencing. Applications own their canonical data and commits.
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
persistence, and final commits. The DOM package reports what happened; it does
|
|
10
|
-
not own application data.
|
|
8
|
+
## Imports
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Use the root package import for application code:
|
|
10
|
+
Use `@mk-drag-and-drop/dom` for application code:
|
|
15
11
|
|
|
16
12
|
```ts
|
|
17
13
|
import {
|
|
18
14
|
createDragController,
|
|
15
|
+
createDragHandle,
|
|
19
16
|
createDraggable,
|
|
17
|
+
createDropContainer,
|
|
20
18
|
createDroppable,
|
|
21
19
|
createSortable,
|
|
20
|
+
type DragUpdateEvent,
|
|
21
|
+
type SortableDropPlacement,
|
|
22
|
+
type SortablePreview,
|
|
22
23
|
} from "@mk-drag-and-drop/dom";
|
|
23
24
|
```
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
## Public Root API
|
|
30
|
-
|
|
31
|
-
The root export includes:
|
|
32
|
-
|
|
33
|
-
- `createDragController`
|
|
34
|
-
- `createDraggable`
|
|
35
|
-
- `createDroppable`
|
|
36
|
-
- `createDropContainer`
|
|
37
|
-
- `createSortable`
|
|
38
|
-
- `createDragHandle`
|
|
39
|
-
- controller types: `DragController`, `DragControllerOptions`,
|
|
40
|
-
`DragControllerOverlayInput`, `DragControllerAnnouncements`
|
|
41
|
-
- lifecycle types: `DragStartEvent`, `DragUpdateEvent`, `DragEndEvent`,
|
|
42
|
-
`DropEvent`, `DragSource`, `DragEndResult`, `DragLifecycleCallbacks`,
|
|
43
|
-
`DragLifecycleHelpers`
|
|
44
|
-
- placement types: `SortableDropPlacement`, `RemeasureDropTargetsInput`
|
|
45
|
-
- overlay types: `OverlayReleaseMode`
|
|
46
|
-
- targeting helpers and types: `pointerToCenter`, `centerToCenter`,
|
|
47
|
-
`pointerToRectDistance`, `getDistanceToRect`,
|
|
48
|
-
`maxPointerDistanceToRect`, `maxOverlayCenterDistanceToRect`, `DropTarget`,
|
|
49
|
-
`TargetingAlgorithm`, `TargetingAlgorithmInput`,
|
|
50
|
-
`TargetingConstraint`, `TargetingConstraintInput`
|
|
51
|
-
- modifiers and types: `lockToXAxis`, `lockToYAxis`, `restrictToContainer`,
|
|
52
|
-
`RestrictToContainerResolver`, `DragModifier`, `DragModifierInput`,
|
|
53
|
-
`DragModifierSetupInput`, `DragModifierTransformInput`
|
|
54
|
-
- input and geometry types: `KeyboardCommand`, `KeyboardConfiguration`,
|
|
55
|
-
`PointerConfiguration`, `DragPoint`, `DragRect`
|
|
56
|
-
|
|
57
|
-
Internal classes and helpers such as the underlying runtime class, registries,
|
|
58
|
-
input controllers, measurement helpers, sortable preview internals, and modifier
|
|
59
|
-
pipeline internals are not public root APIs.
|
|
60
|
-
|
|
61
|
-
## Integration Subpath
|
|
62
|
-
|
|
63
|
-
`@mk-drag-and-drop/dom/integration` exports:
|
|
64
|
-
|
|
65
|
-
- `createDragRuntimeScope`
|
|
66
|
-
- `DragRuntimeScope`, `DragRuntimeScopeOptions`,
|
|
67
|
-
`DragRuntimeScopeConfigureInput`
|
|
68
|
-
- `DragState`, `DragOverlayPhase`, `DragOverlayRenderState`,
|
|
69
|
-
`OverlayReleaseMode`
|
|
70
|
-
- `DragRuntimeSubscription`
|
|
71
|
-
- `createDomDraggable`, `createDomDroppable`, `createDomDropContainer`,
|
|
72
|
-
`createDomSortable`
|
|
73
|
-
- the related DOM behavior/input/runtime types
|
|
74
|
-
- `domDragHandleAttribute`
|
|
75
|
-
|
|
76
|
-
Use this subpath when building a framework adapter or custom behavior layer. For
|
|
77
|
-
ordinary DOM usage, prefer the root controller and binding helpers.
|
|
78
|
-
|
|
79
|
-
## Controller
|
|
80
|
-
|
|
81
|
-
`createDragController(options?)` creates the public DOM drag-and-drop scope used
|
|
82
|
-
by the root binding helpers. Controller options include:
|
|
83
|
-
|
|
84
|
-
- lifecycle callbacks: `onDragStart`, `onDragUpdate`, `onDragEnd`, `onDrop`
|
|
85
|
-
- `announcements`: lifecycle callbacks that return polite live-region text
|
|
86
|
-
- `dragOverlay(input)`: returns an overlay `HTMLElement` or `null`
|
|
87
|
-
- `overlayRoot`: optional root for the DOM overlay wrapper
|
|
88
|
-
- `overlayRelease`: `"auto"` removes overlays on drag end; `"manual"` keeps a
|
|
89
|
-
released overlay until its `removeOverlay` callback is called
|
|
90
|
-
- `targetingAlgorithm` and `targetingConstraint`
|
|
91
|
-
- `modifiers`
|
|
92
|
-
- `pointerConfiguration`
|
|
93
|
-
- `keyboardConfiguration`
|
|
94
|
-
|
|
95
|
-
The returned controller has:
|
|
96
|
-
|
|
97
|
-
- `remeasureDropTargets(input?)`: remeasures all targets, one target id, an
|
|
98
|
-
array of target ids, or `{ group }`
|
|
99
|
-
- `remeasureOverlay()`: remeasures the currently mounted drag overlay element;
|
|
100
|
-
it is a safe no-op when no overlay is mounted or no drag is active
|
|
101
|
-
- `recomputeActiveDrag()`: reruns active targeting and drag update from the
|
|
102
|
-
last pointer position; it is a safe no-op when no drag is active and does not
|
|
103
|
-
remeasure drop targets
|
|
104
|
-
|
|
105
|
-
The controller does not expose runtime teardown, disposal, update, or broad
|
|
106
|
-
overlay removal methods. Runtime objects are ordinary JavaScript objects; DOM
|
|
107
|
-
bindings and active drag resources are owned by their own lifetimes.
|
|
108
|
-
|
|
109
|
-
## Drag Overlays
|
|
110
|
-
|
|
111
|
-
`dragOverlay(input)` is a creation hook. The controller calls it when overlay
|
|
112
|
-
content is mounted for the `"dragging"` phase. By default, overlays are removed
|
|
113
|
-
immediately when a drag ends. When `overlayRelease: "manual"` is configured, the
|
|
114
|
-
controller calls `dragOverlay` once more for the `"released"` phase and passes
|
|
115
|
-
`removeOverlay`; call that function when app-owned release animation is done.
|
|
116
|
-
Pointer movement does not call `dragOverlay`.
|
|
117
|
-
|
|
118
|
-
The overlay input includes:
|
|
119
|
-
|
|
120
|
-
- `dragState`: item id, group, source rect, start pointer, and current pointer.
|
|
121
|
-
- `phase`: `"dragging"` or `"released"`.
|
|
122
|
-
- `remeasureOverlay`: manually refreshes the cached overlay measurement.
|
|
123
|
-
- `removeOverlay`: present only for `"released"` overlays in manual release
|
|
124
|
-
mode; call it when app-owned release animation should remove the overlay.
|
|
125
|
-
|
|
126
|
-
`removeOverlay` is only present for released overlays in manual release mode.
|
|
127
|
-
Calling it more than once is safe. It removes the overlay host state only; it is
|
|
128
|
-
not a controller or runtime teardown API.
|
|
129
|
-
|
|
130
|
-
Apps own the returned overlay element and any dynamic content inside it. The
|
|
131
|
-
package owns the overlay wrapper, movement, release, and geometry measurement
|
|
132
|
-
used by targeting and modifiers. The wrapper is positioned with `position:
|
|
133
|
-
fixed`, source rect dimensions, `pointer-events: none`, and a transform derived
|
|
134
|
-
from the current pointer delta.
|
|
135
|
-
|
|
136
|
-
The controller measures the returned overlay element on mount/replacement. When
|
|
137
|
-
`ResizeObserver` is available, it also remeasures when that element changes
|
|
138
|
-
size. The runtime derives the current overlay rect from that cached measurement
|
|
139
|
-
plus modified pointer movement, and it does not measure overlay DOM on every
|
|
140
|
-
pointer move.
|
|
141
|
-
|
|
142
|
-
Manual `remeasureOverlay()` is for cases automatic observation cannot cover or
|
|
143
|
-
where the app knows visual geometry changed. CSS transforms can change visual
|
|
144
|
-
bounds without necessarily triggering `ResizeObserver`.
|
|
26
|
+
`@mk-drag-and-drop/dom/integration` is the intentional adapter entry point. It
|
|
27
|
+
exports `createDragRuntimeScope`, DOM behavior factories, subscription and
|
|
28
|
+
active-reset types, and related behavior types. Registries, sortable
|
|
29
|
+
coordinators, and deep source/build paths are not public.
|
|
145
30
|
|
|
146
|
-
|
|
147
|
-
controller.remeasureOverlay();
|
|
148
|
-
```
|
|
31
|
+
## Controller and bindings
|
|
149
32
|
|
|
150
33
|
```ts
|
|
151
34
|
const controller = createDragController({
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
element.addEventListener("transitionend", () => {
|
|
157
|
-
remeasureOverlay();
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
return element;
|
|
35
|
+
pointerConfiguration: {
|
|
36
|
+
activationDelay: 180,
|
|
37
|
+
activationDistance: 6,
|
|
161
38
|
},
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
For dynamic overlay content, keep a reference to the element and update it from
|
|
166
|
-
lifecycle callbacks or subscriptions:
|
|
167
|
-
|
|
168
|
-
```ts
|
|
169
|
-
let overlayElement: HTMLElement | null = null;
|
|
170
|
-
|
|
171
|
-
const controller = createDragController({
|
|
172
|
-
dragOverlay({ dragState }) {
|
|
173
|
-
overlayElement = document.createElement("div");
|
|
174
|
-
overlayElement.textContent = dragState.draggableId;
|
|
175
|
-
return overlayElement;
|
|
176
|
-
},
|
|
177
|
-
onDragUpdate({ pointerPosition }) {
|
|
178
|
-
if (overlayElement) {
|
|
179
|
-
overlayElement.textContent = `${pointerPosition.x}, ${pointerPosition.y}`;
|
|
180
|
-
}
|
|
39
|
+
onDragUpdate(event) {
|
|
40
|
+
routePreview(event.group, event.sortablePreview);
|
|
181
41
|
},
|
|
182
|
-
|
|
183
|
-
|
|
42
|
+
onDrop(event) {
|
|
43
|
+
commitDrop(event);
|
|
184
44
|
},
|
|
185
45
|
});
|
|
46
|
+
|
|
47
|
+
createSortable({
|
|
48
|
+
controller,
|
|
49
|
+
element,
|
|
50
|
+
draggableId: "row-1",
|
|
51
|
+
group: "table-rows",
|
|
52
|
+
axis: "vertical",
|
|
53
|
+
});
|
|
186
54
|
```
|
|
187
55
|
|
|
188
|
-
|
|
56
|
+
The public controller methods are:
|
|
189
57
|
|
|
190
|
-
|
|
58
|
+
- `cancelDrag()`
|
|
59
|
+
- `remeasureDropTargets(input?)`
|
|
60
|
+
- `remeasureOverlay()`
|
|
61
|
+
- `recomputeActiveDrag()`
|
|
191
62
|
|
|
192
|
-
|
|
63
|
+
Bindings return `void`; their connected-element registrations are scope owned.
|
|
64
|
+
Call `cancelDrag()` before a Vanilla owner removes its registered DOM. It is an
|
|
65
|
+
idle-safe no-op, cancels pending activation or an active pointer/keyboard drag,
|
|
66
|
+
restores sortable preview DOM, and never produces a drop.
|
|
67
|
+
|
|
68
|
+
## Lifecycle types
|
|
193
69
|
|
|
194
70
|
```ts
|
|
195
|
-
type
|
|
71
|
+
export type SortablePreview =
|
|
72
|
+
| { status: "inactive" }
|
|
73
|
+
| { status: "source"; placement: SortableDropPlacement }
|
|
74
|
+
| { status: "projected"; placement: SortableDropPlacement };
|
|
75
|
+
|
|
76
|
+
export type DragStartEvent = {
|
|
196
77
|
draggableId: string;
|
|
78
|
+
group: string;
|
|
197
79
|
source: DragSource;
|
|
198
80
|
pointerPosition: DragPoint;
|
|
199
81
|
sourceRect: DragRect;
|
|
200
82
|
};
|
|
201
83
|
|
|
202
|
-
type DragUpdateEvent = {
|
|
84
|
+
export type DragUpdateEvent = {
|
|
203
85
|
draggableId: string;
|
|
86
|
+
group: string;
|
|
204
87
|
source: DragSource;
|
|
205
88
|
pointerPosition: DragPoint;
|
|
206
89
|
overlayRect: DragRect | null;
|
|
207
90
|
activeDropTargetId: string | null;
|
|
208
91
|
previousDropTargetId: string | null;
|
|
92
|
+
sortablePreview: SortablePreview;
|
|
209
93
|
};
|
|
210
94
|
|
|
211
|
-
type
|
|
212
|
-
|
|
213
|
-
type DragEndResult =
|
|
214
|
-
| "dropped"
|
|
215
|
-
| "no-target"
|
|
216
|
-
| "invalid-target"
|
|
217
|
-
| "canceled";
|
|
218
|
-
|
|
219
|
-
type DragEndEvent = {
|
|
95
|
+
export type DragEndEvent = {
|
|
220
96
|
draggableId: string;
|
|
97
|
+
group: string;
|
|
221
98
|
source: DragSource;
|
|
222
99
|
result: DragEndResult;
|
|
223
|
-
dropTargetId: string | null;
|
|
224
100
|
overlayRect: DragRect | null;
|
|
101
|
+
dropTargetId: string | null;
|
|
225
102
|
};
|
|
226
103
|
|
|
227
|
-
type DropEvent = {
|
|
104
|
+
export type DropEvent = {
|
|
228
105
|
draggableId: string;
|
|
106
|
+
group: string;
|
|
229
107
|
source: DragSource;
|
|
230
108
|
dropTargetId: string;
|
|
231
109
|
sortablePlacement?: SortableDropPlacement;
|
|
232
110
|
};
|
|
233
111
|
|
|
234
|
-
type
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
nextDraggableId: string | null;
|
|
239
|
-
targetDraggableId: string | null;
|
|
240
|
-
side: "before" | "after" | null;
|
|
112
|
+
export type ActiveDragResetEvent = {
|
|
113
|
+
draggableId: string;
|
|
114
|
+
group: string;
|
|
115
|
+
source: DragSource;
|
|
241
116
|
};
|
|
242
117
|
```
|
|
243
118
|
|
|
244
|
-
`
|
|
245
|
-
|
|
246
|
-
at the moment the drag ends. Both are `null` when no drag overlay is configured.
|
|
247
|
-
When an overlay is configured, the runtime uses cached overlay measurement plus
|
|
248
|
-
modified pointer movement. Before overlay content has been measured, it uses the
|
|
249
|
-
same translated source-rect fallback as the visual overlay. The drag update and
|
|
250
|
-
drag end paths do not read overlay DOM just to produce this field.
|
|
251
|
-
|
|
252
|
-
Helpers:
|
|
119
|
+
`DragSource` is `"pointer" | "keyboard"`. `DragEndResult` is `"dropped" |
|
|
120
|
+
"no-target" | "invalid-target" | "canceled"`.
|
|
253
121
|
|
|
254
|
-
|
|
122
|
+
The group is captured when activation succeeds and remains stable through every
|
|
123
|
+
event and announcement. Re-registering the source with another group may
|
|
124
|
+
invalidate it, but cannot change the session group.
|
|
255
125
|
|
|
256
|
-
|
|
257
|
-
ends. `result: "dropped"` means a valid target was accepted and `onDrop` also
|
|
258
|
-
runs. `result: "no-target"` means the user ended normally with no active target.
|
|
259
|
-
`result: "invalid-target"` means an active target candidate was stale by drag
|
|
260
|
-
end. `result: "canceled"` means the drag was canceled, such as Escape,
|
|
261
|
-
pointercancel, or runtime cancellation.
|
|
126
|
+
## Live sortable preview
|
|
262
127
|
|
|
263
|
-
|
|
128
|
+
`sortablePreview` is included in every normal drag update.
|
|
264
129
|
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
130
|
+
| Status | Exact meaning |
|
|
131
|
+
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
132
|
+
| `inactive` | The source is a plain draggable or is no longer a connected, valid sortable registration in the captured group. It does not merely mean there is no active target. |
|
|
133
|
+
| `source` | The normalized package-owned preview equals the source container and sibling anchors captured at activation. This includes initial position, no target before movement, valid no-op, and a return to the original location. |
|
|
134
|
+
| `projected` | The normalized preview differs from source. This includes same- or cross-container movement, container-only placement, and a moved preview retained after the pointer leaves valid targets. |
|
|
268
135
|
|
|
269
|
-
|
|
136
|
+
A source placement describes the captured source container and adjacent sortable
|
|
137
|
+
siblings; `targetDraggableId` and `side` are `null`. Container-only projected
|
|
138
|
+
placement also has null target/side while its container and neighboring anchors
|
|
139
|
+
describe the location. Siblings from other groups and disconnected or replaced
|
|
140
|
+
registrations are excluded.
|
|
270
141
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
- `draggableId`
|
|
274
|
-
- `group`, defaulting to `"default"`
|
|
275
|
-
|
|
276
|
-
`createDroppable(input)` accepts:
|
|
277
|
-
|
|
278
|
-
- `controller`
|
|
279
|
-
- `element`
|
|
280
|
-
- `dropTargetId`
|
|
281
|
-
- `group`, defaulting to `"default"`
|
|
282
|
-
- `containerId`, defaulting to `null`
|
|
283
|
-
|
|
284
|
-
`createDropContainer(input)` accepts:
|
|
285
|
-
|
|
286
|
-
- `controller`
|
|
287
|
-
- `element`
|
|
288
|
-
- `containerId`
|
|
289
|
-
- `group`, defaulting to `"default"`
|
|
290
|
-
|
|
291
|
-
`createSortable(input)` accepts:
|
|
292
|
-
|
|
293
|
-
- `controller`
|
|
294
|
-
- `element`
|
|
295
|
-
- `draggableId`
|
|
296
|
-
- `group`, defaulting to `"default"`
|
|
297
|
-
- `containerId`, defaulting to `null`
|
|
298
|
-
|
|
299
|
-
`createDragHandle({ element })` marks an element with the drag-handle data
|
|
300
|
-
attribute. When a draggable or sortable contains a handle, pointer and keyboard
|
|
301
|
-
dragging are handled from that handle instead of unrelated children.
|
|
302
|
-
|
|
303
|
-
## Placement Data
|
|
304
|
-
|
|
305
|
-
Plain droppable drops are id-only: `draggableId`, `dropTargetId`, and `source`.
|
|
306
|
-
Sortable behavior may add sortable-specific placement under
|
|
307
|
-
`event.sortablePlacement`:
|
|
142
|
+
`SortableDropPlacement` is the sole placement payload for both live and final
|
|
143
|
+
placement:
|
|
308
144
|
|
|
309
145
|
```ts
|
|
310
146
|
type SortableDropPlacement = {
|
|
@@ -317,274 +153,165 @@ type SortableDropPlacement = {
|
|
|
317
153
|
};
|
|
318
154
|
```
|
|
319
155
|
|
|
320
|
-
|
|
321
|
-
may omit `sortablePlacement`.
|
|
322
|
-
`targetDraggableId` and `side` preserve the active sortable item anchor when a
|
|
323
|
-
drop lands relative to an item. They are `null` for container-only placements.
|
|
324
|
-
|
|
325
|
-
Sortable behavior owns only a transient DOM preview during the drag. It may move
|
|
326
|
-
DOM nodes to show where an item would land, but it does not commit app data. On
|
|
327
|
-
drop, the app reads `event.sortablePlacement` and updates its own data/rendering.
|
|
328
|
-
|
|
329
|
-
## Targeting
|
|
156
|
+
## Sequencing and completion
|
|
330
157
|
|
|
331
|
-
|
|
158
|
+
The public update guarantee is:
|
|
332
159
|
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
160
|
+
```text
|
|
161
|
+
measure/select target
|
|
162
|
+
-> update package-owned sortable preview
|
|
163
|
+
-> normalize current preview
|
|
164
|
+
-> publish DragUpdateEvent
|
|
338
165
|
```
|
|
339
166
|
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
- `centerToCenter`
|
|
344
|
-
- `pointerToRectDistance`
|
|
345
|
-
|
|
346
|
-
Built-in targeting helpers/constraints:
|
|
347
|
-
|
|
348
|
-
- `getDistanceToRect(point, rect)`
|
|
349
|
-
- `maxPointerDistanceToRect({ maxDistance?, maxXDistance?, maxYDistance? })`
|
|
350
|
-
- `maxOverlayCenterDistanceToRect({ maxDistance?, maxXDistance?, maxYDistance? })`
|
|
351
|
-
|
|
352
|
-
Custom `TargetingAlgorithm` functions receive `pointerPosition`, `overlayRect`,
|
|
353
|
-
and the filtered `dropTargets` list. Algorithms decide which geometry to use:
|
|
354
|
-
`pointerToCenter` and `pointerToRectDistance` are pointer based, while
|
|
355
|
-
`centerToCenter` computes the overlay center from `overlayRect` and returns no
|
|
356
|
-
target when no overlay rect is available. Custom `TargetingConstraint`
|
|
357
|
-
functions receive `pointerPosition`, `overlayRect`, and one `dropTarget`, and
|
|
358
|
-
return whether that candidate is eligible. Use the pointer or overlay-center
|
|
359
|
-
distance helper that matches the intended behavior.
|
|
360
|
-
|
|
361
|
-
Sortable placement is separate from targeting. The configured targeting
|
|
362
|
-
algorithm alone chooses `activeDropTarget`; sortable only decides before/after
|
|
363
|
-
preview placement relative to that active target. For sortable groups, the
|
|
364
|
-
registry may narrow measured candidates to relevant sortable item, neighbor, or
|
|
365
|
-
container entries before the targeting algorithm runs; the algorithm still makes
|
|
366
|
-
the active-target decision from that narrowed measured list.
|
|
367
|
-
|
|
368
|
-
Same-container sortable preview keeps its movement-responsive first-placement
|
|
369
|
-
behavior: forward movement places after a newly active target, backward movement
|
|
370
|
-
places before, and no sortable-axis movement uses the target midpoint. When a
|
|
371
|
-
sortable item first enters a different DOM container, the initial side is based
|
|
372
|
-
on the current sortable placement position against the target midpoint on the
|
|
373
|
-
sortable axis: above or left of midpoint places before, while below or right of
|
|
374
|
-
midpoint places after. Pointer-based targeting uses the pointer as that position;
|
|
375
|
-
rect-based targeting such as `centerToCenter` uses the overlay center.
|
|
376
|
-
|
|
377
|
-
A container-only preview keeps that cross-container entry state through active
|
|
378
|
-
recomputes until the first item target in the destination list receives a
|
|
379
|
-
before/after placement.
|
|
380
|
-
|
|
381
|
-
`placementBoundary` is used after a preview placement already has an established
|
|
382
|
-
movement direction to control same-target reversal and hysteresis thresholds. It
|
|
383
|
-
does not decide the initial side for cross-container sortable entry or delay the
|
|
384
|
-
first movement that follows midpoint-based entry into a list.
|
|
385
|
-
|
|
386
|
-
## Modifiers
|
|
387
|
-
|
|
388
|
-
Modifiers transform pointer movement before drag state updates. Built-ins:
|
|
389
|
-
|
|
390
|
-
- `lockToXAxis()`
|
|
391
|
-
- `lockToYAxis()`
|
|
392
|
-
- `restrictToContainer(resolver)`
|
|
393
|
-
|
|
394
|
-
`restrictToContainer` receives a resolver function with
|
|
395
|
-
`DragModifierSetupInput` and returns an `HTMLElement | null`. The resolver runs
|
|
396
|
-
at drag setup to choose the bounds element; the selected element's rect is
|
|
397
|
-
remeasured during movement so growing or shrinking containers keep constraining
|
|
398
|
-
against current bounds.
|
|
399
|
-
|
|
400
|
-
Custom modifiers can provide:
|
|
401
|
-
|
|
402
|
-
- `setup(input)`: optional setup state for the active drag
|
|
403
|
-
- `transform(input)`: returns the next `DragPoint`
|
|
404
|
-
|
|
405
|
-
Modifier input includes `draggableId`, `group`, source rect, initial pointer
|
|
406
|
-
position, raw pointer position, current pointer position, overlay rect, and
|
|
407
|
-
modifier state.
|
|
408
|
-
|
|
409
|
-
## Measurement
|
|
410
|
-
|
|
411
|
-
Targets are measured when registered and remeasured at drag start. The explicit
|
|
412
|
-
target remeasurement entry point is `controller.remeasureDropTargets(input?)`;
|
|
413
|
-
call it when app-owned layout changes during a drag should affect targeting.
|
|
414
|
-
|
|
415
|
-
Overlay measurement is separate from target measurement. Overlay content is
|
|
416
|
-
measured on mount/replacement and by `ResizeObserver` when available. Use
|
|
417
|
-
`controller.remeasureOverlay()` when the current overlay geometry should be
|
|
418
|
-
refreshed manually, such as after an app-owned transition or transform that
|
|
419
|
-
changes visual bounds without a normal size-observer notification.
|
|
420
|
-
|
|
421
|
-
`RemeasureDropTargetsInput` accepts:
|
|
422
|
-
|
|
423
|
-
- no argument for all targets
|
|
424
|
-
- a target id string
|
|
425
|
-
- an array of target id strings
|
|
426
|
-
- `{ group: string }`
|
|
427
|
-
|
|
428
|
-
Sortable preview movement does not automatically remeasure a group. Targeting
|
|
429
|
-
continues from the runtime's cached target rects until the app explicitly
|
|
430
|
-
remeasures. Final sortable placement is derived from the current preview DOM
|
|
431
|
-
order, so app-owned layout changes such as expanding tree rows or changing
|
|
432
|
-
grouped sections during a drag should call the public remeasure API when those
|
|
433
|
-
changes need to affect targeting.
|
|
434
|
-
|
|
435
|
-
## Active Drag Recompute
|
|
436
|
-
|
|
437
|
-
`controller.recomputeActiveDrag()` reruns the active drag update path from the
|
|
438
|
-
last stored raw pointer position. It reapplies modifiers, derives the overlay
|
|
439
|
-
rect from cached overlay measurement, recomputes the active drop target from
|
|
440
|
-
cached target measurements, updates the overlay host, and sends the normal drag
|
|
441
|
-
update notifications. This is the same update path used by pointer movement.
|
|
442
|
-
Calling it with no active drag is safe and does nothing.
|
|
443
|
-
|
|
444
|
-
Use it when something external changes what is under the pointer during an
|
|
445
|
-
active drag without producing a new pointer event.
|
|
167
|
+
Public callbacks and adapter subscriptions receive a completed event after the
|
|
168
|
+
DOM mutation. Consumers must not inspect carrier DOM to reconstruct placement
|
|
169
|
+
or depend on subscription insertion order.
|
|
446
170
|
|
|
447
|
-
|
|
448
|
-
|
|
171
|
+
The drop guarantee is:
|
|
172
|
+
|
|
173
|
+
```text
|
|
174
|
+
flush final pointer update
|
|
175
|
+
-> validate target
|
|
176
|
+
-> capture normalized placement
|
|
177
|
+
-> restore package preview DOM
|
|
178
|
+
-> publish onDragEnd
|
|
179
|
+
-> publish onDrop for a valid drop
|
|
449
180
|
```
|
|
450
181
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
182
|
+
Live and drop placement use the same normalizer, so a projected drop with no
|
|
183
|
+
intervening update equals the last projected placement. A successful source/no-
|
|
184
|
+
op drop omits `sortablePlacement`. Package-owned carrier DOM is restored before
|
|
185
|
+
public end/drop handlers. Cancellation emits no artificial final update;
|
|
186
|
+
`onDragEnd` ends application projection. An invalid target yields
|
|
187
|
+
`invalid-target` and no `onDrop`, and its disconnected id is not retained as a
|
|
188
|
+
normalized anchor.
|
|
454
189
|
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
190
|
+
## Applying placement
|
|
191
|
+
|
|
192
|
+
Apply the package decision to application ids; do not calculate geometry,
|
|
193
|
+
midpoints, direction, hysteresis, or candidates:
|
|
459
194
|
|
|
460
195
|
```ts
|
|
461
|
-
|
|
462
|
-
|
|
196
|
+
function getProjectedOrder(
|
|
197
|
+
canonicalOrder: readonly string[],
|
|
198
|
+
event: DragUpdateEvent,
|
|
199
|
+
): readonly string[] {
|
|
200
|
+
if (event.sortablePreview.status === "inactive") return canonicalOrder;
|
|
201
|
+
if (event.sortablePreview.status === "source") return canonicalOrder;
|
|
202
|
+
|
|
203
|
+
return applySortablePlacement(
|
|
204
|
+
canonicalOrder,
|
|
205
|
+
event.draggableId,
|
|
206
|
+
event.sortablePreview.placement,
|
|
207
|
+
);
|
|
208
|
+
}
|
|
463
209
|
```
|
|
464
210
|
|
|
465
|
-
|
|
211
|
+
Canonical state remains unchanged during updates. Commit it once from
|
|
212
|
+
`onDrop`. Since `onDragEnd` runs first, keep a successful projection until
|
|
213
|
+
`onDrop` commits; clear it immediately for cancellation, no-target, and invalid
|
|
214
|
+
target.
|
|
466
215
|
|
|
467
|
-
|
|
468
|
-
and container ids are identifiers that your app maps to its own model.
|
|
216
|
+
## Groups
|
|
469
217
|
|
|
470
|
-
|
|
471
|
-
using your app's normal rendering path after the commit.
|
|
218
|
+
Groups isolate target interaction and route lifecycle work:
|
|
472
219
|
|
|
473
|
-
|
|
220
|
+
```ts
|
|
221
|
+
const controller = createDragController({
|
|
222
|
+
onDragUpdate(event) {
|
|
223
|
+
switch (event.group) {
|
|
224
|
+
case "document-blocks":
|
|
225
|
+
break;
|
|
226
|
+
case "table-rows":
|
|
227
|
+
break;
|
|
228
|
+
case "table-columns":
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
});
|
|
233
|
+
```
|
|
474
234
|
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
when unreachable.
|
|
235
|
+
Use one controller when those domains belong to one scope. Do not encode the
|
|
236
|
+
domain in `draggableId`.
|
|
478
237
|
|
|
479
|
-
|
|
480
|
-
and disconnected drop targets/sortables are pruned on drag-critical paths and
|
|
481
|
-
explicit remeasurement. Active drag resources are owned by the input drag
|
|
482
|
-
lifecycle and are released on drop, cancel, and pointercancel.
|
|
238
|
+
## Remeasure and recompute
|
|
483
239
|
|
|
484
|
-
|
|
485
|
-
delay timers, the pending activation state, and the latest pre-activation
|
|
486
|
-
pointer position are canceled by pointerup, pointercancel, activation success,
|
|
487
|
-
activation failure, or active drag reset.
|
|
240
|
+
After scrolling or application layout changes:
|
|
488
241
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
mechanism for those resources.
|
|
242
|
+
```ts
|
|
243
|
+
controller.remeasureDropTargets({ group: "table-columns" });
|
|
244
|
+
controller.recomputeActiveDrag();
|
|
245
|
+
```
|
|
494
246
|
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
247
|
+
Remeasurement refreshes cached geometry and publishes nothing. Recompute reuses
|
|
248
|
+
the last raw pointer position, reapplies modifiers, and runs the same target,
|
|
249
|
+
preview, normalization, and publication path. It does not implicitly
|
|
250
|
+
remeasure. Schedule after visible projection reaches the DOM, compare orders,
|
|
251
|
+
and deduplicate the scheduled work to prevent loops.
|
|
500
252
|
|
|
501
|
-
##
|
|
253
|
+
## Pointer and keyboard handles
|
|
502
254
|
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
255
|
+
`activationDelay` and `activationDistance` use OR semantics: either threshold
|
|
256
|
+
activates. Quick release before activation remains an ordinary click. After an
|
|
257
|
+
activated pointer drag, the browser click belonging to that interaction and
|
|
258
|
+
targeting the initiating draggable subtree is suppressed once; later unrelated,
|
|
259
|
+
programmatic, and keyboard clicks remain available.
|
|
506
260
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
261
|
+
`createDragHandle({ element })` marks a descendant handle. A button may be a
|
|
262
|
+
pointer handle, but Space and Enter are reserved for its button/menu behavior;
|
|
263
|
+
interactive-element protection prevents those keys from starting a drag. Use a
|
|
264
|
+
noninteractive or separately focusable handle, or explicit commands, for
|
|
265
|
+
keyboard sorting. Editable descendants remain protected.
|
|
510
266
|
|
|
511
|
-
|
|
512
|
-
polite live region only when announcement callbacks are provided. The package
|
|
513
|
-
does not claim complete screen-reader drag-and-drop support; apps should provide
|
|
514
|
-
domain-specific instructions and announcements for their interaction model.
|
|
515
|
-
The lifecycle `onDragUpdate` callback runs for drag updates; the announcement
|
|
516
|
-
`onDragUpdate` callback is intended for active-drop-target transitions and
|
|
517
|
-
dedupes repeated messages to avoid live-region spam. Use lifecycle
|
|
518
|
-
`onDragUpdate` for per-frame side effects, not announcements.
|
|
267
|
+
## Targeting and overlays
|
|
519
268
|
|
|
520
|
-
|
|
269
|
+
Pointer-based targeting works without an overlay. `centerToCenter` and other
|
|
270
|
+
rect-based targeting need a measurable overlay rectangle. A configured overlay
|
|
271
|
+
callback receives `dragState.group`, enabling real blank elements sized for row
|
|
272
|
+
or column carriers:
|
|
521
273
|
|
|
522
274
|
```ts
|
|
523
|
-
import {
|
|
524
|
-
createDragController,
|
|
525
|
-
createDraggable,
|
|
526
|
-
createDroppable,
|
|
527
|
-
} from "@mk-drag-and-drop/dom";
|
|
528
|
-
|
|
529
|
-
const state = {
|
|
530
|
-
itemLocation: "todo",
|
|
531
|
-
};
|
|
532
|
-
|
|
533
275
|
const controller = createDragController({
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
276
|
+
dragOverlay({ dragState }) {
|
|
277
|
+
const overlay = document.createElement("div");
|
|
278
|
+
overlay.className =
|
|
279
|
+
dragState.group === "table-rows" ? "rowOverlay" : "columnOverlay";
|
|
280
|
+
return overlay;
|
|
537
281
|
},
|
|
538
282
|
});
|
|
539
|
-
|
|
540
|
-
const item = document.createElement("button");
|
|
541
|
-
item.type = "button";
|
|
542
|
-
item.textContent = "Drag me";
|
|
543
|
-
|
|
544
|
-
createDraggable({
|
|
545
|
-
controller,
|
|
546
|
-
element: item,
|
|
547
|
-
draggableId: "task-1",
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
for (const columnId of ["todo", "done"]) {
|
|
551
|
-
const column = document.createElement("section");
|
|
552
|
-
|
|
553
|
-
createDroppable({
|
|
554
|
-
controller,
|
|
555
|
-
element: column,
|
|
556
|
-
dropTargetId: columnId,
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
document.body.append(column);
|
|
560
|
-
}
|
|
561
|
-
|
|
562
|
-
document.body.append(item);
|
|
563
283
|
```
|
|
564
284
|
|
|
565
|
-
|
|
285
|
+
The wrapper is pointer-inert. The source rect comes from the registered carrier,
|
|
286
|
+
not a thin descendant handle, and is translated until overlay measurement is
|
|
287
|
+
available. Returning `null` from a configured callback is not a measurable blank
|
|
288
|
+
overlay. Sortable behavior itself does not require any overlay.
|
|
566
289
|
|
|
567
|
-
|
|
290
|
+
Built-in targeting algorithms are `pointerToCenter`, `pointerToRectDistance`,
|
|
291
|
+
and `centerToCenter`. Sortable `placementBoundary` controls same-target reversal
|
|
292
|
+
hysteresis; it does not select the active target.
|
|
568
293
|
|
|
569
|
-
|
|
570
|
-
- `dropzoneList.ts`
|
|
571
|
-
- `sortableList.ts`
|
|
572
|
-
- `kanbanExample.ts`
|
|
573
|
-
- `groupedExample.ts`
|
|
574
|
-
- `treeExample.ts`
|
|
294
|
+
## Integration entry point
|
|
575
295
|
|
|
576
|
-
|
|
296
|
+
Adapter code may import:
|
|
577
297
|
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
298
|
+
```ts
|
|
299
|
+
import {
|
|
300
|
+
createDragRuntimeScope,
|
|
301
|
+
createDomSortable,
|
|
302
|
+
type ActiveDragResetEvent,
|
|
303
|
+
type DragRuntimeSubscription,
|
|
304
|
+
} from "@mk-drag-and-drop/dom/integration";
|
|
584
305
|
```
|
|
585
306
|
|
|
586
|
-
|
|
307
|
+
Subscribers observe completed lifecycle events and are not responsible for
|
|
308
|
+
sortable processing. The integration entry point does not expose mutable
|
|
309
|
+
registries or the internal sortable coordinator.
|
|
587
310
|
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
311
|
+
## Carrier table
|
|
312
|
+
|
|
313
|
+
The complete carrier architecture and runnable Vanilla/React examples are
|
|
314
|
+
documented in the repository carrier-table guide. Carriers stay connected,
|
|
315
|
+
contain no table content, match logical row/column geometry, and reflow as
|
|
316
|
+
normal-flow children of absolute overlay lanes. `sortablePreview` drives the
|
|
317
|
+
visible table; `sortablePlacement` performs one canonical drop commit.
|