DragHelper

1.3.6 · abandoned · verified Sun Apr 19

DragHelper is a lightweight, vanilla JavaScript utility designed to simplify the implementation of basic drag and drop functionalities within web applications. Currently at version 1.3.6, the package has not seen any updates since 2016, indicating it is an abandoned project. Its last publish date on npm was over nine years ago, and the GitHub repository shows no activity since August 2016. While it provides a basic API for making DOM elements draggable, it lacks features common in modern drag-and-drop libraries, such as touch event optimization, robust accessibility, or explicit framework integrations (e.g., React, Vue). It is suitable only for extremely basic, legacy projects where minimal footprint is prioritized over active maintenance or advanced capabilities.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a draggable element confined within a parent container using the `DragHelper` utility. It assumes a basic API for event callbacks (`onDragStart`, `onDrag`, `onDragEnd`) and positional updates, reflecting common patterns for vanilla JS drag libraries, though the specific API for this abandoned package is inferred.

<html>
<head>
  <title>DragHelper Quickstart</title>
  <style>
    body { font-family: sans-serif; }
    #container {
      width: 400px;
      height: 300px;
      border: 2px dashed #ccc;
      margin: 50px auto;
      position: relative;
      display: flex;
      align-items: center;
      justify-content: center;
      background-color: #f9f9f9;
    }
    #draggable-element {
      width: 100px;
      height: 100px;
      background-color: #007bff;
      color: white;
      display: flex;
      align-items: center;
      justify-content: center;
      cursor: grab;
      position: absolute;
      border-radius: 8px;
      box-shadow: 0 4px 6px rgba(0,0,0,0.1);
      touch-action: none; /* Prevent default touch behavior */
    }
  </style>
</head>
<body>
  <div id="container">
    <div id="draggable-element">Drag Me!</div>
  </div>

  <script type="module">
    import DragHelper from './node_modules/drag-helper/dist/drag-helper.min.js'; // Adjust path as necessary

    document.addEventListener('DOMContentLoaded', () => {
      const draggableEl = document.getElementById('draggable-element');
      const containerEl = document.getElementById('container');

      if (draggableEl && containerEl) {
        // Assuming DragHelper is a factory function or constructor that takes the element and optional config.
        // The internal API is inferred based on common patterns for 'drag-helper' type libraries.
        const dragInstance = new DragHelper(draggableEl, {
          container: containerEl, // Restrict dragging within this container
          onDragStart: (event, element) => {
            console.log('Drag started:', element.id);
            element.style.borderColor = 'blue';
          },
          onDrag: (event, element, { x, y }) => {
            // Update element's position. This is a common pattern for manual position updates.
            // Some drag libraries handle this internally, but for a basic helper, manual might be needed.
            element.style.left = `${x}px`;
            element.style.top = `${y}px`;
          },
          onDragEnd: (event, element) => {
            console.log('Drag ended:', element.id);
            element.style.borderColor = 'transparent';
          }
        });

        console.log('DragHelper initialized for element:', draggableEl.id);

        // Example of cleanup if the library provides a destroy method
        // setTimeout(() => {
        //   if (dragInstance.destroy) {
        //     dragInstance.destroy();
        //     console.log('DragHelper destroyed.');
        //   }
        // }, 10000);

      } else {
        console.error('Draggable element or container not found.');
      }
    });
  </script>
</body>
</html>

view raw JSON →