29 | {/if}
30 |
31 |
32 |
75 |
76 |
124 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # file-manager custom element
2 |
3 | [](http://npm.im/filemanager-element)
4 | [](https://github.com/Grafikart/FileManagerJS/actions/workflows/test.yml)
5 |
6 | 
7 |
8 | You want a simple file browser for your website, without the hassle of a front-end framework ? Here is a simple custom
9 | element for you.
10 |
11 | - [Demonstration (codesandbox.io)](https://km7mr7.csb.app)
12 |
13 | First register the custom element (the lang is infered from the html "lang" attribute)
14 |
15 | ```js
16 | import {FileManager} from 'filemanager-element'
17 | import 'filemanager-element/FileManager.css'
18 |
19 | FileManager.register();
20 | ```
21 |
22 | Then you can simply use your custom element whenever you want
23 |
24 | ```html
25 |
26 | ```
27 |
28 | You just have to implement the API following this [Open API specification](openapi.yml) and it will work out of the box.
29 |
30 | To interface the editor with your system (for instance when a file is selected) you can simply bind listeners
31 |
32 | ```js
33 | const filemanager = document.querySelector("file-manager");
34 | filemanager.addEventListener("close", () => {
35 | console.log("close");
36 | });
37 |
38 | filemanager.addEventListener("selectfile", e => {
39 | console.log("fileSelected", e.detail);
40 | });
41 | ```
42 |
43 | ## Attributes
44 |
45 | | Attribute | Description | Default |
46 | |--------------|-------------------------------------------------------------|---------|
47 | | endpoint | The base url for the file and folder API | |
48 | | readonly | Do not allow file deletion or creation | false |
49 | | layout | Files layout "rows" or "grid" | grid |
50 | | lazy-folders | Should all folder be lazy loaded with a new call to the API | false |
51 | | hidden | Work like the default HTML attribute | false |
52 |
53 | ## Events
54 |
55 | | Name | Description |
56 | |-------------|----------------------------------------------------|
57 | | close | The user clicked on the overlay to close the modal |
58 | | fileselect | The use selected a file |
59 |
60 | ## Options
61 |
62 | Options can be set on the `register()` method as a second argument. All the options are optional
63 |
64 | | Name | Type | Description |
65 | |-----------------|----------|--------------------------------------------|
66 | | readOnly | bool | Do not allow file deletion or creation |
67 | | endpoint | string | Endpoint for the REST API |
68 | | httpHeaders | object | Additional headers to send to the endpoint |
69 | | getFiles() | function | Custom API to retrieve files |
70 | | getFolders() | function | Custom API to retrieve folders |
71 | | deleteFile() | function | Custom API to delete file |
72 | | deleteFolder() | function | Custom API to delete folder |
73 | | uploadFile() | function | Custom API to upload file |
74 | | createFolder() | function | Custom API to create folder |
75 |
76 | ## Custom API
77 |
78 | If you do not use a traditional REST API you can overwrite the method used to fetch the data.
79 |
80 | ```ts
81 | import type {File as FileType, Folder} from 'filemanager-element'
82 |
83 | FileManager.register('my-file-manager', {
84 | getFiles (folder?: Folder): Promise {
85 | },
86 | getFolders (parent?: Folder): Promise {
87 | },
88 | createFolder (params: Pick): Promise {
89 | },
90 | deleteFile (file: FileType): Promise {
91 | },
92 | deleteFolder (folder: Folder): Promise {
93 | },
94 | uploadFile (file: File, folder: Folder): Promise {
95 | }
96 | })
97 | ```
98 |
--------------------------------------------------------------------------------
/src/FileManager.svelte:
--------------------------------------------------------------------------------
1 |
2 |
3 | {#if !hidden}
4 |