Skip to content

deyihu/filednd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Jul 24, 2024
fa40dc0 · Jul 24, 2024

History

26 Commits
Feb 14, 2023
Feb 13, 2023
Feb 13, 2023
Feb 13, 2023
Feb 13, 2023
Jul 24, 2024
Jul 24, 2024
Feb 13, 2023
Jul 24, 2024
Feb 13, 2023
Feb 13, 2023

Repository files navigation

filednd

Files Drag and Drop

Features

  • Support for multiple files
  • Support folder
  • Support toTree(Data structure of tree)

Demo

filednd

Install

NPM

 npm i filednd
#  or
yarn add filednd 

CDN

<script src="https://unpkg.com/filednd/dist/filednd.js"></script>

API

FileDND

constructor(ele)

  • ele : HTMLElement
import {
    FileDND
} from 'filednd';
const fdnd = new FileDND(document.querySelector('#zone'));

// if you use cdn 
// const fdnd = new filednd.FileDND(document.querySelector('#zone'));

methods

  • dnd(callback) listen htmlelement drag and drop
fdnd.dnd((files) => {
    console.log(files);
});
  • toTree() Convert file collection structure to tree data structure
  const treeData = fdnd.toTree();
  • toFolderTree() Convert file tree to markdown directory text
  const text = fdnd.toFolderTree();
├─ src 
| ├─ assets 
| | ├─ vue.svg 
| ├─ components 
| | ├─ HelloWorld.vue 
| ├─ App.vue 
| ├─ common.js 
| ├─ draw.vue 
| ├─ fly.vue 
| ├─ main.js 
| ├─ style.css 

  • clear() clear all files
 fdnd.clear();
  • dispose()
 fdnd.dispose();

events

  • readstart
const readStart = () => {

}
fdnd.on('readstart', readStart)
//  fdnd.off('readstart', readStart)
  • readend
const readEnd = () => {

}
fdnd.on('readend', readEnd)
//  fdnd.off('readstart', readEnd)

Links

file-type If you want to determine the file type, you can refer to this library