@fluxfiles/tinymce 0.2.2 → 0.3.0
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/LICENSE +21 -0
- package/README.md +17 -5
- package/package.json +3 -2
- package/plugin.js +126 -52
- package/plugin.min.js +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 thai-pc
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -46,11 +46,22 @@ tinymce.init({
|
|
|
46
46
|
|
|
47
47
|
## How It Works
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
49
|
+
Two ways to pick a file:
|
|
50
|
+
|
|
51
|
+
1. **Toolbar button** — click the **FluxFiles** button (folder/browse icon). The
|
|
52
|
+
picker opens; the selection is inserted directly (`<img>` for images with `alt`
|
|
53
|
+
from metadata and `width`/`height` when known, other files as `<a>` links).
|
|
54
|
+
2. **Native Insert/Edit Image dialog** — the plugin registers a
|
|
55
|
+
`file_picker_callback`, so the **Source** field of TinyMCE's own image dialog
|
|
56
|
+
(and the link/media dialogs) gets a *browse* icon. Clicking it opens FluxFiles
|
|
57
|
+
and fills the dialog's **Source + Alt + Width + Height**, so you can fine-tune
|
|
58
|
+
the image in the familiar native dialog before inserting (the "Browse Server" /
|
|
59
|
+
CKFinder pattern — no popup window).
|
|
60
|
+
|
|
61
|
+
The modal closes automatically after selection.
|
|
62
|
+
|
|
63
|
+
> The plugin only sets `file_picker_callback` if you haven't provided your own.
|
|
64
|
+
> Disable the native-dialog integration with `fluxfiles_image_dialog: false`.
|
|
54
65
|
|
|
55
66
|
> **Embedding & expiring URLs.** On a **private** disk the file URL is a
|
|
56
67
|
> *presigned* URL that expires (≤ 24h) — embedding it in saved content will break
|
|
@@ -66,6 +77,7 @@ tinymce.init({
|
|
|
66
77
|
| `fluxfiles_disk` | string | `'local'` | Storage disk |
|
|
67
78
|
| `fluxfiles_locale` | string | `null` | UI language code |
|
|
68
79
|
| `fluxfiles_multiple` | boolean | `false` | Allow multi-file selection |
|
|
80
|
+
| `fluxfiles_image_dialog` | boolean | `true` | Wire `file_picker_callback` into the native image/link/media dialogs |
|
|
69
81
|
|
|
70
82
|
## Compatibility
|
|
71
83
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluxfiles/tinymce",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "TinyMCE plugin for FluxFiles",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "plugin.js",
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
"files": [
|
|
10
10
|
"plugin.js",
|
|
11
11
|
"plugin.min.js",
|
|
12
|
-
"README.md"
|
|
12
|
+
"README.md",
|
|
13
|
+
"LICENSE"
|
|
13
14
|
],
|
|
14
15
|
"scripts": {
|
|
15
16
|
"build": "esbuild plugin.js --minify --legal-comments=none --outfile=plugin.min.js",
|
package/plugin.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* FluxFiles plugin for TinyMCE (4.x / 5.x compatible).
|
|
2
|
+
* FluxFiles plugin for TinyMCE (4.x / 5.x / 6.x compatible).
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Two integration points:
|
|
5
|
+
* 1. A toolbar/menu button ("fluxfiles") that opens the picker and inserts the
|
|
6
|
+
* selection directly (<img> for images, <a> otherwise).
|
|
7
|
+
* 2. A `file_picker_callback` wired into the editor so the native
|
|
8
|
+
* Insert/Edit Image (and link/media) dialog gets a Source "browse" icon that
|
|
9
|
+
* opens FluxFiles — filling the URL + alt + width/height of the native dialog
|
|
10
|
+
* (the "CKFinder" pattern). Disable with `fluxfiles_image_dialog: false`, and
|
|
11
|
+
* a host-provided `file_picker_callback` is always respected.
|
|
6
12
|
*
|
|
7
13
|
* Usage (TinyMCE 4):
|
|
8
14
|
* tinymce.init({
|
|
9
15
|
* selector: '#editor',
|
|
16
|
+
* plugins: 'image link',
|
|
10
17
|
* external_plugins: { fluxfiles: '/path/to/adapters/tinymce/plugin.js' },
|
|
11
|
-
* toolbar: 'fluxfiles',
|
|
18
|
+
* toolbar: 'fluxfiles | image',
|
|
12
19
|
* fluxfiles_endpoint: 'http://localhost:8080',
|
|
13
20
|
* fluxfiles_token: 'JWT_TOKEN',
|
|
14
21
|
* fluxfiles_disk: 'local',
|
|
@@ -16,7 +23,7 @@
|
|
|
16
23
|
* fluxfiles_multiple: false
|
|
17
24
|
* });
|
|
18
25
|
*
|
|
19
|
-
* Usage (TinyMCE 5):
|
|
26
|
+
* Usage (TinyMCE 5 / 6):
|
|
20
27
|
* Same config — the plugin auto-detects the version.
|
|
21
28
|
*/
|
|
22
29
|
(function () {
|
|
@@ -28,66 +35,133 @@
|
|
|
28
35
|
return div.innerHTML;
|
|
29
36
|
}
|
|
30
37
|
|
|
31
|
-
function
|
|
38
|
+
function cfg(editor) {
|
|
39
|
+
return {
|
|
40
|
+
endpoint: editor.getParam('fluxfiles_endpoint', ''),
|
|
41
|
+
token: editor.getParam('fluxfiles_token', ''),
|
|
42
|
+
disk: editor.getParam('fluxfiles_disk', 'local'),
|
|
43
|
+
locale: editor.getParam('fluxfiles_locale', null),
|
|
44
|
+
multiple: editor.getParam('fluxfiles_multiple', false),
|
|
45
|
+
maxUploadMb: editor.getParam('fluxfiles_max_upload_mb', null),
|
|
46
|
+
maxFiles: editor.getParam('fluxfiles_max_files', null)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Normalize a selected file into the bits both insert paths need.
|
|
51
|
+
function fileInfo(file) {
|
|
52
|
+
// Prefer a permanent URL (public disk / public_url) so saved content
|
|
53
|
+
// doesn't embed an expiring presigned URL.
|
|
54
|
+
var url = file.permanent_url || file.url || '';
|
|
55
|
+
var name = file.name || file.basename || file.path || '';
|
|
56
|
+
var meta = file.meta || {};
|
|
57
|
+
|
|
58
|
+
// Still presigned (private disk, no public_url)? Warn — it will expire and
|
|
59
|
+
// break the saved link/image.
|
|
60
|
+
if (/[?&](X-Amz-|Signature=)/.test(url)) {
|
|
61
|
+
console.warn('[FluxFiles] Inserting a presigned (expiring) URL — it will break when the URL expires. Use a public disk or public_url for embeds.');
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
var isImage = (file.mime && file.mime.indexOf('image/') === 0)
|
|
65
|
+
|| /\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(name);
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
url: url, name: name, meta: meta, isImage: isImage,
|
|
69
|
+
width: file.width || null, height: file.height || null
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function open(editor, multiple, onSelect) {
|
|
32
74
|
if (typeof FluxFiles === 'undefined') {
|
|
33
75
|
console.error('[FluxFiles] SDK (fluxfiles.js) is not loaded.');
|
|
34
76
|
return;
|
|
35
77
|
}
|
|
78
|
+
var c = cfg(editor);
|
|
79
|
+
FluxFiles.open({
|
|
80
|
+
endpoint: c.endpoint, token: c.token, disk: c.disk,
|
|
81
|
+
mode: 'picker', multiple: !!multiple,
|
|
82
|
+
maxUploadMb: c.maxUploadMb, maxFiles: c.maxFiles, locale: c.locale,
|
|
83
|
+
onSelect: onSelect
|
|
84
|
+
});
|
|
85
|
+
}
|
|
36
86
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
87
|
+
// ── 1) Standalone button: insert the selection directly ─────────────────
|
|
88
|
+
function openPicker(editor) {
|
|
89
|
+
open(editor, cfg(editor).multiple, function (payload) {
|
|
90
|
+
var files = Array.isArray(payload) ? payload : [payload];
|
|
91
|
+
for (var i = 0; i < files.length; i++) {
|
|
92
|
+
var file = files[i];
|
|
93
|
+
if (!file || file.is_dir) continue;
|
|
94
|
+
var info = fileInfo(file);
|
|
44
95
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
maxFiles: maxFiles,
|
|
53
|
-
locale: locale,
|
|
54
|
-
onSelect: function (payload) {
|
|
55
|
-
var files = Array.isArray(payload) ? payload : [payload];
|
|
56
|
-
|
|
57
|
-
for (var i = 0; i < files.length; i++) {
|
|
58
|
-
var file = files[i];
|
|
59
|
-
if (!file || file.is_dir) continue;
|
|
60
|
-
|
|
61
|
-
// Prefer a permanent URL (public disk / public_url) so saved
|
|
62
|
-
// content doesn't embed an expiring presigned URL.
|
|
63
|
-
var url = file.permanent_url || file.url || '';
|
|
64
|
-
var name = file.name || file.basename || file.path || '';
|
|
65
|
-
var meta = file.meta || {};
|
|
66
|
-
|
|
67
|
-
// Still presigned (private disk, no public_url)? Warn — it will
|
|
68
|
-
// expire and break the saved link/image.
|
|
69
|
-
if (/[?&](X-Amz-|Signature=)/.test(url)) {
|
|
70
|
-
console.warn('[FluxFiles] Inserting a presigned (expiring) URL — it will break when the URL expires. Use a public disk or public_url for embeds.');
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
var isImage = (file.mime && file.mime.indexOf('image/') === 0)
|
|
74
|
-
|| /\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(name);
|
|
75
|
-
|
|
76
|
-
if (isImage) {
|
|
77
|
-
var dim = '';
|
|
78
|
-
if (file.width) { dim += ' width="' + parseInt(file.width, 10) + '"'; }
|
|
79
|
-
if (file.height) { dim += ' height="' + parseInt(file.height, 10) + '"'; }
|
|
80
|
-
editor.insertContent('<img src="' + escHtml(url) + '" alt="' + escHtml(meta.alt_text || name) + '"' + dim + ' />');
|
|
81
|
-
} else {
|
|
82
|
-
editor.insertContent('<a href="' + escHtml(url) + '">' + escHtml(meta.title || name) + '</a>');
|
|
83
|
-
}
|
|
96
|
+
if (info.isImage) {
|
|
97
|
+
var dim = '';
|
|
98
|
+
if (info.width) { dim += ' width="' + parseInt(info.width, 10) + '"'; }
|
|
99
|
+
if (info.height) { dim += ' height="' + parseInt(info.height, 10) + '"'; }
|
|
100
|
+
editor.insertContent('<img src="' + escHtml(info.url) + '" alt="' + escHtml(info.meta.alt_text || info.name) + '"' + dim + ' />');
|
|
101
|
+
} else {
|
|
102
|
+
editor.insertContent('<a href="' + escHtml(info.url) + '">' + escHtml(info.meta.title || info.name) + '</a>');
|
|
84
103
|
}
|
|
85
104
|
}
|
|
86
105
|
});
|
|
87
106
|
}
|
|
88
107
|
|
|
108
|
+
// ── 2) Native dialog source: file_picker_callback ───────────────────────
|
|
109
|
+
function makeFilePicker(editor) {
|
|
110
|
+
// Signature per TinyMCE: (callback, value, meta) => …; meta.filetype is
|
|
111
|
+
// 'image' | 'media' | 'file' depending on which dialog opened it.
|
|
112
|
+
return function (callback, value, meta) {
|
|
113
|
+
open(editor, false, function (payload) {
|
|
114
|
+
var file = Array.isArray(payload) ? payload[0] : payload;
|
|
115
|
+
if (!file || file.is_dir) return;
|
|
116
|
+
var info = fileInfo(file);
|
|
117
|
+
var data = {};
|
|
118
|
+
|
|
119
|
+
if (meta && meta.filetype === 'image') {
|
|
120
|
+
data.alt = info.meta.alt_text || info.name;
|
|
121
|
+
if (info.width) { data.width = String(info.width); }
|
|
122
|
+
if (info.height) { data.height = String(info.height); }
|
|
123
|
+
} else if (meta && meta.filetype === 'media') {
|
|
124
|
+
// Source field only; the dialog handles the rest.
|
|
125
|
+
} else {
|
|
126
|
+
data.text = info.meta.title || info.name;
|
|
127
|
+
data.title = info.meta.title || info.name;
|
|
128
|
+
}
|
|
129
|
+
callback(info.url, data);
|
|
130
|
+
});
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// Register the picker so the native image/link/media dialogs can browse
|
|
135
|
+
// FluxFiles. Respects a host-provided file_picker_callback and the
|
|
136
|
+
// `fluxfiles_image_dialog: false` opt-out.
|
|
137
|
+
function wireFilePicker(editor) {
|
|
138
|
+
if (editor.getParam('fluxfiles_image_dialog', true) === false) return;
|
|
139
|
+
if (typeof editor.getParam('file_picker_callback') === 'function') return;
|
|
140
|
+
|
|
141
|
+
var fn = makeFilePicker(editor);
|
|
142
|
+
|
|
143
|
+
// v4: dialogs read editor.settings at open time.
|
|
144
|
+
if (editor.settings) {
|
|
145
|
+
editor.settings.file_picker_callback = fn;
|
|
146
|
+
if (!editor.settings.file_picker_types) {
|
|
147
|
+
editor.settings.file_picker_types = 'file image media';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// v5 / v6: the options registry is the source of truth.
|
|
151
|
+
try {
|
|
152
|
+
if (editor.options && typeof editor.options.set === 'function') {
|
|
153
|
+
editor.options.set('file_picker_callback', fn);
|
|
154
|
+
if (!editor.options.get('file_picker_types')) {
|
|
155
|
+
editor.options.set('file_picker_types', 'file image media');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} catch (e) { /* option not registered yet — the settings path covers v4/older */ }
|
|
159
|
+
}
|
|
160
|
+
|
|
89
161
|
// Single registration — version check inside callback (safe regardless of load order)
|
|
90
162
|
tinymce.PluginManager.add('fluxfiles', function (editor) {
|
|
163
|
+
wireFilePicker(editor);
|
|
164
|
+
|
|
91
165
|
var majorVersion = parseInt(tinymce.majorVersion, 10);
|
|
92
166
|
|
|
93
167
|
if (majorVersion >= 5) {
|
package/plugin.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";function
|
|
1
|
+
(function(){"use strict";function u(e){var i=document.createElement("div");return i.appendChild(document.createTextNode(e||"")),i.innerHTML}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),multiple:e.getParam("fluxfiles_multiple",!1),maxUploadMb:e.getParam("fluxfiles_max_upload_mb",null),maxFiles:e.getParam("fluxfiles_max_files",null)}}function m(e){var i=e.permanent_url||e.url||"",a=e.name||e.basename||e.path||"",t=e.meta||{};/[?&](X-Amz-|Signature=)/.test(i)&&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.");var s=e.mime&&e.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(a);return{url:i,name:a,meta:t,isImage:s,width:e.width||null,height:e.height||null}}function o(e,i,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:!!i,maxUploadMb:t.maxUploadMb,maxFiles:t.maxFiles,locale:t.locale,onSelect:a})}function f(e){o(e,c(e).multiple,function(i){for(var a=Array.isArray(i)?i:[i],t=0;t<a.length;t++){var s=a[t];if(!(!s||s.is_dir)){var n=m(s);if(n.isImage){var l="";n.width&&(l+=' width="'+parseInt(n.width,10)+'"'),n.height&&(l+=' height="'+parseInt(n.height,10)+'"'),e.insertContent('<img src="'+u(n.url)+'" alt="'+u(n.meta.alt_text||n.name)+'"'+l+" />")}else e.insertContent('<a href="'+u(n.url)+'">'+u(n.meta.title||n.name)+"</a>")}}})}function p(e){return function(i,a,t){o(e,!1,function(s){var n=Array.isArray(s)?s[0]:s;if(!(!n||n.is_dir)){var l=m(n),r={};t&&t.filetype==="image"?(r.alt=l.meta.alt_text||l.name,l.width&&(r.width=String(l.width)),l.height&&(r.height=String(l.height))):t&&t.filetype==="media"||(r.text=l.meta.title||l.name,r.title=l.meta.title||l.name),i(l.url,r)}})}}function g(e){if(e.getParam("fluxfiles_image_dialog",!0)!==!1&&typeof e.getParam("file_picker_callback")!="function"){var i=p(e);e.settings&&(e.settings.file_picker_callback=i,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",i),e.options.get("file_picker_types")||e.options.set("file_picker_types","file image media"))}catch{}}}tinymce.PluginManager.add("fluxfiles",function(e){g(e);var i=parseInt(tinymce.majorVersion,10);if(i>=5)return e.ui.registry.addIcon("fluxfiles",'<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" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>'),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",{icon:"browse",tooltip:"FluxFiles",onclick:function(){f(e)}}),e.addMenuItem("fluxfiles",{icon:"browse",text:"FluxFiles",onclick:function(){f(e)},context:"insert"})})})();
|