|
1 | 1 | !function() { |
2 | 2 | let e = null; |
3 | 3 | tinymce.PluginManager.add("supercode", function(o) { |
4 | | - let t, n, r, d = 0, a = false; |
| 4 | + let t, n, r, a = 0, d = false; |
5 | 5 | const c = { theme: "chrome", fontSize: 14, wrap: true, icon: void 0, iconName: "sourcecode", autocomplete: false, language: "html", renderer: null, parser: null, shortcut: true, aceCss: null, fontFamily: null, fallbackModal: false, modalPrimaryColor: "#ffffff", modalSecondaryColor: "#222f3e", dark: false, debug: true }, s = () => { |
6 | 6 | const e2 = {}; |
7 | 7 | c.autocomplete && (e2.enableLiveAutocompletion = true), c.fontFamily && (e2.fontFamily = c.fontFamily), r.setOptions(e2), r.setTheme(`ace/theme/${c.theme}`), r.setFontSize(c.fontSize), r.setShowPrintMargin(false); |
8 | | - }, i = (e2, o2) => { |
| 8 | + }, l = (e2, o2) => { |
9 | 9 | const t2 = o2.cloneNode(true); |
10 | 10 | t2.style.position = "relative"; |
11 | 11 | const n2 = t2.querySelector(".tox-menubar"); |
12 | 12 | n2 && (n2.innerHTML = "<b style='font-size: 14px; font-weight: bold; padding: 11px 9px;'>Source Code Editor</b>"); |
13 | | - let r2 = null, d2 = false; |
| 13 | + let r2 = null, a2 = false; |
14 | 14 | t2.querySelectorAll(".tox-tbtn, .tox-split-button").forEach((e3) => { |
15 | | - "supercode" != e3.getAttribute("data-mce-name") ? ("overflow-button" === e3.getAttribute("data-mce-name") && (r2 = e3), e3.classList.remove("tox-tbtn--enabled"), e3.classList.add("tox-tbtn--disabled"), e3.removeAttribute("data-mce-name")) : (d2 = true, e3.setAttribute("data-mce-name", "supercode-toggle"), e3.classList.add("tox-tbtn--enabled"), e3.onclick = y); |
16 | | - }), !d2 && r2 && (r2.classList = "tox-tbtn tox-tbtn--enabled", r2.innerHTML = `<span class="tox-icon tox-tbtn__icon-wrap">${c.icon}</span>`, r2.onclick = y), e2.innerHTML = "", e2.append(t2); |
17 | | - }, l = (e2, o2) => { |
| 15 | + "supercode" != e3.getAttribute("data-mce-name") ? ("overflow-button" === e3.getAttribute("data-mce-name") && (r2 = e3), e3.classList.remove("tox-tbtn--enabled"), e3.classList.add("tox-tbtn--disabled"), e3.removeAttribute("data-mce-name")) : (a2 = true, e3.setAttribute("data-mce-name", "supercode-toggle"), e3.classList.add("tox-tbtn--enabled"), e3.onclick = b); |
| 16 | + }), !a2 && r2 && (r2.classList = "tox-tbtn tox-tbtn--enabled", r2.innerHTML = `<span class="tox-icon tox-tbtn__icon-wrap">${c.icon}</span>`, r2.onclick = b), e2.innerHTML = "", e2.append(t2); |
| 17 | + }, i = (e2, o2) => { |
18 | 18 | e2.style.width = o2 + "px", e2.style.height = "100%", e2.style.position = "relative", ((e3) => { |
19 | 19 | if (e3.attachShadow({ mode: "open" }), c.aceCss) { |
20 | 20 | const o4 = new CSSStyleSheet(); |
@@ -84,43 +84,57 @@ Use debug:false option to disable this warning`)), c.fallbackModal || (true === |
84 | 84 | })("\n\n :root{\n --supercode-modal-primary: #ffffff;\n --supercode-modal-secondary: #222f3e;\n --supercode-modal-border: rgba(0, 0, 0, 0.1);\n }\n\n /* Media query for mobile devices */\n @media only screen and (max-width: 767px) {\n #supercode-modal {\n width: 100% !important;\n height: 100% !important;\n border-radius: 0 !important;\n }\n }\n .disable-scroll {\n overflow: hidden;\n }\n #supercode-modal-container {\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n display: flex;\n align-items: center;\n justify-content: center;\n z-index: 990;\n display: none;\n opacity: 0;\n transition: opacity 0.1s linear;\n }\n #supercode-backdrop {\n position: absolute;\n top: 0;\n left: 0;\n background: black;\n opacity: 0.7;\n width: 100%;\n height: 100%;\n z-index: 1;\n }\n #supercode-modal {\n width: 90%;\n height: 80%;\n max-width: 1200px;\n z-index: 2;\n overflow: hidden;\n border-radius: 10px;\n display: flex;\n flex-direction: column;\n background: var(--supercode-modal-primary);\n }\n #supercode-header {\n display: flex;\n padding: 0.5rem 1rem;\n border-bottom: 1px solid var(--supercode-modal-border);\n color: var(--supercode-modal-secondary);\n }\n #supercode-modal h1 {\n flex-grow: 1;\n margin: auto;\n font-size: 14px;\n }\n #supercode-close-btn {\n background: none;\n border: none;\n padding: 0;\n height: 100%;\n cursor: pointer;\n fill: var(--supercode-modal-secondary);\n }\n #supercode-editor {\n width: 100%;\n height: 100%;\n position: relative;\n }\n #supercode-footer {\n padding: 0.5rem 1rem;\n display: flex;\n justify-content: end;\n gap: 1rem;\n border-top: 1px solid var(--supercode-modal-border);\n }\n #supercode-footer button {\n padding: 0.5rem 1rem;\n border-radius: 5px;\n font-weight: bold;\n border: none;\n cursor: pointer;\n min-width: 5rem;\n transition: opacity 0.1s linear;\n }\n #supercode-footer button:hover {\n opacity: 0.8;\n }\n #supercode-cancel-btn {\n background: transparent;\n color: var(--supercode-modal-secondary);\n }\n #supercode-save-btn {\n background: var(--supercode-modal-secondary);\n color: var(--supercode-modal-primary);\n }\n "), document.body.append(o2), e = { element: o2, editor: ace.edit(o2.querySelector("#supercode-editor")) }; |
85 | 85 | } |
86 | 86 | r = e.editor, s(), e.element.querySelector("#supercode-backdrop").onclick = m, e.element.querySelector("#supercode-close-btn").onclick = m, e.element.querySelector("#supercode-cancel-btn").onclick = m, e.element.querySelector("#supercode-save-btn").onclick = () => { |
87 | | - y(), m(); |
| 87 | + b(), m(); |
88 | 88 | }, c.shortcut && e.element.querySelector("#supercode-editor").addEventListener("keydown", u), document.querySelector("body").classList.add("disable-scroll"), document.body.style.setProperty("--supercode-modal-primary", c.modalPrimaryColor), document.body.style.setProperty("--supercode-modal-secondary", c.modalSecondaryColor), c.dark && document.body.style.setProperty("--supercode-modal-border", "rgba(255, 255, 255, 0.1)"), e.element.querySelector("#supercode-close-btn").innerHTML = ((_c = (_b = (_a = o.ui.registry).getAll) == null ? void 0 : _b.call(_a).icons) == null ? void 0 : _c.close) ?? '<svg width="24" height="24"><path d="M17.3 8.2 13.4 12l3.9 3.8a1 1 0 0 1-1.5 1.5L12 13.4l-3.8 3.9a1 1 0 0 1-1.5-1.5l3.9-3.8-3.9-3.8a1 1 0 0 1 1.5-1.5l3.8 3.9 3.8-3.9a1 1 0 0 1 1.5 1.5Z" fill-rule="evenodd"></path></svg>', e.element.style.display = "flex", setTimeout(() => { |
89 | 89 | e.element.style.opacity = 1; |
90 | | - }, 10), h(); |
| 90 | + }, 10), f(); |
91 | 91 | }, m = () => { |
92 | 92 | c.shortcut && removeEventListener("keydown", u), document.querySelector("body").classList.remove("disable-scroll"), e.element.style.opacity = 0, o.focus(), setTimeout(() => { |
93 | 93 | e.element.style.display = "none"; |
94 | 94 | }, 10); |
95 | 95 | }, y = () => { |
96 | | - o.focus(), o.undoManager.transact(function() { |
| 96 | + o.undoManager.transact(function() { |
97 | 97 | let e2 = r.getValue(); |
98 | 98 | c.renderer && (e2 = c.renderer(e2)), o.setContent(e2); |
99 | | - }), o.selection.setCursorLocation(), o.nodeChanged(), o.execCommand("ToggleView", false, "supercode"); |
100 | | - }, b = (e2) => { |
101 | | - (" " === e2.key && e2.ctrlKey || "Escape" === e2.key) && y(); |
102 | | - }, h = () => { |
| 99 | + }), o.nodeChanged(); |
| 100 | + }, b = () => { |
| 101 | + o.focus(), c.fallbackModal && (o.undoManager.transact(function() { |
| 102 | + let e2 = r.getValue(); |
| 103 | + c.renderer && (e2 = c.renderer(e2)), o.setContent(e2); |
| 104 | + }), o.selection.setCursorLocation(), o.nodeChanged()), o.execCommand("ToggleView", false, "supercode"); |
| 105 | + }, h = (e2) => { |
| 106 | + (" " === e2.key && e2.ctrlKey || "Escape" === e2.key) && b(); |
| 107 | + }, f = () => { |
103 | 108 | let e2 = (t2 = o.getContent(), c.parser ? c.parser(t2) : html_beautify(t2)); |
104 | 109 | var t2; |
105 | | - n || (n = ace.createEditSession(e2, `ace/mode/${c.language}`), n.setUseWrapMode(c.wrap)), r.setSession(n), n.setValue(e2), r.gotoLine(1 / 0), r.focus(); |
106 | | - }, f = function() { |
| 110 | + if (!n && (n = ace.createEditSession(e2, `ace/mode/${c.language}`), n.setUseWrapMode(c.wrap), !c.fallbackModal)) { |
| 111 | + const e3 = /* @__PURE__ */ ((e4, o2) => { |
| 112 | + let t3; |
| 113 | + return (...n2) => { |
| 114 | + clearTimeout(t3), t3 = setTimeout(() => e4.apply(null, n2), o2); |
| 115 | + }; |
| 116 | + })(y, 300); |
| 117 | + n.on("change", e3); |
| 118 | + } |
| 119 | + r.setSession(n), n.setValue(e2), r.gotoLine(1 / 0), r.focus(); |
| 120 | + }, g = function() { |
107 | 121 | if (c.fallbackModal) |
108 | 122 | p(); |
109 | 123 | else { |
110 | 124 | const e2 = o.getContainer(); |
111 | | - d && (a = d != e2.clientWidth), d = e2.clientWidth, !a && t || (t = e2.querySelector(".tox-editor-header")), o.execCommand("ToggleView", false, "supercode"); |
| 125 | + a && (d = a != e2.clientWidth), a = e2.clientWidth, !d && t || (t = e2.querySelector(".tox-editor-header")), o.execCommand("ToggleView", false, "supercode"); |
112 | 126 | } |
113 | 127 | }; |
114 | 128 | if (!c.fallbackModal) { |
115 | 129 | const e2 = { onShow: (e3) => { |
116 | 130 | const o2 = e3.getContainer(); |
117 | | - a && (i(o2.querySelector(".supercode-header"), t), o2.querySelector(".supercode-body ").style.width = d + "px", r.resize()), 0 === o2.childElementCount && (o2.style.padding = 0, o2.style.display = "flex", o2.style.flexDirection = "column", o2.innerHTML = '<div class="supercode-header"></div><div class="supercode-body"></div>', c.shortcut && o2.addEventListener("keydown", b), i(o2.querySelector(".supercode-header"), t), l(o2.querySelector(".supercode-body "), d)), h(); |
| 131 | + d && (l(o2.querySelector(".supercode-header"), t), o2.querySelector(".supercode-body ").style.width = a + "px", r.resize()), 0 === o2.childElementCount && (o2.style.padding = 0, o2.style.display = "flex", o2.style.flexDirection = "column", o2.innerHTML = '<div class="supercode-header"></div><div class="supercode-body"></div>', c.shortcut && o2.addEventListener("keydown", h), l(o2.querySelector(".supercode-header"), t), i(o2.querySelector(".supercode-body "), a)), f(); |
118 | 132 | }, onHide: () => { |
119 | | - c.shortcut && removeEventListener("keydown", b); |
| 133 | + c.shortcut && removeEventListener("keydown", h); |
120 | 134 | } }; |
121 | 135 | o.ui.registry.addView("supercode", e2); |
122 | 136 | } |
123 | | - return o.ui.registry.addButton("supercode", { icon: c.iconName, tooltip: "Source Code Editor (Ctrl + space)", onAction: f }), o.ui.registry.addMenuItem("supercode", { icon: c.iconName, text: "Source Code", onAction: f }), o.ui.registry.addContextMenu("supercode", { update: (e2) => "supercode" }), c.shortcut && o.shortcuts.add("ctrl+32", "Toggles Source Code Editing Mode", f), { getMetadata: function() { |
| 137 | + return o.ui.registry.addButton("supercode", { icon: c.iconName, tooltip: "Source Code Editor (Ctrl + space)", onAction: g }), o.ui.registry.addMenuItem("supercode", { icon: c.iconName, text: "Source Code", onAction: g }), o.ui.registry.addContextMenu("supercode", { update: (e2) => "supercode" }), c.shortcut && o.shortcuts.add("ctrl+32", "Toggles Source Code Editing Mode", g), { getMetadata: function() { |
124 | 138 | return { name: "Supercode", url: "https://github.com/prathamVaidya/supercode-tinymce-plugin" }; |
125 | 139 | } }; |
126 | 140 | }); |
|
0 commit comments