@fluxfiles/ckeditor4 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 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
@@ -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
@@ -42,10 +47,26 @@ CKEDITOR.replace('editor', {
42
47
 
43
48
  ## How It Works
44
49
 
45
- - Click the **FluxFiles** toolbar button (folder icon) in the **Insert** toolbar group.
46
- - The FluxFiles picker opens as a modal overlay.
47
- - Select a file — images are inserted as `<img>`, other files as `<a>` links.
48
- - The modal closes automatically after selection.
50
+ Two ways to pick a file:
51
+
52
+ 1. **Toolbar button** — click the **FluxFiles** button (folder icon) in the
53
+ **Insert** group. The picker opens; the selection is inserted directly
54
+ (`<img>` for images with `alt` from metadata and `width`/`height` when known,
55
+ other files as `<a>` links).
56
+ 2. **Native Image dialog** — the plugin injects a **Browse FluxFiles** button into
57
+ CKEditor's own *Image Properties* dialog. Clicking it opens FluxFiles inline
58
+ (no popup) and fills the dialog's **URL + Alternative Text + Width + Height**,
59
+ so you can set border/alignment/etc. in the native dialog before inserting
60
+ (the "Browse Server" / CKFinder pattern).
61
+
62
+ The modal closes automatically after selection.
63
+
64
+ > Disable the native Image-dialog button with `fluxfiles: { imageDialog: false }`.
65
+
66
+ > **Embedding & expiring URLs.** On a **private** disk the file URL is a
67
+ > *presigned* URL that expires (≤ 24h) — embedding it in saved content will break
68
+ > once it expires (the plugin logs a `console.warn`). For editor embeds use a
69
+ > **public** disk or a `public_url` so the inserted URL is permanent.
49
70
 
50
71
  ## Configuration
51
72
 
@@ -56,6 +77,11 @@ CKEDITOR.replace('editor', {
56
77
  | `disk` | string | `'local'` | Storage disk |
57
78
  | `locale` | string | `null` | UI language code |
58
79
  | `multiple` | boolean | `false` | Allow multi-file selection |
80
+ | `imageDialog` | boolean | `true` | Inject the **Browse FluxFiles** button into the native Image dialog |
81
+
82
+ ## License
83
+
84
+ MIT — see [LICENSE](LICENSE) for details.
59
85
 
60
86
  ## Links
61
87
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluxfiles/ckeditor4",
3
- "version": "0.2.2",
3
+ "version": "0.3.0",
4
4
  "description": "CKEditor 4 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,8 +1,14 @@
1
1
  /**
2
2
  * FluxFiles plugin for CKEditor 4.
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 button ("FluxFiles") that opens the picker and inserts the
6
+ * selection directly (<img> for images, <a> otherwise).
7
+ * 2. A "Browse FluxFiles" button injected into the native **Image** dialog
8
+ * (Image Properties) that opens FluxFiles inline and fills the dialog's
9
+ * URL + Alt + Width + Height fields — the "Browse Server" / CKFinder
10
+ * pattern, but without a popup window. Disable with
11
+ * `config.fluxfiles.imageDialog = false`.
6
12
  *
7
13
  * Usage:
8
14
  * CKEDITOR.replace('editor', {
@@ -27,41 +33,102 @@
27
33
  + 'stroke="#575757" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
28
34
  var ICON_URI = 'data:image/svg+xml,' + encodeURIComponent(ICON_SVG);
29
35
 
36
+ // Normalize a selected file into the bits the insert / dialog paths need.
37
+ function fileInfo(file) {
38
+ var url = file.permanent_url || file.url || '';
39
+ var name = file.name || file.basename || file.path || '';
40
+ var meta = file.meta || {};
41
+ if (/[?&](X-Amz-|Signature=)/.test(url)) {
42
+ console.warn('[FluxFiles] Inserting a presigned (expiring) URL — it will break when the URL expires. Use a public disk or public_url for embeds.');
43
+ }
44
+ var isImage = (file.mime && file.mime.indexOf('image/') === 0)
45
+ || /\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(name);
46
+ return { url: url, name: name, meta: meta, isImage: isImage, width: file.width || null, height: file.height || null };
47
+ }
48
+
49
+ function open(cfg, multiple, onSelect) {
50
+ if (typeof FluxFiles === 'undefined') {
51
+ console.error('[FluxFiles] SDK (fluxfiles.js) is not loaded.');
52
+ return;
53
+ }
54
+ FluxFiles.open({
55
+ endpoint: cfg.endpoint || '', token: cfg.token || '', disk: cfg.disk || 'local',
56
+ mode: 'picker', multiple: !!multiple,
57
+ maxUploadMb: cfg.maxUploadMb || null, maxFiles: cfg.maxFiles || null, locale: cfg.locale || null,
58
+ onSelect: onSelect
59
+ });
60
+ }
61
+
62
+ function firstFile(payload) {
63
+ var f = Array.isArray(payload) ? payload[0] : payload;
64
+ return (f && !f.is_dir) ? f : null;
65
+ }
66
+
67
+ // ── 2) Native Image dialog: a "Browse FluxFiles" button that fills fields ──
68
+ // Registered once, globally; reads each editor's own config.
69
+ if (!CKEDITOR.fluxfilesDialogHook) {
70
+ CKEDITOR.fluxfilesDialogHook = true;
71
+ CKEDITOR.on('dialogDefinition', function (ev) {
72
+ if (ev.data.name !== 'image' && ev.data.name !== 'image2') return;
73
+ var editor = ev.editor;
74
+ // Only for editors using this plugin, and not opted out.
75
+ var cfg = editor && editor.config && editor.config.fluxfiles;
76
+ if (!cfg || cfg.imageDialog === false) return;
77
+
78
+ var def = ev.data.definition;
79
+ var infoTab = def.getContents('info') || def.getContents('Upload');
80
+ if (!infoTab) return;
81
+
82
+ infoTab.add({
83
+ type: 'button',
84
+ id: 'fluxfilesBrowse',
85
+ label: 'Browse FluxFiles',
86
+ title: 'Browse FluxFiles',
87
+ onClick: function () {
88
+ var dialog = this.getDialog();
89
+ open(cfg, false, function (payload) {
90
+ var file = firstFile(payload);
91
+ if (!file) return;
92
+ var info = fileInfo(file);
93
+ var set = function (id, val) {
94
+ var el = dialog.getContentElement('info', id);
95
+ if (el && val != null && val !== '') el.setValue(String(val));
96
+ };
97
+ set('txtUrl', info.url);
98
+ set('txtAlt', info.meta.alt_text || info.name);
99
+ if (info.width) set('txtWidth', info.width);
100
+ if (info.height) set('txtHeight', info.height);
101
+ // Nudge the dialog to refresh its preview from the new URL.
102
+ var urlEl = dialog.getContentElement('info', 'txtUrl');
103
+ if (urlEl && typeof urlEl.onChange === 'function') urlEl.onChange();
104
+ });
105
+ }
106
+ });
107
+ });
108
+ }
109
+
30
110
  CKEDITOR.plugins.add('fluxfiles', {
31
111
  init: function (editor) {
32
112
  var cfg = editor.config.fluxfiles || {};
33
113
 
114
+ // ── 1) Standalone button: insert the selection directly ──────────
34
115
  editor.addCommand('openFluxFiles', {
35
116
  exec: function () {
36
- if (typeof FluxFiles === 'undefined') {
37
- console.error('[FluxFiles] SDK (fluxfiles.js) is not loaded.');
38
- return;
39
- }
40
-
41
- FluxFiles.open({
42
- endpoint: cfg.endpoint || '',
43
- token: cfg.token || '',
44
- disk: cfg.disk || 'local',
45
- mode: 'picker',
46
- multiple: !!cfg.multiple,
47
- maxUploadMb: cfg.maxUploadMb || null,
48
- maxFiles: cfg.maxFiles || null,
49
- locale: cfg.locale || null,
50
- onSelect: function (payload) {
51
- var files = Array.isArray(payload) ? payload : (payload && payload.files ? payload.files : [payload]);
52
-
53
- for (var i = 0; i < files.length; i++) {
54
- var file = files[i];
55
- if (!file) continue;
56
-
57
- var url = file.url || '';
58
- var name = file.basename || file.name || file.path || '';
117
+ open(cfg, cfg.multiple, function (payload) {
118
+ var files = Array.isArray(payload) ? payload : [payload];
119
+ var enc = CKEDITOR.tools.htmlEncode;
120
+ for (var i = 0; i < files.length; i++) {
121
+ var file = files[i];
122
+ if (!file || file.is_dir) continue;
123
+ var info = fileInfo(file);
59
124
 
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) + '" />');
62
- } else {
63
- editor.insertHtml('<a href="' + CKEDITOR.tools.htmlEncode(url) + '">' + CKEDITOR.tools.htmlEncode(name) + '</a>');
64
- }
125
+ if (info.isImage) {
126
+ var dim = '';
127
+ if (info.width) { dim += ' width="' + parseInt(info.width, 10) + '"'; }
128
+ if (info.height) { dim += ' height="' + parseInt(info.height, 10) + '"'; }
129
+ editor.insertHtml('<img src="' + enc(info.url) + '" alt="' + enc(info.meta.alt_text || info.name) + '"' + dim + ' />');
130
+ } else {
131
+ editor.insertHtml('<a href="' + enc(info.url) + '">' + enc(info.meta.title || info.name) + '</a>');
65
132
  }
66
133
  }
67
134
  });
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 x='<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(x);function f(e){var t=e.permanent_url||e.url||"",n=e.name||e.basename||e.path||"",r=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 a=e.mime&&e.mime.indexOf("image/")===0||/\.(jpe?g|png|gif|webp|svg|bmp|ico|avif)$/i.test(n);return{url:t,name:n,meta:r,isImage:a,width:e.width||null,height:e.height||null}}function d(e,t,n){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:!!t,maxUploadMb:e.maxUploadMb||null,maxFiles:e.maxFiles||null,locale:e.locale||null,onSelect:n})}function p(e){var t=Array.isArray(e)?e[0]:e;return t&&!t.is_dir?t:null}CKEDITOR.fluxfilesDialogHook||(CKEDITOR.fluxfilesDialogHook=!0,CKEDITOR.on("dialogDefinition",function(e){if(!(e.data.name!=="image"&&e.data.name!=="image2")){var t=e.editor,n=t&&t.config&&t.config.fluxfiles;if(!(!n||n.imageDialog===!1)){var r=e.data.definition,a=r.getContents("info")||r.getContents("Upload");a&&a.add({type:"button",id:"fluxfilesBrowse",label:"Browse FluxFiles",title:"Browse FluxFiles",onClick:function(){var o=this.getDialog();d(n,!1,function(s){var i=p(s);if(i){var l=f(i),u=function(v,g){var h=o.getContentElement("info",v);h&&g!=null&&g!==""&&h.setValue(String(g))};u("txtUrl",l.url),u("txtAlt",l.meta.alt_text||l.name),l.width&&u("txtWidth",l.width),l.height&&u("txtHeight",l.height);var m=o.getContentElement("info","txtUrl");m&&typeof m.onChange=="function"&&m.onChange()}})}})}}})),CKEDITOR.plugins.add("fluxfiles",{init:function(e){var t=e.config.fluxfiles||{};e.addCommand("openFluxFiles",{exec:function(){d(t,t.multiple,function(n){for(var r=Array.isArray(n)?n:[n],a=CKEDITOR.tools.htmlEncode,o=0;o<r.length;o++){var s=r[o];if(!(!s||s.is_dir)){var i=f(s);if(i.isImage){var l="";i.width&&(l+=' width="'+parseInt(i.width,10)+'"'),i.height&&(l+=' height="'+parseInt(i.height,10)+'"'),e.insertHtml('<img src="'+a(i.url)+'" alt="'+a(i.meta.alt_text||i.name)+'"'+l+" />")}else e.insertHtml('<a href="'+a(i.url)+'">'+a(i.meta.title||i.name)+"</a>")}}})}}),e.ui.addButton("FluxFiles",{label:"FluxFiles",command:"openFluxFiles",toolbar:"insert",icon:c})}})})();