@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.
@@ -33,6 +33,7 @@ export type DragControllerOptions = {
33
33
  targetingConstraint?: TargetingConstraint;
34
34
  } & DragLifecycleCallbacks;
35
35
  export type DragController = {
36
+ cancelDrag: () => void;
36
37
  remeasureDropTargets: (input?: RemeasureDropTargetsInput) => void;
37
38
  remeasureOverlay: () => void;
38
39
  recomputeActiveDrag: () => void;
@@ -19,6 +19,9 @@ export function createDragController(options = {}) {
19
19
  configureRuntime(options);
20
20
  syncLiveRegion();
21
21
  const controller = {
22
+ cancelDrag: () => {
23
+ runtime.cancelDrag();
24
+ },
22
25
  remeasureDropTargets: (input) => {
23
26
  runtime.remeasureDropTargets(input);
24
27
  },
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export { createDropContainer, type CreateDropContainerInput, } from "./droppable
5
5
  export { createSortable, type CreateSortableInput, } from "./sortable/create-sortable-binding.js";
6
6
  export type { SortableAxis, SortablePlacementBoundary, } from "./sortable/sortable-options.js";
7
7
  export { createDragHandle, type CreateDragHandleInput, } from "./input/create-drag-handle.js";
8
- export type { DragEndResult, DragEndEvent, DragLifecycleCallbacks, DragLifecycleHelpers, DragSource, DragStartEvent, DragUpdateEvent, DropEvent, } from "./runtime/lifecycle.js";
8
+ export type { DragEndResult, DragEndEvent, DragLifecycleCallbacks, DragLifecycleHelpers, DragSource, DragStartEvent, DragUpdateEvent, DropEvent, ActiveDragResetEvent, SortablePreview, } from "./runtime/lifecycle.js";
9
9
  export type { RemeasureDropTargetsInput, SortableDropPlacement, } from "./runtime/drop-target-registry.js";
10
10
  export type { OverlayReleaseMode } from "./runtime/types.js";
11
11
  export { centerToCenter, pointerToCenter, pointerToRectDistance, } from "./targeting/algorithms.js";
@@ -0,0 +1 @@
1
+ export declare const globalPointerListenerCapture = true;
@@ -0,0 +1,3 @@
1
+ // Global drag observation must not be blocked by application handlers that
2
+ // stop pointer events while the package owns the interaction.
3
+ export const globalPointerListenerCapture = true;
@@ -1,3 +1,4 @@
1
+ import { globalPointerListenerCapture } from "./global-pointer-listeners.js";
1
2
  export class PointerActivationController {
2
3
  options;
3
4
  pendingActivation = null;
@@ -54,13 +55,13 @@ export class PointerActivationController {
54
55
  }
55
56
  this.cancelPendingActivation();
56
57
  };
57
- window.addEventListener("pointermove", handlePointerMove);
58
- window.addEventListener("pointerup", handlePointerEnd);
59
- window.addEventListener("pointercancel", handlePointerEnd);
58
+ window.addEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
59
+ window.addEventListener("pointerup", handlePointerEnd, globalPointerListenerCapture);
60
+ window.addEventListener("pointercancel", handlePointerEnd, globalPointerListenerCapture);
60
61
  pendingActivation.releasePendingPointerListeners = () => {
61
- window.removeEventListener("pointermove", handlePointerMove);
62
- window.removeEventListener("pointerup", handlePointerEnd);
63
- window.removeEventListener("pointercancel", handlePointerEnd);
62
+ window.removeEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
63
+ window.removeEventListener("pointerup", handlePointerEnd, globalPointerListenerCapture);
64
+ window.removeEventListener("pointercancel", handlePointerEnd, globalPointerListenerCapture);
64
65
  };
65
66
  this.pendingActivation = pendingActivation;
66
67
  if (activationDelay !== null) {
@@ -1,6 +1,6 @@
1
1
  export { createDragRuntimeScope, type DragRuntimeScope, type DragRuntimeScopeConfigureInput, type DragRuntimeScopeOptions, } from "../runtime/drag-runtime-scope.js";
2
2
  export type { DragOverlayHostUpdate, DragOverlayPhase, DragOverlayRenderState, DragState, OverlayReleaseMode, } from "../runtime/types.js";
3
- export type { DragRuntimeSubscription } from "../runtime/lifecycle.js";
3
+ export type { ActiveDragResetEvent, DragRuntimeSubscription, SortablePreview, } from "../runtime/lifecycle.js";
4
4
  export { createDomDraggable, type CreateDomDraggableInput, type DomDraggableBehavior, type DomDraggableKeyDownEvent, type DomDraggablePointerDownEvent, type DomDraggableRuntime, } from "../draggable/create-draggable.js";
5
5
  export { createDomDroppable, type CreateDomDroppableInput, type DomDroppableBehavior, type DomDroppableRuntime, } from "../droppable/create-droppable.js";
6
6
  export { createDomDropContainer, type CreateDomDropContainerInput, type DomDropContainerBehavior, type DomDropContainerRuntime, } from "../droppable/create-drop-container.js";
@@ -4,6 +4,7 @@ import type { DomDropContainerRuntime } from "../droppable/create-drop-container
4
4
  import type { DomDroppableRuntime } from "../droppable/create-droppable.js";
5
5
  import type { DomSortableRuntime } from "../sortable/sortable-registry.js";
6
6
  import { type StaleDomBindingRecord } from "./drag-runtime.js";
7
+ import type { DragRuntimeSubscription } from "./lifecycle.js";
7
8
  import type { DragRuntimeConfigureInput, DragRuntimeOptions } from "./types.js";
8
9
  export type DragRuntimeScopeOptions = DragRuntimeOptions;
9
10
  export type DragRuntimeScopeConfigureInput = DragRuntimeConfigureInput;
@@ -13,6 +14,7 @@ export type DragRuntimeScope = DomDraggableRuntime & DomDroppableRuntime & DomDr
13
14
  releaseActiveDragResources: () => void;
14
15
  recomputeActiveDrag: () => void;
15
16
  setOverlayRect: (overlayRect: DragRect | null) => void;
17
+ subscribe: (subscription: DragRuntimeSubscription) => () => void;
16
18
  };
17
19
  export type InternalStaleDomBindingRuntime = {
18
20
  registerStaleDomBinding: (record: StaleDomBindingRecord) => () => void;
@@ -1,4 +1,5 @@
1
1
  import { DragRuntime } from "./drag-runtime.js";
2
+ import { linkSortableCoordinatorHost } from "./sortable-coordinator.js";
2
3
  export function createDragRuntimeScope(options) {
3
4
  const runtime = new DragRuntime(options);
4
5
  const scope = {
@@ -29,5 +30,6 @@ export function createDragRuntimeScope(options) {
29
30
  pruneDisconnectedDomBindings: () => runtime.pruneDisconnectedDomBindings(),
30
31
  getStaleDomBindingRecordCount: () => runtime.getStaleDomBindingRecordCount(),
31
32
  };
33
+ linkSortableCoordinatorHost(scope, runtime);
32
34
  return scope;
33
35
  }
@@ -18,6 +18,7 @@ export declare class DragRuntime {
18
18
  private activeDragModifiers;
19
19
  private releaseActiveInputListeners;
20
20
  private restoreTextSelectionSuppression;
21
+ private releasePostDragClickSuppression;
21
22
  private queuedPointerPosition;
22
23
  private pointerFrameId;
23
24
  private subscriptions;
@@ -70,6 +71,8 @@ export declare class DragRuntime {
70
71
  private releaseOverlayAfterDrag;
71
72
  private bindPointerWindowListeners;
72
73
  private bindKeyboardWindowListeners;
74
+ private suppressNextRelatedClick;
75
+ private clearPostDragClickSuppression;
73
76
  private suppressTextSelection;
74
77
  private resetActiveDragState;
75
78
  private releaseActiveInputResources;
@@ -81,6 +84,7 @@ export declare class DragRuntime {
81
84
  private getActiveInput;
82
85
  private getDraggingSession;
83
86
  private getDropEventSortablePlacement;
87
+ private getSortablePreview;
84
88
  private createDragState;
85
89
  private getLifecycleDropTargetRect;
86
90
  private createLifecycleDropTargetRectSnapshot;
@@ -90,7 +94,6 @@ export declare class DragRuntime {
90
94
  private getCurrentDragRectAt;
91
95
  private removeDisconnectedDropTargets;
92
96
  private pruneDisconnectedDomBindingRecords;
93
- private clearActiveDropTargetIdIfRemoved;
94
97
  private notifyDragStartSubscriptions;
95
98
  private notifyDragStartLifecycle;
96
99
  private notifyDragUpdate;
@@ -2,10 +2,12 @@ import { measureDomElement } from "../geometry/measurement.js";
2
2
  import { getOverlayMeasurement, getOverlayRect, } from "../geometry/overlay.js";
3
3
  import { defaultKeyboardConfiguration, normalizeKeyboardConfiguration, normalizePointerConfiguration, } from "../input/config.js";
4
4
  import { KeyboardDragController, } from "../input/keyboard-drag.js";
5
+ import { globalPointerListenerCapture } from "../input/global-pointer-listeners.js";
5
6
  import { PointerActivationController } from "../input/pointer-activation.js";
6
7
  import { applyDragModifiers, createActiveDragModifiers, } from "../modifiers/pipeline.js";
7
8
  import { getBuiltInTargetingAlgorithmKind, pointerToCenter, } from "../targeting/algorithms.js";
8
9
  import { DropTargetRegistry, } from "./drop-target-registry.js";
10
+ import { getSortableCoordinator } from "./sortable-coordinator.js";
9
11
  const noopUpdateOverlayHost = () => { };
10
12
  export class DragRuntime {
11
13
  isDragging = false;
@@ -18,6 +20,7 @@ export class DragRuntime {
18
20
  activeDragModifiers = [];
19
21
  releaseActiveInputListeners = null;
20
22
  restoreTextSelectionSuppression = null;
23
+ releasePostDragClickSuppression = null;
21
24
  queuedPointerPosition = null;
22
25
  pointerFrameId = null;
23
26
  subscriptions = new Set();
@@ -50,6 +53,7 @@ export class DragRuntime {
50
53
  group: request.group,
51
54
  inputType: "pointer",
52
55
  pointerId: request.pointerId,
56
+ element: request.element,
53
57
  pointerPosition: request.pointerPosition,
54
58
  sourceRect: measureDomElement(request.element),
55
59
  });
@@ -63,6 +67,7 @@ export class DragRuntime {
63
67
  group: activation.group,
64
68
  inputType: "pointer",
65
69
  pointerId: activation.pointerId,
70
+ element: activation.element,
66
71
  pointerPosition: activation.initialPointerPosition,
67
72
  sourceRect: measureDomElement(activation.element),
68
73
  });
@@ -109,6 +114,7 @@ export class DragRuntime {
109
114
  this.pointerConfiguration = normalizePointerConfiguration(input.pointerConfiguration);
110
115
  }
111
116
  requestDragStart(input) {
117
+ this.clearPostDragClickSuppression();
112
118
  this.pruneDisconnectedDomBindings();
113
119
  this.pointerActivation.request(input);
114
120
  }
@@ -218,25 +224,39 @@ export class DragRuntime {
218
224
  rawPointerPosition,
219
225
  pointerPosition,
220
226
  activeDropTargetId,
227
+ sortablePreview: session.sortablePreview,
221
228
  };
222
229
  this.setSession(nextSession);
223
230
  this.updateOverlayHost({
224
231
  type: "move",
225
232
  dragState: this.createDragState(nextSession),
226
233
  });
227
- const updateEvent = {
234
+ getSortableCoordinator(this)?.update({
228
235
  draggableId: nextSession.draggableId,
236
+ group: nextSession.group,
229
237
  source: nextSession.source,
230
238
  pointerPosition,
231
- overlayRect,
232
239
  activeDropTargetId: nextSession.activeDropTargetId,
233
- previousDropTargetId,
234
- };
235
- this.notifyDragUpdate(updateEvent, {
236
- ...updateEvent,
237
240
  placementPosition: sortablePlacementPosition,
238
241
  movementPosition: rawPointerPosition,
239
242
  });
243
+ const sortablePreview = this.getSortablePreview(nextSession);
244
+ const completedSession = {
245
+ ...nextSession,
246
+ sortablePreview,
247
+ };
248
+ this.setSession(completedSession);
249
+ const updateEvent = {
250
+ draggableId: completedSession.draggableId,
251
+ group: completedSession.group,
252
+ source: completedSession.source,
253
+ pointerPosition,
254
+ overlayRect,
255
+ activeDropTargetId: completedSession.activeDropTargetId,
256
+ previousDropTargetId,
257
+ sortablePreview,
258
+ };
259
+ this.notifyDragUpdate(updateEvent);
240
260
  }
241
261
  updatePointerNowOrRelease(rawPointerPosition) {
242
262
  try {
@@ -262,7 +282,8 @@ export class DragRuntime {
262
282
  });
263
283
  }
264
284
  cancelDrag() {
265
- this.finishDragAfterQueuedPointerUpdate({
285
+ this.cancelQueuedPointerUpdate();
286
+ this.finishDrag({
266
287
  reason: "cancel",
267
288
  overlayRelease: this.overlayRelease,
268
289
  });
@@ -271,23 +292,19 @@ export class DragRuntime {
271
292
  this.pointerActivation.cancelPendingActivation();
272
293
  }
273
294
  registerDropTarget(dropTargetId, element, group, options) {
274
- const removedTargets = this.dropTargetRegistry.register(dropTargetId, element, group, options);
275
- this.clearActiveDropTargetIdIfRemoved(removedTargets);
295
+ this.dropTargetRegistry.register(dropTargetId, element, group, options);
276
296
  }
277
297
  unregisterDropTarget(dropTargetId, element) {
278
- const removedTargets = this.dropTargetRegistry.unregister(dropTargetId, element);
279
- this.clearActiveDropTargetIdIfRemoved(removedTargets);
298
+ this.dropTargetRegistry.unregister(dropTargetId, element);
280
299
  }
281
300
  registerDropContainer(containerId, element, group) {
282
- const removedTargets = this.dropTargetRegistry.register(containerId, element, group, {
301
+ this.dropTargetRegistry.register(containerId, element, group, {
283
302
  containerId,
284
303
  container: true,
285
304
  });
286
- this.clearActiveDropTargetIdIfRemoved(removedTargets);
287
305
  }
288
306
  unregisterDropContainer(containerId, element) {
289
- const removedTargets = this.dropTargetRegistry.unregister(containerId, element);
290
- this.clearActiveDropTargetIdIfRemoved(removedTargets);
307
+ this.dropTargetRegistry.unregister(containerId, element);
291
308
  }
292
309
  releaseActiveDragResources() {
293
310
  const activeSession = this.getDraggingSession();
@@ -296,15 +313,28 @@ export class DragRuntime {
296
313
  let hasReleaseError = false;
297
314
  if (activeSession) {
298
315
  try {
299
- this.notifyActiveDragReset({
316
+ getSortableCoordinator(this)?.release({
300
317
  draggableId: activeSession.draggableId,
301
- source: activeSession.source,
318
+ group: activeSession.group,
302
319
  });
303
320
  }
304
321
  catch (error) {
305
322
  firstReleaseError = error;
306
323
  hasReleaseError = true;
307
324
  }
325
+ try {
326
+ this.notifyActiveDragReset({
327
+ draggableId: activeSession.draggableId,
328
+ group: activeSession.group,
329
+ source: activeSession.source,
330
+ });
331
+ }
332
+ catch (error) {
333
+ if (!hasReleaseError) {
334
+ firstReleaseError = error;
335
+ hasReleaseError = true;
336
+ }
337
+ }
308
338
  }
309
339
  this.resetActiveDragState();
310
340
  try {
@@ -323,6 +353,7 @@ export class DragRuntime {
323
353
  hasReleaseError = true;
324
354
  }
325
355
  }
356
+ this.clearPostDragClickSuppression();
326
357
  if (hasReleaseError) {
327
358
  throw firstReleaseError;
328
359
  }
@@ -345,9 +376,7 @@ export class DragRuntime {
345
376
  }
346
377
  getCurrentDragRect() {
347
378
  const session = this.getDraggingSession();
348
- return session
349
- ? this.getCurrentDragRectAt(session.pointerPosition)
350
- : null;
379
+ return session ? this.getCurrentDragRectAt(session.pointerPosition) : null;
351
380
  }
352
381
  setOverlayRect(overlayRect) {
353
382
  const session = this.getDraggingSession();
@@ -435,6 +464,11 @@ export class DragRuntime {
435
464
  });
436
465
  const sourceContainerId = this.dropTargetRegistry.getDropTargetRegistration(input.draggableId, input.group)?.containerId ?? null;
437
466
  const sourceSortablePlacement = this.dropTargetRegistry.getSortableItemPlacement(input.draggableId, input.group);
467
+ const sourceSortableRegistration = this.dropTargetRegistry.getDropTargetRegistration(input.draggableId, input.group);
468
+ const sourceSortableElement = sourceSortablePlacement &&
469
+ sourceSortableRegistration?.capabilities.sortable
470
+ ? sourceSortableRegistration.element
471
+ : null;
438
472
  const nextSession = {
439
473
  status: "dragging",
440
474
  source: input.inputType,
@@ -443,16 +477,19 @@ export class DragRuntime {
443
477
  sourceRect: input.sourceRect,
444
478
  sourceContainerId,
445
479
  sourceSortablePlacement,
480
+ sourceSortableElement,
446
481
  overlayMeasurement: null,
447
482
  startPointerPosition: rawPointerPosition,
448
483
  rawPointerPosition,
449
484
  pointerPosition: effectivePointerPosition,
450
485
  activeDropTargetId: null,
486
+ sortablePreview: { status: "inactive" },
451
487
  };
452
488
  this.setSession(nextSession);
453
489
  this.remeasureDropTargets({ group: input.group });
454
490
  const dragStartEvent = {
455
491
  draggableId: input.draggableId,
492
+ group: input.group,
456
493
  source: input.inputType,
457
494
  pointerPosition: effectivePointerPosition,
458
495
  sourceRect: input.sourceRect,
@@ -460,15 +497,16 @@ export class DragRuntime {
460
497
  const startOverlayRect = this.hasDragOverlay
461
498
  ? this.getCurrentDragRectAt(effectivePointerPosition)
462
499
  : null;
463
- const dragStartSubscriptionEvent = {
500
+ const placementPosition = this.getSortablePlacementPosition({
501
+ pointerPosition: effectivePointerPosition,
502
+ overlayRect: startOverlayRect,
503
+ });
504
+ getSortableCoordinator(this)?.start({
464
505
  ...dragStartEvent,
465
- placementPosition: this.getSortablePlacementPosition({
466
- pointerPosition: effectivePointerPosition,
467
- overlayRect: startOverlayRect,
468
- }),
506
+ placementPosition,
469
507
  movementPosition: rawPointerPosition,
470
- };
471
- this.notifyDragStartSubscriptions(dragStartSubscriptionEvent);
508
+ });
509
+ this.notifyDragStartSubscriptions(dragStartEvent);
472
510
  this.updateOverlayHost({
473
511
  type: "mount",
474
512
  state: {
@@ -478,7 +516,7 @@ export class DragRuntime {
478
516
  });
479
517
  this.suppressTextSelection();
480
518
  if (input.inputType === "pointer") {
481
- this.bindPointerWindowListeners(input.pointerId);
519
+ this.bindPointerWindowListeners(input.pointerId, input.element);
482
520
  }
483
521
  else {
484
522
  this.bindKeyboardWindowListeners();
@@ -492,9 +530,7 @@ export class DragRuntime {
492
530
  finishDrag(input) {
493
531
  this.cancelPendingActivation();
494
532
  const session = this.getDraggingSession();
495
- const releasedDragState = session
496
- ? this.createDragState(session)
497
- : null;
533
+ const releasedDragState = session ? this.createDragState(session) : null;
498
534
  const activeDropTargetId = input.reason === "drop" ? session?.activeDropTargetId ?? null : null;
499
535
  const validDropTarget = session && activeDropTargetId
500
536
  ? this.dropTargetRegistry.getDropTargetRegistration(activeDropTargetId, session.group)
@@ -513,7 +549,7 @@ export class DragRuntime {
513
549
  ? this.getCurrentDragRectAt(session.pointerPosition)
514
550
  : null;
515
551
  const sortablePlacement = session && dropTargetId
516
- ? this.getDropEventSortablePlacement(session, dropTargetId)
552
+ ? this.getDropEventSortablePlacement(session)
517
553
  : undefined;
518
554
  const lifecycleDropTargetRectSnapshot = session
519
555
  ? this.createLifecycleDropTargetRectSnapshot({
@@ -531,11 +567,26 @@ export class DragRuntime {
531
567
  finishError = error;
532
568
  hasFinishError = true;
533
569
  }
534
- if (session && result) {
570
+ if (session) {
571
+ try {
572
+ getSortableCoordinator(this)?.release({
573
+ draggableId: session.draggableId,
574
+ group: session.group,
575
+ });
576
+ }
577
+ catch (error) {
578
+ if (!hasFinishError) {
579
+ finishError = error;
580
+ hasFinishError = true;
581
+ }
582
+ }
583
+ }
584
+ if (session && result && !hasFinishError) {
535
585
  this.lifecycleDropTargetRectSnapshot = lifecycleDropTargetRectSnapshot;
536
586
  try {
537
587
  this.notifyDragEnd({
538
588
  draggableId: session.draggableId,
589
+ group: session.group,
539
590
  source: session.source,
540
591
  result,
541
592
  overlayRect,
@@ -544,6 +595,7 @@ export class DragRuntime {
544
595
  if (result === "dropped" && dropTargetId) {
545
596
  this.notifyDrop({
546
597
  draggableId: session.draggableId,
598
+ group: session.group,
547
599
  source: session.source,
548
600
  dropTargetId,
549
601
  ...(sortablePlacement ? { sortablePlacement } : {}),
@@ -601,7 +653,7 @@ export class DragRuntime {
601
653
  }
602
654
  this.clearOverlayHost();
603
655
  }
604
- bindPointerWindowListeners(pointerId) {
656
+ bindPointerWindowListeners(pointerId, initiatingElement) {
605
657
  this.releaseActiveInputListeners?.();
606
658
  let listenersReleased = false;
607
659
  const handlePointerMove = (event) => {
@@ -617,31 +669,71 @@ export class DragRuntime {
617
669
  if (event.pointerId !== pointerId) {
618
670
  return;
619
671
  }
620
- this.endDrag();
672
+ try {
673
+ this.endDrag();
674
+ this.suppressNextRelatedClick(initiatingElement);
675
+ }
676
+ catch (error) {
677
+ this.clearPostDragClickSuppression();
678
+ throw error;
679
+ }
621
680
  };
622
681
  const handlePointerCancel = (event) => {
623
682
  if (event.pointerId !== pointerId) {
624
683
  return;
625
684
  }
685
+ this.clearPostDragClickSuppression();
626
686
  this.cancelDrag();
627
687
  };
628
- window.addEventListener("pointermove", handlePointerMove);
629
- window.addEventListener("pointerup", handlePointerUp);
630
- window.addEventListener("pointercancel", handlePointerCancel);
688
+ window.addEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
689
+ window.addEventListener("pointerup", handlePointerUp, globalPointerListenerCapture);
690
+ window.addEventListener("pointercancel", handlePointerCancel, globalPointerListenerCapture);
631
691
  this.releaseActiveInputListeners = () => {
632
692
  if (listenersReleased) {
633
693
  return;
634
694
  }
635
695
  listenersReleased = true;
636
- window.removeEventListener("pointermove", handlePointerMove);
637
- window.removeEventListener("pointerup", handlePointerUp);
638
- window.removeEventListener("pointercancel", handlePointerCancel);
696
+ window.removeEventListener("pointermove", handlePointerMove, globalPointerListenerCapture);
697
+ window.removeEventListener("pointerup", handlePointerUp, globalPointerListenerCapture);
698
+ window.removeEventListener("pointercancel", handlePointerCancel, globalPointerListenerCapture);
639
699
  };
640
700
  }
641
701
  bindKeyboardWindowListeners() {
642
702
  this.releaseActiveInputListeners?.();
643
703
  this.releaseActiveInputListeners = this.keyboardDrag.bindWindowListeners();
644
704
  }
705
+ suppressNextRelatedClick(initiatingElement) {
706
+ this.clearPostDragClickSuppression();
707
+ let timeoutId = null;
708
+ const handleClick = (event) => {
709
+ if (event.detail === 0 ||
710
+ !(event.target instanceof Node) ||
711
+ !initiatingElement.contains(event.target)) {
712
+ return;
713
+ }
714
+ this.clearPostDragClickSuppression();
715
+ event.preventDefault();
716
+ event.stopImmediatePropagation();
717
+ };
718
+ const release = () => {
719
+ window.removeEventListener("click", handleClick, true);
720
+ if (timeoutId !== null) {
721
+ window.clearTimeout(timeoutId);
722
+ timeoutId = null;
723
+ }
724
+ if (this.releasePostDragClickSuppression === release) {
725
+ this.releasePostDragClickSuppression = null;
726
+ }
727
+ };
728
+ window.addEventListener("click", handleClick, true);
729
+ this.releasePostDragClickSuppression = release;
730
+ timeoutId = window.setTimeout(release, 0);
731
+ }
732
+ clearPostDragClickSuppression() {
733
+ const release = this.releasePostDragClickSuppression;
734
+ this.releasePostDragClickSuppression = null;
735
+ release?.();
736
+ }
645
737
  suppressTextSelection() {
646
738
  this.restoreTextSelectionSuppression?.();
647
739
  const root = document.documentElement;
@@ -733,18 +825,41 @@ export class DragRuntime {
733
825
  getDraggingSession() {
734
826
  return this.session.status === "dragging" ? this.session : null;
735
827
  }
736
- getDropEventSortablePlacement(session, dropTargetId) {
737
- const placement = this.dropTargetRegistry.getSortableDropPlacement({
828
+ getDropEventSortablePlacement(session) {
829
+ const preview = this.getSortablePreview(session);
830
+ return preview.status === "projected" ? preview.placement : undefined;
831
+ }
832
+ getSortablePreview(session) {
833
+ const currentRegistration = this.dropTargetRegistry.getDropTargetRegistration(session.draggableId, session.group);
834
+ if (!session.sourceSortablePlacement ||
835
+ !session.sourceSortableElement ||
836
+ !currentRegistration?.capabilities.sortable ||
837
+ currentRegistration.element !== session.sourceSortableElement) {
838
+ return { status: "inactive" };
839
+ }
840
+ const placement = this.dropTargetRegistry.normalizeSortablePlacement({
738
841
  draggableId: session.draggableId,
739
- dropTargetId,
842
+ activeDropTargetId: session.activeDropTargetId,
740
843
  group: session.group,
741
844
  sourceContainerId: session.sourceContainerId,
742
845
  });
743
- if (!placement ||
744
- isSameSortablePlacement(placement, session.sourceSortablePlacement)) {
745
- return undefined;
846
+ if (!placement) {
847
+ return { status: "inactive" };
848
+ }
849
+ if (isSameSortableLocation(placement, session.sourceSortablePlacement)) {
850
+ return {
851
+ status: "source",
852
+ placement: {
853
+ sourceContainerId: session.sourceContainerId,
854
+ containerId: session.sourceContainerId,
855
+ previousDraggableId: session.sourceSortablePlacement.previousDraggableId,
856
+ nextDraggableId: session.sourceSortablePlacement.nextDraggableId,
857
+ targetDraggableId: null,
858
+ side: null,
859
+ },
860
+ };
746
861
  }
747
- return placement;
862
+ return { status: "projected", placement };
748
863
  }
749
864
  createDragState(session) {
750
865
  return {
@@ -826,8 +941,7 @@ export class DragRuntime {
826
941
  });
827
942
  }
828
943
  removeDisconnectedDropTargets(group) {
829
- const removedTargets = this.dropTargetRegistry.pruneDisconnected(group);
830
- this.clearActiveDropTargetIdIfRemoved(removedTargets);
944
+ this.dropTargetRegistry.pruneDisconnected(group);
831
945
  }
832
946
  pruneDisconnectedDomBindingRecords(skipRecord) {
833
947
  for (const storedRecord of Array.from(this.staleDomBindingRecords)) {
@@ -845,21 +959,6 @@ export class DragRuntime {
845
959
  storedRecord.record.release();
846
960
  }
847
961
  }
848
- clearActiveDropTargetIdIfRemoved(removedTargets) {
849
- if (this.session.status !== "dragging") {
850
- return;
851
- }
852
- const session = this.session;
853
- const removedActiveTarget = removedTargets.some((removedTarget) => removedTarget.id === session.activeDropTargetId &&
854
- removedTarget.group === session.group);
855
- if (!removedActiveTarget) {
856
- return;
857
- }
858
- this.setSession({
859
- ...session,
860
- activeDropTargetId: null,
861
- });
862
- }
863
962
  notifyDragStartSubscriptions(subscriptionEvent) {
864
963
  for (const subscription of Array.from(this.subscriptions)) {
865
964
  subscription.onDragStart?.(subscriptionEvent);
@@ -868,9 +967,9 @@ export class DragRuntime {
868
967
  notifyDragStartLifecycle(event) {
869
968
  this.lifecycleCallbacks.onDragStart?.(event, this.lifecycleHelpers);
870
969
  }
871
- notifyDragUpdate(event, subscriptionEvent) {
970
+ notifyDragUpdate(event) {
872
971
  for (const subscription of Array.from(this.subscriptions)) {
873
- subscription.onDragUpdate?.(subscriptionEvent);
972
+ subscription.onDragUpdate?.(event);
874
973
  }
875
974
  this.lifecycleCallbacks.onDragUpdate?.(event, this.lifecycleHelpers);
876
975
  }
@@ -916,16 +1015,9 @@ function getRectCenter(rect) {
916
1015
  export function createDragRuntime(options) {
917
1016
  return new DragRuntime(options);
918
1017
  }
919
- function isSameSortablePlacement(placement, sourcePlacement) {
920
- if (sourcePlacement === null ||
1018
+ function isSameSortableLocation(placement, sourcePlacement) {
1019
+ return !(sourcePlacement === null ||
921
1020
  placement.containerId !== sourcePlacement.containerId ||
922
1021
  placement.previousDraggableId !== sourcePlacement.previousDraggableId ||
923
- placement.nextDraggableId !== sourcePlacement.nextDraggableId) {
924
- return false;
925
- }
926
- if (placement.targetDraggableId === null || placement.side === null) {
927
- return true;
928
- }
929
- return sourcePlacement.exactAnchors.some((anchor) => anchor.targetDraggableId === placement.targetDraggableId &&
930
- anchor.side === placement.side);
1022
+ placement.nextDraggableId !== sourcePlacement.nextDraggableId);
931
1023
  }
@@ -41,13 +41,8 @@ export type SortableItemPlacement = {
41
41
  containerId: string | null;
42
42
  previousDraggableId: string | null;
43
43
  nextDraggableId: string | null;
44
- exactAnchors: readonly SortablePlacementAnchor[];
45
44
  };
46
45
  export type SortablePlacementSide = "before" | "after";
47
- export type SortablePlacementAnchor = {
48
- targetDraggableId: string;
49
- side: SortablePlacementSide;
50
- };
51
46
  export type SortableDropPlacement = {
52
47
  sourceContainerId: string | null;
53
48
  containerId: string | null;
@@ -69,9 +64,9 @@ export declare class DropTargetRegistry {
69
64
  getDropTargetRegistration(id: string, group?: DragGroup): DropTargetRegistration | null;
70
65
  getAvailableDropTargets(input: GetAvailableDropTargetsInput): DropTarget[];
71
66
  private getAvailableDropTargetsFromEntries;
72
- getSortableDropPlacement(input: {
67
+ normalizeSortablePlacement(input: {
73
68
  draggableId: string;
74
- dropTargetId: string | null;
69
+ activeDropTargetId: string | null;
75
70
  group: DragGroup | null;
76
71
  sourceContainerId: string | null;
77
72
  }): SortableDropPlacement | null;
@@ -91,9 +86,7 @@ export declare class DropTargetRegistry {
91
86
  private syncSortableAxisIndexAfterRegister;
92
87
  private addSortableDomNeighborCandidates;
93
88
  private findContainerRegistrationForElement;
94
- private getSiblingPlacement;
95
- private getTargetPlacement;
96
- private getExactSortableItemAnchors;
89
+ private getNormalizedTargetPlacement;
97
90
  private getPreviewDomTargetPlacement;
98
91
  private isSkippedSortableSibling;
99
92
  private getNearestSortableSiblingDraggableId;