@fluxfiles/ckeditor4 0.2.2 → 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
@@ -44,9 +49,15 @@ CKEDITOR.replace('editor', {
44
49
 
45
50
  - Click the **FluxFiles** toolbar button (folder icon) in the **Insert** toolbar group.
46
51
  - The FluxFiles picker opens as a modal overlay.
47
- - 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.
48
54
  - The modal closes automatically after selection.
49
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
+
50
61
  ## Configuration
51
62
 
52
63
  | Option | Type | Default | Description |
@@ -57,6 +68,10 @@ CKEDITOR.replace('editor', {
57
68
  | `locale` | string | `null` | UI language code |
58
69
  | `multiple` | boolean | `false` | Allow multi-file selection |
59
70
 
71
+ ## License
72
+
73
+ MIT — see [LICENSE](LICENSE) for details.
74
+
60
75
  ## Links
61
76
 
62
77
  - Main repository: `https://github.com/thai-pc/fluxfiles`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluxfiles/ckeditor4",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "CKEditor 4 plugin for FluxFiles",
5
5
  "license": "MIT",
6
6
  "main": "plugin.js",
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 CHANGED
@@ -1 +1 @@
1
- (function(){"use strict";var r='<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>',u="data:image/svg+xml,"+encodeURIComponent(r);CKEDITOR.plugins.add("fluxfiles",{init:function(n){var e=n.config.fluxfiles||{};n.addCommand("openFluxFiles",{exec:function(){if(typeof FluxFiles>"u"){console.error("[FluxFiles] SDK (fluxfiles.js) is not loaded.");return}FluxFiles.open({endpoint:e.endpoint||"",token:e.token||"",disk:e.disk||"local",mode:"picker",multiple:!!e.multiple,maxUploadMb:e.maxUploadMb||null,maxFiles:e.maxFiles||null,locale:e.locale||null,onSelect:function(l){for(var s=Array.isArray(l)?l:l&&l.files?l.files:[l],t=0;t<s.length;t++){var o=s[t];if(o){var a=o.url||"",i=o.basename||o.name||o.path||"";/\.(jpe?g|png|gif|webp|svg|bmp|ico)$/i.test(i)?n.insertHtml('<img src="'+CKEDITOR.tools.htmlEncode(a)+'" alt="'+CKEDITOR.tools.htmlEncode(i)+'" />'):n.insertHtml('<a href="'+CKEDITOR.tools.htmlEncode(a)+'">'+CKEDITOR.tools.htmlEncode(i)+"</a>")}}}})}}),n.ui.addButton("FluxFiles",{label:"FluxFiles",command:"openFluxFiles",toolbar:"insert",icon:u})}})})();
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})}})})();