1.0.3 • Published 7 months ago

d-resouce v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
7 months ago

🔦 d-resouce

Web-based resource (file, folder) reading tool If this library is helpful to you, I look forward to Star encouragement

简体中文 | English

🎲 Support

A tool built into web applications that facilitates resource (file and folder) reading, making development tasks more efficient and enjoyable.

Key Features:

  • Drag-and-Drop Support: Allows users to drag and drop files and folders directly into the tool, simplifying resource import.
  • Clipboard Support: Supports copying and pasting files from the clipboard.
  • System File and Folder Selection: Enables users to select files or folders directly from their system.
  • Multiple Data Formats: Offers data in two formats - as an array or in a tree structure, catering to different use cases.
  • Read-Only files Mode: Supports read-only access to files.
  • Real-Time Filtering: Provides real-time filtering of files and folders, making it easier to locate specific resources.
  • Rule Validation: Offers real-time validation of file rules; if a file doesn't meet the specified criteria, the operation can be interrupted.
  • Folder Size Tracking: Automatically calculates and displays the total size of all files within each level of a folder.
  • Customizable UI Hooks: Exposes drag-and-drop hover and leave hooks, allowing for UI customization and enhanced user experiences.

🛵 Use

  1. Install the d-resouce dependency
npm install d-resouce
  1. Instantiate the ResHandle
import { ResHandle } from "d-resouce";

const resHandle = new ResHandle(options);
  1. Use helper functions
import { selectResource, selectFileChange, selectFolderChange, filterSize } from "d-resouce"

📒 Document

options

FieldTypeDescriptionparams
targetDomHTMLElementThe DOM element associated with the drag-and-drop event----
dragoverFucFunctionHover event for the drag-and-drop objectEvent object
dragleaveFucFunctionLeave event for the drag-and-drop objectEvent object
beforeReadFucFunctionHook function for reading drag-and-drop or paste events before data is read----
readDataFucFunctionHook function for reading drag-and-drop or paste events' resultsData assembled according to the specified mode
validFucFunctionAll resources read are passed to this function; returning false aborts the read operationFile: size、fullPath、name、type、file
filterFucFunctionAll resources read are passed to this function; returning false filters out the resource. Note: Filtering out a folder will exclude its contents from the readTwo types: files (parameters as in validFuc) and folders: totalSize, fullPath, name, type, file, children
modeStringValue can be 'array' or 'tree'----
onlyFileBooleanIndicates whether to read only files, ignoring folders----
targetDomHTMLElementThe DOM element associated with the drag-and-drop event----

other

FieldTypeDescriptionEnter paramsReturn params
selectResourceFunctionOpens the system resource dialog for selecting resources1. Whether it's a directory upload 2. An object with additional attributes for the <input type="file>, for example: { multiple: true }Native reading results
selectFolderChangeFunctionHandles folder upload and assembles data according to the specified mode1. Results from folder upload 2. Mode type ('array' or 'tree').Processed results
selectFileChangeFunctionHandles file upload results (without hierarchy) and does not require specifying a mode1. Results from file upload 2.Custom formatting methodProcessed results (default format according to readDataFuc)
filterSizeFunctionConverts file sizes to specific units (B, KB, MB, GB, TB)1.File sizeSize as a string with units (e.g., "2.5 MB")

🙌 交流讨论

wetChat: yl66915 qq email: 1205836625@qq.com

1.0.3

7 months ago

1.0.1

7 months ago

1.0.0

7 months ago