UNPKG

froala-editor

Version:

The next generation Javascript WYSIWYG HTML rich text editor made by devs for devs. High performance and modern design make it easy to use for developers and loved by users.

7 lines (6 loc) 12.8 kB
/*! * froala_editor v4.7.0 (https://www.froala.com/wysiwyg-editor) * License https://froala.com/wysiwyg-editor/terms/ * Copyright 2014-2025 Froala Labs */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(require("froala-editor")):"function"==typeof define&&define.amd?define(["froala-editor"],t):t(e.FroalaEditor)}(this,function(e){"use strict";function c(e,t,r,n,o,i,l){try{var a=e[i](l),c=a.value}catch(e){return void r(e)}a.done?t(c):Promise.resolve(c).then(n,o)}function o(a){return function(){var e=this,l=arguments;return new Promise(function(t,r){var n=a.apply(e,l);function o(e){c(n,t,r,o,i,"next",e)}function i(e){c(n,t,r,o,i,"throw",e)}o(void 0)})}}function T(){var h,g,e="function"==typeof Symbol?Symbol:{},t=e.iterator||"@@iterator",r=e.toStringTag||"@@toStringTag";function n(e,t,r,f){var n=t&&t.prototype instanceof i?t:i,o=Object.create(n.prototype);return u(o,"_invoke",function(n,o,e){var i,l,a,c=0,s=f||[],u=!1,p={p:0,n:0,v:h,a:d,f:d.bind(h,4),d:function(e,t){return i=e,l=0,a=h,p.n=t,m}};function d(e,t){for(l=e,a=t,g=0;!u&&c&&!r&&g<s.length;g++){var r,n=s[g],o=p.p,i=n[2];3<e?(r=i===t)&&(a=n[(l=n[4])?5:(l=3,3)],n[4]=n[5]=h):n[0]<=o&&((r=e<2&&o<n[1])?(l=0,p.v=t,p.n=n[1]):o<i&&(r=e<3||n[0]>t||i<t)&&(n[4]=e,n[5]=t,p.n=i,l=0))}if(r||1<e)return m;throw u=!0,t}return function(e,t,r){if(1<c)throw TypeError("Generator is already running");for(u&&1===t&&d(t,r),l=t,a=r;(g=l<2?h:a)||!u;){i||(l?l<3?(1<l&&(p.n=-1),d(l,a)):p.n=a:p.v=a);try{if(c=2,i){if(l||(e="next"),g=i[e]){if(!(g=g.call(i,a)))throw TypeError("iterator result is not an object");if(!g.done)return g;a=g.value,l<2&&(l=0)}else 1===l&&(g=i["return"])&&g.call(i),l<2&&(a=TypeError("The iterator does not provide a '"+e+"' method"),l=1);i=h}else if((g=(u=p.n<0)?a:n.call(o,p))!==m)break}catch(g){i=h,l=1,a=g}finally{c=1}}return{value:g,done:u}}}(e,r),!0),o}var m={};function i(){}function o(){}function l(){}g=Object.getPrototypeOf;var a=[][t]?g(g([][t]())):(u(g={},t,function(){return this}),g),c=l.prototype=i.prototype=Object.create(a);function s(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,l):(e.__proto__=l,u(e,r,"GeneratorFunction")),e.prototype=Object.create(c),e}return u(c,"constructor",o.prototype=l),u(l,"constructor",o),u(l,r,o.displayName="GeneratorFunction"),u(c),u(c,r,"Generator"),u(c,t,function(){return this}),u(c,"toString",function(){return"[object Generator]"}),(T=function(){return{w:n,m:s}})()}function u(e,t,r,n){var i=Object.defineProperty;try{i({},"",{})}catch(e){i=0}(u=function(e,t,r,n){function o(t,r){u(e,t,function(e){return this._invoke(t,r,e)})}t?i?i(e,t,{value:r,enumerable:!n,configurable:!n,writable:!n}):e[t]=r:(o("next",0),o("throw",1),o("return",2))})(e,t,r,n)}function a(e){if(null!=e){var t=e["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],r=0;if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}}}throw new TypeError(typeof e+" is not iterable")}e=e&&e.hasOwnProperty("default")?e["default"]:e,Object.assign(e.POPUP_TEMPLATES,{"wordExport.error":"[_EXPORT_LAYER_]"}),Object.assign(e.DEFAULTS,{wordExportFileName:"froala_editor"}),e.PLUGINS.exportToWord=function(d){var p=d.$,f="";function h(e){var t="<div style='text-align:right;' class='fr-buttons'>\n <button class='fr-trim-button fr-plugins-ok'>".concat(d.language.translate("OK"),"</button> \n </div>"),r={export_layer:"<div style= 'padding:10px'>\n <div class = 'fr-message fr-error-message'><h3 style ='font-size: 16px; margin: 10px 10px;font-weight: normal;'>".concat(d.language.translate(e),"</h3></div>\n ").concat(t,"\n ")},n=d.popups.create("wordExport.error",r);d.popups.setContainer("wordExport.error",d.$tb);var o=n.find(".fr-plugins-ok")[0];return o&&o.addEventListener("click",function(e){d.popups.hide("wordExport.error"),e.preventDefault()}),n}function g(e,t){var r=new RegExp("\\b".concat(t,"\\s*:\\s*([^;]+)"),"i").exec(e);return r?r[1].trim():""}function m(e,t){var r=g(e,"border");if(r)return r;var n=g(e,"border-width")||t.width,o=g(e,"border-style")||t.style,i=g(e,"border-color")||t.color;return"".concat(n," ").concat(o," ").concat(i)}function i(e){return t.apply(this,arguments)}function t(){return(t=o(T().m(function e(t){var r,S,H,n,o,i,l,k;return T().w(function(e){for(;;)switch(e.n){case 0:for((r=document.createElement("div")).innerHTML=t,S=r.querySelectorAll("img"),H=d.el.querySelectorAll("img"),n=0;n<S.length;n++)o=S[n],(i=o.parentElement).classList.contains("fr-img-wrap")&&(o=i.parentElement,i=o.parentElement),i&&"SPAN"===i.tagName&&!i.classList.contains("fr-marker")&&(i.parentNode.insertBefore(o,i),0!==i.childNodes.length&&""!==i.textContent.trim()||i.remove());l=T().m(function L(){var t,r,n,o,i,l,a,c,s,u,p,d,f,h,g,m,b,y,v,w,x,A,E,C;return T().w(function(e){for(;;)switch(e.p=e.n){case 0:if(t=S[k],r=H[k],!(n=t.getAttribute("src"))||n.startsWith("data:"))return e.a(2,1);e.n=1;break;case 1:return r=r.closest("span.fr-img-caption")?r.closest("span.fr-img-caption"):r,o=r?window.getComputedStyle(r):{},i=o["float"]||"",l=o.height||t.getAttribute("height")||"100px",a=o.width||t.getAttribute("width")||"100px",c=o.marginLeft&&"0px"!==o.marginLeft?o.marginLeft:"",s=o.marginRight&&"0px"!==o.marginRight?o.marginRight:"",u="0px"===c||""==c?"left":"0px"===s||""===s?"right":"center",e.p=2,e.n=3,fetch(n).then(function(e){return e.blob()});case 3:return p=e.v,e.n=4,new Promise(function(e,t){var r=new FileReader;r.onloadend=function(){return e(r.result)},r.onerror=t,r.readAsDataURL(p)});case 4:d=e.v,(f=document.createElement("img")).setAttribute("src",d),f.setAttribute("width",parseInt(a)),f.setAttribute("height",parseInt(l)),f.style.display="block",h=t.closest("span.fr-img-caption")||null,g=null,h&&((g=document.createElement("table")).style.borderCollapse="collapse",g.style.margin="auto",g.classList.add("fr-img-caption"),m=document.createElement("tr"),(b=document.createElement("td")).style.textAlign="center",b.appendChild(f),m.appendChild(b),g.appendChild(m),y=document.createElement("tr"),(v=document.createElement("td")).style.textAlign="center",v.style.width=a+"px",w=h.querySelector("span.fr-inner"),x=w.cloneNode(!0),v.appendChild(x),y.appendChild(v),g.appendChild(y)),(A=h?g:f).style.display="inline-block","left"===i||"right"===i?(A.setAttribute("align",i),h?h.replaceWith(A):(A.style.margin="0 0 1em 1em",(E=document.createElement("p")).setAttribute("align",i),E.style.display="inline-block",E.appendChild(A),t.replaceWith(E))):"none"===i&&("5px"===c||"5px"===s?(A.setAttribute("align",u),A.style.textAlign=u,h?h.replaceWith(A):t.replaceWith(A)):((C=document.createElement("div")).setAttribute("align",u),C.style.textAlign=u,C.appendChild(A),h?h.replaceWith(C):t.replaceWith(C))),e.n=6;break;case 5:e.p=5,e.v;case 6:return e.a(2)}},L,null,[[2,5]])}),k=0;case 1:if(k<S.length)return e.d(a(l()),2);e.n=4;break;case 2:if(e.v)return e.a(3,3);e.n=3;break;case 3:k++,e.n=1;break;case 4:return e.a(2,r.innerHTML)}},e)}))).apply(this,arguments)}function r(){return(r=o(T().m(function e(t){var r,n,o,i,l,a,c,s,u;return T().w(function(e){for(;;)switch(e.n){case 0:return r=d.$el.find(".fr-selected-cell"),n=d.$el.find(".fr-selection-handle-selected"),0<r.length&&r.each(function(){var e=p(this);e.removeClass("fr-selected-cell"),""===e.attr("class")&&e.removeAttr("class")}),0<n.length&&((o=p(this)).removeClass("fr-selection-handle-selected"),""===o.attr("class")&&o.removeAttr("class")),d.popups.hideAll(),f=t||d.html.get(),e.n=1,d.events.trigger("word.beforeExport",[f]);case 1:if(!1===(f=e.v))return e.a(2,!1);e.n=2;break;case 2:d.popups.get("wordExport.error")||h(d.language.translate("Export libraries are missing.")),window.htmlDocx&&window.saveAs?(i=window.htmlDocx.asBlob(f),l=d.opts.wordExportFileName,window.saveAs(i,l+".docx")):(a=d.$tb.find('.fr-command[data-cmd="export_to_word"]'),c=d.button.getPosition(a),s=c.left,u=c.top,d.popups.show("wordExport.error",s,u,a.outerHeight(),!0)),d.events.trigger("word.afterExport",[f]);case 3:return e.a(2)}},e,this)}))).apply(this,arguments)}return d.events.on("word.beforeExport",function(){var t=o(T().m(function e(t){var r,n,o;return T().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,i(t);case 1:return r=e.v,(n=document.createElement("div")).innerHTML=r,n.querySelectorAll(".fr-emoticon").forEach(function(e){var t=(e.getAttribute("style")||"").match(/url\(["']?(.*?)["']?\)/);if(t&&t[1]){var r=document.createElement("img");r.src=t[1],r.alt="emoji",r.setAttribute("width","20"),r.setAttribute("height","20"),e.replaceWith(r)}}),n.querySelectorAll("table:not(.fr-img-caption)").forEach(function(e,t){e.setAttribute("border","1"),e.setAttribute("cellpadding","10"),e.setAttribute("cellspacing","0");var r,n,o,i=e.getAttribute("style")||"",c=d.el.querySelectorAll("table")[t];r=e,o="left",/\bfloat\s*:\s*right\b/i.test(n=i)?o="right":/\bmargin\s*:\s*auto\b/i.test(n)&&(o="center"),r.setAttribute("align",o);var l,s=window.getComputedStyle(c).border||"1px solid #DDD",u=(l=s.match(/^(\d+(?:\.\d+)?)/))?parseFloat(l[1]):1;e.style.borderCollapse=g(i,"border-collapse")||"collapse";var a=e.querySelectorAll("tr"),p=a.length;a.forEach(function(e,i){var t=e.querySelectorAll("td, th"),l=t.length,a=c?c.querySelectorAll("tr")[i]:null;e.style.backgroundColor=window.getComputedStyle(a).backgroundColor||"",t.forEach(function(e,t){var r=a?a.querySelectorAll("td, th")[t]:null,n=window.getComputedStyle(r)||"";e.style.padding="10px",e.style.height=e.style.height||"50px",e.setAttribute("valign","top"),e.style.verticalAlign="top",e.style.backgroundColor=n.backgroundColor;var o=m(e.getAttribute("style")||"",{width:"1px",style:"solid",color:"#DDD"});e.style.borderTop||(e.style.borderTop=o),e.style.borderBottom||(e.style.borderBottom=o),e.style.borderLeft||(e.style.borderLeft=o),e.style.borderRight||(e.style.borderRight=o),1<u&&(0===i&&(e.style.borderTop=s),i===p-1&&(e.style.borderBottom=s),0===t&&(e.style.borderLeft=s),t===l-1&&(e.style.borderRight=s)),e.style.borderStyle="none"!==n.borderStyle&&n.borderStyle?n.borderStyle:"solid"})})}),n.innerHTML=n.innerHTML.replace(/<strong>/g,'<span style="font-weight:bold;">').replace(/<\/strong>/g,"</span>").replace(/<em>/g,'<span style="font-style:italic;">').replace(/<\/em>/g,"</span>"),n.querySelectorAll('[data-title="PageBreak"]').forEach(function(e){var t=d.doc.createElement("span");t.innerHTML='<br clear=all style="mso-special-character:line-break;page-break-before:always">',e.replaceWith(t)}),o="\n <html xmlns:o='urn:schemas-microsoft-com:office:office'\n xmlns:w='urn:schemas-microsoft-com:office:word'\n xmlns='http://www.w3.org/TR/REC-html40'>\n <head><meta charset='utf-8'></head>\n <body>".concat(n.innerHTML,"</body>\n </html>"),e.a(2,o);case 2:return e.p=2,e.v,e.a(2,!1)}},e,null,[[0,2]])}));return function(e){return t.apply(this,arguments)}}()),{"export":function n(e){return r.apply(this,arguments)}}},e.DefineIcon("export_to_word",{template:"svgMultiplePath",PATHS:'\n <path d="M22.5247 17.7645L18.6914 21.5978L14.858 17.7645L16.1997 16.4228L17.733 17.9561V13.9551H19.6497V17.9561L21.183 16.4228L22.5247 17.7645Z" fill="#333333"/>\n <path fill-rule="evenodd" clip-rule="evenodd" d="M9.06971 15.1051H2.62971C2.18513 15.1051 1.82471 14.7447 1.82471 14.3001V7.86008C1.82471 7.4155 2.18513 7.05508 2.62971 7.05508H9.06971C9.51429 7.05508 9.87471 7.4155 9.87471 7.86008V14.3001C9.87471 14.7447 9.51429 15.1051 9.06971 15.1051ZM4.50294 12.3628C4.49849 12.2917 4.48924 12.2085 4.47499 12.1129C4.46074 12.0176 4.44601 11.9408 4.43072 11.8829L3.74411 9.06758H2.83096L3.94451 13.0926H5.00877L5.715 10.4345C5.73029 10.3727 5.75058 10.2774 5.77579 10.1482C5.801 10.0191 5.81799 9.92188 5.82676 9.85639H5.83987C5.84641 9.91252 5.86338 10.0024 5.89076 10.1258C5.91814 10.2493 5.94277 10.3493 5.96468 10.4261L6.71689 13.0926H7.76482L8.86846 9.06758H7.97174L7.34101 11.8519C7.2972 12.0428 7.26984 12.2112 7.25888 12.3572H7.24577C7.21953 12.1457 7.18669 11.9718 7.14723 11.8352L6.35886 9.06758H5.37341L4.61139 11.8773C4.59384 11.9428 4.57571 12.0232 4.55712 12.1186C4.53853 12.2141 4.52596 12.2954 4.51937 12.3628H4.50294Z" fill="#333333"/>\n <path d="M5.27471 5.90508V4.37174C5.27471 3.84466 5.46238 3.39345 5.83773 3.0181C6.21307 2.64275 6.66429 2.45508 7.19137 2.45508H13.8997L19.6497 8.20508V11.104H17.733V9.16341H12.9414V4.37174H7.19137V5.90508H5.27471Z" fill="#333333"/>\n <path d="M5.83773 19.1421C6.21307 19.5174 6.66429 19.7051 7.19137 19.7051H12.9414V17.7884H7.19137V16.2551H5.27471V17.7884C5.27471 18.3155 5.46238 18.7667 5.83773 19.1421Z" fill="#333333"/>\n '}),e.RegisterCommand("export_to_word",{title:"Export to Word",focus:!1,undo:!1,refreshAfterCallback:!1,callback:function(){this.exportToWord["export"]()}})});