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 🙏

© 2024 – Pkg Stats / Ryan Hefner

draggable-ts

v1.1.1

Published

### 高性能的ts通用拖拽库

Downloads

98

Readme

高性能的通用拖拽库

特点:

  1. 统一移动端与 PC 端拖拽事件,并进一步抽象出常见拖拽场景的各种事件
  2. 提供拖拽镜像、落点提示线、边缘滚动等基础 plugin
  3. 完善的 TS 类型,优秀的代码设计

使用指南

名次解释

  • source:拖拽的目标元素
  • mirror:镜像元素
  • over:拖拽过程中经过的 dropable 的元素

Quick Start

// default options
const options = {
  draggable: ".draggable", // 可拖拽元素的selector,
  dropable: ".draggable", // 可放置元素的selector,主要影响拖拽事件的over属性
  condition: {
    // 触发拖拽的条件
    delay: {
      // 需要长按多少ms才会触发拖拽
      mouse: 0,
      touch: 100, // 防止移动端滚动页面时触发拖拽
      drag: 0,
    },
    distance: 0, // 需要移动超过这个距离才会触发拖拽,防止click误触
  },
  sensors: [MouseSensor], // 要使用的Sensor
  plugins: [Mirror], // 要使用的plugin
  mirror: {
    // Mirror plugin的配置
    constrainDimensions: true, // mirror是否维持source的外观
    xAxis: true, // 是否允许y轴移动
    yAxis: true, // 是否允许x轴移动
    cursorOffsetX: null, // 元素相对于鼠标的x轴偏移,null表示元素距离鼠标的x轴距离,此时正好mirror的位置与source重合
    cursorOffsetY: null, // 元素相对于鼠标的y轴偏移,与cursorOffsetX同理
    thresholdX: 0, // mirror在x轴移动的步长
    thresholdY: 0, // mirror在y轴移动的步长
  },
};

const draggable = new Draggable(options);

// 拖拽结束时将source插入到over之前
draggable.emitter.on("drag:end", (e) => {
  if (e.over) {
    e.over.parentElement?.insertBefore(e.over, e.source);
  }
});