@dnd-kit/abstract 0.0.1

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/index.cjs ADDED
@@ -0,0 +1,928 @@
1
+ 'use strict';
2
+
3
+ var state = require('@dnd-kit/state');
4
+ var geometry = require('@dnd-kit/geometry');
5
+
6
+ var __defProp = Object.defineProperty;
7
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
8
+ var __decorateClass = (decorators, target, key, kind) => {
9
+ var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
10
+ for (var i = decorators.length - 1, decorator; i >= 0; i--)
11
+ if (decorator = decorators[i])
12
+ result = (kind ? decorator(target, key, result) : decorator(result)) || result;
13
+ if (kind && result)
14
+ __defProp(target, key, result);
15
+ return result;
16
+ };
17
+
18
+ // src/core/plugins/utilities.ts
19
+ function configure(plugin, options) {
20
+ return {
21
+ plugin,
22
+ options
23
+ };
24
+ }
25
+ function configurator(plugin) {
26
+ return (options) => {
27
+ return configure(plugin, options);
28
+ };
29
+ }
30
+ function descriptor(plugin) {
31
+ if (typeof plugin === "function") {
32
+ return {
33
+ plugin,
34
+ options: void 0
35
+ };
36
+ }
37
+ return plugin;
38
+ }
39
+
40
+ // src/core/plugins/plugin.ts
41
+ var Plugin = class {
42
+ constructor(manager, options) {
43
+ this.manager = manager;
44
+ this.options = options;
45
+ }
46
+ disabled = false;
47
+ /**
48
+ * Enable a disabled plugin instance.
49
+ * Triggers effects.
50
+ */
51
+ enable() {
52
+ this.disabled = false;
53
+ }
54
+ /**
55
+ * Disable an enabled plugin instance.
56
+ * Triggers effects.
57
+ */
58
+ disable() {
59
+ this.disabled = true;
60
+ }
61
+ /**
62
+ * Whether the plugin instance is disabled.
63
+ * Does not trigger effects when accessed.
64
+ */
65
+ isDisabled() {
66
+ return state.untracked(() => {
67
+ return this.disabled;
68
+ });
69
+ }
70
+ /**
71
+ * Configure a plugin instance with new options.
72
+ */
73
+ configure(options) {
74
+ this.options = options;
75
+ }
76
+ /**
77
+ * Destroy a plugin instance.
78
+ */
79
+ destroy() {
80
+ }
81
+ /**
82
+ * Configure a plugin constructor with options.
83
+ * This method is used to configure the options that the
84
+ * plugin constructor will use to create plugin instances.
85
+ */
86
+ static configure(options) {
87
+ return configure(this, options);
88
+ }
89
+ };
90
+ __decorateClass([
91
+ state.reactive
92
+ ], Plugin.prototype, "disabled", 2);
93
+ var CorePlugin = class extends Plugin {
94
+ };
95
+
96
+ // src/core/plugins/registry.ts
97
+ var PluginRegistry = class {
98
+ constructor(manager) {
99
+ this.manager = manager;
100
+ }
101
+ instances = /* @__PURE__ */ new Map();
102
+ get values() {
103
+ return Array.from(this.instances.values());
104
+ }
105
+ #previousValues = [];
106
+ set values(entries) {
107
+ const descriptos = entries.map(descriptor);
108
+ const constructors = descriptos.map(({ plugin }) => plugin);
109
+ for (const plugin of this.#previousValues) {
110
+ if (!constructors.includes(plugin)) {
111
+ if (plugin.prototype instanceof CorePlugin) {
112
+ continue;
113
+ }
114
+ this.unregister(plugin);
115
+ }
116
+ }
117
+ for (const { plugin, options } of descriptos) {
118
+ this.register(plugin, options);
119
+ }
120
+ this.#previousValues = constructors;
121
+ }
122
+ get(plugin) {
123
+ const instance = this.instances.get(plugin);
124
+ return instance;
125
+ }
126
+ register(plugin, options) {
127
+ const existingInstance = this.instances.get(plugin);
128
+ if (existingInstance) {
129
+ return existingInstance;
130
+ }
131
+ const instance = new plugin(this.manager, options);
132
+ this.instances.set(plugin, instance);
133
+ return instance;
134
+ }
135
+ unregister(plugin) {
136
+ const instance = this.instances.get(plugin);
137
+ if (instance) {
138
+ instance.destroy();
139
+ this.instances.delete(plugin);
140
+ }
141
+ }
142
+ destroy() {
143
+ for (const plugin of this.instances.values()) {
144
+ plugin.destroy();
145
+ }
146
+ this.instances.clear();
147
+ }
148
+ };
149
+
150
+ // src/core/collision/utilities.ts
151
+ function sortCollisions(a, b) {
152
+ if (a.priority === b.priority) {
153
+ return b.value - a.value;
154
+ }
155
+ return b.priority - a.priority;
156
+ }
157
+
158
+ // src/core/collision/observer.ts
159
+ var DEFAULT_VALUE = [];
160
+ var CollisionObserver = class extends Plugin {
161
+ constructor(manager) {
162
+ super(manager);
163
+ this.computeCollisions = this.computeCollisions.bind(this);
164
+ this.#collisions = state.computed(this.computeCollisions, state.deepEqual);
165
+ this.destroy = state.effect(() => {
166
+ const { dragOperation } = this.manager;
167
+ if (dragOperation.status.initialized) {
168
+ this.forceUpdate();
169
+ }
170
+ });
171
+ }
172
+ forceUpdateCount = state.signal(0);
173
+ forceUpdate(refresh = true) {
174
+ state.untracked(() => {
175
+ const { source } = this.manager.dragOperation;
176
+ state.batch(() => {
177
+ if (refresh) {
178
+ for (const droppable of this.manager.registry.droppables) {
179
+ if (source && !droppable.accepts(source)) {
180
+ continue;
181
+ }
182
+ droppable.refreshShape();
183
+ }
184
+ }
185
+ this.forceUpdateCount.value++;
186
+ });
187
+ });
188
+ }
189
+ computeCollisions(entries, collisionDetector) {
190
+ const { registry, dragOperation } = this.manager;
191
+ const { source, shape, status } = dragOperation;
192
+ if (!status.initialized || !shape) {
193
+ return DEFAULT_VALUE;
194
+ }
195
+ const collisions = [];
196
+ this.forceUpdateCount.value;
197
+ for (const entry of entries ?? registry.droppables) {
198
+ if (entry.disabled) {
199
+ continue;
200
+ }
201
+ if (source && !entry.accepts(source)) {
202
+ continue;
203
+ }
204
+ const detectCollision = collisionDetector ?? entry.collisionDetector;
205
+ if (!detectCollision) {
206
+ continue;
207
+ }
208
+ const collision = state.untracked(
209
+ () => detectCollision({
210
+ droppable: entry,
211
+ dragOperation
212
+ })
213
+ );
214
+ if (collision) {
215
+ if (entry.collisionPriority != null) {
216
+ collision.priority = entry.collisionPriority;
217
+ }
218
+ collisions.push(collision);
219
+ }
220
+ }
221
+ collisions.sort(sortCollisions);
222
+ return collisions;
223
+ }
224
+ get collisions() {
225
+ return this.#collisions.value;
226
+ }
227
+ #collisions;
228
+ };
229
+
230
+ // src/core/manager/events.ts
231
+ var Monitor = class {
232
+ registry = /* @__PURE__ */ new Map();
233
+ addEventListener(name, handler) {
234
+ const { registry } = this;
235
+ const listeners = new Set(registry.get(name));
236
+ listeners.add(handler);
237
+ registry.set(name, listeners);
238
+ return () => this.removeEventListener(name, handler);
239
+ }
240
+ removeEventListener(name, handler) {
241
+ const { registry } = this;
242
+ const listeners = new Set(registry.get(name));
243
+ listeners.delete(handler);
244
+ registry.set(name, listeners);
245
+ }
246
+ dispatch(name, ...args) {
247
+ const { registry } = this;
248
+ const listeners = registry.get(name);
249
+ if (!listeners) {
250
+ return;
251
+ }
252
+ for (const listener of listeners) {
253
+ listener(...args);
254
+ }
255
+ }
256
+ };
257
+ var DragDropMonitor = class extends Monitor {
258
+ constructor(manager) {
259
+ super();
260
+ this.manager = manager;
261
+ }
262
+ dispatch(type, event) {
263
+ const args = [event, this.manager];
264
+ super.dispatch(type, ...args);
265
+ }
266
+ };
267
+ function defaultPreventable(event, cancelable = true) {
268
+ let defaultPrevented = false;
269
+ return {
270
+ ...event,
271
+ cancelable,
272
+ get defaultPrevented() {
273
+ return defaultPrevented;
274
+ },
275
+ preventDefault() {
276
+ if (!cancelable) {
277
+ return;
278
+ }
279
+ defaultPrevented = true;
280
+ }
281
+ };
282
+ }
283
+
284
+ // src/core/collision/notifier.ts
285
+ var CollisionNotifier = class extends CorePlugin {
286
+ constructor(manager) {
287
+ super(manager);
288
+ this.destroy = state.effect(() => {
289
+ const { collisionObserver, monitor } = manager;
290
+ const { collisions } = collisionObserver;
291
+ if (collisionObserver.isDisabled()) {
292
+ return;
293
+ }
294
+ const event = defaultPreventable({
295
+ collisions
296
+ });
297
+ monitor.dispatch("collision", event);
298
+ if (event.defaultPrevented) {
299
+ return;
300
+ }
301
+ const [firstCollision] = collisions;
302
+ state.untracked(() => {
303
+ if (firstCollision?.id !== manager.dragOperation.target?.id) {
304
+ collisionObserver.disable();
305
+ manager.actions.setDropTarget(firstCollision?.id).then(() => {
306
+ collisionObserver.enable();
307
+ });
308
+ }
309
+ });
310
+ });
311
+ }
312
+ };
313
+
314
+ // src/core/collision/types.ts
315
+ var CollisionPriority = /* @__PURE__ */ ((CollisionPriority2) => {
316
+ CollisionPriority2[CollisionPriority2["Lowest"] = 0] = "Lowest";
317
+ CollisionPriority2[CollisionPriority2["Low"] = 1] = "Low";
318
+ CollisionPriority2[CollisionPriority2["Normal"] = 2] = "Normal";
319
+ CollisionPriority2[CollisionPriority2["High"] = 3] = "High";
320
+ CollisionPriority2[CollisionPriority2["Highest"] = 4] = "Highest";
321
+ return CollisionPriority2;
322
+ })(CollisionPriority || {});
323
+ var Entity = class {
324
+ /**
325
+ * Creates a new instance of the `Entity` class.
326
+ *
327
+ * @param input - An object containing the initial properties of the entity.
328
+ * @param manager - The manager that controls the drag and drop operations.
329
+ */
330
+ constructor(input, manager) {
331
+ this.manager = manager;
332
+ const { effects: getInputEffects, id, data = null, disabled = false } = input;
333
+ this.id = id;
334
+ this.data = data;
335
+ this.disabled = disabled;
336
+ queueMicrotask(() => {
337
+ const inputEffects = getInputEffects?.(this) ?? [];
338
+ this.destroy = state.effects(
339
+ () => {
340
+ manager.registry.register(this);
341
+ return () => manager.registry.unregister(this);
342
+ },
343
+ ...inputEffects
344
+ );
345
+ });
346
+ }
347
+ id;
348
+ data;
349
+ disabled;
350
+ /**
351
+ * A method that cleans up the entity when it is no longer needed.
352
+ * @returns void
353
+ */
354
+ destroy() {
355
+ }
356
+ };
357
+ __decorateClass([
358
+ state.reactive
359
+ ], Entity.prototype, "id", 2);
360
+ __decorateClass([
361
+ state.reactive
362
+ ], Entity.prototype, "data", 2);
363
+ __decorateClass([
364
+ state.reactive
365
+ ], Entity.prototype, "disabled", 2);
366
+ var EntityRegistry = class {
367
+ map = state.signal(/* @__PURE__ */ new Map());
368
+ /**
369
+ * Iterator for the EntityRegistry class.
370
+ * @returns An iterator for the values in the map.
371
+ */
372
+ [Symbol.iterator]() {
373
+ return this.map.peek().values();
374
+ }
375
+ get value() {
376
+ return this.map.value.values();
377
+ }
378
+ /**
379
+ * Checks if a entity with the given identifier exists in the registry.
380
+ * @param identifier - The unique identifier of the entity.
381
+ * @returns True if the entity exists, false otherwise.
382
+ */
383
+ has(identifier) {
384
+ return this.map.value.has(identifier);
385
+ }
386
+ /**
387
+ * Retrieves a entity from the registry using its identifier.
388
+ * @param identifier - The unique identifier of the entity.
389
+ * @returns The entity if it exists, undefined otherwise.
390
+ */
391
+ get(identifier) {
392
+ return this.map.value.get(identifier);
393
+ }
394
+ /**
395
+ * Registers a entity in the registry.
396
+ * @param key - The unique identifier of the entity.
397
+ * @param value - The entity to register.
398
+ * @returns A function that unregisters the entity.
399
+ */
400
+ register = (key, value) => {
401
+ const current = this.map.peek();
402
+ if (current.get(key) === value) {
403
+ return;
404
+ }
405
+ const updatedMap = new Map(current);
406
+ updatedMap.set(key, value);
407
+ this.map.value = updatedMap;
408
+ return () => this.unregister(key, value);
409
+ };
410
+ /**
411
+ * Unregisters an entity from the registry.
412
+ * @param key - The unique identifier of the entity.
413
+ * @param value - The entity instance to unregister.
414
+ */
415
+ unregister = (key, value) => {
416
+ const current = this.map.peek();
417
+ if (current.get(key) !== value) {
418
+ return;
419
+ }
420
+ const updatedMap = new Map(current);
421
+ updatedMap.delete(key);
422
+ this.map.value = updatedMap;
423
+ };
424
+ /**
425
+ * Destroys all entries in the registry and clears the registry.
426
+ */
427
+ destroy() {
428
+ for (const entry of this) {
429
+ entry.destroy();
430
+ }
431
+ this.map.value = /* @__PURE__ */ new Map();
432
+ }
433
+ };
434
+ var Draggable = class extends Entity {
435
+ constructor({ modifiers, type, ...input }, manager) {
436
+ super(input, manager);
437
+ this.manager = manager;
438
+ this.type = type;
439
+ if (modifiers?.length) {
440
+ this.modifiers = modifiers.map((modifier) => {
441
+ const { plugin, options } = descriptor(modifier);
442
+ return new plugin(manager, options);
443
+ });
444
+ }
445
+ }
446
+ modifiers;
447
+ type;
448
+ get isDragSource() {
449
+ const { dragOperation } = this.manager;
450
+ return dragOperation.source?.id === this.id;
451
+ }
452
+ };
453
+ __decorateClass([
454
+ state.reactive
455
+ ], Draggable.prototype, "type", 2);
456
+ __decorateClass([
457
+ state.derived
458
+ ], Draggable.prototype, "isDragSource", 1);
459
+ var Droppable = class extends Entity {
460
+ constructor({
461
+ accept,
462
+ collisionDetector,
463
+ collisionPriority = 2 /* Normal */,
464
+ type,
465
+ ...input
466
+ }, manager) {
467
+ super(input, manager);
468
+ this.manager = manager;
469
+ this.accept = accept;
470
+ this.collisionDetector = collisionDetector;
471
+ this.collisionPriority = collisionPriority;
472
+ this.type = type;
473
+ }
474
+ accept;
475
+ type;
476
+ /**
477
+ * Checks whether or not the droppable accepts a given draggable.
478
+ *
479
+ * @param {Draggable} draggable
480
+ * @returns {boolean}
481
+ */
482
+ accepts(draggable) {
483
+ const { accept } = this;
484
+ if (!accept) {
485
+ return true;
486
+ }
487
+ if (!draggable.type) {
488
+ return false;
489
+ }
490
+ if (Array.isArray(accept)) {
491
+ return accept.includes(draggable.type);
492
+ }
493
+ if (typeof accept === "function") {
494
+ return accept(draggable);
495
+ }
496
+ return draggable.type === accept;
497
+ }
498
+ collisionDetector;
499
+ collisionPriority;
500
+ shape;
501
+ get isDropTarget() {
502
+ return this.manager.dragOperation.target?.id === this.id;
503
+ }
504
+ refreshShape() {
505
+ }
506
+ };
507
+ __decorateClass([
508
+ state.reactive
509
+ ], Droppable.prototype, "accept", 2);
510
+ __decorateClass([
511
+ state.reactive
512
+ ], Droppable.prototype, "type", 2);
513
+ __decorateClass([
514
+ state.reactive
515
+ ], Droppable.prototype, "collisionDetector", 2);
516
+ __decorateClass([
517
+ state.reactive
518
+ ], Droppable.prototype, "collisionPriority", 2);
519
+ __decorateClass([
520
+ state.reactive
521
+ ], Droppable.prototype, "shape", 2);
522
+ __decorateClass([
523
+ state.derived
524
+ ], Droppable.prototype, "isDropTarget", 1);
525
+
526
+ // src/core/sensors/sensor.ts
527
+ var Sensor = class extends Plugin {
528
+ constructor(manager, options) {
529
+ super(manager, options);
530
+ this.manager = manager;
531
+ this.options = options;
532
+ }
533
+ };
534
+
535
+ // src/core/modifiers/modifier.ts
536
+ var Modifier = class extends Plugin {
537
+ constructor(manager, options) {
538
+ super(manager, options);
539
+ this.manager = manager;
540
+ this.options = options;
541
+ }
542
+ apply(operation) {
543
+ return operation.transform;
544
+ }
545
+ };
546
+
547
+ // src/core/manager/registry.ts
548
+ var DragDropRegistry = class {
549
+ constructor(manager) {
550
+ this.plugins = new PluginRegistry(manager);
551
+ this.sensors = new PluginRegistry(manager);
552
+ this.modifiers = new PluginRegistry(manager);
553
+ }
554
+ draggables = new EntityRegistry();
555
+ droppables = new EntityRegistry();
556
+ plugins;
557
+ sensors;
558
+ modifiers;
559
+ register(input, options) {
560
+ if (input instanceof Draggable) {
561
+ return this.draggables.register(input.id, input);
562
+ }
563
+ if (input instanceof Droppable) {
564
+ return this.droppables.register(input.id, input);
565
+ }
566
+ if (input.prototype instanceof Modifier) {
567
+ return this.modifiers.register(input, options);
568
+ }
569
+ if (input.prototype instanceof Sensor) {
570
+ return this.sensors.register(input, options);
571
+ }
572
+ if (input.prototype instanceof Plugin) {
573
+ return this.plugins.register(input, options);
574
+ }
575
+ throw new Error("Invalid instance type");
576
+ }
577
+ unregister(input) {
578
+ if (input instanceof Entity) {
579
+ if (input instanceof Draggable) {
580
+ return this.draggables.unregister(input.id, input);
581
+ }
582
+ if (input instanceof Droppable) {
583
+ return this.droppables.unregister(input.id, input);
584
+ }
585
+ return () => {
586
+ };
587
+ }
588
+ if (input.prototype instanceof Modifier) {
589
+ return this.modifiers.unregister(input);
590
+ }
591
+ if (input.prototype instanceof Sensor) {
592
+ return this.sensors.unregister(input);
593
+ }
594
+ if (input.prototype instanceof Plugin) {
595
+ return this.plugins.unregister(input);
596
+ }
597
+ throw new Error("Invalid instance type");
598
+ }
599
+ destroy() {
600
+ this.draggables.destroy();
601
+ this.droppables.destroy();
602
+ this.plugins.destroy();
603
+ this.sensors.destroy();
604
+ this.modifiers.destroy();
605
+ }
606
+ };
607
+ var Status = /* @__PURE__ */ ((Status2) => {
608
+ Status2["Idle"] = "idle";
609
+ Status2["Initializing"] = "initializing";
610
+ Status2["Dragging"] = "dragging";
611
+ Status2["Dropping"] = "dropping";
612
+ return Status2;
613
+ })(Status || {});
614
+ function DragOperationManager(manager) {
615
+ const {
616
+ registry: { draggables, droppables },
617
+ monitor
618
+ } = manager;
619
+ const status = state.signal("idle" /* Idle */);
620
+ const shape = {
621
+ initial: state.signal(null),
622
+ current: state.signal(null)
623
+ };
624
+ const canceled = state.signal(false);
625
+ const position = new geometry.Position({ x: 0, y: 0 });
626
+ const activatorEvent = state.signal(null);
627
+ const sourceIdentifier = state.signal(null);
628
+ const targetIdentifier = state.signal(null);
629
+ const dragging = state.computed(() => status.value === "dragging" /* Dragging */);
630
+ const initialized = state.computed(() => status.value !== "idle" /* Idle */);
631
+ const initializing = state.computed(() => status.value === "initializing" /* Initializing */);
632
+ const idle = state.computed(() => status.value === "idle" /* Idle */);
633
+ const dropping = state.computed(() => status.value === "dropping" /* Dropping */);
634
+ let previousSource;
635
+ const source = state.computed(() => {
636
+ const identifier = sourceIdentifier.value;
637
+ if (identifier == null)
638
+ return null;
639
+ const value = draggables.get(identifier);
640
+ if (value) {
641
+ previousSource = value;
642
+ }
643
+ return value ?? previousSource ?? null;
644
+ });
645
+ const target = state.computed(() => {
646
+ const identifier = targetIdentifier.value;
647
+ return identifier != null ? droppables.get(identifier) ?? null : null;
648
+ });
649
+ const transform = state.computed(() => {
650
+ const { x, y } = position.delta;
651
+ const modifiers = source?.value?.modifiers ?? manager.modifiers;
652
+ let transform2 = { x, y };
653
+ const initialShape = shape.initial.peek();
654
+ const currentShape = shape.current.peek();
655
+ const operation2 = {
656
+ activatorEvent: activatorEvent.peek(),
657
+ canceled: canceled.peek(),
658
+ source: source.peek(),
659
+ target: target.peek(),
660
+ status: {
661
+ current: status.peek(),
662
+ idle: idle.peek(),
663
+ initializing: initializing.peek(),
664
+ initialized: initialized.peek(),
665
+ dragging: dragging.peek(),
666
+ dropping: dropping.peek()
667
+ },
668
+ shape: initialShape && currentShape ? { initial: initialShape, current: currentShape } : null,
669
+ position
670
+ };
671
+ for (const modifier of modifiers) {
672
+ transform2 = modifier.apply({ ...operation2, transform: transform2 });
673
+ }
674
+ return transform2;
675
+ });
676
+ const operation = {
677
+ get activatorEvent() {
678
+ return activatorEvent.value;
679
+ },
680
+ get canceled() {
681
+ return canceled.value;
682
+ },
683
+ get source() {
684
+ return source.value;
685
+ },
686
+ get target() {
687
+ return target.value;
688
+ },
689
+ status: {
690
+ get current() {
691
+ return status.value;
692
+ },
693
+ get idle() {
694
+ return idle.value;
695
+ },
696
+ get initializing() {
697
+ return initializing.value;
698
+ },
699
+ get initialized() {
700
+ return initialized.value;
701
+ },
702
+ get dragging() {
703
+ return dragging.value;
704
+ },
705
+ get dropping() {
706
+ return dropping.value;
707
+ }
708
+ },
709
+ get shape() {
710
+ const initial = shape.initial.value;
711
+ const current = shape.current.value;
712
+ return initial && current ? { initial, current } : null;
713
+ },
714
+ set shape(value) {
715
+ if (value && shape.current.peek()?.equals(value)) {
716
+ return;
717
+ }
718
+ const initial = shape.initial.peek();
719
+ if (!initial) {
720
+ shape.initial.value = value;
721
+ }
722
+ shape.current.value = value;
723
+ },
724
+ get transform() {
725
+ return transform.value;
726
+ },
727
+ position
728
+ };
729
+ const reset = () => {
730
+ state.batch(() => {
731
+ status.value = "idle" /* Idle */;
732
+ sourceIdentifier.value = null;
733
+ targetIdentifier.value = null;
734
+ shape.current.value = null;
735
+ shape.initial.value = null;
736
+ position.reset({ x: 0, y: 0 });
737
+ });
738
+ };
739
+ return {
740
+ operation,
741
+ actions: {
742
+ setDragSource(identifier) {
743
+ sourceIdentifier.value = identifier;
744
+ },
745
+ setDropTarget(identifier) {
746
+ const id = identifier ?? null;
747
+ if (targetIdentifier.peek() === id) {
748
+ return Promise.resolve();
749
+ }
750
+ targetIdentifier.value = id;
751
+ monitor.dispatch(
752
+ "dragover",
753
+ defaultPreventable({
754
+ operation: snapshot(operation)
755
+ })
756
+ );
757
+ return manager.renderer.rendering;
758
+ },
759
+ start({ event, coordinates }) {
760
+ state.batch(() => {
761
+ canceled.value = false;
762
+ activatorEvent.value = event;
763
+ position.reset(coordinates);
764
+ });
765
+ const beforeStartEvent = defaultPreventable({
766
+ operation: snapshot(operation)
767
+ });
768
+ monitor.dispatch("beforedragstart", beforeStartEvent);
769
+ manager.renderer.rendering.then(() => {
770
+ if (beforeStartEvent.defaultPrevented) {
771
+ reset();
772
+ return;
773
+ }
774
+ status.value = "initializing" /* Initializing */;
775
+ requestAnimationFrame(() => {
776
+ status.value = "dragging" /* Dragging */;
777
+ monitor.dispatch("dragstart", {
778
+ operation: snapshot(operation),
779
+ cancelable: false
780
+ });
781
+ });
782
+ });
783
+ },
784
+ move({
785
+ by,
786
+ to,
787
+ cancelable = true
788
+ }) {
789
+ if (!dragging.peek()) {
790
+ return;
791
+ }
792
+ const event = defaultPreventable(
793
+ {
794
+ operation: snapshot(operation),
795
+ by,
796
+ to
797
+ },
798
+ cancelable
799
+ );
800
+ monitor.dispatch("dragmove", event);
801
+ queueMicrotask(() => {
802
+ if (event.defaultPrevented) {
803
+ return;
804
+ }
805
+ const coordinates = to ?? {
806
+ x: position.current.x + by.x,
807
+ y: position.current.y + by.y
808
+ };
809
+ position.update(coordinates);
810
+ });
811
+ },
812
+ stop({ canceled: eventCanceled = false } = {}) {
813
+ let promise;
814
+ const suspend = () => {
815
+ const output = {
816
+ resume: () => {
817
+ },
818
+ abort: () => {
819
+ }
820
+ };
821
+ promise = new Promise((resolve, reject) => {
822
+ output.resume = resolve;
823
+ output.abort = reject;
824
+ });
825
+ return output;
826
+ };
827
+ const end = () => {
828
+ manager.renderer.rendering.then(() => {
829
+ status.value = "dropping" /* Dropping */;
830
+ manager.renderer.rendering.then(reset);
831
+ });
832
+ };
833
+ canceled.value = eventCanceled;
834
+ monitor.dispatch("dragend", {
835
+ operation: snapshot(operation),
836
+ canceled: eventCanceled,
837
+ suspend
838
+ });
839
+ if (promise) {
840
+ promise.then(end).catch(reset);
841
+ } else {
842
+ end();
843
+ }
844
+ }
845
+ }
846
+ };
847
+ }
848
+ function snapshot(obj) {
849
+ return {
850
+ ...obj
851
+ };
852
+ }
853
+
854
+ // src/core/manager/renderer.ts
855
+ var defaultRenderer = {
856
+ get rendering() {
857
+ return Promise.resolve();
858
+ }
859
+ };
860
+
861
+ // src/core/manager/manager.ts
862
+ var DragDropManager = class {
863
+ actions;
864
+ collisionObserver;
865
+ dragOperation;
866
+ monitor;
867
+ registry;
868
+ renderer;
869
+ constructor(config) {
870
+ const {
871
+ plugins = [],
872
+ sensors = [],
873
+ modifiers = [],
874
+ renderer = defaultRenderer
875
+ } = config ?? {};
876
+ const monitor = new DragDropMonitor(this);
877
+ const registry = new DragDropRegistry(this);
878
+ this.registry = registry;
879
+ this.monitor = monitor;
880
+ this.renderer = renderer;
881
+ const { actions, operation } = DragOperationManager(this);
882
+ this.actions = actions;
883
+ this.dragOperation = operation;
884
+ this.collisionObserver = new CollisionObserver(this);
885
+ this.plugins = [CollisionNotifier, ...plugins];
886
+ this.modifiers = modifiers;
887
+ this.sensors = sensors;
888
+ }
889
+ get plugins() {
890
+ return this.registry.plugins.values;
891
+ }
892
+ set plugins(plugins) {
893
+ this.registry.plugins.values = plugins;
894
+ }
895
+ get modifiers() {
896
+ return this.registry.modifiers.values;
897
+ }
898
+ set modifiers(modifiers) {
899
+ this.registry.modifiers.values = modifiers;
900
+ }
901
+ get sensors() {
902
+ return this.registry.sensors.values;
903
+ }
904
+ set sensors(sensors) {
905
+ this.registry.sensors.values = sensors;
906
+ }
907
+ destroy() {
908
+ this.registry.destroy();
909
+ this.collisionObserver.destroy();
910
+ }
911
+ };
912
+
913
+ exports.CollisionPriority = CollisionPriority;
914
+ exports.CorePlugin = CorePlugin;
915
+ exports.DragDropManager = DragDropManager;
916
+ exports.DragOperationStatus = Status;
917
+ exports.Draggable = Draggable;
918
+ exports.Droppable = Droppable;
919
+ exports.Modifier = Modifier;
920
+ exports.Plugin = Plugin;
921
+ exports.PluginRegistry = PluginRegistry;
922
+ exports.Sensor = Sensor;
923
+ exports.configurator = configurator;
924
+ exports.configure = configure;
925
+ exports.descriptor = descriptor;
926
+ exports.sortCollisions = sortCollisions;
927
+ //# sourceMappingURL=out.js.map
928
+ //# sourceMappingURL=index.cjs.map