@fluxfiles/ckeditor4 0.2.3 → 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 +21 -0
- package/README.md +16 -5
- package/package.json +3 -2
- package/plugin.js +97 -46
- package/plugin.min.js +1 -1
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
|
@@ -47,11 +47,21 @@ CKEDITOR.replace('editor', {
|
|
|
47
47
|
|
|
48
48
|
## How It Works
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 }`.
|
|
55
65
|
|
|
56
66
|
> **Embedding & expiring URLs.** On a **private** disk the file URL is a
|
|
57
67
|
> *presigned* URL that expires (≤ 24h) — embedding it in saved content will break
|
|
@@ -67,6 +77,7 @@ CKEDITOR.replace('editor', {
|
|
|
67
77
|
| `disk` | string | `'local'` | Storage disk |
|
|
68
78
|
| `locale` | string | `null` | UI language code |
|
|
69
79
|
| `multiple` | boolean | `false` | Allow multi-file selection |
|
|
80
|
+
| `imageDialog` | boolean | `true` | Inject the **Browse FluxFiles** button into the native Image dialog |
|
|
70
81
|
|
|
71
82
|
## License
|
|
72
83
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluxfiles/ckeditor4",
|
|
3
|
-
"version": "0.
|
|
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
|
-
*
|
|
5
|
-
*
|
|
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,57 +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
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
+
}
|
|
33
48
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
+
}
|
|
40
66
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
var files = Array.isArray(payload) ? payload : [payload];
|
|
52
|
-
var enc = CKEDITOR.tools.htmlEncode;
|
|
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;
|
|
53
77
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
78
|
+
var def = ev.data.definition;
|
|
79
|
+
var infoTab = def.getContents('info') || def.getContents('Upload');
|
|
80
|
+
if (!infoTab) return;
|
|
57
81
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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
|
+
}
|
|
63
109
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
}
|
|
110
|
+
CKEDITOR.plugins.add('fluxfiles', {
|
|
111
|
+
init: function (editor) {
|
|
112
|
+
var cfg = editor.config.fluxfiles || {};
|
|
69
113
|
|
|
70
|
-
|
|
71
|
-
|
|
114
|
+
// ── 1) Standalone button: insert the selection directly ──────────
|
|
115
|
+
editor.addCommand('openFluxFiles', {
|
|
116
|
+
exec: function () {
|
|
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);
|
|
72
124
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
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>');
|
|
81
132
|
}
|
|
82
133
|
}
|
|
83
134
|
});
|
package/plugin.min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";var
|
|
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})}})})();
|