Coder Social home page Coder Social logo

carlosjorger / vue-fluid-dnd Goto Github PK

View Code? Open in Web Editor NEW
198.0 5.0 5.0 2.4 MB

A drag and drop🤜🫳library for Vue 3🌿

Home Page: https://vue-fluid-dnd.netlify.app

License: MIT License

HTML 0.33% Vue 18.42% TypeScript 78.95% CSS 2.31%
drag-and-drop typescript vue3 sortable vue draggable droppable lightweight no-dependencies ease-of-use

vue-fluid-dnd's Introduction

Icon
Vue Fluid DnD

npm bundle size license version GitHub issues GitHub stars twitter test_coverage

A fluid, smooth and versatil drag and drop library for lists on Vue3. It's a lightweight tool ~7 Kb (gzip) with no depenencies.

✨ Features

  • Fully customizable 🎨.
  • Zero dependencies 🪶.
  • Work with horizontal➡️and vertical list ⬇️.
  • Mouse 🐭 and touch 👉📱 (mobile, tablet and so on) support.
  • Nice documentation 📑 and examples.
  • Fully tested 🧪, typed and reliable.

🚀 Getting Started

  1. Install vue-fluid-dnd:

    # with npm:
    npm i vue-fluid-dnd
    
    # with yarn:
    yarn add vue-fluid-dnd
    
    # with pnpm:
    pnpm i vue-fluid-dnd
  2. Import the vue composable

    import { useDragAndDrop } from "vue-fluid-dnd";
  3. Create a list that your want to sort an use useDragAndDrop

    // Each element have its own styles or classes and the draggable-id
    const listToSort = ref([
      {
        number: 1,
        style:
          "color: white; background-color: red; width: 50px; margin: 23px 0;",
      },
      //...
    ]);
    // create the parent element and set drag and drop configuration on the parent and children elements (creating events, statees, styles, etc) calling useDragAndDrop composable
    const { parent } = useDragAndDrop(listToSort);
  4. Create childrens

    <template>
       <div ref="parent" style="width: 40%; display: block">
          <div
             v-for="(element, index) in listToSort"
             :index="index"
             :style="element.style"
          >{{ element.number }}
          </div>
       </div>
    </template>
  5. Documentation

  • 📚 Check out all the docs.
  • 🛠️ Edit the previous here.
  • 📘 See others examples here.

🤝 Contributing

If you're interested in contributing to vue-fluid-dnd, please read our contributing docs before submitting a pull request CONTRIBUTING.

🔑 License

vue-fluid-dnd's People

Contributors

carlosjorger avatar geniuscorn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

vue-fluid-dnd's Issues

Change the API

Change the API for a much simpler one using a vue composable instead of draggable and droppable components.

Demo not working.

It seems like the demo page is not working. It says can't reach page. I really wanted to try this out.

Edit: It was because of some temporary network issue. Can someone with admin access delete this. I am really sorry for the inconvenience caused.

How to bind the 'dragstart' and 'dragend' events to child elements.

Your library is amazing! Thank you! However, I've encountered a tricky issue. How can I listen for the 'dragstart' and 'dragend' events on child elements?

The function I bound to the event is not taking effect.

<script lang="ts" setup>
import { useDragAndDrop } from 'vue-fluid-dnd'

// Each element have its own styles or classes and the draggable-id
const listToSort = ref([1, 2, 3, 4])
// create the parent element and set drag and drop configuration on the parent and children elements (creating events, statees, styles, etc) calling useDragAndDrop composable
const { parent: dragListRef } = useDragAndDrop(listToSort)

function onDragStart() {
  console.log('drag start')
}

function onDragEnd() {
  console.log('drag end')
}
</script>

<template>
  <div class="flex flex-col h-full">
    <div
      ref="dragListRef"
      class="flex w-50vw flex-col gap-10px h-600px overflow-y-scroll"
    >
      <div
        v-for="(element, index) in listToSort"
        :key="index"
        :index="index"
        class="h-100px bg-red rounded shadow shrink-0"
        @dragstart="onDragStart"
        @dragend="onDragEnd"
      >
        {{ element }}
      </div>
    </div>
  </div>
</template>

I hope to receive your assistance.

List items inaccessible

I implemented a basic vertical list with handle. But in my case the list items are a checkbox and an input. The list is working and is sortable but I am unable to edit the input or change the checkbox.

Code

<script setup>
import { useDragAndDrop } from "vue-fluid-dnd";

const nlist = ref([
  {
    value: false,
    label: "Item 1",
  },
  {
    value: false,
    label: "Item 2",
  },
  {
    value: false,
    label: "Item 3",
  },
]);

const { parent } = useDragAndDrop(nlist, { handlerSelector: ".handle" });

const triggerClick = () => {
  console.log("click");
};
</script>
<template>
  <UCard class="w-[300px]">
    <template #header>
      <div class="flex items-center justify-between">
        <p>QuikNote</p>
        <UButton variant="ghost" size="xs" class="p-0">
          <IX class="h-5 w-5 p-0" />
        </UButton>
      </div>
    </template>
    <ul ref="parent" class="ul">
      <li class="li flex" v-for="(item, index) in nlist" :index="index">
        <div class="handle">
          <IGripVertical />
        </div>
        <UCheckbox v-model="item.value" :class="{ dull: item.value }" />

        <UInput
          class="pl-5"
          v-model="item.label"
          variant="none"
          :padded="false"
          placeholder="List Item"
          :class="{ dull: item.value }"
          @click="triggerClick"
        />
      </li>
    </ul>
    <template #footer>
      <div class="flex gap-2">
        <UButton @click="addItem">New Item</UButton>
      </div>
    </template>
  </UCard>
</template>
<style lang="scss" scoped>
.li {
  margin-bottom: 10px;
  .dull {
    color: rgb(var(--color-gray-500));
  }
}
</style>

PS: I am using Nuxt with NuxtUI

Got an usability error on Firefox - Touch Events

I was trying the examples. But I couldn't drag and drop. I am using Firefox (v.124.0.1). I checked the console and I got this:

Uncaught ReferenceError: TouchEvent is not defined
    Be https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.BrKkVjjl.js:1
    K https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.BrKkVjjl.js:1
    N https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.BrKkVjjl.js:1

I searched a little and apparently I needed to enabled touch events for Firefox. Mainly, this setting

dom.w3c_touch_events.enabled

on the about:config page.

It has 3 states:

0 - disable
1 - enable
2 - auto-detect

In my case, it was in auto-detect but didn't work the TouchEvents, So I changed it to 1 (enable) and it works perfectly.

Perhaps you should include this somewhere in the docs for Firefox users. (also check Safari)

Bests,
Keep up the good work

onDrop issue for newely created items

I got a simple demo running. However, When I push a new el to the array and try to move it. it gets removed from the array. this only happen on elements which has been pushed after the useSortable has been initiated in setup script. any idea?

Not working on firefox

Its trowing this error on console

Uncaught ReferenceError: TouchEvent is not defined  
    be https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    T https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    A https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    le https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    H https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    gt https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    d https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    i https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    ut https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    ut https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    ut https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    i https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    dt https://vue-fluid-dnd.netlify.app/_astro/_plugin-vue_export-helper.CM-bNX2R.js:1  
    Ue https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    Oe https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    J https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    Ue https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    Kn https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    Kn https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    promise callback*kn https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    ds https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    resolve https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    registerDep https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    promise callback*registerDep https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    ce https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    h https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    wl https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    h https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    ne https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    b https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    run https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:9  
    update https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    P https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    ce https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    h https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    p https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    mount https://vue-fluid-dnd.netlify.app/_astro/runtime-core.esm-bundler.BxjKewf9.js:13  
    mount https://vue-fluid-dnd.netlify.app/_astro/client.tihex4gh.js:5  
    vt https://vue-fluid-dnd.netlify.app/_astro/client.tihex4gh.js:5  
    u https://vue-fluid-dnd.netlify.app/example/vertical-list/single-vertical-list-autoscroll/:36  
    e https://vue-fluid-dnd.netlify.app/example/vertical-list/single-vertical-list-autoscroll/:36  
    start https://vue-fluid-dnd.netlify.app/example/vertical-list/single-vertical-list-autoscroll/:36  
    childrenConnectedCallback https://vue-fluid-dnd.netlify.app/example/vertical-list/single-vertical-list-autoscroll/:36  
    e https://vue-fluid-dnd.netlify.app/example/vertical-list/single-vertical-list-autoscroll/:36  
    n https://vue-fluid-dnd.netlify.app/example/vertical-list/single-vertical-list-autoscroll/:36  
    connectedCallback https://vue-fluid-dnd.netlify.app/example/vertical-list/single-vertical-list-autoscroll/:36  
    LifecycleConnectedCallback* https://vue-fluid-dnd.netlify.app/example/vertical-list/single-vertical-list-autoscroll/:36  
    <anonymous> https://vue-fluid-dnd.netlify.app/example/vertical-list/single-vertical-list-autoscroll/:36  
49 _plugin-vue_export-helper.CM-bNX2R.js:1:2620

TouchEvent if you don't have a touch input device connected, which is causing "TouchEvent is not defined" errors:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.