index.mjs 922 B

123456789101112131415161718192021222324252627
  1. import { Feature } from '../../motion/features/Feature.mjs';
  2. import { noop } from 'motion-utils';
  3. import { VisualElementDragControls } from './VisualElementDragControls.mjs';
  4. class DragGesture extends Feature {
  5. constructor(node) {
  6. super(node);
  7. this.removeGroupControls = noop;
  8. this.removeListeners = noop;
  9. this.controls = new VisualElementDragControls(node);
  10. }
  11. mount() {
  12. // If we've been provided a DragControls for manual control over the drag gesture,
  13. // subscribe this component to it on mount.
  14. const { dragControls } = this.node.getProps();
  15. if (dragControls) {
  16. this.removeGroupControls = dragControls.subscribe(this.controls);
  17. }
  18. this.removeListeners = this.controls.addListeners() || noop;
  19. }
  20. unmount() {
  21. this.removeGroupControls();
  22. this.removeListeners();
  23. }
  24. }
  25. export { DragGesture };