fluxfiles 0.2.3 → 0.2.5

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.js CHANGED
@@ -3,6 +3,9 @@
3
3
 
4
4
  var VERSION = 1;
5
5
  var SOURCE = 'fluxfiles';
6
+ // Permissions-Policy granted to the embedded UI iframe (fullscreen + clipboard).
7
+ // Keep identical across SDK/React/Vue/WordPress — scripts/check-iframe-allow.sh guards it.
8
+ var IFRAME_ALLOW = 'clipboard-write; fullscreen';
6
9
  var iframe = null;
7
10
  var listeners = {};
8
11
  var config = {};
@@ -139,10 +142,18 @@
139
142
  iframe.style.cssText = 'width:100%;height:100%;border:none;';
140
143
  // `fullscreen` lets the embedded app's "fullscreen" button work; the
141
144
  // legacy attribute covers older browsers.
142
- iframe.setAttribute('allow', 'clipboard-write; fullscreen');
145
+ iframe.setAttribute('allow', IFRAME_ALLOW);
143
146
  iframe.setAttribute('allowfullscreen', 'true');
144
147
 
145
148
  if (!config.container) {
149
+ // Theme the modal chrome to match the embedded UI's theme, so dark
150
+ // mode darkens the window/header too (not just the iframe content).
151
+ var chromeDark = config.theme === 'dark' ||
152
+ (config.theme !== 'light' && window.matchMedia &&
153
+ window.matchMedia('(prefers-color-scheme: dark)').matches);
154
+ var chromeBg = chromeDark ? '#2b2b2e' : '#f5f5f7';
155
+ var chromeBorder = chromeDark ? 'rgba(255,255,255,0.08)' : 'rgba(0,0,0,0.06)';
156
+
146
157
  // Modal overlay — UI scaled down 5% (icons, text, spacing)
147
158
  var overlay = document.createElement('div');
148
159
  overlay.id = 'fluxfiles-overlay';
@@ -150,11 +161,11 @@
150
161
 
151
162
  var modal = document.createElement('div');
152
163
  modal.id = 'fluxfiles-modal';
153
- modal.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;';
164
+ modal.style.cssText = 'width:90vw;height:85vh;max-width:1200px;background:' + chromeBg + ';border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;';
154
165
 
155
166
  // Header — macOS-style red close button (left) with × icon
156
167
  var header = document.createElement('div');
157
- header.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;';
168
+ header.style.cssText = 'flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid ' + chromeBorder + ';background:' + chromeBg + ';';
158
169
  var closeBtn = document.createElement('button');
159
170
  closeBtn.type = 'button';
160
171
  closeBtn.setAttribute('aria-label', 'Close');
package/fluxfiles.min.js CHANGED
@@ -1 +1 @@
1
- (function(F){"use strict";var k=1,b="fluxfiles",r=null,s={},t={},h=!1,f="",c=!1;function w(){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:w(),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(i){c=!1,i?(t.token=i,l("FM_TOKEN_UPDATED",{token:i})):l("FM_TOKEN_FAILED",{reason:"refresh_returned_null"})}).catch(function(i){c=!1,console.error("FluxFiles: onTokenRefresh failed",i),l("FM_TOKEN_FAILED",{reason:i.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 i=s[e]||[],m=0;m<i.length;m++)try{i[m](n)}catch(a){console.error("FluxFiles listener error:",a)}}var d={open:function(e){t=e||{};var n=(t.endpoint||"").replace(/\/+$/,""),i=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; fullscreen"),r.setAttribute("allowfullscreen","true"),t.container)i.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 o=document.createElement("button");o.type="button",o.setAttribute("aria-label","Close"),o.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;",o.textContent="\xD7";var E=function(){o.style.color="rgba(0,0,0,0.55)",o.style.filter="brightness(0.93)"},y=function(){o.style.color="rgba(0,0,0,0)",o.style.filter="none"};o.addEventListener("mouseenter",E),o.addEventListener("mouseleave",y),o.addEventListener("focus",E),o.addEventListener("blur",y),o.addEventListener("click",function(){d.close()}),x.appendChild(o),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(_){_.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})},imgUrl:function(e,n){if(!e||!e.img_base)return"";n=n||{};var i=[];return n.width&&i.push("width="+encodeURIComponent(n.width)),n.quality&&i.push("quality="+encodeURIComponent(n.quality)),n.format&&i.push("format="+encodeURIComponent(n.format)),e.img_base+(i.length?"&"+i.join("&"):"")},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(i){return i!==n}))}};typeof module<"u"&&module.exports?module.exports=d:typeof define=="function"&&define.amd?define(function(){return d}):F.FluxFiles=d})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this);
1
+ (function(w){"use strict";var M=1,v="fluxfiles",T="clipboard-write; fullscreen",r=null,a={},t={},x=!1,f="",c=!1;function C(){return"ff-"+Math.random().toString(36).substr(2,9)+Date.now().toString(36)}function s(e,n){!r||!r.contentWindow||r.contentWindow.postMessage({source:v,type:e,v:M,id:C(),payload:n||{}},f||"*")}function E(e){if(!(f&&e.origin!==f)){var n=e.data;if(!(!n||n.source!==v))switch(n.type){case"FM_READY":x=!0,s("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),l.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(i){c=!1,i?(t.token=i,s("FM_TOKEN_UPDATED",{token:i})):s("FM_TOKEN_FAILED",{reason:"refresh_returned_null"})}).catch(function(i){c=!1,console.error("FluxFiles: onTokenRefresh failed",i),s("FM_TOKEN_FAILED",{reason:i.message||"refresh_error"})}):(c=!1,s("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 i=a[e]||[],m=0;m<i.length;m++)try{i[m](n)}catch(p){console.error("FluxFiles listener error:",p)}}var l={open:function(e){t=e||{};var n=(t.endpoint||"").replace(/\/+$/,""),i=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",T),r.setAttribute("allowfullscreen","true"),t.container)i.appendChild(r);else{var p=t.theme==="dark"||t.theme!=="light"&&window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches,y=p?"#2b2b2e":"#f5f5f7",L=p?"rgba(255,255,255,0.08)":"rgba(0,0,0,0.06)",d=document.createElement("div");d.id="fluxfiles-overlay",d.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 h=document.createElement("div");h.id="fluxfiles-modal",h.style.cssText="width:90vw;height:85vh;max-width:1200px;background:"+y+";border-radius:10px;overflow:hidden;box-shadow:0 25px 50px rgba(0,0,0,0.22);display:flex;flex-direction:column;";var g=document.createElement("div");g.style.cssText="flex-shrink:0;display:flex;align-items:center;justify-content:flex-start;padding:10px 12px;border-bottom:1px solid "+L+";background:"+y+";";var o=document.createElement("button");o.type="button",o.setAttribute("aria-label","Close"),o.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;",o.textContent="\xD7";var _=function(){o.style.color="rgba(0,0,0,0.55)",o.style.filter="brightness(0.93)"},F=function(){o.style.color="rgba(0,0,0,0)",o.style.filter="none"};o.addEventListener("mouseenter",_),o.addEventListener("mouseleave",F),o.addEventListener("focus",_),o.addEventListener("blur",F),o.addEventListener("click",function(){l.close()}),g.appendChild(o),h.appendChild(g);var b=document.createElement("div");b.style.cssText="flex:1;min-height:0;display:flex;flex-direction:column;",b.appendChild(r),h.appendChild(b),d.appendChild(h),document.body.appendChild(d),d.addEventListener("click",function(k){k.target===d&&l.close()})}window.addEventListener("message",E)},close:function(){x=!1,window.removeEventListener("message",E);var e=document.getElementById("fluxfiles-overlay");e&&e.remove();var n=document.getElementById("fluxfiles-iframe");n&&n.remove(),r=null},command:function(e,n){s("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})},imgUrl:function(e,n){if(!e||!e.img_base)return"";n=n||{};var i=[];return n.width&&i.push("width="+encodeURIComponent(n.width)),n.quality&&i.push("quality="+encodeURIComponent(n.quality)),n.format&&i.push("format="+encodeURIComponent(n.format)),e.img_base+(i.length?"&"+i.join("&"):"")},updateToken:function(e){t.token=e,x&&r&&s("FM_TOKEN_UPDATED",{token:e})},on:function(e,n){return a[e]||(a[e]=[]),a[e].push(n),function(){l.off(e,n)}},off:function(e,n){a[e]&&(a[e]=a[e].filter(function(i){return i!==n}))}};typeof module<"u"&&module.exports?module.exports=l:typeof define=="function"&&define.amd?define(function(){return l}):w.FluxFiles=l})(typeof globalThis<"u"?globalThis:typeof window<"u"?window:this);
package/package.json CHANGED
@@ -1,44 +1,44 @@
1
1
  {
2
- "name": "fluxfiles",
3
- "version": "0.2.3",
4
- "description": "FluxFiles JavaScript SDK — embed the file manager in any web app",
5
- "license": "MIT",
6
- "main": "fluxfiles.js",
7
- "types": "fluxfiles.d.ts",
8
- "unpkg": "fluxfiles.min.js",
9
- "jsdelivr": "fluxfiles.min.js",
10
- "files": [
11
- "fluxfiles.js",
12
- "fluxfiles.min.js",
13
- "fluxfiles.d.ts",
14
- "LICENSE"
15
- ],
16
- "scripts": {
17
- "build": "esbuild fluxfiles.js --minify --legal-comments=none --outfile=fluxfiles.min.js",
18
- "test": "vitest run"
19
- },
20
- "devDependencies": {
21
- "esbuild": "^0.28.0",
22
- "jsdom": "^25.0.1",
23
- "vitest": "^2.1.8"
24
- },
25
- "author": "thai-pc",
26
- "homepage": "https://github.com/thai-pc/fluxfiles",
27
- "repository": {
28
- "type": "git",
29
- "url": "git+https://github.com/thai-pc/fluxfiles.git"
30
- },
31
- "bugs": {
32
- "url": "https://github.com/thai-pc/fluxfiles/issues"
33
- },
34
- "keywords": [
35
- "fluxfiles",
36
- "file-manager",
37
- "sdk",
38
- "iframe",
39
- "s3",
40
- "r2",
41
- "upload",
42
- "media"
43
- ]
2
+ "name": "fluxfiles",
3
+ "version": "0.2.5",
4
+ "description": "FluxFiles JavaScript SDK — embed the file manager in any web app",
5
+ "license": "MIT",
6
+ "main": "fluxfiles.js",
7
+ "types": "fluxfiles.d.ts",
8
+ "unpkg": "fluxfiles.min.js",
9
+ "jsdelivr": "fluxfiles.min.js",
10
+ "files": [
11
+ "fluxfiles.js",
12
+ "fluxfiles.min.js",
13
+ "fluxfiles.d.ts",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "build": "esbuild fluxfiles.js --minify --legal-comments=none --outfile=fluxfiles.min.js",
18
+ "test": "vitest run"
19
+ },
20
+ "devDependencies": {
21
+ "esbuild": "^0.28.0",
22
+ "jsdom": "^25.0.1",
23
+ "vitest": "^2.1.8"
24
+ },
25
+ "author": "thai-pc",
26
+ "homepage": "https://github.com/thai-pc/fluxfiles",
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/thai-pc/fluxfiles.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/thai-pc/fluxfiles/issues"
33
+ },
34
+ "keywords": [
35
+ "fluxfiles",
36
+ "file-manager",
37
+ "sdk",
38
+ "iframe",
39
+ "s3",
40
+ "r2",
41
+ "upload",
42
+ "media"
43
+ ]
44
44
  }