MCPcopy
hub / github.com/clauderic/dnd-kit / DragDropRegistry

Class DragDropRegistry

packages/abstract/src/core/manager/registry.ts:31–158  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

29 * @template V - The type of drag and drop manager
30 */
31export class DragDropRegistry<
32 T extends Draggable,
33 U extends Droppable,
34 V extends DragDropManager<T, U>,
35> {
36 /**
37 * Creates a new registry instance.
38 *
39 * @param manager - The drag and drop manager that owns this registry
40 */
41 constructor(manager: V) {
42 this.plugins = new PluginRegistry<V, PluginConstructor<V>>(manager);
43 this.sensors = new PluginRegistry<V, SensorConstructor<V>>(manager);
44 this.modifiers = new PluginRegistry<V, ModifierConstructor<V>>(manager);
45 }
46
47 /** Registry for draggable entities */
48 public draggables = new EntityRegistry<T>();
49
50 /** Registry for droppable entities */
51 public droppables = new EntityRegistry<U>();
52
53 /** Registry for plugins */
54 public plugins: PluginRegistry<V, PluginConstructor<V>>;
55
56 /** Registry for sensors */
57 public sensors: PluginRegistry<V, SensorConstructor<V>>;
58
59 /** Registry for modifiers */
60 public modifiers: PluginRegistry<V, ModifierConstructor<V>>;
61
62 /**
63 * Registers a new entity, plugin, sensor, or modifier.
64 *
65 * @param input - The entity, plugin constructor, sensor constructor, or modifier constructor to register
66 * @param options - Optional configuration for plugins and sensors
67 * @returns A cleanup function or the registered instance
68 * @throws {Error} If the input type is invalid
69 */
70 public register(input: Entity): () => void;
71 public register(input: Draggable): () => void;
72 public register(input: Droppable): () => void;
73 public register(input: SensorConstructor, options?: SensorOptions): Sensor;
74 public register(input: ModifierConstructor): Modifier;
75 public register(input: PluginConstructor, options?: PluginOptions): Plugin;
76 public register(input: any, options?: Record<string, any>) {
77 if (input instanceof Draggable) {
78 return this.draggables.register(input.id, input as T);
79 }
80
81 if (input instanceof Droppable) {
82 return this.droppables.register(input.id, input as U);
83 }
84
85 if (input.prototype instanceof Modifier) {
86 return this.modifiers.register(input, options);
87 }
88

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected