npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@drag-list/core

v1.0.6

Published

一个轻量级的可拖动排序列表组件

Readme

@drag-list/core

一个轻量级的可拖动排序列表核心功能库,提供基础的拖拽功能,零依赖。

安装

pnpm add @drag-list/core

使用

import { useDraggableList } from '@drag-list/core';

const { init, destroy, state } = useDraggableList({
  container: '#list-container',
  onDragStart: (item) => {
    console.log('开始拖动:', item);
  },
  onDragMove: (item, currentIndex) => {
    console.log('拖动中:', item, '当前位置:', currentIndex);
  },
  onDragEnd: (startIndex, endIndex) => {
    console.log('拖动结束:', startIndex, '->', endIndex);
  }
});

// 初始化
init();

// 销毁
destroy();

API

useDraggableList

创建一个可拖动的列表功能。

参数

| 参数名 | 类型 | 默认值 | 描述 | |--------|------|--------|------| | longPressDuration | number | 100 | 长按触发时间(毫秒) | | container | HTMLElement | string | - | 列表容器选择器或元素 | | itemSelector | string | '.dl-item' | 列表项选择器 | | onDragStart | (item: DraggableItem) => void | - | 拖动开始时的回调 | | onDragMove | (item: DraggableItem, currentIndex: number) => void | - | 拖动过程中的回调 | | onDragEnd | (startIndex: number, endIndex: number) => void | - | 拖动结束时的回调 | | enableTouch | boolean | true | 是否启用触摸支持 | | enableMouse | boolean | true | 是否启用鼠标支持 | | draggingClass | string | 'dl-dragging' | 自定义拖动时的样式类名 |

返回值

| 参数名 | 类型 | 描述 | |--------|------|------| | state | DraggableListState | 拖动状态 | | init | () => void | 初始化函数 | | destroy | () => void | 销毁函数 |

DraggableItem

拖动项的类型定义。

interface DraggableItem {
  element: HTMLElement;  // 元素
  index: number;         // 索引
}

DraggableListState

拖动状态的类型定义。

interface DraggableListState {
  items: DraggableItem[];        // 所有项
  draggingItem: DraggableItem | null;  // 当前拖动的项
  startY: number;                // 开始位置
  currentY: number;              // 当前位置
  startIndex: number;            // 开始索引
  currentIndex: number;          // 当前索引
  isDragging: boolean;           // 是否正在拖动
}

样式

默认样式:

.dl-container {
  position: relative;
  user-select: none;
}

.dl-item {
  transition: transform 0.2s ease;
  cursor: grab;
}

.dl-item.dl-dragging {
  cursor: grabbing;
  opacity: 0.8;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 1;
}

.dl-item.dl-dragging * {
  pointer-events: none;
}

你可以通过 draggingClass 选项自定义拖动时的样式类名。