@mk-drag-and-drop/dom 0.4.5 → 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 CHANGED
@@ -1,310 +1,146 @@
1
1
  # @mk-drag-and-drop/dom
2
2
 
3
- `@mk-drag-and-drop/dom` is the DOM-first behavior package for
4
- `mk-drag-and-drop`. It handles pointer and keyboard drag input, target
5
- registration and measurement, targeting, lifecycle callbacks, drag overlays,
6
- movement modifiers, sortable previews, and drop-container placement.
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
- The package is headless. Apps own DOM structure, rendering, styling, data,
9
- persistence, and final commits. The DOM package reports what happened; it does
10
- not own application data.
8
+ ## Imports
11
9
 
12
- ## Import Paths
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
- The package also exports `@mk-drag-and-drop/dom/integration` for adapter authors
26
- who need lower-level DOM behavior factories and a runtime scope. Deep imports
27
- into `src` or `dist` files are not part of the public package exports.
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
- ```ts
147
- controller.remeasureOverlay();
148
- ```
31
+ ## Controller and bindings
149
32
 
150
33
  ```ts
151
34
  const controller = createDragController({
152
- dragOverlay({ dragState, remeasureOverlay }) {
153
- const element = document.createElement("div");
154
- element.textContent = dragState.draggableId;
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
- onDragEnd() {
183
- overlayElement = null;
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
- ## Lifecycle Events
56
+ The public controller methods are:
189
57
 
190
- Lifecycle callbacks receive an event and helper methods.
58
+ - `cancelDrag()`
59
+ - `remeasureDropTargets(input?)`
60
+ - `remeasureOverlay()`
61
+ - `recomputeActiveDrag()`
191
62
 
192
- Event shapes:
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 DragStartEvent = {
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 DragSource = "pointer" | "keyboard";
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 SortableDropPlacement = {
235
- sourceContainerId: string | null;
236
- containerId: string | null;
237
- previousDraggableId: string | null;
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
- `DragUpdateEvent.overlayRect` is the current viewport-space rectangle for the
245
- drag overlay. `DragEndEvent.overlayRect` is the final viewport-space rectangle
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
- - `getDropTargetRect(dropTargetId)`
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
- `onDrop` only runs for a valid successful drop. `onDragEnd` runs whenever a drag
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
- ## Bindings
128
+ `sortablePreview` is included in every normal drag update.
264
129
 
265
- Root binding helpers attach behavior to DOM elements and return `void`.
266
- Registrations are WeakRef-backed and stale disconnected elements are pruned on
267
- drag-critical paths and explicit remeasurement.
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
- `createDraggable(input)` accepts:
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
- - `controller`
272
- - `element`
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
- No sortable placement is included for plain droppable drops. No-op sortable drops
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
- A measured target passed to custom targeting code has:
158
+ The public update guarantee is:
332
159
 
333
- ```ts
334
- type DropTarget = {
335
- dropTargetId: string;
336
- dropTargetRect: DragRect;
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
- Built-in targeting algorithms:
341
-
342
- - `pointerToCenter`
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
- ```ts
448
- controller.recomputeActiveDrag();
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
- Recompute does not remeasure drop targets. If target geometry or registrations
452
- changed and those changes should affect targeting, remeasure first and then
453
- recompute.
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
- ```ts
456
- controller.remeasureDropTargets({ group: "items" });
457
- controller.recomputeActiveDrag();
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
- // Example: after external scrolling changes what is under the pointer
462
- controller.recomputeActiveDrag();
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
- ## Data Ownership
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
- The DOM package never owns application data. Item ids, target ids, group ids,
468
- and container ids are identifiers that your app maps to its own model.
216
+ ## Groups
469
217
 
470
- Commit data in lifecycle callbacks, usually `onDrop`. Rerender or patch the DOM
471
- using your app's normal rendering path after the commit.
218
+ Groups isolate target interaction and route lifecycle work:
472
219
 
473
- ## Lifetime Model
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
- Root binding helpers do not return per-item disposers. Runtime/controller
476
- objects are ordinary JavaScript objects and are released by garbage collection
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
- DOM registrations are a separate lifetime. Bindings keep WeakRef-backed records,
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
- Pending pointer activation is also separate from an active drag. Activation
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
- Active drag resources include pointer/window listeners, keyboard listeners, RAF
490
- pointer updates, text-selection suppression, active target/session state,
491
- overlay host state, active modifiers, and sortable preview/snapshot state. They
492
- are released by active drag lifecycle paths. Runtime disposal is not the cleanup
493
- mechanism for those resources.
242
+ ```ts
243
+ controller.remeasureDropTargets({ group: "table-columns" });
244
+ controller.recomputeActiveDrag();
245
+ ```
494
246
 
495
- Sortable registration state and sortable active preview state are separate.
496
- Registered sortable elements, ids, groups, containers, and options remain until
497
- they are unregistered or pruned as stale DOM. Per-drag sortable snapshots,
498
- dragged attributes, preview placement, and moved DOM are restored by active drag
499
- cleanup.
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
- ## Accessibility Scope
253
+ ## Pointer and keyboard handles
502
254
 
503
- Keyboard dragging is available when `keyboardConfiguration.enabled` is not
504
- disabled. Defaults use Space or Enter to start/drop, Escape to cancel, arrow
505
- keys to move, and a default movement distance of 24.
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
- Draggable or sortable elements may receive `tabIndex` and keyboard handlers
508
- when keyboard dragging is enabled. Drag handles and focusable draggable elements
509
- should have clear labels.
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
- Announcements are opt-in through `announcements`. The controller creates a
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
- ## Example
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
- onDrop({ draggableId, dropTargetId }) {
535
- state.itemLocation = dropTargetId;
536
- console.log(`${draggableId} moved to ${dropTargetId}`);
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
- ## Examples
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
- Vanilla DOM examples live in `apps/web/src/vanilla`:
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
- - `basicDrag.ts`
570
- - `dropzoneList.ts`
571
- - `sortableList.ts`
572
- - `kanbanExample.ts`
573
- - `groupedExample.ts`
574
- - `treeExample.ts`
294
+ ## Integration entry point
575
295
 
576
- They use root imports from `@mk-drag-and-drop/dom`.
296
+ Adapter code may import:
577
297
 
578
- ## Development
579
-
580
- ```bash
581
- pnpm --filter @mk-drag-and-drop/dom build
582
- pnpm --filter @mk-drag-and-drop/dom lint
583
- pnpm --filter @mk-drag-and-drop/dom test
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
- Example app verification:
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
- ```bash
589
- pnpm --filter web build
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.