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

filemanager-element

v0.1.2

Published

[![npm](https://img.shields.io/npm/v/filemanager-element.svg)](http://npm.im/filemanager-element) [![Test](https://github.com/Grafikart/FileManagerJS/actions/workflows/test.yml/badge.svg)](https://github.com/Grafikart/FileManagerJS/actions/workflows/test.

Downloads

367

Readme

file-manager custom element

npm Test

You want a simple file browser for your website, without the hassle of a front-end framework ? Here is a simple custom element for you.

First register the custom element (the lang is infered from the html "lang" attribute)

import {FileManager} from 'filemanager-element'
import 'filemanager-element/FileManager.css'

FileManager.register();

Then you can simply use your custom element whenever you want

<file-manager endpoint="http://your.api.com/endpoint"></file-manager>

You just have to implement the API following this Open API specification and it will work out of the box.

To interface the editor with your system (for instance when a file is selected) you can simply bind listeners

const filemanager = document.querySelector("file-manager");
filemanager.addEventListener("close", () => {
  console.log("close");
});

filemanager.addEventListener("selectfile", e => {
  console.log("fileSelected", e.detail);
});

Attributes

| Attribute | Description | Default | |--------------|-------------------------------------------------------------|---------| | endpoint | The base url for the file and folder API | | | readonly | Do not allow file deletion or creation | false | | layout | Files layout "rows" or "grid" | grid | | lazy-folders | Should all folder be lazy loaded with a new call to the API | false | | hidden | Work like the default HTML attribute | false |

Events

| Name | Description | |-------------|----------------------------------------------------| | close | The user clicked on the overlay to close the modal | | fileselect | The use selected a file |

Options

Options can be set on the register() method as a second argument. All the options are optional

| Name | Type | Description | |-----------------|----------|--------------------------------------------| | readOnly | bool | Do not allow file deletion or creation | | endpoint | string | Endpoint for the REST API | | httpHeaders | object | Additional headers to send to the endpoint | | getFiles() | function | Custom API to retrieve files | | getFolders() | function | Custom API to retrieve folders | | deleteFile() | function | Custom API to delete file | | deleteFolder() | function | Custom API to delete folder | | uploadFile() | function | Custom API to upload file | | createFolder() | function | Custom API to create folder |

Custom API

If you do not use a traditional REST API you can overwrite the method used to fetch the data.

import type {File as FileType, Folder} from 'filemanager-element'

FileManager.register('my-file-manager', {
  getFiles (folder?: Folder): Promise<FileType[]> {
  },
  getFolders (parent?: Folder): Promise<Folder> {
  },
  createFolder (params: Pick<Folder, "parent" | "name">): Promise<Folder> {
  },
  deleteFile (file: FileType): Promise<void> {
  },
  deleteFolder (folder: Folder): Promise<void> {
  },
  uploadFile (file: File, folder: Folder): Promise<Filetype> {
  }
})