/** * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ * * Version: 5.0.9 (2019-06-26) */ !function(m){"use strict";var l=function(e){var t=e,n=function(){return t};return{get:n,set:function(e){t=e},clone:function(){return l(n())}}},y=function(){},C=function(n,r){return function(){for(var e=[],t=0;tn.maxRow()||sn.maxCol()||(Dn.getAt(t,l,s).filter(r).isNone()?(o=f,i=e[l].element(),u=Pe.fromTag("td"),zt(u,Pe.fromTag("br")),(o?zt:jt)(i,u)):f=!0)}(m,g,p,d),o=e,f=p,s=_(hn.firstLayer(o,"tr"),function(e){return 0===e.dom().childElementCount}),M(s,Vt),f.minCol()!==f.maxCol()&&f.minRow()!==f.maxRow()||M(hn.firstLayer(o,"th,td"),function(e){Te(e,"rowspan"),Te(e,"colspan")}),Te(o,"width"),Te(o,"height"),qe(o,"width"),qe(o,"height"),e};var Nn=function ls(n,r){var o=function(e){return n(e)?x.from(e.dom().nodeValue):x.none()},e=St.detect().browser,t=e.isIE()&&10===e.version.major?function(e){try{return o(e)}catch(t){return x.none()}}:o;return{get:function(e){if(!n(e))throw new Error("Can only get "+r+" value of a "+r+" node");return t(e).getOr("")},getOption:t,set:function(e,t){if(!n(e))throw new Error("Can only set raw "+r+" value of a "+r+" node");e.dom().nodeValue=t}}}(be,"text"),kn=function(e){return Nn.get(e)},In=function(e){return Nn.getOption(e)},Pn=function(e,t){Nn.set(e,t)},Bn=function(e){return"img"===me(e)?1:In(e).fold(function(){return Mt(e).length},function(e){return e.length})},Mn=["img","br"],Wn=function(e){return In(e).filter(function(e){return 0!==e.trim().length||-1=e.startCol()&&t.column()+t.colspan()-1<=e.finishCol()&&t.row()>=e.startRow()&&t.row()+t.rowspan()-1<=e.finishRow()},Jn=function(e,t){var n=t.column(),r=t.column()+t.colspan()-1,o=t.row(),i=t.row()+t.rowspan()-1;return n<=e.finishCol()&&r>=e.startCol()&&o<=e.finishRow()&&i>=e.startRow()},Qn=function(e,t){for(var n=!0,r=b($n,t),o=t.startRow();o<=t.finishRow();o++)for(var i=t.startCol();i<=t.finishCol();i++)n=n&&Dn.getAt(e,o,i).exists(r);return n?x.some(t):x.none()},Zn=function(e,t,n){var r=Dn.findItem(e,t,Dt),o=Dn.findItem(e,n,Dt);return r.bind(function(r){return o.map(function(e){return t=r,n=e,rn(Math.min(t.row(),n.row()),Math.min(t.column(),n.column()),Math.max(t.row()+t.rowspan()-1,n.row()+n.rowspan()-1),Math.max(t.column()+t.colspan()-1,n.column()+n.colspan()-1));var t,n})})},er=Zn,tr=function(t,e,n){return Zn(t,e,n).bind(function(e){return Qn(t,e)})},nr=function(r,e,o,i){return Dn.findItem(r,e,Dt).bind(function(e){var t=0=t.length-1)return x.none();var e=t[n].fold(function(){var e=Y(t.slice(0,n));return Wo(e,function(e,t){return e.map(function(e){return{value:e,delta:t+1}})})},function(e){return x.some({value:e,delta:0})}),r=t[n+1].fold(function(){var e=t.slice(n+1);return Wo(e,function(e,t){return e.map(function(e){return{value:e,delta:t+1}})})},function(e){return x.some({value:e,delta:1})});return e.bind(function(n){return r.map(function(e){var t=e.delta+n.delta;return Math.abs(e.value-n.value)/t})})},$o=function(e,t,n){var r=e();return z(r,t).orThunk(function(){return x.from(r[0]).orThunk(n)}).map(function(e){return e.element()})},Jo=function(n){var e=n.grid(),t=Ko(0,e.columns()),r=Ko(0,e.rows());return B(t,function(t){return $o(function(){return V(r,function(e){return Dn.getAt(n,e,t).filter(function(e){return e.column()===t}).fold(S([]),function(e){return[e]})})},function(e){return 1===e.colspan()},function(){return Dn.getAt(n,0,t)})})},Qo=function(n){var e=n.grid(),t=Ko(0,e.rows()),r=Ko(0,e.columns());return B(t,function(t){return $o(function(){return V(r,function(e){return Dn.getAt(n,t,e).filter(function(e){return e.row()===t}).fold(S([]),function(e){return[e]})})},function(e){return 1===e.rowspan()},function(){return Dn.getAt(n,t,0)})})},Zo=function(e){var t=e.replace(/\./g,"-");return{resolve:function(e){return t+"-"+e}}},ei={resolve:Zo("ephox-snooker").resolve},ti=function(e,t,n,r,o){var i=Pe.fromTag("div");return ze(i,{position:"absolute",left:t-r/2+"px",top:n+"px",height:o+"px",width:r+"px"}),Se(i,{"data-column":e,role:"presentation"}),i},ni=function(e,t,n,r,o){var i=Pe.fromTag("div");return ze(i,{position:"absolute",left:t+"px",top:n-o/2+"px",height:o+"px",width:r+"px"}),Se(i,{"data-row":e,role:"presentation"}),i},ri=ei.resolve("resizer-bar"),oi=ei.resolve("resizer-rows"),ii=ei.resolve("resizer-cols"),ui=function(e){var t=an(e.parent(),"."+ri);M(t,Vt)},ci=function(n,e,r){var o=n.origin();M(e,function(e,t){e.each(function(e){var t=r(o,e);Vo(t,ri),zt(n.parent(),t)})})},ai=function(e,t,n,r,o,i){var u,c,a,l,f=vo(t),s=0=t.length||e.column()>bi.cellLength(t[0]))return Ii.error("invalid start address out of table bounds, row: "+e.row()+", column: "+e.column());var r=t.slice(e.row()),o=r[0].cells().slice(e.column()),i=bi.cellLength(n[0]),u=n.length;return Ii.value({rowDelta:S(r.length-u),colDelta:S(o.length-i)})},_i=function(e,t){var n=bi.cellLength(e[0]),r=bi.cellLength(t[0]);return{rowDelta:S(0),colDelta:S(n-r)}},Li=function(e,t,n){var r=t.colDelta()<0?Mi:o;return(t.rowDelta()<0?Bi:o)(r(e,Math.abs(t.colDelta()),n),Math.abs(t.rowDelta()),n)},ji=function(e,t,n,r){if(0===e.length)return e;for(var o=t.startRow();o<=t.finishRow();o++)for(var i=t.startCol();i<=t.finishCol();i++)bi.mutateCell(e[o],i,Zt(r(),!1));return e},zi=function(e,t,n,r){for(var o=!0,i=0;i',r.insertBefore(o,r.firstChild)),""===u.align?Ec(n,r):Dc(n,r,u.align),n.focus(),n.addVisual()})},da=function(e,t){var n,r=e.dom,o=Fc(e,hc(e));!1===t?(n=r.getParent(e.selection.getStart(),"table"))?o=jc(e,n,hc(e)):hc(e)&&(o.borderstyle="",o.bordercolor="",o.backgroundcolor=""):(o.cols="1",o.rows="1",hc(e)&&(o.borderstyle="",o.bordercolor="",o.backgroundcolor=""));var i=0=e.left&&t<=e.right&&n>=e.top&&n<=e.bottom},al=function(n,r,e,t,o){var i=function(e){var t=n.dom().createRange();return t.setStart(r.dom(),e),t.collapse(!0),t},u=kn(r).length,c=function(e,t,n,r,o){if(0===o)return 0;if(t===r)return o-1;for(var i=r,u=1;ur.left&&o.left ("+e.right()+", "+e.bottom()+")"}},yf=function(e){return wf.nu({left:e.left,top:e.top,right:e.right,bottom:e.bottom})},Cf=function(e,t){return x.some(e.getRect(t))},Sf=function(e,t,n){return ve(t)?Cf(e,t).map(yf):be(t)?(r=e,o=t,i=n,0<=i&&in.right();var t,n})});var n,o,i},Of={point:wf.getTop,adjuster:function(e,t,n,r,o){var i=wf.moveUp(o,5);return Math.abs(n.top()-r.top())<1?Rf.retry(i):n.bottom()o.bottom()?Rf.retry(i):n.top()===o.bottom()?Rf.retry(wf.moveDown(o,1)):Tf(e,t,o)?Rf.retry(wf.translate(i,5,0)):Rf.none()},move:wf.moveDown,gather:uf},Af=function(n,r,o,i,u){return 0===u?x.some(i):(a=n,l=i.left(),f=r.point(i),a.elementFromPoint(l,f).filter(function(e){return"table"===me(e)}).isSome()?(t=i,c=u-1,Af(n,e=r,o,e.move(t,5),c)):n.situsFromPoint(i.left(),r.point(i)).bind(function(e){return e.start().fold(x.none,function(t){return xf(n,t).bind(function(e){return r.adjuster(n,t,e,o,i).fold(x.none,function(e){return Af(n,r,o,e,u-1)})}).orThunk(function(){return x.some(i)})},x.none)}));var e,t,c,a,l,f},Ef=function(t,n,e){var r,o,i,u=t.move(e,5),c=Af(n,t,e,u,100).getOr(u);return(r=t,o=c,i=n,r.point(o)>i.getInnerHeight()?x.some(r.point(o)-i.getInnerHeight()):r.point(o)<0?x.some(-r.point(o)):x.none()).fold(function(){return n.situsFromPoint(c.left(),t.point(c))},function(e){return n.scrollBy(0,e),n.situsFromPoint(c.left(),t.point(c)-e)})},Nf={tryUp:b(Ef,Of),tryDown:b(Ef,Df),ieTryUp:function(e,t){return e.situsFromPoint(t.left(),t.top()-5)},ieTryDown:function(e,t){return e.situsFromPoint(t.left(),t.bottom()+5)},getJumpSize:S(5)},kf=St.detect(),If=function(r,o,i,u,c,a){return 0===a?x.none():Mf(r,o,i,u,c).bind(function(e){var t=r.fromSitus(e),n=ff.verify(r,i,u,t.finish(),t.foffset(),c.failure,o);return ff.cata(n,function(){return x.none()},function(){return x.some(e)},function(e){return Dt(i,e)&&0===u?Pf(r,i,u,wf.moveUp,c):If(r,o,e,0,c,a-1)},function(e){return Dt(i,e)&&u===Bn(e)?Pf(r,i,u,wf.moveDown,c):If(r,o,e,Bn(e),c,a-1)})})},Pf=function(t,e,n,r,o){return Sf(t,e,n).bind(function(e){return Bf(t,o,r(e,Nf.getJumpSize()))})},Bf=function(e,t,n){return kf.browser.isChrome()||kf.browser.isSafari()||kf.browser.isFirefox()||kf.browser.isEdge()?t.otherRetry(e,n):kf.browser.isIE()?t.ieRetry(e,n):x.none()},Mf=function(t,e,n,r,o){return Sf(t,n,r).bind(function(e){return Bf(t,o,e)})},Wf=function(t,n,r){return(o=t,i=n,u=r,o.getSelection().bind(function(r){return hf(i,r.finish(),r.foffset(),u).fold(function(){return x.some(cf(r.finish(),r.foffset()))},function(e){var t=o.fromSitus(e),n=ff.verify(o,r.finish(),r.foffset(),t.finish(),t.foffset(),u.failure,i);return vf(n)})})).bind(function(e){return If(t,n,e.element(),e.offset(),r,20).map(t.fromSitus)});var o,i,u},_f=St.detect(),Lf=function(e,t){return fn(e,function(e){return kt(e).exists(function(e){return Dt(e,t)})},n).isSome();var n},jf=function(t,r,o,e,i){return gn(e,"td,th",r).bind(function(n){return gn(n,"table",r).bind(function(e){return Lf(i,e)?Wf(t,r,o).bind(function(t){return gn(t.finish(),"td,th",r).map(function(e){return{start:S(n),finish:S(e),range:S(t)}})}):x.none()})})},zf=function(e,t,n,r,o,i){return _f.browser.isIE()?x.none():i(r,t).orThunk(function(){return jf(e,t,n,r,o).map(function(e){var t=e.range();return Ll.create(x.some(zl.makeSitus(t.start(),t.soffset(),t.finish(),t.foffset())),!0)})})},Hf=function(e,t,n,r,o,i,u){return jf(e,n,r,o,i).bind(function(e){return Fl.detect(t,n,e.start(),e.finish(),u)})},Ff=function(e,u){return gn(e,"tr",u).bind(function(i){return gn(i,"table",u).bind(function(e){var t,n,r,o=an(e,"tr");return Dt(i,o[0])?(t=e,n=function(e){return Ln(e).isSome()},r=u,tf(rf,t,n,r)).map(function(e){var t=Bn(e);return Ll.create(x.some(zl.makeSitus(e,t,e,t)),!0)}):x.none()})})},Uf=function(e,u){return gn(e,"tr",u).bind(function(i){return gn(i,"table",u).bind(function(e){var t,n,r,o=an(e,"tr");return Dt(i,o[o.length-1])?(t=e,n=function(e){return _n(e).isSome()},r=u,nf(rf,t,n,r)).map(function(e){return Ll.create(x.some(zl.makeSitus(e,0,e,0)),!0)}):x.none()})})},qf=function(e,t){return gn(e,"td,th",t)};var Vf={down:{traverse:Bt,gather:uf,relative:$a.before,otherRetry:Nf.tryDown,ieRetry:Nf.ieTryDown,failure:ff.failedDown},up:{traverse:Pt,gather:of,relative:$a.before,otherRetry:Nf.tryUp,ieRetry:Nf.ieTryUp,failure:ff.failedUp}},Gf=function(t){return function(e){return e===t}},Yf=Gf(38),Kf=Gf(40),Xf={ltr:{isBackward:Gf(37),isForward:Gf(39)},rtl:{isBackward:Gf(39),isForward:Gf(37)},isUp:Yf,isDown:Kf,isNavigation:function(e){return 37<=e&&e<=40}},$f=(St.detect().browser.isSafari(),function(c){return{elementFromPoint:function(e,t){return Pe.fromPoint(Pe.fromDom(c.document),e,t)},getRect:function(e){return e.dom().getBoundingClientRect()},getRangedRect:function(e,t,n,r){var o=Qa.exact(e,t,n,r);return El(c,o).map(function(e){return Q(e,a)})},getSelection:function(){return Al(c).map(function(e){return zl.convertToRange(c,e)})},fromSitus:function(e){var t=Qa.relative(e.start(),e.finish());return zl.convertToRange(c,t)},situsFromPoint:function(e,t){return Nl(c,e,t).map(function(e){return jl(e.start(),e.soffset(),e.finish(),e.foffset())})},clearSelection:function(){c.getSelection().removeAllRanges()},setSelection:function(e){var t,n,r,o,i,u;t=c,n=e.start(),r=e.soffset(),o=e.finish(),i=e.foffset(),u=yl(n,r,o,i),Rl(t,u)},setRelativeSelection:function(e,t){var n,r;n=c,r=wl(e,t),Rl(n,r)},selectContents:function(e){Dl(c,e)},getInnerHeight:function(){return c.innerHeight},getScrollY:function(){var e,t,n,r;return(e=Pe.fromDom(c.document),t=e!==undefined?e.dom():m.document,n=t.body.scrollLeft||t.documentElement.scrollLeft,r=t.body.scrollTop||t.documentElement.scrollTop,po(n,r)).top()},scrollBy:function(e,t){var n,r,o;n=e,r=t,((o=Pe.fromDom(c.document))!==undefined?o.dom():m.document).defaultView.scrollBy(n,r)}}}),Jf=ne("rows","cols"),Qf={mouse:function(e,t,n,r){var o=function c(o,i,t,u){var n=x.none(),r=function(){n=x.none()};return{mousedown:function(e){u.clear(i),n=qf(e.target(),t)},mouseover:function(e){n.each(function(r){u.clear(i),qf(e.target(),t).each(function(n){Tr(r,n,t).each(function(e){var t=e.boxes().getOr([]);(1