@fluxfiles/tinymce 1.0.1 → 1.0.3
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 +16 -6
- package/package.json +1 -1
- package/plugin.js +74 -7
- package/plugin.min.js +2 -1
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# FluxFiles — TinyMCE Plugin
|
|
2
2
|
|
|
3
|
-
Adds a **FluxFiles** toolbar button to TinyMCE 4
|
|
3
|
+
Adds a **FluxFiles** toolbar button to TinyMCE 4 to 8 for browsing and inserting files.
|
|
4
4
|
|
|
5
5
|
## Requirements
|
|
6
6
|
|
|
7
|
-
- TinyMCE 4.
|
|
8
|
-
- A running **FluxFiles core** server (the PHP backend / standalone app in `packages/core`). This plugin is only the editor button
|
|
7
|
+
- TinyMCE 4, 5, 6, 7 or 8. Self-hosted TinyMCE 7 and later also needs `license_key: 'gpl'` (or your commercial key) in `tinymce.init`; that is a TinyMCE requirement, not a FluxFiles one.
|
|
8
|
+
- A running **FluxFiles core** server (the PHP backend / standalone app in `packages/core`). This plugin is only the editor button: your page must load the FluxFiles SDK (`fluxfiles.js`, served by that server at `/fluxfiles.js`) before TinyMCE initialises, and `fluxfiles_endpoint` must point at that server.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
@@ -79,13 +79,23 @@ 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
|
-
- **TinyMCE 4
|
|
87
|
-
- **TinyMCE 5
|
|
88
|
-
-
|
|
94
|
+
- **TinyMCE 4** — uses the `addButton` / `addMenuItem` API.
|
|
95
|
+
- **TinyMCE 5, 6, 7, 8** — use the `ui.registry.addButton` / `ui.registry.addMenuItem` API.
|
|
96
|
+
- The version is detected when the plugin loads.
|
|
97
|
+
|
|
98
|
+
Checked in a real browser on 2026-11-20 against FluxFiles core 1.6.3 with TinyMCE 6.8.6, 7.9.3 and 8.10.2: the toolbar button opens the picker and inserts the image with `alt`, `width` and `height`, and the browse icon in TinyMCE's own *Insert/edit image* dialog fills Source, Alt, Width and Height.
|
|
89
99
|
|
|
90
100
|
## License
|
|
91
101
|
|
package/package.json
CHANGED
package/plugin.js
CHANGED
|
@@ -75,11 +75,72 @@
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
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
|
+
|
|
78
136
|
// Normalize a selected file into the bits both insert paths need.
|
|
79
|
-
function fileInfo(file) {
|
|
137
|
+
function fileInfo(file, endpoint, notify) {
|
|
80
138
|
// Prefer a permanent URL (public disk / public_url) so saved content
|
|
81
139
|
// doesn't embed an expiring presigned URL.
|
|
82
|
-
var
|
|
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
|
|
83
144
|
var name = file.name || file.basename || file.path || '';
|
|
84
145
|
var meta = file.meta || {};
|
|
85
146
|
|
|
@@ -92,7 +153,9 @@
|
|
|
92
153
|
// permanent_url. So we refuse here rather than insert a clean/broken image.
|
|
93
154
|
var embeddable = url !== '';
|
|
94
155
|
if (!embeddable) {
|
|
95
|
-
|
|
156
|
+
var msg = refusalMessage(reason, name);
|
|
157
|
+
console.warn('[FluxFiles] ' + msg);
|
|
158
|
+
if (notify) { notify(msg); }
|
|
96
159
|
} else if (/[?&](X-Amz-|Signature=)/.test(url)) {
|
|
97
160
|
// Still presigned (private disk, no public_url)? Warn — it will expire
|
|
98
161
|
// and break the saved link/image.
|
|
@@ -128,11 +191,12 @@
|
|
|
128
191
|
function openPicker(editor) {
|
|
129
192
|
open(editor, cfg(editor).multiple, function (payload) {
|
|
130
193
|
var files = Array.isArray(payload) ? payload : [payload];
|
|
194
|
+
var refused = [];
|
|
131
195
|
for (var i = 0; i < files.length; i++) {
|
|
132
196
|
var file = files[i];
|
|
133
197
|
if (!file || file.is_dir) continue;
|
|
134
|
-
var info = fileInfo(file);
|
|
135
|
-
if (!info.embeddable) continue; //
|
|
198
|
+
var info = fileInfo(file, cfg(editor).endpoint, function (m) { refused.push(m); });
|
|
199
|
+
if (!info.embeddable) continue; // refused → reported below
|
|
136
200
|
|
|
137
201
|
if (info.isImage) {
|
|
138
202
|
var dim = '';
|
|
@@ -143,6 +207,7 @@
|
|
|
143
207
|
editor.insertContent('<a href="' + escHtml(info.url) + '">' + escHtml(info.meta.title || info.name) + '</a>');
|
|
144
208
|
}
|
|
145
209
|
}
|
|
210
|
+
notifyUser(editor, refused);
|
|
146
211
|
});
|
|
147
212
|
}
|
|
148
213
|
|
|
@@ -154,8 +219,10 @@
|
|
|
154
219
|
open(editor, false, function (payload) {
|
|
155
220
|
var file = Array.isArray(payload) ? payload[0] : payload;
|
|
156
221
|
if (!file || file.is_dir) return;
|
|
157
|
-
var
|
|
158
|
-
|
|
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
|
|
159
226
|
var data = {};
|
|
160
227
|
|
|
161
228
|
if (meta && meta.filetype === 'image') {
|
package/plugin.min.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
(function(){"use strict";function
|
|
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,""").replace(/'/g,"'")}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"})})})();
|