@fluxfiles/tinymce 0.2.0 → 0.2.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 +21 -2
- package/package.json +9 -3
- package/plugin.js +22 -7
- package/plugin.min.js +1 -0
package/README.md
CHANGED
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Adds a **FluxFiles** toolbar button to TinyMCE 4.x / 5.x for browsing and inserting files.
|
|
4
4
|
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- TinyMCE 4.x or 5.x
|
|
8
|
+
- A running **FluxFiles core** server (the PHP backend / standalone app in `packages/core`). This plugin is only the editor button — it loads the FluxFiles SDK (`fluxfiles.js`) from that server and `fluxfiles_endpoint` must point at it.
|
|
9
|
+
|
|
5
10
|
## Installation
|
|
6
11
|
|
|
7
12
|
```bash
|
|
@@ -14,10 +19,14 @@ the plugin folder into your TinyMCE `plugins/` directory:
|
|
|
14
19
|
|
|
15
20
|
```
|
|
16
21
|
tinymce/plugins/fluxfiles/
|
|
17
|
-
├── plugin.js
|
|
22
|
+
├── plugin.js # readable source
|
|
23
|
+
├── plugin.min.js # minified (~1.8 KB) — use in production
|
|
18
24
|
└── README.md
|
|
19
25
|
```
|
|
20
26
|
|
|
27
|
+
A minified `plugin.min.js` ships alongside the source (CDN `unpkg`/`jsdelivr`
|
|
28
|
+
resolve to it); regenerate with `npm run build` (esbuild).
|
|
29
|
+
|
|
21
30
|
2. Load the FluxFiles SDK (`fluxfiles.js`) on the page.
|
|
22
31
|
|
|
23
32
|
3. Enable the plugin:
|
|
@@ -39,9 +48,15 @@ tinymce.init({
|
|
|
39
48
|
|
|
40
49
|
- Click the **FluxFiles** toolbar button (folder/browse icon).
|
|
41
50
|
- The FluxFiles picker opens as a modal overlay.
|
|
42
|
-
- Select a file — images are inserted as `<img
|
|
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.
|
|
43
53
|
- The modal closes automatically after selection.
|
|
44
54
|
|
|
55
|
+
> **Embedding & expiring URLs.** On a **private** disk the file URL is a
|
|
56
|
+
> *presigned* URL that expires (≤ 24h) — embedding it in saved content will break
|
|
57
|
+
> once it expires (the plugin logs a `console.warn`). For editor embeds use a
|
|
58
|
+
> **public** disk or a `public_url` so the inserted URL is permanent.
|
|
59
|
+
|
|
45
60
|
## Configuration
|
|
46
61
|
|
|
47
62
|
| Option | Type | Default | Description |
|
|
@@ -58,6 +73,10 @@ tinymce.init({
|
|
|
58
73
|
- **TinyMCE 5.x** — Uses `ui.registry.addButton` / `ui.registry.addMenuItem` API
|
|
59
74
|
- Auto-detects version at load time.
|
|
60
75
|
|
|
76
|
+
## License
|
|
77
|
+
|
|
78
|
+
MIT — see [LICENSE](LICENSE) for details.
|
|
79
|
+
|
|
61
80
|
## Links
|
|
62
81
|
|
|
63
82
|
- Main repository: `https://github.com/thai-pc/fluxfiles`
|
package/package.json
CHANGED
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluxfiles/tinymce",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "TinyMCE plugin for FluxFiles",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "plugin.js",
|
|
7
|
+
"unpkg": "plugin.min.js",
|
|
8
|
+
"jsdelivr": "plugin.min.js",
|
|
7
9
|
"files": [
|
|
8
10
|
"plugin.js",
|
|
11
|
+
"plugin.min.js",
|
|
9
12
|
"README.md"
|
|
10
13
|
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "esbuild plugin.js --minify --legal-comments=none --outfile=plugin.min.js",
|
|
16
|
+
"test": "vitest run"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": { "esbuild": "^0.28.0", "jsdom": "^25.0.1", "vitest": "^2.1.8" },
|
|
13
19
|
"publishConfig": { "access": "public" },
|
|
14
20
|
"author": "thai-pc",
|
|
15
21
|
"homepage": "https://github.com/thai-pc/fluxfiles#tinymce-4x--5x",
|
package/plugin.js
CHANGED
|
@@ -52,19 +52,34 @@
|
|
|
52
52
|
maxFiles: maxFiles,
|
|
53
53
|
locale: locale,
|
|
54
54
|
onSelect: function (payload) {
|
|
55
|
-
var files = Array.isArray(payload) ? payload :
|
|
55
|
+
var files = Array.isArray(payload) ? payload : [payload];
|
|
56
56
|
|
|
57
57
|
for (var i = 0; i < files.length; i++) {
|
|
58
58
|
var file = files[i];
|
|
59
|
-
if (!file) continue;
|
|
59
|
+
if (!file || file.is_dir) continue;
|
|
60
60
|
|
|
61
|
-
|
|
62
|
-
|
|
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 || {};
|
|
63
66
|
|
|
64
|
-
|
|
65
|
-
|
|
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 + ' />');
|
|
66
81
|
} else {
|
|
67
|
-
editor.insertContent('<a href="' + escHtml(url) + '">' + escHtml(name) + '</a>');
|
|
82
|
+
editor.insertContent('<a href="' + escHtml(url) + '">' + escHtml(meta.title || name) + '</a>');
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
85
|
}
|
package/plugin.min.js
ADDED
|
@@ -0,0 +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"})})})();
|