jodit-pro
Version:
PRO Version of Jodit Editor
8 lines • 3.47 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 r=t();for(var o in r)("object"==typeof exports?exports:e)[o]=r[o]}}(self,function(){return(self.webpackChunkjodit_pro=self.webpackChunkjodit_pro||[]).push([[726],{36347:function(e,t,r){r(6441).Config.prototype.highlightSignature={processDelay:0,processInChunkCount:300,schema:{},excludeTags:["pre"]}},46958:function(e,t,r){r.r(t),r.d(t,{highlightSignature:function(){return c}});var o=r(82749),i=r(31635);r(36347);var s=r(65478),a=r(2748),n=r(29960),l=r(20356),h=r(2692);class c extends l.Plugin{afterInit(e){Object.keys(e.o.highlightSignature.schema).length&&(e.e.on("change afterSetMode",this.walkNodes).on("afterGetValueFromEditor",c.removeUtilWrappers),this.walkNodes())}beforeDestruct(e){e.e.off("change afterSetMode",this.walkNodes).off("afterGetValueFromEditor",c.removeUtilWrappers)}walkNodes(){if(!this.j.isEditorMode())return;this.checkUtilsBoxToSchema();let{j:e}=this,t=e.ed.createNodeIterator(e.editor,NodeFilter.SHOW_TEXT);this.abortController?.abort(),this.workLoop(t)}runWorker(e){let t;this.j.e.mute();let r=0,{processInChunkCount:o}=this.j.o.highlightSignature;try{do{if(r+=1,!(t=e.nextNode())||this.checkNormalizing(t))return;this.checkReplaceSchemas(t)}while(t&&o>r)}finally{this.j.e.unmute()}this.workLoop(e)}workLoop(e){this.abortController=new AbortController,this.j.async.schedulerPostTask(()=>this.runWorker(e),{delay:this.j.o.highlightSignature.processDelay}).catch(()=>null)}checkNormalizing(e){return!!a.Dom.isText(e.nextSibling)&&(this.j.editor.normalize(),this.walkNodes(),!0)}checkReplaceSchemas(e){if(c.hasUtilWrapper(e))return;let t=e.nodeValue;if(null==t)return;let{j:r}=this,o=r.o.highlightSignature;for(let r in o.schema){let i=RegExp(r);if(i.test(t)){let s=t.match(i);if(!s||void 0===s.index)continue;let n=o.schema[r](this.j,s);if(n){a.Dom.markTemporary(n,{dataHighlightSchema:r}),this.replaceMatchedTextToElm(e,t,s,n);return}}}}replaceMatchedTextToElm(e,t,r,o){let{j:i}=this,{range:s}=i.s,n=s.startContainer===e,l=s.startOffset,h=r.index??0;e.nodeValue=t.substring(0,h);let c=t.substring(h+r[0].length);if(c.length){let t=i.createInside.text(c);a.Dom.after(e,t)}o.innerText=r[0],a.Dom.after(e,o),n&&this.restoreCursorPosition(l,e,o.firstChild,o.nextSibling)}static hasUtilWrapper(e){return a.Dom.isTemporary(e.parentElement)}static removeUtilWrappers(e){e.value=a.Dom.replaceTemporaryFromString(e.value)}restoreCursorPosition(e,...t){for(let r of t)if(r&&r.nodeValue){let t=r.nodeValue;if(t.length>=e){let t=this.j.s.createRange();t.setStart(r,e),this.j.s.selectRange(t,!1);break}e-=t.length}}checkUtilsBoxToSchema(){a.Dom.temporaryList(this.j.editor).forEach(e=>{let t=(0,n.attr)(e,"dataHighlightSchema");if(!t)return;let r=RegExp(t),o=e.innerText??"";(!r.test(o)||o.replace(r,"").length)&&(this.j.s.save(),a.Dom.unwrap(e),this.j.s.restore())})}constructor(...e){super(...e),(0,o._)(this,"abortController",null)}}(0,o._)(c,"requires",["license"]),(0,i.__decorate)([(0,s.debounce)()],c.prototype,"walkNodes",null),(0,i.__decorate)([s.autobind],c.prototype,"runWorker",null),h.JoditPro.plugins.add("highlight-signature",c)}},function(e){return e(e.s=46958)}])});