diff --git a/dist/index.min.js b/dist/index.min.js index a77e264..124b7c9 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.CodeBox=t():e.CodeBox=t()}(window,(function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="/",n(n.s=0)}([function(e,t,n){function r(e,t){for(var n=0;n'}}},{key:"displayInToolbox",get:function(){return!0}},{key:"enableLineBreaks",get:function(){return!0}}],(n=[{key:"render",value:function(){var e=this,t=document.createElement("pre"),n=this._createLanguageSelectElement();return t.setAttribute("class","codeBoxHolder"),this.codeArea.setAttribute("class","codeBoxTextArea ".concat(this.config.useDefaultTheme," ").concat(this.data.language)),this.codeArea.setAttribute("contenteditable",!0),this.codeArea.innerHTML=this.data.code,this.api.listeners.on(this.codeArea,"blur",(function(t){return e._highlightCodeArea(t)}),!1),this.api.listeners.on(this.codeArea,"paste",(function(t){return e._handleCodeAreaPaste(t)}),!1),t.appendChild(this.codeArea),t.appendChild(n),t}},{key:"save",value:function(e){return Object.assign(this.data,{code:this.codeArea.innerHTML,theme:this._getThemeURLFromConfig()})}},{key:"validate",value:function(e){return!!e.code.trim()}},{key:"destroy",value:function(){var e=this;this.api.listeners.off(window,"click",this._closeAllLanguageSelects,!0),this.api.listeners.off(this.codeArea,"blur",(function(t){return e._highlightCodeArea(t)}),!1),this.api.listeners.off(this.codeArea,"paste",(function(t){return e._handleCodeAreaPaste(t)}),!1),this.api.listeners.off(this.selectInput,"click",(function(t){return e._handleSelectInputClick(t)}),!1)}},{key:"_createLanguageSelectElement",value:function(){var e=this,t=document.createElement("div"),n=document.createElement("div"),r=Object.entries(a);return t.setAttribute("class","codeBoxSelectDiv"),this.selectDropIcon.setAttribute("class","codeBoxSelectDropIcon ".concat(this.config.useDefaultTheme)),this.selectDropIcon.innerHTML="↓",this.selectInput.setAttribute("class","codeBoxSelectInput ".concat(this.config.useDefaultTheme)),this.selectInput.setAttribute("type","text"),this.selectInput.setAttribute("readonly",!0),this.selectInput.value=this.data.language,this.api.listeners.on(this.selectInput,"click",(function(t){return e._handleSelectInputClick(t)}),!1),n.setAttribute("class","codeBoxSelectPreview"),r.forEach((function(t){var r=document.createElement("p");r.setAttribute("class","codeBoxSelectItem ".concat(e.config.useDefaultTheme)),r.setAttribute("data-key",t[0]),r.textContent=t[1],e.api.listeners.on(r,"click",(function(n){return e._handleSelectItemClick(n,t)}),!1),n.appendChild(r)})),t.appendChild(this.selectDropIcon),t.appendChild(this.selectInput),t.appendChild(n),t}},{key:"_highlightCodeArea",value:function(e){hljs.highlightBlock(this.codeArea)}},{key:"_handleCodeAreaPaste",value:function(e){e.stopPropagation()}},{key:"_handleSelectInputClick",value:function(e){e.target.nextSibling.classList.toggle("codeBoxShow")}},{key:"_handleSelectItemClick",value:function(e,t){e.target.parentNode.parentNode.querySelector(".codeBoxSelectInput").value=t[1],e.target.parentNode.classList.remove("codeBoxShow"),this.codeArea.removeAttribute("class"),this.data.language=t[0],this.codeArea.setAttribute("class","codeBoxTextArea ".concat(this.config.useDefaultTheme," ").concat(this.data.language)),hljs.highlightBlock(this.codeArea)}},{key:"_closeAllLanguageSelects",value:function(){for(var e=document.querySelectorAll(".codeBoxSelectPreview"),t=0,n=e.length;t=0&&h.splice(t,1)}function v(e){var t=document.createElement("style");return void 0===e.attrs.type&&(e.attrs.type="text/css"),b(t,e.attrs),g(e,t),t}function b(e,t){Object.keys(t).forEach((function(n){e.setAttribute(n,t[n])}))}function y(e,t){var n,r,o,i;if(t.transform&&e.css){if(!(i=t.transform(e.css)))return function(){};e.css=i}if(t.singleton){var a=u++;n=l||(l=v(t)),r=A.bind(null,n,a,!1),o=A.bind(null,n,a,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",b(t,e.attrs),g(e,t),t}(t),r=C.bind(null,n,t),o=function(){m(n),n.href&&URL.revokeObjectURL(n.href)}):(n=v(t),r=w.bind(null,n),o=function(){m(n)});return r(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;r(e=t)}else o()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=a()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=p(e,t);return d(n,t),function(e){for(var r=[],o=0;o'}}},{key:"isReadOnlySupported",get:function(){return!0}},{key:"displayInToolbox",get:function(){return!0}},{key:"enableLineBreaks",get:function(){return!0}}],(n=[{key:"render",value:function(){var e=this,t=document.createElement("pre"),n=this._createLanguageSelectElement();return t.setAttribute("class","codeBoxHolder"),this.codeArea.setAttribute("class","codeBoxTextArea ".concat(this.config.useDefaultTheme," ").concat(this.data.language)),this.codeArea.setAttribute("contenteditable",!0),this.codeArea.innerHTML=this.data.code,this.api.listeners.on(this.codeArea,"blur",(function(t){return e._highlightCodeArea(t)}),!1),this.api.listeners.on(this.codeArea,"paste",(function(t){return e._handleCodeAreaPaste(t)}),!1),this.readOnly?this.codeArea.setAttribute("contenteditable",!1):this.codeArea.setAttribute("contenteditable",!0),t.appendChild(this.codeArea),t.appendChild(n),t}},{key:"save",value:function(e){return Object.assign(this.data,{code:this.codeArea.innerHTML,theme:this._getThemeURLFromConfig()})}},{key:"validate",value:function(e){return!!e.code.trim()}},{key:"destroy",value:function(){var e=this;this.api.listeners.off(window,"click",this._closeAllLanguageSelects,!0),this.api.listeners.off(this.codeArea,"blur",(function(t){return e._highlightCodeArea(t)}),!1),this.api.listeners.off(this.codeArea,"paste",(function(t){return e._handleCodeAreaPaste(t)}),!1),this.api.listeners.off(this.selectInput,"click",(function(t){return e._handleSelectInputClick(t)}),!1)}},{key:"_createLanguageSelectElement",value:function(){var e=this,t=document.createElement("div"),n=document.createElement("div"),o=Object.entries(a);return t.setAttribute("class","codeBoxSelectDiv"),this.selectDropIcon.setAttribute("class","codeBoxSelectDropIcon ".concat(this.config.useDefaultTheme)),this.selectDropIcon.innerHTML="↓",this.selectInput.setAttribute("class","codeBoxSelectInput ".concat(this.config.useDefaultTheme)),this.selectInput.setAttribute("type","text"),this.selectInput.setAttribute("readonly",!0),this.selectInput.value=this.data.language,this.api.listeners.on(this.selectInput,"click",(function(t){return e._handleSelectInputClick(t)}),!1),n.setAttribute("class","codeBoxSelectPreview"),o.forEach((function(t){var o=document.createElement("p");o.setAttribute("class","codeBoxSelectItem ".concat(e.config.useDefaultTheme)),o.setAttribute("data-key",t[0]),o.textContent=t[1],e.api.listeners.on(o,"click",(function(n){return e._handleSelectItemClick(n,t)}),!1),n.appendChild(o)})),t.appendChild(this.selectDropIcon),t.appendChild(this.selectInput),t.appendChild(n),t}},{key:"_highlightCodeArea",value:function(e){hljs.highlightBlock(this.codeArea)}},{key:"_handleCodeAreaPaste",value:function(e){e.stopPropagation()}},{key:"_handleSelectInputClick",value:function(e){e.target.nextSibling.classList.toggle("codeBoxShow")}},{key:"_handleSelectItemClick",value:function(e,t){e.target.parentNode.parentNode.querySelector(".codeBoxSelectInput").value=t[1],e.target.parentNode.classList.remove("codeBoxShow"),this.codeArea.removeAttribute("class"),this.data.language=t[0],this.codeArea.setAttribute("class","codeBoxTextArea ".concat(this.config.useDefaultTheme," ").concat(this.data.language)),hljs.highlightBlock(this.codeArea)}},{key:"_closeAllLanguageSelects",value:function(){for(var e=document.querySelectorAll(".codeBoxSelectPreview"),t=0,n=e.length;t=0&&h.splice(t,1)}function v(e){var t=document.createElement("style");return void 0===e.attrs.type&&(e.attrs.type="text/css"),b(t,e.attrs),g(e,t),t}function b(e,t){Object.keys(t).forEach((function(n){e.setAttribute(n,t[n])}))}function y(e,t){var n,o,i,r;if(t.transform&&e.css){if(!(r=t.transform(e.css)))return function(){};e.css=r}if(t.singleton){var a=u++;n=l||(l=v(t)),o=A.bind(null,n,a,!1),i=A.bind(null,n,a,!0)}else e.sourceMap&&"function"==typeof URL&&"function"==typeof URL.createObjectURL&&"function"==typeof URL.revokeObjectURL&&"function"==typeof Blob&&"function"==typeof btoa?(n=function(e){var t=document.createElement("link");return void 0===e.attrs.type&&(e.attrs.type="text/css"),e.attrs.rel="stylesheet",b(t,e.attrs),g(e,t),t}(t),o=C.bind(null,n,t),i=function(){m(n),n.href&&URL.revokeObjectURL(n.href)}):(n=v(t),o=w.bind(null,n),i=function(){m(n)});return o(e),function(t){if(t){if(t.css===e.css&&t.media===e.media&&t.sourceMap===e.sourceMap)return;o(e=t)}else i()}}e.exports=function(e,t){if("undefined"!=typeof DEBUG&&DEBUG&&"object"!=typeof document)throw new Error("The style-loader cannot be used in a non-browser environment");(t=t||{}).attrs="object"==typeof t.attrs?t.attrs:{},t.singleton||"boolean"==typeof t.singleton||(t.singleton=a()),t.insertInto||(t.insertInto="head"),t.insertAt||(t.insertAt="bottom");var n=p(e,t);return f(n,t),function(e){for(var o=[],i=0;i this._highlightCodeArea(event), false); this.api.listeners.on(this.codeArea, 'paste', event => this._handleCodeAreaPaste(event), false); + if(this.readOnly) { + this.codeArea.setAttribute('contenteditable', false); + } else { + this.codeArea.setAttribute('contenteditable', true); + } + codeAreaHolder.appendChild(this.codeArea); codeAreaHolder.appendChild(languageSelect);