@fluxfiles/ckeditor4 0.2.1 → 0.2.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 CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  Adds a **FluxFiles** toolbar button to CKEditor 4 for browsing and inserting files.
4
4
 
5
+ ## Requirements
6
+
7
+ - CKEditor 4
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 `endpoint` must point at it.
9
+
5
10
  ## Installation
6
11
 
7
12
  ```bash
@@ -14,12 +19,14 @@ or copy the plugin folder into your CKEditor `plugins/` directory:
14
19
 
15
20
  ```
16
21
  ckeditor/plugins/fluxfiles/
17
- ├── plugin.js
22
+ ├── plugin.js # readable source
23
+ ├── plugin.min.js # minified (~1.3 KB) — use in production
18
24
  └── README.md
19
25
  ```
20
26
 
21
- The toolbar icon is an inline SVG (no separate image file) — the same folder
22
- glyph the TinyMCE plugin uses.
27
+ A minified `plugin.min.js` ships alongside the source (CDN `unpkg`/`jsdelivr`
28
+ resolve to it); regenerate with `npm run build` (esbuild). The toolbar icon is an
29
+ inline SVG (no separate image file) — the same folder glyph the TinyMCE plugin uses.
23
30
 
24
31
  2. Load the FluxFiles SDK (`fluxfiles.js`) on the page.
25
32
 
@@ -42,9 +49,15 @@ CKEDITOR.replace('editor', {
42
49
 
43
50
  - Click the **FluxFiles** toolbar button (folder icon) in the **Insert** toolbar group.
44
51
  - The FluxFiles picker opens as a modal overlay.
45
- - Select a file — images are inserted as `<img>`, other files as `<a>` links.
52
+ - Select a file — images are inserted as `<img>` (with `alt` from the file's
53
+ metadata and `width`/`height` when known), other files as `<a>` links.
46
54
  - The modal closes automatically after selection.
47
55
 
56
+ > **Embedding & expiring URLs.** On a **private** disk the file URL is a
57
+ > *presigned* URL that expires (≤ 24h) — embedding it in saved content will break
58
+ > once it expires (the plugin logs a `console.warn`). For editor embeds use a
59
+ > **public** disk or a `public_url` so the inserted URL is permanent.
60
+
48
61
  ## Configuration
49
62
 
50
63
  | Option | Type | Default | Description |
@@ -55,6 +68,10 @@ CKEDITOR.replace('editor', {
55
68
  | `locale` | string | `null` | UI language code |
56
69
  | `multiple` | boolean | `false` | Allow multi-file selection |
57
70
 
71
+ ## License
72
+
73
+ MIT — see [LICENSE](LICENSE) for details.
74
+
58
75
  ## Links
59
76
 
60
77
  - Main repository: `https://github.com/thai-pc/fluxfiles`
package/package.json CHANGED
@@ -1,15 +1,21 @@
1
1
  {
2
2
  "name": "@fluxfiles/ckeditor4",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "CKEditor 4 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": { "test": "vitest run" },
12
- "devDependencies": { "jsdom": "^25.0.1", "vitest": "^2.1.8" },
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#ckeditor-4",
package/plugin.js CHANGED
@@ -48,19 +48,35 @@
48
48
  maxFiles: cfg.maxFiles || null,
49
49
  locale: cfg.locale || null,
50
50
  onSelect: function (payload) {
51
- var files = Array.isArray(payload) ? payload : (payload && payload.files ? payload.files : [payload]);
51
+ var files = Array.isArray(payload) ? payload : [payload];
52
+ var enc = CKEDITOR.tools.htmlEncode;
52
53
 
53
54
  for (var i = 0; i < files.length; i++) {
54
55
  var file = files[i];
55
- if (!file) continue;
56
+ if (!file || file.is_dir) continue;
56
57
 
57
- var url = file.url || '';
58
- var name = file.basename || file.name || file.path || '';
58
+ // Prefer a permanent URL (public disk / public_url) so saved
59
+ // content doesn't embed an expiring presigned URL.
60
+ var url = file.permanent_url || file.url || '';
61
+ var name = file.name || file.basename || file.path || '';
62
+ var meta = file.meta || {};
59
63
 
60
- if (/\.(jpe?g|png|gif|webp|svg|bmp|ico)$/i.test(name)) {
61
- editor.insertHtml('<img src="' + CKEDITOR.tools.htmlEncode(url) + '" alt="' + CKEDITOR.tools.htmlEncode(name) + '" />');
64
+ // Still presigned (private disk, no public_url)? Warn — it will
65
+ // expire and break the saved link/image.
66
+ if (/[?&](X-Amz-|Signature=)/.test(url)) {
67
+ console.warn('[FluxFiles] Inserting a presigned (expiring) URL — it will break when the URL expires. Use a public disk or public_url for embeds.');
68
+ }
69
+
70
+ var isImage = (file.mime && file.mime.indexOf('image/') === 0)
71
+ || /\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(name);
72
+
73
+ if (isImage) {
74
+ var dim = '';
75
+ if (file.width) { dim += ' width="' + parseInt(file.width, 10) + '"'; }
76
+ if (file.height) { dim += ' height="' + parseInt(file.height, 10) + '"'; }
77
+ editor.insertHtml('<img src="' + enc(url) + '" alt="' + enc(meta.alt_text || name) + '"' + dim + ' />');
62
78
  } else {
63
- editor.insertHtml('<a href="' + CKEDITOR.tools.htmlEncode(url) + '">' + CKEDITOR.tools.htmlEncode(name) + '</a>');
79
+ editor.insertHtml('<a href="' + enc(url) + '">' + enc(meta.title || name) + '</a>');
64
80
  }
65
81
  }
66
82
  }
package/plugin.min.js ADDED
@@ -0,0 +1 @@
1
+ (function(){"use strict";var p='<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" 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="#575757" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>',c="data:image/svg+xml,"+encodeURIComponent(p);CKEDITOR.plugins.add("fluxfiles",{init:function(i){var n=i.config.fluxfiles||{};i.addCommand("openFluxFiles",{exec:function(){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}FluxFiles.open({endpoint:n.endpoint||"",token:n.token||"",disk:n.disk||"local",mode:"picker",multiple:!!n.multiple,maxUploadMb:n.maxUploadMb||null,maxFiles:n.maxFiles||null,locale:n.locale||null,onSelect:function(l){for(var u=Array.isArray(l)?l:[l],t=CKEDITOR.tools.htmlEncode,a=0;a<u.length;a++){var e=u[a];if(!(!e||e.is_dir)){var s=e.permanent_url||e.url||"",o=e.name||e.basename||e.path||"",d=e.meta||{};/[?&](X-Amz-|Signature=)/.test(s)&&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 m=e.mime&&e.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(o);if(m){var r="";e.width&&(r+=' width="'+parseInt(e.width,10)+'"'),e.height&&(r+=' height="'+parseInt(e.height,10)+'"'),i.insertHtml('<img src="'+t(s)+'" alt="'+t(d.alt_text||o)+'"'+r+" />")}else i.insertHtml('<a href="'+t(s)+'">'+t(d.title||o)+"</a>")}}}})}}),i.ui.addButton("FluxFiles",{label:"FluxFiles",command:"openFluxFiles",toolbar:"insert",icon:c})}})})();