0.1.2 • Published 2 years ago

filemanager-element v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

file-manager custom element

npm Test

npm.io

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

AttributeDescriptionDefault
endpointThe base url for the file and folder API
readonlyDo not allow file deletion or creationfalse
layoutFiles layout "rows" or "grid"grid
lazy-foldersShould all folder be lazy loaded with a new call to the APIfalse
hiddenWork like the default HTML attributefalse

Events

NameDescription
closeThe user clicked on the overlay to close the modal
fileselectThe use selected a file

Options

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

NameTypeDescription
readOnlyboolDo not allow file deletion or creation
endpointstringEndpoint for the REST API
httpHeadersobjectAdditional headers to send to the endpoint
getFiles()functionCustom API to retrieve files
getFolders()functionCustom API to retrieve folders
deleteFile()functionCustom API to delete file
deleteFolder()functionCustom API to delete folder
uploadFile()functionCustom API to upload file
createFolder()functionCustom 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> {
  }
})
0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago