|
1 | 1 | (function() { |
2 | 2 | let i; |
3 | | - const b = (n) => { |
4 | | - const l = { |
| 3 | + const S = (n) => { |
| 4 | + const c = { |
5 | 5 | "ace-default": { |
6 | 6 | url: "https://cdnjs.cloudflare.com/ajax/libs/ace/1.9.6/ace.js", |
7 | 7 | loaded: !1, |
|
18 | 18 | required: !1 |
19 | 19 | } |
20 | 20 | }; |
21 | | - n.autocomplete && (l["ace-autocomplete"].required = !0), Object.values(l).forEach((d) => { |
22 | | - if (d.loaded) |
| 21 | + n.autocomplete && (c["ace-autocomplete"].required = !0), Object.values(c).forEach((l) => { |
| 22 | + if (l.loaded) |
23 | 23 | return; |
24 | | - let c = document.createElement("script"); |
25 | | - c.src = d.url, c.type = "text/javascript", document.body.appendChild(c); |
| 24 | + let d = document.createElement("script"); |
| 25 | + d.src = l.url, d.type = "text/javascript", document.body.appendChild(d); |
26 | 26 | }); |
27 | | - }, S = (n) => n.getParam("inline") !== !0, w = function(n) { |
28 | | - if (!S(n)) |
| 27 | + }, w = (n) => n.getParam("inline") !== !0, x = function(n) { |
| 28 | + if (!w(n)) |
29 | 29 | return console.error("Supercode Plugin is not supported in inline mode"), !1; |
30 | | - let l = 0, d, c = !0, u, t = { |
| 30 | + let c = 0, l, d = !1, u, t = { |
31 | 31 | theme: "chrome", |
32 | 32 | fontSize: 14, |
33 | 33 | // in px |
|
43 | 43 | aceCss: null, |
44 | 44 | fontFamily: null |
45 | 45 | }; |
46 | | - const x = (e) => { |
| 46 | + const C = (e) => { |
47 | 47 | const o = e.getParam("supercode"); |
48 | 48 | if (o && typeof o == "object") { |
49 | 49 | for (const r in o) |
|
74 | 74 | } |
75 | 75 | if (t.icon = e.ui.registry.getAll().icons[t.iconName], !t.icon) |
76 | 76 | throw new Error("Supercode Icon name is invalid"); |
77 | | - }, C = (e) => { |
| 77 | + }, E = (e) => { |
78 | 78 | if (e.attachShadow({ mode: "open" }), t.aceCss) { |
79 | 79 | const s = new CSSStyleSheet(); |
80 | 80 | s.replaceSync(t.aceCss), e.shadowRoot.adoptedStyleSheets.push(s); |
|
85 | 85 | o.style.width = "100%", o.style.height = "100%", i = ace.edit(o), i.renderer.attachToShadowRoot(); |
86 | 86 | const r = {}; |
87 | 87 | t.autocomplete && (r.enableLiveAutocompletion = !0), t.fontFamily && (r.fontFamily = t.fontFamily), i.setOptions(r), i.setTheme(`ace/theme/${t.theme}`), i.setFontSize(t.fontSize), i.setShowPrintMargin(!1); |
88 | | - }, E = (e, o, r) => { |
| 88 | + }, m = (e, o, r) => { |
89 | 89 | const s = o.cloneNode(!0); |
90 | 90 | s.style.position = "relative"; |
91 | | - const y = s.querySelector(".tox-menubar"); |
92 | | - y && (y.innerHTML = ` |
93 | | - <b style='font-size: 14px; font-weight: bold; padding: 9px;'>Source Code Editor</b> |
94 | | - `); |
95 | | - let g = !0; |
| 91 | + const g = s.querySelector(".tox-menubar"); |
| 92 | + g && (g.innerHTML = "<b style='font-size: 14px; font-weight: bold; padding: 9px;'>Source Code Editor</b>"); |
| 93 | + let b = !0; |
96 | 94 | if (s.querySelectorAll(".tox-tbtn, .tox-split-button").forEach((a) => { |
97 | 95 | if (a.getAttribute("data-mce-name") != "supercode") { |
98 | 96 | if (a.getAttribute("data-mce-name") === "overflow-button") { |
|
101 | 99 | } |
102 | 100 | a.classList.remove("tox-tbtn--enabled"), a.classList.add("tox-tbtn--disabled"), a.removeAttribute("data-mce-name"); |
103 | 101 | } else |
104 | | - g = !1, a.setAttribute("data-mce-name", "supercode-toggle"), a.classList.add("tox-tbtn--enabled"), a.onclick = r; |
105 | | - }), g) { |
| 102 | + b = !1, a.setAttribute("data-mce-name", "supercode-toggle"), a.classList.add("tox-tbtn--enabled"), a.onclick = r; |
| 103 | + }), b) { |
106 | 104 | const a = document.createElement("div"); |
107 | 105 | a.classList = "tox-toolbar__group", a.style.position = "absolute", a.style.right = 0, a.style.height = "100%"; |
108 | 106 | const p = document.createElement("button"); |
109 | 107 | p.classList = "tox-tbtn tox-tbtn--enabled", p.innerHTML = `<span class="tox-icon tox-tbtn__icon-wrap">${t.icon}</span>`, p.onclick = r, a.append(p), s.append(a); |
110 | 108 | } |
111 | | - e.append(s); |
| 109 | + e.innerHTML = "", e.append(s); |
112 | 110 | }, v = (e, o) => { |
113 | | - e.style.width = o + "px", e.style.height = "100%", e.style.position = "relative", C(e); |
| 111 | + e.style.width = o + "px", e.style.height = "100%", e.style.position = "relative", E(e); |
114 | 112 | }; |
115 | | - x(n), b(t); |
| 113 | + C(n), S(t); |
116 | 114 | const f = () => { |
117 | 115 | n.focus(), n.undoManager.transact(function() { |
118 | 116 | let e = i.getValue(); |
119 | 117 | t.renderer && (e = t.renderer(e)), n.setContent(e); |
120 | 118 | }), n.selection.setCursorLocation(), n.nodeChanged(), n.execCommand("ToggleView", !1, "supercode"); |
121 | | - }, m = (e) => { |
| 119 | + }, h = (e) => { |
122 | 120 | (e.key === " " && e.ctrlKey || e.key === "Escape") && f(); |
123 | 121 | }, L = (e) => t.parser ? t.parser(e) : html_beautify(e), j = { |
124 | 122 | onShow: (e) => { |
125 | 123 | const o = e.getContainer(); |
126 | | - o.style.padding = 0, o.style.display = "flex", o.style.flexDirection = "column", (c || o.childElementCount === 0) && (o.innerHTML = '<div class="supercode-header"></div><div class="supercode-body no-tox-style" id="no-tox-style"></div>', t.shortcut && o.addEventListener("keydown", m), E(o.querySelector(".supercode-header"), d, f), v(o.querySelector(".supercode-body "), l)); |
| 124 | + d && (m(o.querySelector(".supercode-header"), l, f), o.querySelector(".supercode-body ").style.width = c + "px"), o.childElementCount === 0 && (o.style.padding = 0, o.style.display = "flex", o.style.flexDirection = "column", o.innerHTML = '<div class="supercode-header"></div><div class="supercode-body"></div>', t.shortcut && o.addEventListener("keydown", h), m(o.querySelector(".supercode-header"), l, f), v(o.querySelector(".supercode-body "), c)); |
127 | 125 | let r = L(n.getContent()); |
128 | 126 | u || (u = ace.createEditSession(r, `ace/mode/${t.language}`), u.setUseWrapMode(t.wrap), i.setSession(u)), u.setValue(r), i.gotoLine(1 / 0), i.focus(); |
129 | 127 | }, |
130 | 128 | onHide: () => { |
131 | | - t.shortcut && removeEventListener("keydown", m); |
| 129 | + t.shortcut && removeEventListener("keydown", h); |
132 | 130 | } |
133 | | - }, h = function() { |
| 131 | + }, y = function() { |
134 | 132 | const e = n.getContainer(); |
135 | | - c = l != e.clientWidth, l = e.clientWidth, (c || !d) && (d = e.querySelector(".tox-editor-header")), n.execCommand("ToggleView", !1, "supercode"); |
| 133 | + c && (d = c != e.clientWidth), c = e.clientWidth, (d || !l) && (l = e.querySelector(".tox-editor-header")), n.execCommand("ToggleView", !1, "supercode"); |
136 | 134 | }; |
137 | 135 | return n.ui.registry.addView("supercode", j), n.ui.registry.addButton("supercode", { |
138 | 136 | icon: t.iconName, |
139 | 137 | tooltip: "Source Code Editor (Ctrl + space)", |
140 | | - onAction: h |
141 | | - }), t.shortcut && n.shortcuts.add("ctrl+32", "Toggles Source Code Editing Mode", h), { |
| 138 | + onAction: y |
| 139 | + }), t.shortcut && n.shortcuts.add("ctrl+32", "Toggles Source Code Editing Mode", y), { |
142 | 140 | getMetadata: function() { |
143 | 141 | return { |
144 | | - name: "Source Code Editor", |
145 | | - url: "" |
| 142 | + name: "Supercode", |
| 143 | + url: "https://github.com/prathamVaidya/supercode-tinymce-plugin" |
146 | 144 | }; |
147 | 145 | } |
148 | 146 | }; |
149 | 147 | }; |
150 | | - tinymce.PluginManager.add("supercode", w); |
| 148 | + tinymce.PluginManager.add("supercode", x); |
151 | 149 | })(); |
0 commit comments