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

dndlist

v0.3.0

Published

drag and drop list

Downloads

31

Readme

https://github.com/tarzandong/tzComponents.git

Drag and Drop in list component

How to use

/// main.ts
import { createApp } from 'vue'
import App from './App.vue'
//import dndComponents from 'dndlist' //global import, not recommended
import 'dndlist/style.css'

const app = createApp(App)
//app.use(dndComponents)
...
/// foo.vue
<template>
  <DNDList :list="testList" item-id="id" v-slot="{item}" @change="change" ref="listRef">
    <div>
      <div>{{ item.name }}</div>
      <div>{{ item.age + ' ' +item.id }}</div>
    </div>
  </DNDList>
</template>

<script lang='ts' setup>
import {DNDList} from 'dndlist' //import by required
  const testList = ref([
    {id:...,
    name,
    age},
    ...
  ])

  const listRef = ref(null)

  function change(list: any[], changeLog: {from: number, to: number}) {
    console.log(list)
    console.log(`you have changed the item from ${changeLog.from} to ${changeLog.to}`)
  }

  function cancelChange() {
    listRef.restore()
  }
</script>

Props and others in DNDList component

  • list: The target list you want to render in row flex display.
  • item-id: The unique id key of the list item obj, if the list is just a string[], you can keep item-id=''.
  • wrap-class?: The css class you want use on the flex wrap.
  • item-class?: The css class you want use on the list item. That item will be the parent Node of the default slot.
  • direction?: the flex-direction. can be 'row' or 'column'.
  • @change: The drop event will emit with param of the updated list and the changed item info of the index in the list.
  • method restore: The component expose a method restore to cancel the update about the list.
  • You need render the item in your own way by the default slot. please refer the example in How to use.

Notice

  • Recommand to render the slot item with fixed width & height, or the position maybe change not by your expectation.

Drag Element component

How to use

/// main.ts
same as the list component
/// foo.vue
<template>
  <DNDEle handlerId="handler" left="200px" top="500px" @drag-start="dragStart">
    <div>
      <div class="w100 h50 bcwarning" id="handler"></div>
      <div class="w100 h150 bcwhite" ></div>
    </div>
  </DNDEle>
</template>

<script lang='ts' setup>
import {DNDEle} from 'dndlist' //import by required
function dragStart(position: {x: number, y: number}) {
  console.log(position)
}  
</script>

Props and others in DNDList component

  • handlerId: string, The drag-and-drop handler element id.
  • left: string, The init left position of the target, must with unit like 'px'.
  • top: string, The init top position of the target, must with unit like 'px'.
  • notFixed: boolean, the DNDEle's default style.position is fixed, if you want to use static, you need set the prop to true.
  • emits: 2 emits as @drag-start and @drag-end, with the position param {x, y}

Notice

Once you draged the DNDEle, notFixed will be ignored, the DNDEle positon style will change to and maintain 'fixed'.