jodit-pro
Version:
PRO Version of Jodit Editor
8 lines • 9.36 kB
JavaScript
/*!
* jodit-pro - PRO Version of Jodit Editor
* Author: Chupurnov Valerii <chupurnov@gmail.com>
* Version: v4.9.27
* Url: https://xdsoft.net/jodit/pro/
* License(s): SEE LICENSE IN LICENSE.md
*/
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var a=t();for(var n in a)("object"==typeof exports?exports:e)[n]=a[n]}}(self,function(){return(self.webpackChunkjodit_pro=self.webpackChunkjodit_pro||[]).push([[150],{41406:function(e,t,a){"use strict";a.r(t),a.d(t,{pasteCode:function(){return L}});var n=a(77688),i=a(80294),o=a(20616),r=a(67709),l=a(82749),s=a(18766),c=a(23078),u=a(31635),d=a(62361);a(83967);var h=a(82758),g=a(65478),p=a(21537),f=a(87612),m=a(53326),v=a(50911),_=a(67510),C=a(41409),b=a(2692),L=function(e){function t(){var e;return(0,o._)(this,t),e=(0,i._)(this,t,arguments),(0,l._)(e,"buttons",[{name:"pasteCode",group:"clipboard"}]),(0,l._)(e,"__highlightLibJSIsLoaded",!1),(0,l._)(e,"__loadLanguage",new Map),(0,l._)(e,"__initHighlightLibLoading",function(t){return(0,n._)(function(){var a,n,i,o,r,l,s,c,u,g;return(0,d._)(this,function(d){switch(d.label){case 0:if(n=(a=e.j.o.pasteCode).globalHighlightLib,o=(i=a.highlightLib).css,r=i.js,l=i.langUrl,s=i.highlight,c=i.isLangLoaded,u=i.beforeLibLoad,g=i.afterLibLoad,e.__highlightLibJSIsLoaded||n||(e.__highlightLibJSIsLoaded=Promise.resolve(null==u?void 0:u()).then(function(){return x(e.async,Promise.allSettled([(0,p.loadNextStyle)(e.jodit,o).catch(function(){return null}),(0,p.loadNext)(e.jodit,r).catch(function(){return null})]))}).then(function(){return null==g?void 0:g()})),(0,f.isBoolean)(e.__highlightLibJSIsLoaded))return[3,2];return[4,e.__highlightLibJSIsLoaded];case 1:d.sent(),d.label=2;case 2:if(!(t&&!c(t)&&!n))return[3,4];return e.__loadLanguage.has(t)||(h.IS_PROD,e.__loadLanguage.set(t,x(e.async,(0,p.appendScriptAsync)(e.jodit,l(t)).catch(function(){return null})))),[4,e.__loadLanguage.get(t)];case 3:d.sent(),d.label=4;case 4:return[2,{highlight:s}]}})})()}),e}return(0,s._)(t,e),(0,r._)(t,[{key:"className",value:function(){return"pasteCode"}},{key:"afterInit",value:function(e){var t=this;e.registerCommand("pasteCode",function(){return t.__openCodeEditDialog()}),e.async.requestIdleCallback(function(){return t.__initHighlightLibLoading()})}},{key:"__openCodeEditDialog",value:function(e,t,a){var n=this,i=this.j,o=this.__createForm(),r=(0,p.refs)(o.container),l=r.code,s=r.language;e&&(s.value=e),t&&(l.value=t),i.async.requestIdleCallback(function(){l.focus()}),i.s.save(),this.__createDialog(function(){if(o.validate()){i.s.restore();var e=i.createInside.fromHTML(i.o.pasteCode.insertTemplate(i,s.value,l.value));if(a)C.Dom.replace(a,e,i.createInside,!1,!0);else{var t=i.s.current(),r=C.Dom.up(t,C.Dom.isBlock,i.editor);r&&!C.Dom.isCell(r)?C.Dom.after(r,e):i.s.insertNode(e)}n.__imdOnChange();return}return!1},function(){i.s.restore()}).setContent(o.container).open(!0)}},{key:"beforeDestruct",value:function(e){}},{key:"__createForm",value:function(){var e=this.jodit;return new _.UIForm(e,[new _.UISelect(e,{name:"language",label:"Language",value:e.o.pasteCode.defaultLanguage,options:e.o.pasteCode.languages,required:!0}),new _.UITextArea(e,{label:"Code view",resizable:!1,name:"code",required:!0,className:"jodit-paste-code__textarea"})],{className:"jodit-paste-code"})}},{key:"__createDialog",value:function(e,t){var a=new C.Dialog({language:this.j.o.language});return a.setHeader("Insert/Edit Code Sample").setSize(this.j.o.pasteCode.dialog.width,this.j.o.pasteCode.dialog.height).setFooter([(0,_.Button)(a,"","Cancel","default").onAction(function(){a.close(),t()}),(0,_.Button)(a,"save","Save","primary").onAction(function(){a.close(),e()})]),a}},{key:"__onChange",value:function(){this.__imdOnChange()}},{key:"__imdOnChange",value:function(){var e=this;(0,p.$$)("pre",this.j.editor).forEach(function(t){(0,p.attr)(t,"contenteditable")||((0,p.attr)(t,"contenteditable",!1),e.__highlightCode(t).catch(function(){return null}))})}},{key:"__highlightCode",value:function(e){return(0,n._)(function(){var t,a,n;return(0,d._)(this,function(i){switch(i.label){case 0:return t=this.__parseLanguage(e),[4,this.__initHighlightLibLoading(t)];case 1:return a=i.sent().highlight,n=e,e.firstElementChild===e.lastElementChild&&C.Dom.isTag(e.firstElementChild,"code")&&(n=e.firstElementChild),n.innerHTML=a(n.innerText,t),[2]}})}).call(this)}},{key:"onPreEdit",value:function(e){var t=C.Dom.isNode(e)&&C.Dom.isTag(e,"pre")?e:C.Dom.closest(e.target,"pre",this.j.editor);if(t){var a=this.__parseLanguage(t);this.__openCodeEditDialog(a,t.innerText,t)}}},{key:"__parseLanguage",value:function(e){var t=null,a=function(e){return e.classList.forEach(function(e){if(/language-/.test(e)){var a=/language-(.*)/.exec(e);a&&a[1]&&(t=a[1])}})};return a(e),null==t&&e.firstElementChild===e.lastElementChild&&C.Dom.isTag(e.firstElementChild,"code")&&a(e.firstElementChild),this.jodit.o.pasteCode.canonicalLanguageCode(t||"html")}},{key:"onAfterGetValueFromEditor",value:function(e){var t=this,a=function(e,a,n,i,o,r){return"".concat(a.trim()).concat(i).concat((0,m.htmlspecialchars)((0,p.stripTags)(o,t.j.ed,new Set(["br"])))).concat(r)};e.value=e.value.replace(RegExp("(<pre[^>]*)contenteditable\\s*=\\s*(['\"]?)false\\2([^>]*>\\s*<code[^>]*>)(.*?)(<\\/code>\\s*<\\/pre>)","gis"),a).replace(RegExp("(<pre[^>]*)contenteditable\\s*=\\s*(['\"]?)false\\2([^>]*>)(.*?)(<\\/pre>)","gis"),a)}}]),t}((0,c._)(v.Plugin));function x(e,t){return e.promise(function(e,a){t.then(e).catch(a)}).catch(function(){return null})}(0,l._)(L,"requires",["license"]),(0,u.__decorate)([g.autobind],L.prototype,"__openCodeEditDialog",null),(0,u.__decorate)([(0,g.watch)(["?:change","?:afterInit"]),(0,g.debounce)()],L.prototype,"__onChange",null),(0,u.__decorate)([(0,g.watch)(["?:dblclick","?:editPreInPasteCode"])],L.prototype,"onPreEdit",null),(0,u.__decorate)([(0,g.watch)("?:afterGetValueFromEditor")],L.prototype,"onAfterGetValueFromEditor",null),L=(0,u.__decorate)([g.component],L),b.JoditPro.plugins.add("paste-code",L)},75689:function(e){e.exports='<svg viewBox="0 0 24 24" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"> <path d="M2.5244141,23.5h18.9511719c0.4140625,0,0.75-0.3359375,0.75-0.75V4.9208984 c0-0.1992188-0.0795898-0.390625-0.2207031-0.53125L18.3198242,0.71875C18.1791992,0.5786133,17.9887695,0.5,17.7905273,0.5 H2.5244141c-0.4140625,0-0.75,0.3359375-0.75,0.75v21.5C1.7744141,23.1640625,2.1103516,23.5,2.5244141,23.5z M20.7128296,5.2197266 h-2.6986694V2.531189L20.7128296,5.2197266z M3.2744141,2h13.2397461v3.9697266c0,0.4140625,0.3359375,0.75,0.75,0.75h3.4614258V22 H3.2744141V2z" fill="#1D1D1D"/> <path d="M8.75,10.25h1.75c0.4140625,0,0.75-0.3359375,0.75-0.75s-0.3359375-0.75-0.75-0.75H8 c-0.4140625,0-0.75,0.3359375-0.75,0.75v2.75H6c-0.4140625,0-0.75,0.3359375-0.75,0.75S5.5859375,13.75,6,13.75h1.25v2.75 c0,0.4140625,0.3359375,0.75,0.75,0.75h2.5c0.4140625,0,0.75-0.3359375,0.75-0.75s-0.3359375-0.75-0.75-0.75H8.75V10.25z" fill="#1D1D1D"/> <path d="M18.5,12.25h-1.25V9.5c0-0.4140625-0.3359375-0.75-0.75-0.75H14c-0.4140625,0-0.75,0.3359375-0.75,0.75 s0.3359375,0.75,0.75,0.75h1.75v5.5H14c-0.4140625,0-0.75,0.3359375-0.75,0.75s0.3359375,0.75,0.75,0.75h2.5 c0.4140625,0,0.75-0.3359375,0.75-0.75v-2.75h1.25c0.4140625,0,0.75-0.3359375,0.75-0.75S18.9140625,12.25,18.5,12.25z" fill="#1D1D1D"/></svg>'},83967:function(e,t,a){"use strict";var n=a(75689),i=a.n(n),o=a(6441),r=a(53326);o.Config.prototype.controls.pasteCode={icon:i(),tooltip:"Paste code",command:"pasteCode"},o.Config.prototype.pasteCode={globalHighlightLib:!1,canonicalLanguageCode:function(e){switch(e){case"ts":return"typescript";case"js":return"javascript";case"markup":return"html"}return e},highlightLib:{beforeLibLoad:function(){window.Prism=window.Prism||{},window.Prism.manual=!0},highlight:function(e,t){return"u">typeof Prism?Prism.highlight(e,Prism.languages[t]||Prism.languages.plain,t):(0,r.htmlspecialchars)(e)},isLangLoaded:function(e){return"html"===e||"u">typeof Prism&&!!Prism.languages[e]},js:["https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/prism.min.js","https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"],langUrl:function(e){return"https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-".concat(e,".min.js")},css:["https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism.min.css"]},defaultLanguage:"html",insertTemplate:function(e,t,a){return'<pre class="language-'.concat(t,'">').concat((0,r.htmlspecialchars)(a),"</pre>")},languages:[{value:"plaintext",text:"Plain"},{value:"html",text:"HTML/XML"},{value:"bash",text:"Bash"},{value:"php",text:"PHP"},{value:"javascript",text:"JavaScript"},{value:"typescript",text:"TypeScript"},{value:"jsx",text:"JSX"},{value:"java",text:"Java"},{value:"css",text:"CSS"},{value:"php",text:"PHP"},{value:"ruby",text:"Ruby"},{value:"python",text:"Python"},{value:"java",text:"Java"},{value:"c",text:"C"},{value:"csharp",text:"C#"},{value:"cpp",text:"C++"},{value:"sql",text:"SQL"},{value:"docker",text:"Docker"},{value:"http",text:"HTTP"},{value:"ini",text:"INI"},{value:"yaml",text:"YAML"},{value:"json",text:"JSON"},{value:"json5",text:"JSON5"},{value:"makefile",text:"Makefile"},{value:"swift",text:"Swift"}],dialog:{width:700,height:600}}}},function(e){return e(e.s=41406)}])});