@fluxfiles/tinymce 1.0.0 → 1.0.2

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 CHANGED
@@ -79,8 +79,16 @@ The modal closes automatically after selection.
79
79
  | `fluxfiles_locale` | string | `null` | UI language code |
80
80
  | `fluxfiles_theme` | string | `null` | Picker theme: `light` / `dark` / `auto` |
81
81
  | `fluxfiles_multiple` | boolean | `false` | Allow multi-file selection |
82
+ | `fluxfiles_allowed_types` | string[] | `null` | Extensions (`.pdf` or `pdf`) or MIME types / patterns (`image/*`, `application/pdf`). Shown only in picker mode: non-matching files are hidden and cannot be selected. UI convenience, not a security boundary (the token's `allowed_ext` claim is the server-side check) |
82
83
  | `fluxfiles_image_dialog` | boolean | `true` | Wire `file_picker_callback` into the native image/link/media dialogs |
83
84
 
85
+ **Files with no permanent URL.** Two cases:
86
+
87
+ - On a gated local disk (`FLUXFILES_LOCAL_PRIVATE`) or an SFTP disk without `public_url`, `permanent_url` is `null` and the only link is an expiring `/api/fm/img|stream?token=` URL. The plugin never saves that into content: it shows one notification listing the refused files. Use a public disk or set `public_url`.
88
+ - A private bucket without `public_url` yields a presigned URL (up to 24h). That one **is** still inserted, with a `console.warn`, and it stops working when it expires.
89
+
90
+ Only `http(s)` URLs are ever inserted.
91
+
84
92
  ## Compatibility
85
93
 
86
94
  - **TinyMCE 4.x** — Uses `addButton` / `addMenuItem` API
@@ -94,5 +102,5 @@ MIT — see [LICENSE](LICENSE) for details.
94
102
  ## Links
95
103
 
96
104
  - Main repository: `https://github.com/thai-pc/fluxfiles`
97
- - Documentation: `https://github.com/thai-pc/fluxfiles#tinymce-4x--5x`
105
+ - Documentation: `https://github.com/thai-pc/fluxfiles#framework-adapters`
98
106
  - Issues: `https://github.com/thai-pc/fluxfiles/issues`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluxfiles/tinymce",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "TinyMCE plugin for FluxFiles",
5
5
  "license": "MIT",
6
6
  "main": "plugin.js",
@@ -19,7 +19,7 @@
19
19
  "devDependencies": { "esbuild": "^0.28.0", "jsdom": "^25.0.1", "vitest": "^2.1.8" },
20
20
  "publishConfig": { "access": "public" },
21
21
  "author": "thai-pc",
22
- "homepage": "https://github.com/thai-pc/fluxfiles#tinymce-4x--5x",
22
+ "homepage": "https://github.com/thai-pc/fluxfiles#framework-adapters",
23
23
  "repository": {
24
24
  "type": "git",
25
25
  "url": "git+https://github.com/thai-pc/fluxfiles.git",
package/plugin.js CHANGED
@@ -30,15 +30,16 @@
30
30
  (function () {
31
31
  'use strict';
32
32
 
33
- // Toolbar glyph: a folder with an "F", so it can't be mistaken for the editor's
34
- // own folder/browse buttons. Same shape as the CKEditor 4 and Summernote plugins.
33
+ // Toolbar glyph: the FluxFiles logo's square folder silhouette with an "F", as a
34
+ // line icon, so it can't be mistaken for the editor's own folder/browse buttons.
35
+ // Identical in the CKEditor 4, CKEditor 5 and Summernote plugins.
35
36
  // fill="none" sits on each <path>: TinyMCE's toolbar CSS sets `fill` on the <svg>,
36
37
  // which the paths would otherwise inherit (a solid black folder with no visible F).
37
38
  function iconSvg(color) {
38
39
  return '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">'
39
- + '<path d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" '
40
+ + '<path d="M3 5a2 2 0 012-2h5l2 2h7a2 2 0 012 2v12a2 2 0 01-2 2H5a2 2 0 01-2-2V5z" '
40
41
  + 'fill="none" stroke="' + color + '" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>'
41
- + '<path d="M10 16.5v-6h4.5M10 13.5h3.5" '
42
+ + '<path d="M10 16.5v-7h4.5M10 13h3.5" '
42
43
  + 'fill="none" stroke="' + color + '" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
43
44
  }
44
45
 
@@ -74,11 +75,72 @@
74
75
  };
75
76
  }
76
77
 
78
+ // Selected URLs must be absolute and permanent. Older cores return a
79
+ // root-relative url ('/storage/uploads/x') that would resolve against the HOST
80
+ // page; resolve it against the FluxFiles endpoint's origin. And never let an
81
+ // expiring .../img|stream ?token= URL reach saved content.
82
+ function absUrl(u, endpoint) {
83
+ if (typeof u !== 'string') return '';
84
+ // Strip leading whitespace/control chars first: browsers ignore them, so
85
+ // " \tjavascript:..." would otherwise slip past a scheme check.
86
+ var t = u.replace(/^[\u0000-\u0020]+/, '');
87
+ if (t === '') return '';
88
+ var r = null;
89
+ try { r = new URL(t, endpoint || window.location.href); } catch (e) {
90
+ try { r = new URL(t, window.location.href); } catch (e2) { return ''; }
91
+ }
92
+ // Only http(s) may reach saved content (drops javascript:, data:, vbscript:, ...).
93
+ return (r.protocol === 'http:' || r.protocol === 'https:') ? r.href : '';
94
+ }
95
+ function isTokenUrl(u) {
96
+ return /\/(img|stream)(\.php)?\?([^#]*&)?token=/.test(u);
97
+ }
98
+ // Why a selection cannot be inserted: 'preview' (no URL), 'unsafe' (not http/https),
99
+ // 'token' (only an expiring /img|/stream token link, e.g. a private local or SFTP disk).
100
+ function refusalReason(raw, url) {
101
+ if (raw === '') return 'preview';
102
+ if (url === '') return 'unsafe';
103
+ return isTokenUrl(url) ? 'token' : '';
104
+ }
105
+ function refusalMessage(reason, name) {
106
+ if (reason === 'token') {
107
+ return '"' + name + '" is only available through an expiring link (private disk without a public URL), so it was not inserted. Use a public disk or set public_url.';
108
+ }
109
+ if (reason === 'unsafe') {
110
+ return '"' + name + '" has a URL that is not http(s), so it was not inserted.';
111
+ }
112
+ return '"' + name + '" is preview-only (no embeddable URL, e.g. a watermark overlay with allow_download=false), so it was not inserted. Burn in the watermark (Watermark editor, Apply) or issue a downloadable token to embed it.';
113
+ }
114
+ // User-visible refusal (a console.warn alone is invisible to editors).
115
+ // One combined message per selection (at most 5 lines).
116
+ function joinRefusals(msgs) {
117
+ var out = msgs.slice(0, 5);
118
+ if (msgs.length > 5) { out.push('… and ' + (msgs.length - 5) + ' more'); }
119
+ return out;
120
+ }
121
+ // TinyMCE 4 and 5 (< 5.10.8) render a notification's text as raw HTML and the
122
+ // messages carry file names (which can hold markup): escape them. Newer versions
123
+ // sanitize/render the same escaped text, so it displays as plain characters.
124
+ function notifyUser(editor, msgs) {
125
+ if (!msgs.length) return;
126
+ var lines = joinRefusals(msgs);
127
+ try {
128
+ if (editor && editor.notificationManager) {
129
+ editor.notificationManager.open({ text: lines.map(escHtml).join('<br>'), type: 'warning', timeout: 8000 });
130
+ return;
131
+ }
132
+ } catch (e) { /* fall through */ }
133
+ if (typeof window.alert === 'function') { try { window.alert(lines.join('\n')); } catch (e) { /* ignore */ } }
134
+ }
135
+
77
136
  // Normalize a selected file into the bits both insert paths need.
78
- function fileInfo(file) {
137
+ function fileInfo(file, endpoint, notify) {
79
138
  // Prefer a permanent URL (public disk / public_url) so saved content
80
139
  // doesn't embed an expiring presigned URL.
81
- var url = file.permanent_url || file.url || '';
140
+ var raw = file.permanent_url || file.url || '';
141
+ var url = absUrl(raw, endpoint);
142
+ var reason = refusalReason(raw, url);
143
+ if (reason) { url = ''; } // expiring token / non-http(s) URL: never save it
82
144
  var name = file.name || file.basename || file.path || '';
83
145
  var meta = file.meta || {};
84
146
 
@@ -91,7 +153,9 @@
91
153
  // permanent_url. So we refuse here rather than insert a clean/broken image.
92
154
  var embeddable = url !== '';
93
155
  if (!embeddable) {
94
- console.warn('[FluxFiles] "' + name + '" is preview-only (no embeddable URL — e.g. a watermark overlay with allow_download=false), so it was not inserted. Burn in the watermark (Watermark editor → Apply) or issue a downloadable token to embed it.');
156
+ var msg = refusalMessage(reason, name);
157
+ console.warn('[FluxFiles] ' + msg);
158
+ if (notify) { notify(msg); }
95
159
  } else if (/[?&](X-Amz-|Signature=)/.test(url)) {
96
160
  // Still presigned (private disk, no public_url)? Warn — it will expire
97
161
  // and break the saved link/image.
@@ -127,11 +191,12 @@
127
191
  function openPicker(editor) {
128
192
  open(editor, cfg(editor).multiple, function (payload) {
129
193
  var files = Array.isArray(payload) ? payload : [payload];
194
+ var refused = [];
130
195
  for (var i = 0; i < files.length; i++) {
131
196
  var file = files[i];
132
197
  if (!file || file.is_dir) continue;
133
- var info = fileInfo(file);
134
- if (!info.embeddable) continue; // preview-only → already warned
198
+ var info = fileInfo(file, cfg(editor).endpoint, function (m) { refused.push(m); });
199
+ if (!info.embeddable) continue; // refused → reported below
135
200
 
136
201
  if (info.isImage) {
137
202
  var dim = '';
@@ -142,6 +207,7 @@
142
207
  editor.insertContent('<a href="' + escHtml(info.url) + '">' + escHtml(info.meta.title || info.name) + '</a>');
143
208
  }
144
209
  }
210
+ notifyUser(editor, refused);
145
211
  });
146
212
  }
147
213
 
@@ -153,8 +219,10 @@
153
219
  open(editor, false, function (payload) {
154
220
  var file = Array.isArray(payload) ? payload[0] : payload;
155
221
  if (!file || file.is_dir) return;
156
- var info = fileInfo(file);
157
- if (!info.embeddable) return; // preview-only → already warned
222
+ var refused = [];
223
+ var info = fileInfo(file, cfg(editor).endpoint, function (m) { refused.push(m); });
224
+ notifyUser(editor, refused);
225
+ if (!info.embeddable) return; // refused → already reported
158
226
  var data = {};
159
227
 
160
228
  if (meta && meta.filetype === 'image') {
package/plugin.min.js CHANGED
@@ -1 +1,2 @@
1
- (function(){"use strict";function o(e){return'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"><path d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" fill="none" stroke="'+e+'" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M10 16.5v-6h4.5M10 13.5h3.5" fill="none" stroke="'+e+'" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>'}function m(){return"data:image/svg+xml,"+encodeURIComponent(o("#595959"))}function u(e){var l=document.createElement("div");return l.appendChild(document.createTextNode(e||"")),l.innerHTML.replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function c(e){return{endpoint:e.getParam("fluxfiles_endpoint",""),token:e.getParam("fluxfiles_token",""),disk:e.getParam("fluxfiles_disk","local"),locale:e.getParam("fluxfiles_locale",null),theme:e.getParam("fluxfiles_theme",null),disks:e.getParam("fluxfiles_disks",null),multiple:e.getParam("fluxfiles_multiple",!1),maxUploadMb:e.getParam("fluxfiles_max_upload_mb",null),maxFiles:e.getParam("fluxfiles_max_files",null),allowedTypes:e.getParam("fluxfiles_allowed_types",null),path:e.getParam("fluxfiles_path",null)}}function p(e){var l=e.permanent_url||e.url||"",a=e.name||e.basename||e.path||"",t=e.meta||{},s=l!=="";s?/[?&](X-Amz-|Signature=)/.test(l)&&console.warn("[FluxFiles] Inserting a presigned (expiring) URL \u2014 it will break when the URL expires. Use a public disk or public_url for embeds."):console.warn('[FluxFiles] "'+a+'" is preview-only (no embeddable URL \u2014 e.g. a watermark overlay with allow_download=false), so it was not inserted. Burn in the watermark (Watermark editor \u2192 Apply) or issue a downloadable token to embed it.');var i=e.mime&&e.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(a);return{url:l,name:a,meta:t,isImage:i,embeddable:s,width:e.width||null,height:e.height||null}}function g(e,l,a){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}var t=c(e);FluxFiles.open({endpoint:t.endpoint,token:t.token,disk:t.disk,mode:"picker",multiple:!!l,maxUploadMb:t.maxUploadMb,maxFiles:t.maxFiles,locale:t.locale,theme:t.theme,disks:t.disks,allowedTypes:t.allowedTypes,path:t.path,onSelect:a})}function f(e){g(e,c(e).multiple,function(l){for(var a=Array.isArray(l)?l:[l],t=0;t<a.length;t++){var s=a[t];if(!(!s||s.is_dir)){var i=p(s);if(i.embeddable)if(i.isImage){var n="";i.width&&(n+=' width="'+parseInt(i.width,10)+'"'),i.height&&(n+=' height="'+parseInt(i.height,10)+'"'),e.insertContent('<img src="'+u(i.url)+'" alt="'+u(i.meta.alt_text||i.name)+'"'+n+" />")}else e.insertContent('<a href="'+u(i.url)+'">'+u(i.meta.title||i.name)+"</a>")}}})}function h(e){return function(l,a,t){g(e,!1,function(s){var i=Array.isArray(s)?s[0]:s;if(!(!i||i.is_dir)){var n=p(i);if(n.embeddable){var r={};t&&t.filetype==="image"?(r.alt=n.meta.alt_text||n.name,n.width&&(r.width=String(n.width)),n.height&&(r.height=String(n.height))):t&&t.filetype==="media"||(r.text=n.meta.title||n.name,r.title=n.meta.title||n.name),l(n.url,r)}}})}}function d(e){if(e.getParam("fluxfiles_image_dialog",!0)!==!1&&typeof e.getParam("file_picker_callback")!="function"){var l=h(e);e.settings&&(e.settings.file_picker_callback=l,e.settings.file_picker_types||(e.settings.file_picker_types="file image media"));try{e.options&&typeof e.options.set=="function"&&(e.options.set("file_picker_callback",l),e.options.get("file_picker_types")||e.options.set("file_picker_types","file image media"))}catch{}}}tinymce.PluginManager.add("fluxfiles",function(e){d(e);var l=parseInt(tinymce.majorVersion,10);if(l>=5)return e.ui.registry.addIcon("fluxfiles",o("currentColor")),e.ui.registry.addButton("fluxfiles",{icon:"fluxfiles",tooltip:"FluxFiles",onAction:function(){f(e)}}),e.ui.registry.addMenuItem("fluxfiles",{icon:"fluxfiles",text:"FluxFiles",onAction:function(){f(e)}}),{getMetadata:function(){return{name:"FluxFiles",url:"https://github.com/thai-pc/fluxfiles"}}};e.addButton("fluxfiles",{image:m(),tooltip:"FluxFiles",onclick:function(){f(e)}}),e.addMenuItem("fluxfiles",{image:m(),text:"FluxFiles",onclick:function(){f(e)},context:"insert"})})})();
1
+ (function(){"use strict";function m(e){return'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"><path d="M3 5a2 2 0 012-2h5l2 2h7a2 2 0 012 2v12a2 2 0 01-2 2H5a2 2 0 01-2-2V5z" fill="none" stroke="'+e+'" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/><path d="M10 16.5v-7h4.5M10 13h3.5" fill="none" stroke="'+e+'" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>'}function h(){return"data:image/svg+xml,"+encodeURIComponent(m("#595959"))}function o(e){var t=document.createElement("div");return t.appendChild(document.createTextNode(e||"")),t.innerHTML.replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function f(e){return{endpoint:e.getParam("fluxfiles_endpoint",""),token:e.getParam("fluxfiles_token",""),disk:e.getParam("fluxfiles_disk","local"),locale:e.getParam("fluxfiles_locale",null),theme:e.getParam("fluxfiles_theme",null),disks:e.getParam("fluxfiles_disks",null),multiple:e.getParam("fluxfiles_multiple",!1),maxUploadMb:e.getParam("fluxfiles_max_upload_mb",null),maxFiles:e.getParam("fluxfiles_max_files",null),allowedTypes:e.getParam("fluxfiles_allowed_types",null),path:e.getParam("fluxfiles_path",null)}}function k(e,t){if(typeof e!="string")return"";var l=e.replace(/^[\u0000-\u0020]+/,"");if(l==="")return"";var n=null;try{n=new URL(l,t||window.location.href)}catch{try{n=new URL(l,window.location.href)}catch{return""}}return n.protocol==="http:"||n.protocol==="https:"?n.href:""}function w(e){return/\/(img|stream)(\.php)?\?([^#]*&)?token=/.test(e)}function v(e,t){return e===""?"preview":t===""?"unsafe":w(t)?"token":""}function _(e,t){return e==="token"?'"'+t+'" is only available through an expiring link (private disk without a public URL), so it was not inserted. Use a public disk or set public_url.':e==="unsafe"?'"'+t+'" has a URL that is not http(s), so it was not inserted.':'"'+t+'" is preview-only (no embeddable URL, e.g. a watermark overlay with allow_download=false), so it was not inserted. Burn in the watermark (Watermark editor, Apply) or issue a downloadable token to embed it.'}function b(e){var t=e.slice(0,5);return e.length>5&&t.push("\u2026 and "+(e.length-5)+" more"),t}function g(e,t){if(t.length){var l=b(t);try{if(e&&e.notificationManager){e.notificationManager.open({text:l.map(o).join("<br>"),type:"warning",timeout:8e3});return}}catch{}if(typeof window.alert=="function")try{window.alert(l.join(`
2
+ `))}catch{}}}function d(e,t,l){var n=e.permanent_url||e.url||"",r=k(n,t),s=v(n,r);s&&(r="");var i=e.name||e.basename||e.path||"",a=e.meta||{},u=r!=="";if(u)/[?&](X-Amz-|Signature=)/.test(r)&&console.warn("[FluxFiles] Inserting a presigned (expiring) URL \u2014 it will break when the URL expires. Use a public disk or public_url for embeds.");else{var p=_(s,i);console.warn("[FluxFiles] "+p),l&&l(p)}var P=e.mime&&e.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(i);return{url:r,name:i,meta:a,isImage:P,embeddable:u,width:e.width||null,height:e.height||null}}function x(e,t,l){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}var n=f(e);FluxFiles.open({endpoint:n.endpoint,token:n.token,disk:n.disk,mode:"picker",multiple:!!t,maxUploadMb:n.maxUploadMb,maxFiles:n.maxFiles,locale:n.locale,theme:n.theme,disks:n.disks,allowedTypes:n.allowedTypes,path:n.path,onSelect:l})}function c(e){x(e,f(e).multiple,function(t){for(var l=Array.isArray(t)?t:[t],n=[],r=0;r<l.length;r++){var s=l[r];if(!(!s||s.is_dir)){var i=d(s,f(e).endpoint,function(u){n.push(u)});if(i.embeddable)if(i.isImage){var a="";i.width&&(a+=' width="'+parseInt(i.width,10)+'"'),i.height&&(a+=' height="'+parseInt(i.height,10)+'"'),e.insertContent('<img src="'+o(i.url)+'" alt="'+o(i.meta.alt_text||i.name)+'"'+a+" />")}else e.insertContent('<a href="'+o(i.url)+'">'+o(i.meta.title||i.name)+"</a>")}}g(e,n)})}function y(e){return function(t,l,n){x(e,!1,function(r){var s=Array.isArray(r)?r[0]:r;if(!(!s||s.is_dir)){var i=[],a=d(s,f(e).endpoint,function(p){i.push(p)});if(g(e,i),!!a.embeddable){var u={};n&&n.filetype==="image"?(u.alt=a.meta.alt_text||a.name,a.width&&(u.width=String(a.width)),a.height&&(u.height=String(a.height))):n&&n.filetype==="media"||(u.text=a.meta.title||a.name,u.title=a.meta.title||a.name),t(a.url,u)}}})}}function F(e){if(e.getParam("fluxfiles_image_dialog",!0)!==!1&&typeof e.getParam("file_picker_callback")!="function"){var t=y(e);e.settings&&(e.settings.file_picker_callback=t,e.settings.file_picker_types||(e.settings.file_picker_types="file image media"));try{e.options&&typeof e.options.set=="function"&&(e.options.set("file_picker_callback",t),e.options.get("file_picker_types")||e.options.set("file_picker_types","file image media"))}catch{}}}tinymce.PluginManager.add("fluxfiles",function(e){F(e);var t=parseInt(tinymce.majorVersion,10);if(t>=5)return e.ui.registry.addIcon("fluxfiles",m("currentColor")),e.ui.registry.addButton("fluxfiles",{icon:"fluxfiles",tooltip:"FluxFiles",onAction:function(){c(e)}}),e.ui.registry.addMenuItem("fluxfiles",{icon:"fluxfiles",text:"FluxFiles",onAction:function(){c(e)}}),{getMetadata:function(){return{name:"FluxFiles",url:"https://github.com/thai-pc/fluxfiles"}}};e.addButton("fluxfiles",{image:h(),tooltip:"FluxFiles",onclick:function(){c(e)}}),e.addMenuItem("fluxfiles",{image:h(),text:"FluxFiles",onclick:function(){c(e)},context:"insert"})})})();