Ext.namespace("Zarafa.plugins.quill");var editorPlugin={};Ext.isDefined(Zarafa.core.HtmlEditorPlugin)?editorPlugin=Zarafa.core.HtmlEditorPlugin:(Zarafa.plugins.htmleditor&&Zarafa.plugins.htmleditor.Plugin&&(editorPlugin=Zarafa.plugins.htmleditor.Plugin),console.warn("Please upgrade Kopano WebApp to use the Quill plugin"));Zarafa.plugins.quill.QuillPlugin=Ext.extend(editorPlugin,{editorXType:"plugins.quilleditor"});editorPlugin=void 0;
if(!Ext.isIE)Zarafa.onReady(function(){container.registerPlugin(new Zarafa.core.PluginMetaData({name:"quill",allowUserDisable:!1,allowUserVisible:!1,displayName:_("Quill editor"),pluginConstructor:Zarafa.plugins.quill.QuillPlugin}))});Ext.namespace("Zarafa.plugins.quill.ui");var quillIdGen=0;
Zarafa.plugins.quill.ui.QuillEditor=Ext.extend(Ext.Container,{editor:void 0,constructor:function(a){this.id="k-quilleditor-"+quillIdGen++;a=Ext.applyIf(a||{},{xtype:"plugins.quilleditor",cls:"k-quilltextarea",enableSystemContextMenu:!0});Zarafa.plugins.quill.ui.QuillEditor.superclass.constructor.call(this,a);this.initEvents()},initEvents:function(){this.on("activate",this.onActivateEditor,this);this.on("deactivate",this.onDeactivateEditor,this)},bindRecord:function(a){this.record=a},afterRender:function(){Zarafa.plugins.quill.ui.QuillEditor.superclass.afterRender.call(this,
arguments);var a=container.getSettingsModel().get("zarafa/v1/contexts/mail/dialogs/mailcreate/use_html_editor");Ext.isDefined(this.dialog)&&!1===this.dialog.isXType("zarafa.mailcreatecontentpanel")||!1===a||(this.createEditorInstance(),this.editor.container.classList.contains("k-signature-editor")&&this.disable())},onDeactivateEditor:function(){var a=this.editor.container,b=this.editor.getModule("toolbar");!1===a.classList.contains("x-hide-display")&&a.setAttribute("class",a.getAttribute("class")+
" x-hide-display");a=b.container;!1===a.classList.contains("x-hide-display")&&a.setAttribute("class",a.getAttribute("class")+" x-hide-display")},onActivateEditor:function(){if(this.editor){var a=this.editor.container,b=this.editor.getModule("toolbar").container;a.classList.remove("x-hide-display");b.classList.remove("x-hide-display")}else this.createEditorInstance()},createEditorInstance:function(){var a={fontFamilies:this.getFontFamilies().map(function(a){return a.name}),fontSize:Zarafa.common.ui.htmleditor.Fonts.getFontSizeString().split(" ")},
b=this.getActiveWindow();this.activeWindow=b;this.customizeQuill(a);var c=this.id,c=!1===Zarafa.core.BrowserWindowMgr.isMainWindowActive()?b.document.getElementById(c):"#"+c;this.editor=new b.Quill(c,{modules:{toolbar:{container:[["bold","italic","underline","strike"],[{list:"ordered"},{list:"bullet"}],["link","image","blockquote","clean"]],handlers:{clean:this.removeFormatting.bind(this)}},keyboard:{bindings:{selectAll:{key:65,ctrlKey:!0,handler:this.selectAllText},"blockquote empty enter":{key:"Enter",
format:["blockquote"],handler:this.removeEmptyBlockquote.bind(this)},"blockquote empty backspace":{key:"Backspace",format:["blockquote"],empty:!0,handler:this.removeEmptyBlockquote.bind(this)},tab:{key:"Tab",handler:this.onPressTab.bind(this)},backspace:{key:"Backspace",handler:this.onTextRemove.bind(this)},indent:{key:"Tab",format:["list"],empty:!0,handler:this.onEmptyListTab.bind(this)}}}},bounds:c,theme:"snow"});b=this.editor.scroll.domNode;b.classList.contains("zarafa-contextmenu-enabled")||b.classList.add("zarafa-contextmenu-enabled");
this.setDefaultFormatting(a);this.editor.emitter.emit("render",{scope:this});this.editor.on("text-change",this.onTextChange.bind(this));this.editor.root.addEventListener("click",this.onEditorClick.bind(this,Ext.EventObject));this.editor.root.addEventListener("paste",this.onPaste.bind(this));this.editor.on("editor-change",this.onEditorFocus.bind(this));this.editor.root.addEventListener("keydown",this.onLinkTextChange.bind(this))},onLinkTextChange:function(){var a=this.editor,b=this.editor.getSelection(),
c=a.getFormat(),b=a.getText(b.index,1);c.link&&("\n"!==b&&" "!==b||a.format("link",!1,"user"))},removeFormatting:function(){var a=this.editor,b=this.getQuillClass(),c=a.getSelection(),d=this.getDefaultFontFormatting(),b=b["import"]("parchment").Scope,e=a.getFormat();if(null!==c){if(0===c.length)for(var f in e)null!==a.scroll.query(f,b.INLINE)&&a.format(f,!1,"user");else a.removeFormat(c,"user"),a.formatText(c,{font:d.fontFamily,size:d.fontSize});this.setDefaultFormatting()}},onPressTab:function(){var a=
this.editor,b=this.getQuillClass(),c=a.getSelection(),b=b["import"]("delta"),d=a.getFormat(c.index),e=[];d.link&&(d.link=!1);for(var f in d)e[f]=d[f];a.history.cutoff();f=(new b).retain(c.index)["delete"](c.length).insert("\u00a0".repeat(4),e);a.updateContents(f,"user");a.history.cutoff();a.setSelection(c.index+4,"silent")},onTextChange:function(a,b,c){"user"===c&&this.fireEvent("keypress",this,Ext.EventObject)},onPaste:function(){var a=this.getQuillClass(),b=this.getDefaultFontFormatting(),a=a["import"]("delta"),
c=this.editor.getFormat(),d={size:b.fontSize,font:b.fontFamily,background:"white",color:"black"};c.link&&(d={size:b.fontSize,font:b.fontFamily});this.setDefaultFormatting();b=(new a).retain(this.editor.getSelection().index,d);this.editor.updateContents(b,"user");this.editor.format("background","white","user");this.editor.format("color","black","user")},onTextRemove:function(a,b){var c;c=this.editor.getLines(a);0===c.length?(c=this.editor.getFormat(a.index-1),this.editor.deleteText(a.index-1,1,"user")):
(c=this.editor.getIndex(c[0]),c=this.editor.getFormat(c),this.editor.deleteText(a,"user"));if(!c.link)for(var d in c)this.editor.format(d,c[d])},onEditorClick:function(a){var b=this.getQuillClass(),c=this.editor,d=b["import"]("parchment"),b=b["import"]("formats/image");a=d.Registry.find(a.target);a instanceof b&&c.setSelection(a.offset(c.scroll),1,"user");c.isEnabled()||this.disableToolbar()},selectAllText:function(){var a=this.quill;a.setSelection(0,a.getLength());return!0},getActiveWindow:function(){return Zarafa.core.BrowserWindowMgr.getActive()},
getQuillClass:function(){return this.activeWindow.Quill},customizeQuill:function(a){var b=this.getQuillClass(),c=b["import"]("attributors/style/size");c.whitelist=a.fontSize;b.register(c,!0);c=b["import"]("attributors/style/font");c.whitelist=a.fontFamilies;b.register(c,!0);a=b["import"]("blots/block");c=this.getDefaultFontFormatting();a.fontSize=c.fontSize;a.fontType=c.fontFamily;a=b["import"]("parchment");c=new a.StyleAttributor("margin","margin",{scope:a.Scope.BLOCK});b.register(c,!0);c=new a.StyleAttributor("border-left",
"border-left",{scope:a.Scope.BLOCK});b.register(c,!0);a=new a.StyleAttributor("padding-left","padding-left",{scope:a.Scope.BLOCK});b.register(a,!0);b["import"]("formats/link").sanitize=this.sanitizeURL;b["import"]("themes/snow").prototype.buildButtons=this.buildToolbarButtons},sanitizeURL:function(a){a=a.trim();var b=a.slice(0,a.indexOf(":"));-1===this.PROTOCOL_WHITELIST.indexOf(b)&&(a="https://"+a);b=document.createElement("a");b.href=a;b=b.href.slice(0,b.href.indexOf(":"));return-1<this.PROTOCOL_WHITELIST.indexOf(b)?
a:this.SANITIZED_URL},buildToolbarButtons:function(a,b){Array.from(a).forEach(function(a){a.tabIndex=-1;(a.getAttribute("class")||"").split(/\s+/).forEach(function(c){if(c.startsWith("ql-")&&(c=c.slice(3),null!=b[c]))if("direction"===c)a.innerHTML=b[c][""]+b[c].rtl;else if("string"===typeof b[c])a.innerHTML=b[c];else{var d=a.value||"";null!=d&&b[c][d]&&(a.innerHTML=b[c][d])}});var c=a.className.replace("ql-",""),c=c.charAt(0).toUpperCase()+c.slice(1),e=a.value;a.setAttribute("data-title",c);e&&(c=
e.charAt(0).toUpperCase()+e.slice(1),a.setAttribute("data-title",c+" List"))})},getDefaultFontFormatting:function(){var a=container.getSettingsModel().get("zarafa/v1/main/default_font").split(",")[0];switch(a){case "courier new":a="Courier New";break;case "times new roman":a="Times New Roman";break;case "tahoma":a="Tahoma";break;case "verdana":a="Verdana";break;default:a="Arial"}return{fontSize:Zarafa.common.ui.htmleditor.Fonts.getDefaultFontSize(),fontFamily:a}},getFontFamilies:function(){return Zarafa.common.ui.htmleditor.Fonts.getFontFamilies().split(";").map(function(a){return{name:a.split("=")[0],
value:a.split("=")[1].toLowerCase()}})},setDefaultFormatting:function(){var a=this.getDefaultFontFormatting();this.editor.format("size",a.fontSize,"user");this.editor.format("font",a.fontFamily,"user");this.editor.formatLine(0,this.editor.getLength(),"margin","0px 5px");this.editor.formatLine(0,this.editor.getLength(),{"code-block":!1});this.checkValueCorrection(this,"")},indentNewLines:function(a){var b,c=new (this.getQuillClass()["import"]("delta"));c.ops=a.map(function(a){"\n"!==a.insert&&a.attributes&&
(b=a.attributes.indent);"\n"===a.insert&&a.attributes&&(a.attributes.indent=b);return a});return c},onEmptyListTab:function(a,b){var c=b.line.prev,d=b.line.formats().indent;if(b.collapsed&&0!==b.offset)return!0;c&&(c.formats().indent>=d||!d)&&this.editor.format("indent","+1","user");return!1},setValue:function(a){var b=this.editor,c;Ext.isEmpty(a)?b.setContents([{insert:""}]):(c=b.clipboard.convert({html:a}),c=this.indentNewLines(c),c=this.removeCodeBlock(c),b.setContents(c),this.setDefaultFormatting(),
this.checkValueCorrection(this,a))},removeCodeBlock:function(a){var b=new (this.getQuillClass()["import"]("delta"));b.ops=a.map(function(a){var b=a.attributes;b&&b["code-block"]&&(b["code-block"]=!1);return a});return b},onEditorFocus:function(a,b,c,d){b=this.editor;"selection-change"===a&&"user"===d&&(a=b.getSelection(),b.hasFocus()&&b.setSelection(a.index,a.length))},disableToolbar:function(){this.editor.getModule("toolbar").container.classList.add("disable-toolbar")},disable:function(){this.editor||
this.createEditorInstance();this.editor.disable();this.disableToolbar()},enable:function(){this.editor.enable();this.editor.getModule("toolbar").container.classList.remove("disable-toolbar")},focus:function(){this.editor.focus()},getValue:function(){return this.editor.getSemanticHTMLContent()},checkValueCorrection:function(a,b){var c=a.getValue();b!==c&&a.fireEvent("valuecorrection",a,c,b)},insertAtCursor:function(a){var b=this.getQuillClass(),c=this.editor;c.focus();a=(new (b["import"]("delta"))).retain(c.getSelection().index).insert("\n").concat(c.clipboard.convert({html:a}));
c.updateContents(a)},removeEmptyBlockquote:function(){this.editor.format("blockquote",!1,"user");this.editor.format("border-left","","user")},setCursorLocation:Ext.emptyFn});Ext.reg("plugins.quilleditor",Zarafa.plugins.quill.ui.QuillEditor);//# sourceMappingURL=htmleditor-quill.js.map
