-
Notifications
You must be signed in to change notification settings - Fork 3
/
Plugin.ts
43 lines (35 loc) · 1.13 KB
/
Plugin.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Editor, TinyMCE } from "tinymce";
import { setupReactApp, removeReactApp } from "./application/App";
import config from "./config";
declare const tinymce: TinyMCE;
const setup = (editor: Editor) => {
const element = document.createElement("div");
element.setAttribute("id", config.pluginId);
editor.ui.registry.addButton(config.pluginId, {
text: config.pluginButtonText,
onAction: function () {
var pluginContentDiv = document.getElementById(config.pluginContentDiv);
if (!pluginContentDiv) {
var PluginContent = document.createElement("div");
PluginContent.setAttribute("id", config.pluginContentDiv);
document.body.appendChild(PluginContent);
pluginContentDiv = document.getElementById(config.pluginContentDiv);
} else {
removeReactApp(pluginContentDiv);
}
setupReactApp(pluginContentDiv, editor);
},
});
return {
getMetadata: () => {
return {
name: config.pluginName,
url: config.pluginURL,
};
},
render: () => element,
};
};
export default () => {
tinymce.PluginManager.add(config.pluginId, setup);
};