tinymce
Version:
Web based JavaScript HTML WYSIWYG editor control.
1 lines • 15.6 kB
JavaScript
!function(){"use strict";const e=e=>t=>(e=>{const t=typeof e;return null===e?"null":"object"===t&&Array.isArray(e)?"array":"object"===t&&(n=r=e,(o=String).prototype.isPrototypeOf(n)||r.constructor?.name===o.name)?"string":t;var n,r,o})(t)===e,t=e=>t=>typeof t===e,n=e=>t=>e===t,r=e("string"),o=e("object"),s=e("array"),i=n(null),l=t("boolean"),a=n(void 0),c=e=>!(e=>null==e)(e),u=t("function"),d=t("number"),m=()=>{},h=e=>()=>e;function g(e,...t){return(...n)=>{const r=t.concat(n);return e.apply(null,r)}}const p=h(!1),f=h(!0);class v{tag;value;static singletonNone=new v(!1);constructor(e,t){this.tag=e,this.value=t}static some(e){return new v(!0,e)}static none(){return v.singletonNone}fold(e,t){return this.tag?t(this.value):e()}isSome(){return this.tag}isNone(){return!this.tag}map(e){return this.tag?v.some(e(this.value)):v.none()}bind(e){return this.tag?e(this.value):v.none()}exists(e){return this.tag&&e(this.value)}forall(e){return!this.tag||e(this.value)}filter(e){return!this.tag||e(this.value)?this:v.none()}getOr(e){return this.tag?this.value:e}or(e){return this.tag?this:e}getOrThunk(e){return this.tag?this.value:e()}orThunk(e){return this.tag?this:e()}getOrDie(e){if(this.tag)return this.value;throw new Error(e??"Called getOrDie on None")}static from(e){return c(e)?v.some(e):v.none()}getOrNull(){return this.tag?this.value:null}getOrUndefined(){return this.value}each(e){this.tag&&e(this.value)}toArray(){return this.tag?[this.value]:[]}toString(){return this.tag?`some(${this.value})`:"none()"}}const w=Array.prototype.push,y=(e,t)=>{const n=e.length,r=new Array(n);for(let o=0;o<n;o++){const n=e[o];r[o]=t(n,o)}return r},b=(e,t)=>{for(let n=0,r=e.length;n<r;n++)t(e[n],n)},S=(e,t)=>{const n=[];for(let r=0,o=e.length;r<o;r++){const o=e[r];t(o,r)&&n.push(o)}return n},x=(e,t)=>((e,t,n)=>{for(let r=0,o=e.length;r<o;r++){const o=e[r];if(t(o,r))return v.some(o);if(n(o,r))break}return v.none()})(e,t,p),E=Object.keys,F=e=>{let t=e;return{get:()=>t,set:e=>{t=e}}},O="undefined"!=typeof window?window:Function("return this;")(),k=(e,t)=>((e,t)=>{let n=null!=t?t:O;for(let t=0;t<e.length&&null!=n;++t)n=n[e[t]];return n})(e.split("."),t),T=e=>{const t=F(v.none()),n=()=>t.get().each(e);return{clear:()=>{n(),t.set(v.none())},isSet:()=>t.get().isSome(),get:()=>t.get(),set:e=>{n(),t.set(v.some(e))}}},C=()=>T(e=>e.unbind()),A=(e,t,n=0,r)=>{const o=e.indexOf(t,n);return-1!==o&&(!!a(r)||o+t.length<=r)};var R=tinymce.util.Tools.resolve("tinymce.PluginManager");const L=e=>({isFullscreen:()=>null!==e.get()}),M=e=>{if(null==e)throw new Error("Node cannot be null or undefined");return{dom:e}},P=M,D=(e,t)=>{const n=e.dom;if(1!==n.nodeType)return!1;{const e=n;if(void 0!==e.matches)return e.matches(t);if(void 0!==e.msMatchesSelector)return e.msMatchesSelector(t);if(void 0!==e.webkitMatchesSelector)return e.webkitMatchesSelector(t);if(void 0!==e.mozMatchesSelector)return e.mozMatchesSelector(t);throw new Error("Browser lacks native selectors")}},N=()=>H(0,0),H=(e,t)=>({major:e,minor:t}),V={nu:H,detect:(e,t)=>{const n=String(t).toLowerCase();return 0===e.length?N():((e,t)=>{const n=((e,t)=>{for(let n=0;n<e.length;n++){const r=e[n];if(r.test(t))return r}})(e,t);if(!n)return{major:0,minor:0};const r=e=>Number(t.replace(n,"$"+e));return H(r(1),r(2))})(e,n)},unknown:N},W=(e,t)=>{const n=String(t).toLowerCase();return x(e,e=>e.search(n))},q=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,B=e=>t=>A(t,e),I=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:e=>A(e,"edge/")&&A(e,"chrome")&&A(e,"safari")&&A(e,"applewebkit")},{name:"Chromium",brand:"Chromium",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,q],search:e=>A(e,"chrome")&&!A(e,"chromeframe")},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:e=>A(e,"msie")||A(e,"trident")},{name:"Opera",versionRegexes:[q,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:B("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:B("firefox")},{name:"Safari",versionRegexes:[q,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:e=>(A(e,"safari")||A(e,"mobile/"))&&A(e,"applewebkit")}],j=[{name:"Windows",search:B("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:e=>A(e,"iphone")||A(e,"ipad"),versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:B("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"macOS",search:B("mac os x"),versionRegexes:[/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:B("linux"),versionRegexes:[]},{name:"Solaris",search:B("sunos"),versionRegexes:[]},{name:"FreeBSD",search:B("freebsd"),versionRegexes:[]},{name:"ChromeOS",search:B("cros"),versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/]}],_={browsers:h(I),oses:h(j)},z="Edge",K="Chromium",$="Opera",U="Firefox",X="Safari",Y=e=>{const t=e.current,n=e.version,r=e=>()=>t===e;return{current:t,version:n,isEdge:r(z),isChromium:r(K),isIE:r("IE"),isOpera:r($),isFirefox:r(U),isSafari:r(X)}},G=()=>Y({current:void 0,version:V.unknown()}),J=Y,Q=(h(z),h(K),h("IE"),h($),h(U),h(X),"Windows"),Z="Android",ee="Linux",te="macOS",ne="Solaris",re="FreeBSD",oe="ChromeOS",se=e=>{const t=e.current,n=e.version,r=e=>()=>t===e;return{current:t,version:n,isWindows:r(Q),isiOS:r("iOS"),isAndroid:r(Z),isMacOS:r(te),isLinux:r(ee),isSolaris:r(ne),isFreeBSD:r(re),isChromeOS:r(oe)}},ie=()=>se({current:void 0,version:V.unknown()}),le=se,ae=(h(Q),h("iOS"),h(Z),h(ee),h(te),h(ne),h(re),h(oe),(e,t,n)=>{const r=_.browsers(),o=_.oses(),s=t.bind(e=>((e,t)=>((e,t)=>{for(let n=0;n<e.length;n++){const r=t(e[n]);if(r.isSome())return r}return v.none()})(t.brands,t=>{const n=t.brand.toLowerCase();return x(e,e=>n===e.brand?.toLowerCase()).map(e=>({current:e.name,version:V.nu(parseInt(t.version,10),0)}))}))(r,e)).orThunk(()=>((e,t)=>W(e,t).map(e=>{const n=V.detect(e.versionRegexes,t);return{current:e.name,version:n}}))(r,e)).fold(G,J),i=((e,t)=>W(e,t).map(e=>{const n=V.detect(e.versionRegexes,t);return{current:e.name,version:n}}))(o,e).fold(ie,le),l=((e,t,n,r)=>{const o=e.isiOS()&&!0===/ipad/i.test(n),s=e.isiOS()&&!o,i=e.isiOS()||e.isAndroid(),l=i||r("(pointer:coarse)"),a=o||!s&&i&&r("(min-device-width:768px)"),c=s||i&&!a,u=t.isSafari()&&e.isiOS()&&!1===/safari/i.test(n),d=!c&&!a&&!u;return{isiPad:h(o),isiPhone:h(s),isTablet:h(a),isPhone:h(c),isTouch:h(l),isAndroid:e.isAndroid,isiOS:e.isiOS,isWebView:h(u),isDesktop:h(d)}})(i,s,e,n);return{browser:s,os:i,deviceType:l}}),ce=e=>window.matchMedia(e).matches;let ue=(e=>{let t,n=!1;return(...r)=>(n||(n=!0,t=e.apply(null,r)),t)})(()=>ae(window.navigator.userAgent,v.from(window.navigator.userAgentData),ce));const de=Object.getPrototypeOf,me=e=>{const t=k("ownerDocument.defaultView",e);return o(e)&&((e=>((e,t)=>{const n=((e,t)=>k(e,t))(e,t);if(null==n)throw new Error(e+" not available on this browser");return n})("HTMLElement",e))(t).prototype.isPrototypeOf(e)||/^HTML\w*Element$/.test(de(e).constructor.name))},he=e=>t=>(e=>e.dom.nodeType)(t)===e,ge=he(1),pe=he(3),fe=he(11),ve=e=>P(e.dom.ownerDocument),we=e=>y(e.dom.childNodes,P),ye=e=>{const t=(e=>P(e.dom.getRootNode()))(e);return fe(n=t)&&c(n.dom.host)?v.some(t):v.none();var n},be=e=>P(e.dom.host),Se=e=>{const t=P((e=>{if(c(e.target)){const t=P(e.target);if(ge(t)&&c(t.dom.shadowRoot)&&e.composed&&e.composedPath){const t=e.composedPath();if(t)return(e=>0<e.length?v.some(e[0]):v.none())(t)}}return v.from(e.target)})(e).getOr(e.target)),n=()=>e.stopPropagation(),r=()=>e.preventDefault(),o=(s=r,i=n,(...e)=>s(i.apply(null,e)));var s,i;return((e,t,n,r,o,s,i)=>({target:e,x:t,y:n,stop:r,prevent:o,kill:s,raw:i}))(t,e.clientX,e.clientY,n,r,o,e)},xe=(e,t,n,r)=>{e.dom.removeEventListener(t,n,r)},Ee=f,Fe=(e,t,n)=>((e,t,n,r)=>((e,t,n,r,o)=>{const s=((e,t)=>n=>{e(n)&&t(Se(n))})(n,r);return e.dom.addEventListener(t,s,o),{unbind:g(xe,e,t,s,o)}})(e,t,n,r,!1))(e,t,Ee,n),Oe=(e,t)=>{const n=e.dom.getAttribute(t);return null===n?void 0:n},ke=(e,t)=>{e.dom.removeAttribute(t)},Te=e=>void 0!==e.style&&u(e.style.getPropertyValue),Ce=e=>{const t=pe(e)?e.dom.parentNode:e.dom;if(null==t||null===t.ownerDocument)return!1;const n=t.ownerDocument;return ye(P(t)).fold(()=>n.body.contains(t),(r=Ce,o=be,e=>r(o(e))));var r,o},Ae=(e,t,n)=>{if(!r(n))throw console.error("Invalid call to CSS.set. Property ",t,":: Value ",n,":: Element ",e),new Error("CSS value must be a string: "+n);Te(e)&&e.style.setProperty(t,n)},Re=(e,t,n)=>{const r=e.dom;Ae(r,t,n)},Le=(e,t)=>{const n=e.dom;((e,t)=>{const n=E(e);for(let r=0,o=n.length;r<o;r++){const o=n[r];t(e[o],o)}})(t,(e,t)=>{Ae(n,t,e)})},Me=(e,t)=>{const n=e.dom,r=window.getComputedStyle(n).getPropertyValue(t);return""!==r||Ce(e)?r:Pe(n,t)},Pe=(e,t)=>Te(e)?e.style.getPropertyValue(t):"",De=(e,t)=>({left:e,top:t,translate:(n,r)=>De(e+n,t+r)}),Ne=De,He=(e,t,n)=>((e,t,n)=>S(((e,t)=>{const n=u(t)?t:p;let r=e.dom;const o=[];for(;null!==r.parentNode&&void 0!==r.parentNode;){const e=r.parentNode,t=P(e);if(o.push(t),!0===n(t))break;r=e}return o})(e,n),t))(e,e=>D(e,t),n),Ve=(e,t)=>(e=>{return S((e=>v.from(e.dom.parentNode).map(P))(n=e).map(we).map(e=>S(e,e=>{return t=e,!(n.dom===t.dom);var t})).getOr([]),e=>D(e,t));var n})(e),We=e=>{const t=void 0===e?window:e;return ue().browser.isFirefox()?v.none():v.from(t.visualViewport)},qe=(e,t,n,r)=>({x:e,y:t,width:n,height:r,right:e+n,bottom:t+r}),Be=e=>{const t=void 0===e?window:e,n=t.document,r=(e=>{const t=void 0!==e?e.dom:document,n=t.body.scrollLeft||t.documentElement.scrollLeft,r=t.body.scrollTop||t.documentElement.scrollTop;return Ne(n,r)})(P(n));return We(t).fold(()=>{const e=t.document.documentElement,n=e.clientWidth,o=e.clientHeight;return qe(r.left,r.top,n,o)},e=>qe(Math.max(e.pageLeft,r.left),Math.max(e.pageTop,r.top),e.width,e.height))},Ie=(e,t,n)=>We(n).map(n=>{const r=e=>t(Se(e));return n.addEventListener(e,r),{unbind:()=>n.removeEventListener(e,r)}}).getOrThunk(()=>({unbind:m}));var je=tinymce.util.Tools.resolve("tinymce.dom.DOMUtils"),_e=tinymce.util.Tools.resolve("tinymce.Env");const ze=(e,t)=>{e.dispatch("FullscreenStateChanged",{state:t}),e.dispatch("ResizeEditor")},Ke=e=>e.options.get("fullscreen_native");const $e=e=>{return e.dom===(void 0!==(t=ve(e).dom).fullscreenElement?t.fullscreenElement:void 0!==t.msFullscreenElement?t.msFullscreenElement:void 0!==t.webkitFullscreenElement?t.webkitFullscreenElement:null);var t},Ue="data-ephox-mobile-fullscreen-style",Xe="position:absolute!important;",Ye="top:0!important;left:0!important;margin:0!important;padding:0!important;width:100%!important;height:100%!important;overflow:visible!important;",Ge=_e.os.isAndroid(),Je=(e,t,n)=>{const o=t=>n=>{const o=Oe(n,"style"),s=void 0===o?"no-styles":o.trim();s!==t&&(((e,t,n)=>{((e,t,n)=>{if(!(r(n)||l(n)||d(n)))throw console.error("Invalid call to Attribute.set. Key ",t,":: Value ",n,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(t,n+"")})(e.dom,t,n)})(n,Ue,s),Le(n,e.parseStyle(t)))},i=He(t,"*"),a=(e=>{const t=[];for(let n=0,r=e.length;n<r;++n){if(!s(e[n]))throw new Error("Arr.flatten item "+n+" was not an array, input: "+e);w.apply(t,e[n])}return t})(y(i,e=>Ve(e,"*:not(.tox-silver-sink)"))),c=(e=>{const t=Me(e,"background-color");return void 0!==t&&""!==t?"background-color:"+t+"!important":"background-color:rgb(255,255,255)!important;"})(n);b(a,o("display:none!important;")),b(i,o(Xe+Ye+c)),o((!0===Ge?"":Xe)+Ye+c)(t)},Qe=je.DOM,Ze=We().fold(()=>({bind:m,unbind:m}),e=>{const t=(()=>{const e=T(m);return{...e,on:t=>e.get().each(t)}})(),n=C(),r=C(),o=(e=>{let t=null;return{cancel:()=>{i(t)||(clearTimeout(t),t=null)},throttle:(...n)=>{i(t)&&(t=setTimeout(()=>{t=null,e.apply(null,n)},50))}}})(()=>{document.body.scrollTop=0,document.documentElement.scrollTop=0,window.requestAnimationFrame(()=>{t.on(t=>Le(t,{top:e.offsetTop+"px",left:e.offsetLeft+"px",height:e.height+"px",width:e.width+"px"}))})});return{bind:e=>{t.set(e),o.throttle(),n.set(Ie("resize",o.throttle)),r.set(Ie("scroll",o.throttle))},unbind:()=>{t.on(()=>{n.clear(),r.clear()}),t.clear()}}}),et=(e,t)=>{const n=document.body,r=document.documentElement,o=e.getContainer(),s=P(o),i=(l=s,v.from(l.dom.nextSibling).map(P)).filter(e=>(e=>ge(e)&&me(e.dom))(e)&&(e=>(e=>void 0!==e.dom.classList)(e)&&e.dom.classList.contains("tox-silver-sink"))(e));var l;const a=(e=>{const t=P(e.getElement());return ye(t).map(be).getOrThunk(()=>(e=>{const t=e.dom.body;if(null==t)throw new Error("Body is not available yet");return P(t)})(ve(t)))})(e),c=t.get(),u=P(e.getBody()),d=_e.deviceType.isTouch(),m=o.style,h=e.iframeElement,g=h?.style,p=e=>{e(n,"tox-fullscreen"),e(r,"tox-fullscreen"),e(o,"tox-fullscreen"),ye(s).map(e=>be(e).dom).each(t=>{e(t,"tox-fullscreen"),e(t,"tox-shadowhost")})},f=()=>{d&&(e=>{const t=(e=>{const t=document;return 1!==(n=t).nodeType&&9!==n.nodeType&&11!==n.nodeType||0===n.childElementCount?[]:y(t.querySelectorAll(e),P);var n})("["+Ue+"]");b(t,t=>{const n=Oe(t,Ue);n&&"no-styles"!==n?Le(t,e.parseStyle(n)):ke(t,"style"),ke(t,Ue)})})(e.dom),p(Qe.removeClass),Ze.unbind(),v.from(t.get()).each(e=>e.fullscreenChangeHandler.unbind())};if(c)c.fullscreenChangeHandler.unbind(),Ke(e)&&$e(a)&&(e=>{const t=e.dom;t.exitFullscreen?t.exitFullscreen():t.msExitFullscreen?t.msExitFullscreen():t.webkitCancelFullScreen&&t.webkitCancelFullScreen()})(ve(a)),g.width=c.iframeWidth,g.height=c.iframeHeight,m.width=c.containerWidth,m.height=c.containerHeight,m.top=c.containerTop,m.left=c.containerLeft,S=i,x=c.sinkCssPosition,E=(e,t)=>{Re(e,"position",t)},S.isSome()&&x.isSome()?v.some(E(S.getOrDie(),x.getOrDie())):v.none(),f(),w=c.scrollPos,window.scrollTo(w.x,w.y),t.set(null),ze(e,!1),e.off("remove",f);else{const n=Fe(ve(a),void 0!==document.fullscreenElement?"fullscreenchange":void 0!==document.msFullscreenElement?"MSFullscreenChange":void 0!==document.webkitFullscreenElement?"webkitfullscreenchange":"fullscreenchange",n=>{Ke(e)&&($e(a)||null===t.get()||et(e,t))}),r={scrollPos:Be(window),containerWidth:m.width,containerHeight:m.height,containerTop:m.top,containerLeft:m.left,iframeWidth:g.width,iframeHeight:g.height,fullscreenChangeHandler:n,sinkCssPosition:i.map(e=>Me(e,"position"))};d&&Je(e.dom,s,u),g.width=g.height="100%",m.width=m.height="",p(Qe.addClass),i.each(e=>{Re(e,"position","fixed")}),Ze.bind(s),e.on("remove",f),t.set(r),Ke(e)&&(e=>{const t=e.dom;t.requestFullscreen?t.requestFullscreen():t.msRequestFullscreen?t.msRequestFullscreen():t.webkitRequestFullScreen&&t.webkitRequestFullScreen()})(a),ze(e,!0)}var w,S,x,E};var tt=tinymce.util.Tools.resolve("tinymce.util.VK");const nt=(e,t)=>n=>{n.setActive(null!==t.get());const r=e=>n.setActive(e.state);return e.on("FullscreenStateChanged",r),()=>e.off("FullscreenStateChanged",r)},rt="fullscreen";R.add(rt,e=>{const t=F(null);return e.inline||((e=>{(0,e.options.register)("fullscreen_native",{processor:"boolean",default:!1})})(e),((e,t)=>{e.addCommand("mceFullScreen",()=>{et(e,t)})})(e,t),((e,t)=>{const n=()=>e.execCommand("mceFullScreen");e.ui.registry.addToggleMenuItem("fullscreen",{text:"Fullscreen",icon:"fullscreen",shortcut:"Meta+Shift+F",onAction:n,onSetup:nt(e,t),context:"any"}),e.ui.registry.addToggleButton("fullscreen",{tooltip:"Fullscreen",icon:"fullscreen",onAction:n,onSetup:nt(e,t),shortcut:"Meta+Shift+F",context:"any"})})(e,t),((e,t)=>{e.on("init",()=>{e.on("keydown",e=>{e.keyCode!==tt.TAB||e.metaKey||e.ctrlKey||!t.get()||e.preventDefault()})})})(e,t),e.addShortcut("Meta+Shift+F","","mceFullScreen")),{...L(t),getMetadata:()=>({name:"Full Screen",type:"opensource",slug:rt})}})}();