@fluxfiles/tinymce 0.2.2 → 0.3.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/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
- - Click the **FluxFiles** toolbar button (folder/browse icon).
50
- - The FluxFiles picker opens as a modal overlay.
51
- - Select a file — images are inserted as `<img>` (with `alt` from the file's
52
- metadata and `width`/`height` when known), other files as `<a>` links.
53
- - The modal closes automatically after selection.
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
@@ -64,8 +75,11 @@ tinymce.init({
64
75
  | `fluxfiles_endpoint` | string | `''` | FluxFiles server URL |
65
76
  | `fluxfiles_token` | string | `''` | JWT authentication token |
66
77
  | `fluxfiles_disk` | string | `'local'` | Storage disk |
78
+ | `fluxfiles_disks` | string[] | `null` | Disks shown in the picker sidebar |
67
79
  | `fluxfiles_locale` | string | `null` | UI language code |
80
+ | `fluxfiles_theme` | string | `null` | Picker theme: `light` / `dark` / `auto` |
68
81
  | `fluxfiles_multiple` | boolean | `false` | Allow multi-file selection |
82
+ | `fluxfiles_image_dialog` | boolean | `true` | Wire `file_picker_callback` into the native image/link/media dialogs |
69
83
 
70
84
  ## Compatibility
71
85
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluxfiles/tinymce",
3
- "version": "0.2.2",
3
+ "version": "0.3.1",
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,22 +1,30 @@
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
- * Adds a toolbar button that opens the FluxFiles picker.
5
- * Selected images are inserted as <img>, other files as <a>.
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',
15
22
  * fluxfiles_locale: 'en',
23
+ * fluxfiles_theme: 'dark', // optional — light | dark | auto
16
24
  * fluxfiles_multiple: false
17
25
  * });
18
26
  *
19
- * Usage (TinyMCE 5):
27
+ * Usage (TinyMCE 5 / 6):
20
28
  * Same config — the plugin auto-detects the version.
21
29
  */
22
30
  (function () {
@@ -28,66 +36,136 @@
28
36
  return div.innerHTML;
29
37
  }
30
38
 
31
- function openPicker(editor) {
39
+ function cfg(editor) {
40
+ return {
41
+ endpoint: editor.getParam('fluxfiles_endpoint', ''),
42
+ token: editor.getParam('fluxfiles_token', ''),
43
+ disk: editor.getParam('fluxfiles_disk', 'local'),
44
+ locale: editor.getParam('fluxfiles_locale', null),
45
+ theme: editor.getParam('fluxfiles_theme', null),
46
+ disks: editor.getParam('fluxfiles_disks', null),
47
+ multiple: editor.getParam('fluxfiles_multiple', false),
48
+ maxUploadMb: editor.getParam('fluxfiles_max_upload_mb', null),
49
+ maxFiles: editor.getParam('fluxfiles_max_files', null)
50
+ };
51
+ }
52
+
53
+ // Normalize a selected file into the bits both insert paths need.
54
+ function fileInfo(file) {
55
+ // Prefer a permanent URL (public disk / public_url) so saved content
56
+ // doesn't embed an expiring presigned URL.
57
+ var url = file.permanent_url || file.url || '';
58
+ var name = file.name || file.basename || file.path || '';
59
+ var meta = file.meta || {};
60
+
61
+ // Still presigned (private disk, no public_url)? Warn — it will expire and
62
+ // break the saved link/image.
63
+ if (/[?&](X-Amz-|Signature=)/.test(url)) {
64
+ console.warn('[FluxFiles] Inserting a presigned (expiring) URL — it will break when the URL expires. Use a public disk or public_url for embeds.');
65
+ }
66
+
67
+ var isImage = (file.mime && file.mime.indexOf('image/') === 0)
68
+ || /\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(name);
69
+
70
+ return {
71
+ url: url, name: name, meta: meta, isImage: isImage,
72
+ width: file.width || null, height: file.height || null
73
+ };
74
+ }
75
+
76
+ function open(editor, multiple, onSelect) {
32
77
  if (typeof FluxFiles === 'undefined') {
33
78
  console.error('[FluxFiles] SDK (fluxfiles.js) is not loaded.');
34
79
  return;
35
80
  }
81
+ var c = cfg(editor);
82
+ FluxFiles.open({
83
+ endpoint: c.endpoint, token: c.token, disk: c.disk,
84
+ mode: 'picker', multiple: !!multiple,
85
+ maxUploadMb: c.maxUploadMb, maxFiles: c.maxFiles, locale: c.locale,
86
+ theme: c.theme, disks: c.disks,
87
+ onSelect: onSelect
88
+ });
89
+ }
36
90
 
37
- var endpoint = editor.getParam('fluxfiles_endpoint', '');
38
- var token = editor.getParam('fluxfiles_token', '');
39
- var disk = editor.getParam('fluxfiles_disk', 'local');
40
- var locale = editor.getParam('fluxfiles_locale', null);
41
- var multiple = editor.getParam('fluxfiles_multiple', false);
42
- var maxUploadMb = editor.getParam('fluxfiles_max_upload_mb', null);
43
- var maxFiles = editor.getParam('fluxfiles_max_files', null);
91
+ // ── 1) Standalone button: insert the selection directly ─────────────────
92
+ function openPicker(editor) {
93
+ open(editor, cfg(editor).multiple, function (payload) {
94
+ var files = Array.isArray(payload) ? payload : [payload];
95
+ for (var i = 0; i < files.length; i++) {
96
+ var file = files[i];
97
+ if (!file || file.is_dir) continue;
98
+ var info = fileInfo(file);
44
99
 
45
- FluxFiles.open({
46
- endpoint: endpoint,
47
- token: token,
48
- disk: disk,
49
- mode: 'picker',
50
- multiple: !!multiple,
51
- maxUploadMb: maxUploadMb,
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
- }
100
+ if (info.isImage) {
101
+ var dim = '';
102
+ if (info.width) { dim += ' width="' + parseInt(info.width, 10) + '"'; }
103
+ if (info.height) { dim += ' height="' + parseInt(info.height, 10) + '"'; }
104
+ editor.insertContent('<img src="' + escHtml(info.url) + '" alt="' + escHtml(info.meta.alt_text || info.name) + '"' + dim + ' />');
105
+ } else {
106
+ editor.insertContent('<a href="' + escHtml(info.url) + '">' + escHtml(info.meta.title || info.name) + '</a>');
84
107
  }
85
108
  }
86
109
  });
87
110
  }
88
111
 
112
+ // ── 2) Native dialog source: file_picker_callback ───────────────────────
113
+ function makeFilePicker(editor) {
114
+ // Signature per TinyMCE: (callback, value, meta) => …; meta.filetype is
115
+ // 'image' | 'media' | 'file' depending on which dialog opened it.
116
+ return function (callback, value, meta) {
117
+ open(editor, false, function (payload) {
118
+ var file = Array.isArray(payload) ? payload[0] : payload;
119
+ if (!file || file.is_dir) return;
120
+ var info = fileInfo(file);
121
+ var data = {};
122
+
123
+ if (meta && meta.filetype === 'image') {
124
+ data.alt = info.meta.alt_text || info.name;
125
+ if (info.width) { data.width = String(info.width); }
126
+ if (info.height) { data.height = String(info.height); }
127
+ } else if (meta && meta.filetype === 'media') {
128
+ // Source field only; the dialog handles the rest.
129
+ } else {
130
+ data.text = info.meta.title || info.name;
131
+ data.title = info.meta.title || info.name;
132
+ }
133
+ callback(info.url, data);
134
+ });
135
+ };
136
+ }
137
+
138
+ // Register the picker so the native image/link/media dialogs can browse
139
+ // FluxFiles. Respects a host-provided file_picker_callback and the
140
+ // `fluxfiles_image_dialog: false` opt-out.
141
+ function wireFilePicker(editor) {
142
+ if (editor.getParam('fluxfiles_image_dialog', true) === false) return;
143
+ if (typeof editor.getParam('file_picker_callback') === 'function') return;
144
+
145
+ var fn = makeFilePicker(editor);
146
+
147
+ // v4: dialogs read editor.settings at open time.
148
+ if (editor.settings) {
149
+ editor.settings.file_picker_callback = fn;
150
+ if (!editor.settings.file_picker_types) {
151
+ editor.settings.file_picker_types = 'file image media';
152
+ }
153
+ }
154
+ // v5 / v6: the options registry is the source of truth.
155
+ try {
156
+ if (editor.options && typeof editor.options.set === 'function') {
157
+ editor.options.set('file_picker_callback', fn);
158
+ if (!editor.options.get('file_picker_types')) {
159
+ editor.options.set('file_picker_types', 'file image media');
160
+ }
161
+ }
162
+ } catch (e) { /* option not registered yet — the settings path covers v4/older */ }
163
+ }
164
+
89
165
  // Single registration — version check inside callback (safe regardless of load order)
90
166
  tinymce.PluginManager.add('fluxfiles', function (editor) {
167
+ wireFilePicker(editor);
168
+
91
169
  var majorVersion = parseInt(tinymce.majorVersion, 10);
92
170
 
93
171
  if (majorVersion >= 5) {
package/plugin.min.js CHANGED
@@ -1 +1 @@
1
- (function(){"use strict";function i(e){var t=document.createElement("div");return t.appendChild(document.createTextNode(e||"")),t.innerHTML}function l(e){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}var t=e.getParam("fluxfiles_endpoint",""),x=e.getParam("fluxfiles_token",""),m=e.getParam("fluxfiles_disk","local"),p=e.getParam("fluxfiles_locale",null),g=e.getParam("fluxfiles_multiple",!1),d=e.getParam("fluxfiles_max_upload_mb",null),h=e.getParam("fluxfiles_max_files",null);FluxFiles.open({endpoint:t,token:x,disk:m,mode:"picker",multiple:!!g,maxUploadMb:d,maxFiles:h,locale:p,onSelect:function(a){for(var f=Array.isArray(a)?a:[a],s=0;s<f.length;s++){var n=f[s];if(!(!n||n.is_dir)){var r=n.permanent_url||n.url||"",u=n.name||n.basename||n.path||"",c=n.meta||{};/[?&](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.");var v=n.mime&&n.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(u);if(v){var o="";n.width&&(o+=' width="'+parseInt(n.width,10)+'"'),n.height&&(o+=' height="'+parseInt(n.height,10)+'"'),e.insertContent('<img src="'+i(r)+'" alt="'+i(c.alt_text||u)+'"'+o+" />")}else e.insertContent('<a href="'+i(r)+'">'+i(c.title||u)+"</a>")}}}})}tinymce.PluginManager.add("fluxfiles",function(e){var t=parseInt(tinymce.majorVersion,10);if(t>=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(){l(e)}}),e.ui.registry.addMenuItem("fluxfiles",{icon:"fluxfiles",text:"FluxFiles",onAction:function(){l(e)}}),{getMetadata:function(){return{name:"FluxFiles",url:"https://github.com/thai-pc/fluxfiles"}}};e.addButton("fluxfiles",{icon:"browse",tooltip:"FluxFiles",onclick:function(){l(e)}}),e.addMenuItem("fluxfiles",{icon:"browse",text:"FluxFiles",onclick:function(){l(e)},context:"insert"})})})();
1
+ (function(){"use strict";function r(e){var t=document.createElement("div");return t.appendChild(document.createTextNode(e||"")),t.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),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)}}function m(e){var t=e.permanent_url||e.url||"",a=e.name||e.basename||e.path||"",i=e.meta||{};/[?&](X-Amz-|Signature=)/.test(t)&&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:t,name:a,meta:i,isImage:s,width:e.width||null,height:e.height||null}}function o(e,t,a){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}var i=c(e);FluxFiles.open({endpoint:i.endpoint,token:i.token,disk:i.disk,mode:"picker",multiple:!!t,maxUploadMb:i.maxUploadMb,maxFiles:i.maxFiles,locale:i.locale,theme:i.theme,disks:i.disks,onSelect:a})}function f(e){o(e,c(e).multiple,function(t){for(var a=Array.isArray(t)?t:[t],i=0;i<a.length;i++){var s=a[i];if(!(!s||s.is_dir)){var l=m(s);if(l.isImage){var n="";l.width&&(n+=' width="'+parseInt(l.width,10)+'"'),l.height&&(n+=' height="'+parseInt(l.height,10)+'"'),e.insertContent('<img src="'+r(l.url)+'" alt="'+r(l.meta.alt_text||l.name)+'"'+n+" />")}else e.insertContent('<a href="'+r(l.url)+'">'+r(l.meta.title||l.name)+"</a>")}}})}function g(e){return function(t,a,i){o(e,!1,function(s){var l=Array.isArray(s)?s[0]:s;if(!(!l||l.is_dir)){var n=m(l),u={};i&&i.filetype==="image"?(u.alt=n.meta.alt_text||n.name,n.width&&(u.width=String(n.width)),n.height&&(u.height=String(n.height))):i&&i.filetype==="media"||(u.text=n.meta.title||n.name,u.title=n.meta.title||n.name),t(n.url,u)}})}}function p(e){if(e.getParam("fluxfiles_image_dialog",!0)!==!1&&typeof e.getParam("file_picker_callback")!="function"){var t=g(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){p(e);var t=parseInt(tinymce.majorVersion,10);if(t>=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"})})})();