fluxfiles 0.1.2 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/fluxfiles.d.ts +14 -0
- package/fluxfiles.js +6 -1
- package/fluxfiles.min.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Vanilla JavaScript SDK for embedding FluxFiles in any web app (no framework required).
|
|
4
4
|
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- A running **FluxFiles core service** — the backend that serves the UI and performs the storage operations (the PHP app in `packages/core`, e.g. via the Docker image). This SDK is a thin client: it loads `fluxfiles.js` from it and talks to its API at `endpoint`.
|
|
8
|
+
- A user **token**, minted server-side. Your own backend can be anything: use [`@fluxfiles/node`](https://www.npmjs.com/package/@fluxfiles/node) to issue tokens from Node (**no PHP needed**), or the Laravel / WordPress adapters.
|
|
9
|
+
|
|
5
10
|
## Install (npm)
|
|
6
11
|
|
|
7
12
|
```bash
|
|
@@ -36,6 +41,10 @@ production. Same global API:
|
|
|
36
41
|
|
|
37
42
|
It's regenerated from `fluxfiles.js` with `npm run build` (esbuild).
|
|
38
43
|
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
47
|
+
|
|
39
48
|
## Links
|
|
40
49
|
|
|
41
50
|
- Main repository: `https://github.com/thai-pc/fluxfiles`
|
package/fluxfiles.d.ts
CHANGED
|
@@ -12,7 +12,12 @@ interface FluxFilesOpenOptions {
|
|
|
12
12
|
/** Theme: "light", "dark", or "auto". */
|
|
13
13
|
theme?: string;
|
|
14
14
|
allowedTypes?: string[];
|
|
15
|
+
/** Max size per uploaded file, in **megabytes (MB)**. Preferred over `maxSize`. */
|
|
16
|
+
maxUploadMb?: number;
|
|
17
|
+
/** @deprecated Use `maxUploadMb` (MB). Bytes; converted to MB when `maxUploadMb` is unset. */
|
|
15
18
|
maxSize?: number;
|
|
19
|
+
/** Max number of files per upload batch (0/undefined = unlimited). The server enforces the total per prefix via the `max_files` claim. */
|
|
20
|
+
maxFiles?: number;
|
|
16
21
|
container?: string;
|
|
17
22
|
onSelect?: (file: FluxFile | FluxFile[]) => void;
|
|
18
23
|
onClose?: () => void;
|
|
@@ -26,8 +31,13 @@ interface FluxFile {
|
|
|
26
31
|
key?: string;
|
|
27
32
|
name?: string;
|
|
28
33
|
url?: string;
|
|
34
|
+
/** Stable, non-expiring URL for embedding (public disk / public_url). */
|
|
35
|
+
permanent_url?: string;
|
|
29
36
|
size?: number;
|
|
30
37
|
mime?: string;
|
|
38
|
+
/** Image dimensions (present for images uploaded through FluxFiles). */
|
|
39
|
+
width?: number;
|
|
40
|
+
height?: number;
|
|
31
41
|
disk?: string;
|
|
32
42
|
is_dir?: boolean;
|
|
33
43
|
modified?: string;
|
|
@@ -36,6 +46,10 @@ interface FluxFile {
|
|
|
36
46
|
alt_text?: string | null;
|
|
37
47
|
caption?: string | null;
|
|
38
48
|
tags?: string | null;
|
|
49
|
+
mime?: string | null;
|
|
50
|
+
width?: number | null;
|
|
51
|
+
height?: number | null;
|
|
52
|
+
uploaded_by?: string | null;
|
|
39
53
|
} | null;
|
|
40
54
|
/** Image variant URLs (thumb/medium/large WebP). */
|
|
41
55
|
variants?: Record<string, { url: string; key: string }> | null;
|
package/fluxfiles.js
CHANGED
|
@@ -41,7 +41,12 @@
|
|
|
41
41
|
mode: config.mode || 'picker',
|
|
42
42
|
multiple: !!config.multiple,
|
|
43
43
|
allowedTypes: config.allowedTypes || null,
|
|
44
|
-
|
|
44
|
+
// Canonical upload-size limit is megabytes. `maxSize` (bytes)
|
|
45
|
+
// is the deprecated alias — used only when maxUploadMb is absent.
|
|
46
|
+
maxUploadMb: (typeof config.maxUploadMb === 'number')
|
|
47
|
+
? config.maxUploadMb
|
|
48
|
+
: (typeof config.maxSize === 'number' ? Math.round(config.maxSize / (1024 * 1024)) : null),
|
|
49
|
+
maxFiles: (typeof config.maxFiles === 'number') ? config.maxFiles : null,
|
|
45
50
|
endpoint: config.endpoint || '',
|
|
46
51
|
locale: config.locale || null,
|
|
47
52
|
theme: config.theme || null
|
package/fluxfiles.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(_){"use strict";var k=1,b="fluxfiles",r=null,s={},t={},h=!1,f="",c=!1;function M(){return"ff-"+Math.random().toString(36).substr(2,9)+Date.now().toString(36)}function l(e,n){!r||!r.contentWindow||r.contentWindow.postMessage({source:b,type:e,v:k,id:M(),payload:n||{}},f||"*")}function v(e){if(!(f&&e.origin!==f)){var n=e.data;if(!(!n||n.source!==b))switch(n.type){case"FM_READY":h=!0,l("FM_CONFIG",{disk:t.disk||"local",disks:t.disks||["local"],token:t.token||"",path:t.path||"",mode:t.mode||"picker",multiple:!!t.multiple,allowedTypes:t.allowedTypes||null,maxUploadMb:typeof t.maxUploadMb=="number"?t.maxUploadMb:typeof t.maxSize=="number"?Math.round(t.maxSize/(1024*1024)):null,maxFiles:typeof t.maxFiles=="number"?t.maxFiles:null,endpoint:t.endpoint||"",locale:t.locale||null,theme:t.theme||null}),u("FM_READY",n.payload);break;case"FM_SELECT":typeof t.onSelect=="function"&&t.onSelect(n.payload),u("FM_SELECT",n.payload),d.close();break;case"FM_TOKEN_REFRESH":if(c)break;c=!0,u("FM_TOKEN_REFRESH",n.payload),typeof t.onTokenRefresh=="function"?Promise.resolve().then(function(){return t.onTokenRefresh(n.payload)}).then(function(o){c=!1,o?(t.token=o,l("FM_TOKEN_UPDATED",{token:o})):l("FM_TOKEN_FAILED",{reason:"refresh_returned_null"})}).catch(function(o){c=!1,console.error("FluxFiles: onTokenRefresh failed",o),l("FM_TOKEN_FAILED",{reason:o.message||"refresh_error"})}):(c=!1,l("FM_TOKEN_FAILED",{reason:"no_handler"}));break;case"FM_EVENT":u("FM_EVENT",n.payload);break;case"FM_CLOSE":typeof t.onClose=="function"&&t.onClose(),u("FM_CLOSE",n.payload);break}}}function u(e,n){for(var o=s[e]||[],m=0;m<o.length;m++)try{o[m](n)}catch(a){console.error("FluxFiles listener error:",a)}}var d={open:function(e){t=e||{};var n=(t.endpoint||"").replace(/\/+$/,""),o=t.container?document.querySelector(t.container):document.body;try{var m=new URL(n+"/public/index.html");f=m.origin}catch{f=window.location.origin}if(this.close(),r=document.createElement("iframe"),r.id="fluxfiles-iframe",r.src=n+"/public/index.html",r.style.cssText="width:100%;height:100%;border:none;",r.setAttribute("allow","clipboard-write"),t.container)o.appendChild(r);else{var a=document.createElement("div");a.id="fluxfiles-overlay",a.style.cssText="position:fixed;top:0;left:0;right:0;bottom:0;background:rgba(0,0,0,0.5);z-index:99999;display:flex;align-items:center;justify-content:center;";var p=document.createElement("div");p.id="fluxfiles-modal",p.style.cssText="width:90vw;height:85vh;max-width:1200px;background:#f5f5f7;border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;";var x=document.createElement("div");x.style.cssText="flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid rgba(0,0,0,0.06);background:#f5f5f7;";var i=document.createElement("button");i.type="button",i.setAttribute("aria-label","Close"),i.style.cssText="width:13px;height:13px;padding:0;border:none;border-radius:50%;background:#ff5f57;box-shadow:inset 0 0 0 0.5px rgba(0,0,0,0.14);color:rgba(0,0,0,0);cursor:pointer;display:flex;align-items:center;justify-content:center;font-size:11px;line-height:1;font-weight:700;transition:filter .15s,color .15s;flex-shrink:0;",i.textContent="\xD7";var E=function(){i.style.color="rgba(0,0,0,0.55)",i.style.filter="brightness(0.93)"},y=function(){i.style.color="rgba(0,0,0,0)",i.style.filter="none"};i.addEventListener("mouseenter",E),i.addEventListener("mouseleave",y),i.addEventListener("focus",E),i.addEventListener("blur",y),i.addEventListener("click",function(){d.close()}),x.appendChild(i),p.appendChild(x);var g=document.createElement("div");g.style.cssText="flex:1;min-height:0;display:flex;flex-direction:column;",g.appendChild(r),p.appendChild(g),a.appendChild(p),document.body.appendChild(a),a.addEventListener("click",function(F){F.target===a&&d.close()})}window.addEventListener("message",v)},close:function(){h=!1,window.removeEventListener("message",v);var e=document.getElementById("fluxfiles-overlay");e&&e.remove();var n=document.getElementById("fluxfiles-iframe");n&&n.remove(),r=null},command:function(e,n){l("FM_COMMAND",Object.assign({action:e},n||{}))},navigate:function(e){this.command("navigate",{path:e})},setDisk:function(e){this.command("setDisk",{disk:e})},refresh:function(){this.command("refresh")},search:function(e){this.command("search",{q:e})},crossCopy:function(e,n){this.command("crossCopy",{dst_disk:e,dst_path:n||""})},crossMove:function(e,n){this.command("crossMove",{dst_disk:e,dst_path:n||""})},aiTag:function(){this.command("aiTag")},setLocale:function(e){this.command("setLocale",{locale:e})},updateToken:function(e){t.token=e,h&&r&&l("FM_TOKEN_UPDATED",{token:e})},on:function(e,n){return s[e]||(s[e]=[]),s[e].push(n),function(){d.off(e,n)}},off:function(e,n){s[e]&&(s[e]=s[e].filter(function(o){return o!==n}))}};typeof module<"u"&&module.exports?module.exports=d:typeof define=="function"&&define.amd?define(function(){return d}):_.FluxFiles=d})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this);
|