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

@splicetree/plugin-dnd

v1.1.0

Published

为树节点提供拖拽移动能力,支持插入到目标之前、之后或作为子节点。新增工程化的规则引擎,可精细控制「谁可以拖」「拖到哪里」「允许的落点(前/内/后)」。

Readme

@splicetree/plugin-dnd

为树节点提供拖拽移动能力,支持插入到目标之前、之后或作为子节点。新增工程化的规则引擎,可精细控制「谁可以拖」「拖到哪里」「允许的落点(前/内/后)」。

version downloads license Website GitHub

安装

pnpm add @splicetree/plugin-dnd

使用

import { createSpliceTree } from '@splicetree/core'
import dnd, { DropPosition } from '@splicetree/plugin-dnd'

const tree = createSpliceTree(data, {
  plugins: [dnd],
  configuration: {
    dnd: {
      // 控制可拖拽
      disabledDrag: (n) => n.level === 2, // 例如:禁用所有 2 级节点的拖拽
      // 控制可放置
      levelMatrix: {
        // 例如:3 级可以放到 2 级「内」,但 2 级不能放到 1 级「内」
        3: { 2: { inside: true } },
        2: { 1: { inside: false } },
      },
      // 显式禁止某些 ID 对的放置
      denyDropPairs: [
        { fromId: 'a', toId: 'b', positions: [DropPosition.INSIDE] },
      ],
      // 完全自定义:覆盖所有规则(高优先级)
      canDrop: (src, tgt, pos) => {
        if (src.id === 'a' && tgt.id === 'b') return false
        return true
      },
    },
  },
})

Api

Options

| 选项 | 类型 | 默认值 | 说明 | | ------------------ | ------------------------------------------------------------ | ------ | -------------------------------------------------------------------- | | autoUpdateParent | boolean | true | 拖拽后自动更新源节点的父字段;为 false 时不写回且不移动 | | autoExpandOnDrop | boolean | true | 拖入后自动展开目标节点 | | readonly | boolean | false| 只读模式,禁用拖拽与放置 | | reorderOnly | boolean | false| 仅允许同层级排序(禁用 INSIDE 放入子级) | | disabledDrag | boolean \| string[] \| (node: DndNode) => boolean | | 禁用拖拽:布尔、ID 列表或方法 | | levelMatrix | Record<level, Record<level, { before?: boolean; inside?: boolean; after?: boolean }>> | | 基于层级的允许矩阵。未显式配置的组合默认允许 | | denyDropPairs | { fromId: string; toId: string; positions?: DropPosition[] }[] | | 显式禁止某些源-目标的放置;未指定 positions 时,禁止所有落点 | | canDrop | (src: DndNode, tgt: DndNode, position: DropPosition) => boolean | | 自定义总规则(高优先级,返回 true/false 覆盖其它规则) |

Events

| 事件 | 负载 | 说明 | | ------ | ------------------------------------------------------------------------------ | -------- | | move | { id: string, parentId?: string, position: DropPosition, beforeId?: string } | 节点移动 |

实例方法

| 名称 | 参数 | 说明 | | ---------------- | --------------------------------------------------------- | -------------------------- | | drop | srcId: string; targetId: string; position: DropPosition | 执行移动 | | onDragStart | id: string | 标记拖拽源 | | onDragOver | id: string; el: HTMLElement; e: DragEvent \| MouseEvent | 更新目标悬停位置 | | onDragLeave | id: string | 清理悬停位置 | | onDrop | targetId: string | 根据当前悬停位置执行移动 | | hoverPositions | | 目标悬停位置缓存 | | draggingId | | 当前正在拖拽的节点 id | | dragProps | id: string | DOM 事件绑定集合(逐节点) |

节点方法

| 名称 | 参数 | 说明 | | ------------------- | ---- | -------------------- | | getDropPosition() | | 当前节点的悬停位置 | | isDragging() | | 当前节点是否为拖拽源 | | isDisabled() | | 当前节点是否禁用拖拽 |

规则优先级

  • readonly → 全面禁止
  • canDrop → 优先级最高,返回值直接决定是否允许
  • denyDropPairs → 其次,命中即禁止
  • levelMatrix → 再次,根据层级组合与落点决策
  • 默认允许(除去基础非法场景:拖到自己或到父级)