@fluxfiles/tinymce 0.1.1
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 +65 -0
- package/package.json +32 -0
- package/plugin.js +127 -0
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# FluxFiles — TinyMCE Plugin
|
|
2
|
+
|
|
3
|
+
Adds a **FluxFiles** toolbar button to TinyMCE 4.x / 5.x for browsing and inserting files.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @fluxfiles/tinymce
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
TinyMCE loads the plugin from a URL (`external_plugins`), so make `plugin.js`
|
|
12
|
+
reachable — reference it from `node_modules/@fluxfiles/tinymce/plugin.js`, or copy
|
|
13
|
+
the plugin folder into your TinyMCE `plugins/` directory:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
tinymce/plugins/fluxfiles/
|
|
17
|
+
├── plugin.js
|
|
18
|
+
└── README.md
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
2. Load the FluxFiles SDK (`fluxfiles.js`) on the page.
|
|
22
|
+
|
|
23
|
+
3. Enable the plugin:
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
tinymce.init({
|
|
27
|
+
selector: '#editor',
|
|
28
|
+
plugins: 'fluxfiles',
|
|
29
|
+
toolbar: 'undo redo | formatselect | bold italic | fluxfiles | link image',
|
|
30
|
+
fluxfiles_endpoint: 'https://your-fluxfiles-host',
|
|
31
|
+
fluxfiles_token: 'JWT_TOKEN',
|
|
32
|
+
fluxfiles_disk: 'local',
|
|
33
|
+
fluxfiles_locale: 'en',
|
|
34
|
+
fluxfiles_multiple: false
|
|
35
|
+
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## How It Works
|
|
39
|
+
|
|
40
|
+
- Click the **FluxFiles** toolbar button (folder/browse icon).
|
|
41
|
+
- The FluxFiles picker opens as a modal overlay.
|
|
42
|
+
- Select a file — images are inserted as `<img>`, other files as `<a>` links.
|
|
43
|
+
- The modal closes automatically after selection.
|
|
44
|
+
|
|
45
|
+
## Configuration
|
|
46
|
+
|
|
47
|
+
| Option | Type | Default | Description |
|
|
48
|
+
|--------|------|---------|-------------|
|
|
49
|
+
| `fluxfiles_endpoint` | string | `''` | FluxFiles server URL |
|
|
50
|
+
| `fluxfiles_token` | string | `''` | JWT authentication token |
|
|
51
|
+
| `fluxfiles_disk` | string | `'local'` | Storage disk |
|
|
52
|
+
| `fluxfiles_locale` | string | `null` | UI language code |
|
|
53
|
+
| `fluxfiles_multiple` | boolean | `false` | Allow multi-file selection |
|
|
54
|
+
|
|
55
|
+
## Compatibility
|
|
56
|
+
|
|
57
|
+
- **TinyMCE 4.x** — Uses `addButton` / `addMenuItem` API
|
|
58
|
+
- **TinyMCE 5.x** — Uses `ui.registry.addButton` / `ui.registry.addMenuItem` API
|
|
59
|
+
- Auto-detects version at load time.
|
|
60
|
+
|
|
61
|
+
## Links
|
|
62
|
+
|
|
63
|
+
- Main repository: `https://github.com/thai-pc/fluxfiles`
|
|
64
|
+
- Documentation: `https://github.com/thai-pc/fluxfiles#tinymce-4x--5x`
|
|
65
|
+
- Issues: `https://github.com/thai-pc/fluxfiles/issues`
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluxfiles/tinymce",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "TinyMCE plugin for FluxFiles",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "plugin.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"plugin.js",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": { "test": "vitest run" },
|
|
12
|
+
"devDependencies": { "jsdom": "^25.0.1", "vitest": "^2.1.8" },
|
|
13
|
+
"publishConfig": { "access": "public" },
|
|
14
|
+
"author": "thai-pc",
|
|
15
|
+
"homepage": "https://github.com/thai-pc/fluxfiles#tinymce-4x--5x",
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/thai-pc/fluxfiles.git",
|
|
19
|
+
"directory": "packages/tinymce"
|
|
20
|
+
},
|
|
21
|
+
"bugs": { "url": "https://github.com/thai-pc/fluxfiles/issues" },
|
|
22
|
+
"keywords": [
|
|
23
|
+
"fluxfiles",
|
|
24
|
+
"file-manager",
|
|
25
|
+
"tinymce",
|
|
26
|
+
"plugin",
|
|
27
|
+
"s3",
|
|
28
|
+
"r2",
|
|
29
|
+
"upload",
|
|
30
|
+
"media"
|
|
31
|
+
]
|
|
32
|
+
}
|
package/plugin.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FluxFiles plugin for TinyMCE (4.x / 5.x compatible).
|
|
3
|
+
*
|
|
4
|
+
* Adds a toolbar button that opens the FluxFiles picker.
|
|
5
|
+
* Selected images are inserted as <img>, other files as <a>.
|
|
6
|
+
*
|
|
7
|
+
* Usage (TinyMCE 4):
|
|
8
|
+
* tinymce.init({
|
|
9
|
+
* selector: '#editor',
|
|
10
|
+
* external_plugins: { fluxfiles: '/path/to/adapters/tinymce/plugin.js' },
|
|
11
|
+
* toolbar: 'fluxfiles',
|
|
12
|
+
* fluxfiles_endpoint: 'http://localhost:8080',
|
|
13
|
+
* fluxfiles_token: 'JWT_TOKEN',
|
|
14
|
+
* fluxfiles_disk: 'local',
|
|
15
|
+
* fluxfiles_locale: 'en',
|
|
16
|
+
* fluxfiles_multiple: false
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* Usage (TinyMCE 5):
|
|
20
|
+
* Same config — the plugin auto-detects the version.
|
|
21
|
+
*/
|
|
22
|
+
(function () {
|
|
23
|
+
'use strict';
|
|
24
|
+
|
|
25
|
+
function escHtml(str) {
|
|
26
|
+
var div = document.createElement('div');
|
|
27
|
+
div.appendChild(document.createTextNode(str || ''));
|
|
28
|
+
return div.innerHTML;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function openPicker(editor) {
|
|
32
|
+
if (typeof FluxFiles === 'undefined') {
|
|
33
|
+
console.error('[FluxFiles] SDK (fluxfiles.js) is not loaded.');
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
var endpoint = editor.getParam('fluxfiles_endpoint', '');
|
|
38
|
+
var token = editor.getParam('fluxfiles_token', '');
|
|
39
|
+
var disk = editor.getParam('fluxfiles_disk', 'local');
|
|
40
|
+
var locale = editor.getParam('fluxfiles_locale', null);
|
|
41
|
+
var multiple = editor.getParam('fluxfiles_multiple', false);
|
|
42
|
+
|
|
43
|
+
FluxFiles.open({
|
|
44
|
+
endpoint: endpoint,
|
|
45
|
+
token: token,
|
|
46
|
+
disk: disk,
|
|
47
|
+
mode: 'picker',
|
|
48
|
+
multiple: !!multiple,
|
|
49
|
+
locale: locale,
|
|
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 || '';
|
|
59
|
+
|
|
60
|
+
if (/\.(jpe?g|png|gif|webp|svg|bmp|ico)$/i.test(name)) {
|
|
61
|
+
editor.insertContent('<img src="' + escHtml(url) + '" alt="' + escHtml(name) + '" />');
|
|
62
|
+
} else {
|
|
63
|
+
editor.insertContent('<a href="' + escHtml(url) + '">' + escHtml(name) + '</a>');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Single registration — version check inside callback (safe regardless of load order)
|
|
71
|
+
tinymce.PluginManager.add('fluxfiles', function (editor) {
|
|
72
|
+
var majorVersion = parseInt(tinymce.majorVersion, 10);
|
|
73
|
+
|
|
74
|
+
if (majorVersion >= 5) {
|
|
75
|
+
// TinyMCE 5+ API — register custom icon (browse doesn't exist in v5)
|
|
76
|
+
editor.ui.registry.addIcon('fluxfiles',
|
|
77
|
+
'<svg width="24" height="24" viewBox="0 0 24 24" fill="none">'
|
|
78
|
+
+ '<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" '
|
|
79
|
+
+ 'stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>'
|
|
80
|
+
+ '</svg>'
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
editor.ui.registry.addButton('fluxfiles', {
|
|
84
|
+
icon: 'fluxfiles',
|
|
85
|
+
tooltip: 'FluxFiles',
|
|
86
|
+
onAction: function () {
|
|
87
|
+
openPicker(editor);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
editor.ui.registry.addMenuItem('fluxfiles', {
|
|
92
|
+
icon: 'fluxfiles',
|
|
93
|
+
text: 'FluxFiles',
|
|
94
|
+
onAction: function () {
|
|
95
|
+
openPicker(editor);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
getMetadata: function () {
|
|
101
|
+
return {
|
|
102
|
+
name: 'FluxFiles',
|
|
103
|
+
url: 'https://github.com/thai-pc/fluxfiles'
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
} else {
|
|
108
|
+
// TinyMCE 4.x API
|
|
109
|
+
editor.addButton('fluxfiles', {
|
|
110
|
+
icon: 'browse',
|
|
111
|
+
tooltip: 'FluxFiles',
|
|
112
|
+
onclick: function () {
|
|
113
|
+
openPicker(editor);
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
editor.addMenuItem('fluxfiles', {
|
|
118
|
+
icon: 'browse',
|
|
119
|
+
text: 'FluxFiles',
|
|
120
|
+
onclick: function () {
|
|
121
|
+
openPicker(editor);
|
|
122
|
+
},
|
|
123
|
+
context: 'insert'
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
})();
|