@dnd-kit/abstract 0.1.21 → 0.2.0-beta-20251025202520

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.d.cts CHANGED
@@ -247,10 +247,7 @@ declare abstract class Plugin<T extends DragDropManager<any, any> = DragDropMana
247
247
  * @param callback - The effect callback to register
248
248
  * @returns A function to dispose of the effect
249
249
  */
250
- protected registerEffect(callback: () => void): {
251
- (): void;
252
- [Symbol.dispose](): void;
253
- };
250
+ protected registerEffect(callback: () => void): () => void;
254
251
  /**
255
252
  * Destroys a plugin instance and cleans up its resources.
256
253
  *
@@ -915,6 +912,38 @@ declare class Droppable<T extends Data = Data, U extends DragDropManager<any, an
915
912
  get isDropTarget(): boolean;
916
913
  }
917
914
 
915
+ declare class ActivationController<E extends Event> extends AbortController {
916
+ private constraints;
917
+ private onActivate;
918
+ activated: boolean;
919
+ constructor(constraints: ActivationConstraints<E> | undefined, onActivate: (event: E) => void);
920
+ onEvent(event: E): void;
921
+ activate(event: E): void;
922
+ abort(event?: E): void;
923
+ }
924
+ interface ActivationConstraintOptions {
925
+ }
926
+ declare abstract class ActivationConstraint<E extends Event = Event, O extends ActivationConstraintOptions = ActivationConstraintOptions> {
927
+ #private;
928
+ protected options: O;
929
+ set controller(controller: ActivationController<E>);
930
+ constructor(options: O);
931
+ /**
932
+ * Called when the activation is triggered.
933
+ */
934
+ activate(event: E): void;
935
+ /**
936
+ * Called when the activation is aborted.
937
+ */
938
+ abstract abort(event?: E): void;
939
+ /**
940
+ * Called when an input event is received by the sensor.
941
+ * Returns `true` if this event triggers activation immediately.
942
+ */
943
+ abstract onEvent(event: E): void;
944
+ }
945
+ type ActivationConstraints<E extends Event> = ActivationConstraint<E>[];
946
+
918
947
  /**
919
948
  * Provides actions for controlling drag and drop operations.
920
949
  *
@@ -1276,4 +1305,4 @@ declare class DragDropManager<T extends Draggable, U extends Droppable> {
1276
1305
  destroy: () => void;
1277
1306
  }
1278
1307
 
1279
- export { type Collision, type CollisionDetector, CollisionPriority, CollisionType, CorePlugin, type Data, DragActions, type DragDropEvents, DragDropManager, type DragDropManagerInput, type DragOperationSnapshot as DragOperation, Status as DragOperationStatus, Draggable, type Input$1 as DraggableInput, Droppable, type Input as DroppableInput, Entity, Modifier, type ModifierConstructor, type Modifiers, Plugin, type PluginConstructor, type PluginDescriptor, type PluginOptions, PluginRegistry, type Plugins, type Renderer, Sensor, type SensorConstructor, type SensorDescriptor, type SensorOptions, type Sensors, type Type, type UniqueIdentifier, configurator, configure, descriptor, sortCollisions };
1308
+ export { ActivationConstraint, type ActivationConstraints, ActivationController, type Collision, type CollisionDetector, CollisionPriority, CollisionType, CorePlugin, type Data, DragActions, type DragDropEvents, DragDropManager, type DragDropManagerInput, type DragOperationSnapshot as DragOperation, Status as DragOperationStatus, Draggable, type Input$1 as DraggableInput, Droppable, type Input as DroppableInput, Entity, Modifier, type ModifierConstructor, type Modifiers, Plugin, type PluginConstructor, type PluginDescriptor, type PluginOptions, PluginRegistry, type Plugins, type Renderer, Sensor, type SensorConstructor, type SensorDescriptor, type SensorOptions, type Sensors, type Type, type UniqueIdentifier, configurator, configure, descriptor, sortCollisions };
package/index.d.ts CHANGED
@@ -247,10 +247,7 @@ declare abstract class Plugin<T extends DragDropManager<any, any> = DragDropMana
247
247
  * @param callback - The effect callback to register
248
248
  * @returns A function to dispose of the effect
249
249
  */
250
- protected registerEffect(callback: () => void): {
251
- (): void;
252
- [Symbol.dispose](): void;
253
- };
250
+ protected registerEffect(callback: () => void): () => void;
254
251
  /**
255
252
  * Destroys a plugin instance and cleans up its resources.
256
253
  *
@@ -915,6 +912,38 @@ declare class Droppable<T extends Data = Data, U extends DragDropManager<any, an
915
912
  get isDropTarget(): boolean;
916
913
  }
917
914
 
915
+ declare class ActivationController<E extends Event> extends AbortController {
916
+ private constraints;
917
+ private onActivate;
918
+ activated: boolean;
919
+ constructor(constraints: ActivationConstraints<E> | undefined, onActivate: (event: E) => void);
920
+ onEvent(event: E): void;
921
+ activate(event: E): void;
922
+ abort(event?: E): void;
923
+ }
924
+ interface ActivationConstraintOptions {
925
+ }
926
+ declare abstract class ActivationConstraint<E extends Event = Event, O extends ActivationConstraintOptions = ActivationConstraintOptions> {
927
+ #private;
928
+ protected options: O;
929
+ set controller(controller: ActivationController<E>);
930
+ constructor(options: O);
931
+ /**
932
+ * Called when the activation is triggered.
933
+ */
934
+ activate(event: E): void;
935
+ /**
936
+ * Called when the activation is aborted.
937
+ */
938
+ abstract abort(event?: E): void;
939
+ /**
940
+ * Called when an input event is received by the sensor.
941
+ * Returns `true` if this event triggers activation immediately.
942
+ */
943
+ abstract onEvent(event: E): void;
944
+ }
945
+ type ActivationConstraints<E extends Event> = ActivationConstraint<E>[];
946
+
918
947
  /**
919
948
  * Provides actions for controlling drag and drop operations.
920
949
  *
@@ -1276,4 +1305,4 @@ declare class DragDropManager<T extends Draggable, U extends Droppable> {
1276
1305
  destroy: () => void;
1277
1306
  }
1278
1307
 
1279
- export { type Collision, type CollisionDetector, CollisionPriority, CollisionType, CorePlugin, type Data, DragActions, type DragDropEvents, DragDropManager, type DragDropManagerInput, type DragOperationSnapshot as DragOperation, Status as DragOperationStatus, Draggable, type Input$1 as DraggableInput, Droppable, type Input as DroppableInput, Entity, Modifier, type ModifierConstructor, type Modifiers, Plugin, type PluginConstructor, type PluginDescriptor, type PluginOptions, PluginRegistry, type Plugins, type Renderer, Sensor, type SensorConstructor, type SensorDescriptor, type SensorOptions, type Sensors, type Type, type UniqueIdentifier, configurator, configure, descriptor, sortCollisions };
1308
+ export { ActivationConstraint, type ActivationConstraints, ActivationController, type Collision, type CollisionDetector, CollisionPriority, CollisionType, CorePlugin, type Data, DragActions, type DragDropEvents, DragDropManager, type DragDropManagerInput, type DragOperationSnapshot as DragOperation, Status as DragOperationStatus, Draggable, type Input$1 as DraggableInput, Droppable, type Input as DroppableInput, Entity, Modifier, type ModifierConstructor, type Modifiers, Plugin, type PluginConstructor, type PluginDescriptor, type PluginOptions, PluginRegistry, type Plugins, type Renderer, Sensor, type SensorConstructor, type SensorDescriptor, type SensorOptions, type Sensors, type Type, type UniqueIdentifier, configurator, configure, descriptor, sortCollisions };
package/index.js CHANGED
@@ -1121,6 +1121,58 @@ var Sensor = class extends Plugin {
1121
1121
  }
1122
1122
  };
1123
1123
 
1124
+ // src/core/sensors/activation.ts
1125
+ var ActivationController = class extends AbortController {
1126
+ constructor(constraints, onActivate) {
1127
+ super();
1128
+ this.constraints = constraints;
1129
+ this.onActivate = onActivate;
1130
+ this.activated = false;
1131
+ for (const constraint of constraints != null ? constraints : []) {
1132
+ constraint.controller = this;
1133
+ }
1134
+ }
1135
+ onEvent(event) {
1136
+ var _a;
1137
+ if (this.activated) return;
1138
+ if ((_a = this.constraints) == null ? void 0 : _a.length) {
1139
+ for (const constraint of this.constraints) {
1140
+ constraint.onEvent(event);
1141
+ }
1142
+ } else {
1143
+ this.activate(event);
1144
+ }
1145
+ }
1146
+ activate(event) {
1147
+ if (this.activated) return;
1148
+ this.activated = true;
1149
+ this.onActivate(event);
1150
+ }
1151
+ abort(event) {
1152
+ this.activated = false;
1153
+ super.abort(event);
1154
+ }
1155
+ };
1156
+ var _controller;
1157
+ var ActivationConstraint = class {
1158
+ constructor(options) {
1159
+ this.options = options;
1160
+ __privateAdd(this, _controller);
1161
+ }
1162
+ set controller(controller) {
1163
+ __privateSet(this, _controller, controller);
1164
+ controller.signal.addEventListener("abort", () => this.abort());
1165
+ }
1166
+ /**
1167
+ * Called when the activation is triggered.
1168
+ */
1169
+ activate(event) {
1170
+ var _a;
1171
+ (_a = __privateGet(this, _controller)) == null ? void 0 : _a.activate(event);
1172
+ }
1173
+ };
1174
+ _controller = new WeakMap();
1175
+
1124
1176
  // src/core/modifiers/modifier.ts
1125
1177
  var Modifier = class extends Plugin {
1126
1178
  /**
@@ -1467,6 +1519,6 @@ var DragDropManager = class {
1467
1519
  }
1468
1520
  };
1469
1521
 
1470
- export { CollisionPriority, CollisionType, CorePlugin, DragDropManager, Status as DragOperationStatus, Draggable, Droppable, Modifier, Plugin, PluginRegistry, Sensor, configurator, configure, descriptor, sortCollisions };
1522
+ export { ActivationConstraint, ActivationController, CollisionPriority, CollisionType, CorePlugin, DragDropManager, Status as DragOperationStatus, Draggable, Droppable, Modifier, Plugin, PluginRegistry, Sensor, configurator, configure, descriptor, sortCollisions };
1471
1523
  //# sourceMappingURL=index.js.map
1472
1524
  //# sourceMappingURL=index.js.map