123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- !function() {
- let e = null;
- tinymce.PluginManager.add("supercode", function(o) {
- let t, n, r, a = 0, d = false;
- 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 = () => {
- const e2 = {};
- 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);
- }, l = (e2, o2) => {
- const t2 = o2.cloneNode(true);
- t2.style.position = "relative";
- const n2 = t2.querySelector(".tox-menubar");
- n2 && (n2.innerHTML = "<b style='font-size: 14px; font-weight: bold; padding: 11px 9px;'>Source Code Editor</b>");
- let r2 = null, a2 = false;
- t2.querySelectorAll(".tox-tbtn, .tox-split-button").forEach((e3) => {
- "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);
- }), !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);
- }, i = (e2, o2) => {
- e2.style.width = o2 + "px", e2.style.height = "100%", e2.style.position = "relative", ((e3) => {
- if (e3.attachShadow({ mode: "open" }), c.aceCss) {
- const o4 = new CSSStyleSheet();
- o4.replaceSync(c.aceCss), e3.shadowRoot.adoptedStyleSheets.push(o4);
- }
- e3.shadowRoot.innerHTML = '<div class="supercode-editor" style="width: 100%; height: 100%; position: absolute; left:0; top:0"></div>';
- const o3 = e3.shadowRoot.querySelector(".supercode-editor");
- o3.style.width = "100%", o3.style.height = "100%", r = ace.edit(o3), r.renderer.attachToShadowRoot(), s();
- })(e2);
- };
- ((e2) => {
- var _a, _b, _c;
- const o2 = e2.getParam("supercode");
- if (o2 && "object" == typeof o2) {
- for (const e3 in o2)
- if (o2.hasOwnProperty(e3)) {
- const t3 = o2[e3];
- switch (e3) {
- case "theme":
- case "language":
- case "iconName":
- case "aceCss":
- case "fontFamily":
- case "modalPrimaryColor":
- case "modalSecondaryColor":
- "string" == typeof t3 && (c[e3] = t3);
- break;
- case "fontSize":
- "number" == typeof t3 && t3 > 0 && (c.fontSize = parseInt(t3));
- break;
- case "wrap":
- case "autocomplete":
- case "shortcut":
- case "fallbackModal":
- case "dark":
- case "debug":
- "boolean" == typeof t3 && (c[e3] = t3);
- break;
- case "parser":
- case "renderer":
- "function" == typeof t3 && (c[e3] = t3);
- }
- }
- }
- var t2;
- c.icon = (_c = (_b = (_a = e2.ui.registry).getAll) == null ? void 0 : _b.call(_a).icons) == null ? void 0 : _c[c.iconName], c.icon || (c.icon = '<svg width="24" height="24" focusable="false"><g fill-rule="nonzero"><path d="M9.8 15.7c.3.3.3.8 0 1-.3.4-.9.4-1.2 0l-4.4-4.1a.8.8 0 0 1 0-1.2l4.4-4.2c.3-.3.9-.3 1.2 0 .3.3.3.8 0 1.1L6 12l3.8 3.7ZM14.2 15.7c-.3.3-.3.8 0 1 .4.4.9.4 1.2 0l4.4-4.1c.3-.3.3-.9 0-1.2l-4.4-4.2a.8.8 0 0 0-1.2 0c-.3.3-.3.8 0 1.1L18 12l-3.8 3.7Z"></path></g></svg>', t2 = "Supercode Icon name is invalid or you are using older versions of tinyMCE. The icon is set to default fallback code icon.", c.debug && console.warn(`${t2}
- Use debug:false option to disable this warning`)), c.fallbackModal || (true === e2.getParam("inline") || tinymce.majorVersion <= 5) && (c.fallbackModal = true);
- })(o), ((e2) => {
- const o2 = { "ace-default": { url: "https://cdnjs.cloudflare.com/ajax/libs/ace/1.9.6/ace.js", loaded: false, required: true }, "beautify-html": { url: "https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.15.1/beautify-html.min.js", loaded: false, required: true }, "ace-autocomplete": { url: "https://cdnjs.cloudflare.com/ajax/libs/ace/1.9.6/ext-language_tools.min.js", loaded: false, required: false } };
- e2.autocomplete && (o2["ace-autocomplete"].required = true), Object.values(o2).forEach((e3) => {
- if (e3.loaded)
- return;
- let o3 = document.createElement("script");
- o3.src = e3.url, o3.type = "text/javascript", document.body.appendChild(o3);
- });
- })(c);
- const u = (e2) => {
- "Escape" === e2.key && m();
- }, p = () => {
- var _a, _b, _c;
- if (!e) {
- const o2 = document.createElement("div");
- o2.id = "supercode-modal-container", o2.innerHTML = '\n <div id="supercode-backdrop"></div>\n <div id="supercode-modal">\n <div id="supercode-header">\n <h1>Source Code Editor</h1>\n <button id="supercode-close-btn">\n Close\n </button>\n </div>\n <div id="supercode-editor"></div>\n <div id="supercode-footer">\n <button id="supercode-cancel-btn">\n Cancel\n </button>\n <button id="supercode-save-btn">\n Save\n </button>\n </div>\n </div>\n', ((e2) => {
- const o3 = document.createElement("style");
- o3.innerHTML = e2, document.head.append(o3);
- })("\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")) };
- }
- 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 = () => {
- b(), m();
- }, 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(() => {
- e.element.style.opacity = 1;
- }, 10), f();
- }, m = () => {
- c.shortcut && removeEventListener("keydown", u), document.querySelector("body").classList.remove("disable-scroll"), e.element.style.opacity = 0, o.focus(), setTimeout(() => {
- e.element.style.display = "none";
- }, 10);
- }, y = () => {
- o.undoManager.transact(function() {
- let e2 = r.getValue();
- c.renderer && (e2 = c.renderer(e2)), o.setContent(e2);
- }), o.nodeChanged();
- }, b = () => {
- o.focus(), c.fallbackModal && (o.undoManager.transact(function() {
- let e2 = r.getValue();
- c.renderer && (e2 = c.renderer(e2)), o.setContent(e2);
- }), o.selection.setCursorLocation(), o.nodeChanged()), o.execCommand("ToggleView", false, "supercode");
- }, h = (e2) => {
- (" " === e2.key && e2.ctrlKey || "Escape" === e2.key) && b();
- }, f = () => {
- let e2 = (t2 = o.getContent(), c.parser ? c.parser(t2) : html_beautify(t2));
- var t2;
- if (!n && (n = ace.createEditSession(e2, `ace/mode/${c.language}`), n.setUseWrapMode(c.wrap), !c.fallbackModal)) {
- const e3 = /* @__PURE__ */ ((e4, o2) => {
- let t3;
- return (...n2) => {
- clearTimeout(t3), t3 = setTimeout(() => e4.apply(null, n2), o2);
- };
- })(y, 300);
- n.on("change", e3);
- }
- r.setSession(n), n.setValue(e2), r.gotoLine(1 / 0), r.focus();
- }, g = function() {
- if (c.fallbackModal)
- p();
- else {
- const e2 = o.getContainer();
- a && (d = a != e2.clientWidth), a = e2.clientWidth, !d && t || (t = e2.querySelector(".tox-editor-header")), o.execCommand("ToggleView", false, "supercode");
- }
- };
- if (!c.fallbackModal) {
- const e2 = { onShow: (e3) => {
- const o2 = e3.getContainer();
- 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();
- }, onHide: () => {
- c.shortcut && removeEventListener("keydown", h);
- } };
- o.ui.registry.addView("supercode", e2);
- }
- 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() {
- return { name: "Supercode", url: "https://github.com/prathamVaidya/supercode-tinymce-plugin" };
- } };
- });
- }();
|