fluxfiles 0.2.9 → 1.0.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/fluxfiles.d.ts +101 -92
- package/fluxfiles.min.js +1 -1
- package/package.json +1 -1
package/fluxfiles.d.ts
CHANGED
|
@@ -1,101 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
1
|
+
// Named types live in the merged `FluxFiles` namespace, so all of these work:
|
|
2
|
+
// import FluxFiles = require('fluxfiles') / import FluxFiles from 'fluxfiles' (esModuleInterop)
|
|
3
|
+
// import type { FluxFile, FluxFilesOpenOptions, FluxFilesSDK } from 'fluxfiles'
|
|
4
|
+
// const f: FluxFiles.FluxFile (UMD global)
|
|
5
|
+
declare namespace FluxFiles {
|
|
6
|
+
export interface FluxFilesOpenOptions {
|
|
7
|
+
endpoint: string;
|
|
8
|
+
token: string;
|
|
9
|
+
disk?: string;
|
|
10
|
+
/** Available disks shown in sidebar. */
|
|
11
|
+
disks?: string[];
|
|
12
|
+
mode?: 'picker' | 'browser';
|
|
13
|
+
/** Allow multi-select; when true, onSelect receives array of FluxFile */
|
|
14
|
+
multiple?: boolean;
|
|
15
|
+
/** Locale code (e.g. "en", "vi", "ar"). Default: "en". */
|
|
16
|
+
locale?: string;
|
|
17
|
+
/** Theme: "light", "dark", or "auto". */
|
|
18
|
+
theme?: string;
|
|
19
|
+
allowedTypes?: string[];
|
|
20
|
+
/** Max size per uploaded file, in **megabytes (MB)**. Preferred over `maxSize`. */
|
|
21
|
+
maxUploadMb?: number;
|
|
22
|
+
/** @deprecated Use `maxUploadMb` (MB). Bytes; converted to MB when `maxUploadMb` is unset. */
|
|
23
|
+
maxSize?: number;
|
|
24
|
+
/** Max number of files per upload batch (0/undefined = unlimited). The server enforces the total per prefix via the `max_files` claim. */
|
|
25
|
+
maxFiles?: number;
|
|
26
|
+
container?: string;
|
|
27
|
+
onSelect?: (file: FluxFile | FluxFile[]) => void;
|
|
28
|
+
onClose?: () => void;
|
|
29
|
+
/** Called when the iframe needs a fresh JWT (401 received). Return new token or null. */
|
|
30
|
+
onTokenRefresh?: (context: { reason: string; disk?: string; path?: string }) => Promise<string | null>;
|
|
31
|
+
}
|
|
27
32
|
|
|
28
|
-
interface FluxFile {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
33
|
+
export interface FluxFile {
|
|
34
|
+
path: string;
|
|
35
|
+
basename: string;
|
|
36
|
+
key?: string;
|
|
37
|
+
name?: string;
|
|
38
|
+
url?: string;
|
|
39
|
+
/** Stable, non-expiring URL for embedding (public disk / public_url). */
|
|
40
|
+
permanent_url?: string;
|
|
41
|
+
/** Base URL for the on-demand WebP endpoint (images only; when the feature is on). Use `FluxFiles.imgUrl(file, …)`. */
|
|
42
|
+
img_base?: string;
|
|
43
|
+
/** Ready-to-use responsive `srcset` (images only; built from `img_base` + the token's width ladder). */
|
|
44
|
+
img_srcset?: string;
|
|
45
|
+
/** `sizes` attribute to pair with `img_srcset` (only when the token sets `srcset_sizes`). */
|
|
46
|
+
img_sizes?: string;
|
|
47
|
+
size?: number;
|
|
48
|
+
mime?: string;
|
|
49
|
+
/** Image dimensions (present for images uploaded through FluxFiles). */
|
|
50
|
+
width?: number;
|
|
51
|
+
height?: number;
|
|
52
|
+
disk?: string;
|
|
53
|
+
is_dir?: boolean;
|
|
54
|
+
/** Unix seconds. Stable upload/mkdir time (folders carry it too). */
|
|
55
|
+
created?: number;
|
|
56
|
+
/** Unix seconds. Live storage mtime (may be absent for S3/R2 dir prefixes). */
|
|
57
|
+
modified?: number;
|
|
58
|
+
meta?: {
|
|
59
|
+
title?: string | null;
|
|
60
|
+
alt_text?: string | null;
|
|
61
|
+
caption?: string | null;
|
|
62
|
+
tags?: string | null;
|
|
63
|
+
mime?: string | null;
|
|
64
|
+
width?: number | null;
|
|
65
|
+
height?: number | null;
|
|
66
|
+
uploaded_by?: string | null;
|
|
67
|
+
} | null;
|
|
68
|
+
/** Image variant URLs (thumb/medium/large WebP). */
|
|
69
|
+
variants?: Record<string, { url: string; key: string }> | null;
|
|
70
|
+
/** Which variant was selected ("original", "thumb", "medium", "large"). */
|
|
71
|
+
variant?: 'original' | 'thumb' | 'medium' | 'large';
|
|
72
|
+
}
|
|
65
73
|
|
|
66
|
-
interface FluxEvent {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
}
|
|
74
|
+
export interface FluxEvent {
|
|
75
|
+
action: 'upload' | 'delete' | 'move' | 'copy' | 'mkdir' | 'restore' | 'purge' | 'trash' | 'crop' | 'ai_tag';
|
|
76
|
+
disk: string;
|
|
77
|
+
path: string;
|
|
78
|
+
[key: string]: unknown;
|
|
79
|
+
}
|
|
72
80
|
|
|
73
|
-
type FluxFilesEventType = 'FM_READY' | 'FM_SELECT' | 'FM_EVENT' | 'FM_CLOSE' | 'FM_TOKEN_REFRESH';
|
|
81
|
+
export type FluxFilesEventType = 'FM_READY' | 'FM_SELECT' | 'FM_EVENT' | 'FM_CLOSE' | 'FM_TOKEN_REFRESH';
|
|
74
82
|
|
|
75
|
-
interface FluxFilesSDK {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
83
|
+
export interface FluxFilesSDK {
|
|
84
|
+
open(options: FluxFilesOpenOptions): void;
|
|
85
|
+
close(): void;
|
|
86
|
+
command(action: string, data?: Record<string, unknown>): void;
|
|
87
|
+
navigate(path: string): void;
|
|
88
|
+
setDisk(disk: string): void;
|
|
89
|
+
refresh(): void;
|
|
90
|
+
search(query: string): void;
|
|
91
|
+
crossCopy(dstDisk: string, dstPath?: string): void;
|
|
92
|
+
crossMove(dstDisk: string, dstPath?: string): void;
|
|
93
|
+
aiTag(): void;
|
|
94
|
+
/** Switch locale/language at runtime. */
|
|
95
|
+
setLocale(locale: string): void;
|
|
96
|
+
/** Crops the currently open detail file. savePath omitted/'' = overwrite in place, otherwise saves as a new file (must keep the same extension). */
|
|
97
|
+
crop(x: number, y: number, width: number, height: number, savePath?: string): void;
|
|
98
|
+
/** Build an on-demand WebP URL for a selected image from its `img_base`. Returns '' if unavailable. */
|
|
99
|
+
imgUrl(file: FluxFile, opts?: { width?: number; quality?: number; format?: 'webp' | 'auto' }): string;
|
|
100
|
+
/** Push a new token (e.g. after background refresh). */
|
|
101
|
+
updateToken(token: string): void;
|
|
102
|
+
on(event: FluxFilesEventType, callback: (data: unknown) => void): () => void;
|
|
103
|
+
off(event: FluxFilesEventType, callback: (data: unknown) => void): void;
|
|
104
|
+
}
|
|
96
105
|
}
|
|
97
106
|
|
|
98
|
-
declare const FluxFiles: FluxFilesSDK;
|
|
107
|
+
declare const FluxFiles: FluxFiles.FluxFilesSDK;
|
|
99
108
|
|
|
100
109
|
export = FluxFiles;
|
|
101
110
|
export as namespace FluxFiles;
|
package/fluxfiles.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(T){"use strict";var C=1,E="fluxfiles",L="clipboard-write; fullscreen",
|
|
1
|
+
(function(T){"use strict";var C=1,E="fluxfiles",L="clipboard-write; fullscreen",o=null,s={},n={},b=!1,m="",h=!1;function S(){return"ff-"+Math.random().toString(36).substr(2,9)+Date.now().toString(36)}function d(t,e){!o||!o.contentWindow||o.contentWindow.postMessage({source:E,type:t,v:C,id:S(),payload:e||{}},m||"*")}function _(t){if(!(!o||!o.contentWindow||t.source!==o.contentWindow)&&!(m&&t.origin!==m)){var e=t.data;if(!(!e||e.source!==E))switch(e.type){case"FM_READY":b=!0,d("FM_CONFIG",{disk:n.disk||"local",disks:n.disks||["local"],token:n.token||"",path:n.path||"",mode:n.mode||"picker",multiple:!!n.multiple,allowedTypes:n.allowedTypes||null,maxUploadMb:typeof n.maxUploadMb=="number"?n.maxUploadMb:typeof n.maxSize=="number"?Math.round(n.maxSize/(1024*1024)):null,maxFiles:typeof n.maxFiles=="number"?n.maxFiles:null,endpoint:n.endpoint||"",locale:n.locale||null,theme:n.theme||null}),c("FM_READY",e.payload);break;case"FM_SELECT":typeof n.onSelect=="function"&&n.onSelect(e.payload),c("FM_SELECT",e.payload),f.close();break;case"FM_TOKEN_REFRESH":if(h)break;h=!0,c("FM_TOKEN_REFRESH",e.payload),typeof n.onTokenRefresh=="function"?Promise.resolve().then(function(){return n.onTokenRefresh(e.payload)}).then(function(i){h=!1,i?(n.token=i,d("FM_TOKEN_UPDATED",{token:i})):d("FM_TOKEN_FAILED",{reason:"refresh_returned_null"})}).catch(function(i){h=!1,console.error("FluxFiles: onTokenRefresh failed",i),d("FM_TOKEN_FAILED",{reason:i.message||"refresh_error"})}):(h=!1,d("FM_TOKEN_FAILED",{reason:"no_handler"}));break;case"FM_EVENT":c("FM_EVENT",e.payload);break;case"FM_THEME":O(!!(e.payload&&e.payload.theme==="dark")),c("FM_THEME",e.payload);break;case"FM_CLOSE":typeof n.onClose=="function"&&n.onClose(),c("FM_CLOSE",e.payload);break}}}function c(t,e){for(var i=s[t]||[],l=0;l<i.length;l++)try{i[l](e)}catch(r){console.error("FluxFiles listener error:",r)}}function O(t){var e=document.getElementById("fluxfiles-modal");if(e){var i=t?"#2b2b2e":"#f5f5f7",l=t?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)";e.style.background=i;var r=e.firstElementChild;r&&(r.style.background=i,r.style.borderBottom="1px solid "+l)}}var f={open:function(t){n=t||{};var e=(n.endpoint||"").replace(/\/+$/,""),i=n.container?document.querySelector(n.container):document.body;try{var l=new URL(e+"/public/index.html");m=l.origin}catch{m=window.location.origin}if(this.close(),o=document.createElement("iframe"),o.id="fluxfiles-iframe",o.src=e+"/public/index.html",o.style.cssText="width:100%;height:100%;border:none;",o.setAttribute("allow",L),o.setAttribute("allowfullscreen","true"),n.container)i.appendChild(o);else{var r="fluxfiles_theme",x=null;try{x=window.localStorage&&localStorage.getItem(r)}catch{}try{(n.theme==="dark"||n.theme==="light")&&localStorage.setItem(r,n.theme)}catch{}var k=n.theme==="dark"||n.theme!=="light"&&(x==="dark"||x!=="light"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches),w=k?"#2b2b2e":"#f5f5f7",R=k?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)",u=document.createElement("div");u.id="fluxfiles-overlay",u.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:"+w+";border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;";var v=document.createElement("div");v.style.cssText="flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid "+R+";background:"+w+";";var a=document.createElement("button");a.type="button",a.setAttribute("aria-label","Close"),a.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;",a.textContent="\xD7";var F=function(){a.style.color="rgba(0,0,0,0.55)",a.style.filter="brightness(0.93)"},M=function(){a.style.color="rgba(0,0,0,0)",a.style.filter="none"};a.addEventListener("mouseenter",F),a.addEventListener("mouseleave",M),a.addEventListener("focus",F),a.addEventListener("blur",M),a.addEventListener("click",function(){f.close()}),v.appendChild(a),p.appendChild(v);var y=document.createElement("div");y.style.cssText="flex:1;min-height:0;display:flex;flex-direction:column;",y.appendChild(o),p.appendChild(y),u.appendChild(p),document.body.appendChild(u),u.addEventListener("click",function(g){g.target===u&&f.close()})}window.addEventListener("message",_)},close:function(){b=!1,window.removeEventListener("message",_);var t=document.getElementById("fluxfiles-overlay");t&&t.remove();var e=document.getElementById("fluxfiles-iframe");e&&e.remove(),o=null},command:function(t,e){d("FM_COMMAND",Object.assign({action:t},e||{}))},navigate:function(t){this.command("navigate",{path:t})},setDisk:function(t){this.command("setDisk",{disk:t})},refresh:function(){this.command("refresh")},search:function(t){this.command("search",{q:t})},crossCopy:function(t,e){this.command("crossCopy",{dst_disk:t,dst_path:e||""})},crossMove:function(t,e){this.command("crossMove",{dst_disk:t,dst_path:e||""})},aiTag:function(){this.command("aiTag")},setLocale:function(t){this.command("setLocale",{locale:t})},crop:function(t,e,i,l,r){this.command("crop",{x:t,y:e,width:i,height:l,save_path:r||""})},imgUrl:function(t,e){if(!t||!t.img_base)return"";e=e||{};var i=[];return e.width&&i.push("width="+encodeURIComponent(e.width)),e.quality&&i.push("quality="+encodeURIComponent(e.quality)),e.format&&i.push("format="+encodeURIComponent(e.format)),t.img_base+(i.length?"&"+i.join("&"):"")},updateToken:function(t){n.token=t,b&&o&&d("FM_TOKEN_UPDATED",{token:t})},on:function(t,e){return s[t]||(s[t]=[]),s[t].push(e),function(){f.off(t,e)}},off:function(t,e){s[t]&&(s[t]=s[t].filter(function(i){return i!==e}))}};typeof module<"u"&&module.exports?module.exports=f:typeof define=="function"&&define.amd?define(function(){return f}):T.FluxFiles=f})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this);
|