/** * 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.1.3 (2019-12-04) */ !function(f){"use strict";function o(e){return e}var R=function(e){function n(){return t}var t=e;return{get:n,set:function(e){t=e},clone:function(){return R(n())}}},T=function(){},O=function(t,r){return function(){for(var e=[],n=0;nt.maxRow()||st.maxCol()))mt.getAt(n,l,s).filter(r).isNone()?(o=f,void 0,i=e[l].element(),u=on.fromTag("td"),Mn(u,on.fromTag("br")),(o?Mn:Te)(i,u)):f=!0}}(r,o,i,t),function(e,n){var t=h(ut.firstLayer(e,"tr"),function(e){return 0===e.dom().childElementCount});p(t,Wn),n.minCol()!==n.maxCol()&&n.minRow()!==n.maxRow()||p(ut.firstLayer(e,"th,td"),function(e){Y(e,"rowspan"),Y(e,"colspan")}),Y(e,"width"),Y(e,"height"),ue(e,"width"),ue(e,"height")}(e,i),e};function ht(e){return Bt.get(e)}function vt(e){return Bt.getOption(e)}function bt(e,n){Bt.set(e,n)}function wt(e){return"img"===en(e)?1:vt(e).fold(function(){return Ce(e).length},function(e){return e.length})}function yt(e){return function(e){return vt(e).filter(function(e){return 0!==e.trim().length||-1=e.startCol()&&n.column()+n.colspan()-1<=e.finishCol()&&n.row()>=e.startRow()&&n.row()+n.rowspan()-1<=e.finishRow()}function It(e,n,t){var r=mt.findItem(e,n,In),o=mt.findItem(e,t,In);return r.bind(function(n){return o.map(function(e){return function(e,n){return Yn(Math.min(e.row(),n.row()),Math.min(e.column(),n.column()),Math.max(e.row()+e.rowspan()-1,n.row()+n.rowspan()-1),Math.max(e.column()+e.colspan()-1,n.column()+n.colspan()-1))}(n,e)})})}var Bt=function Qf(t,r){var n=function(e){return t(e)?Me.from(e.dom().nodeValue):Me.none()};return{get:function(e){if(!t(e))throw new Error("Can only get "+r+" value of a "+r+" node");return n(e).getOr("")},getOption:n,set:function(e,n){if(!t(e))throw new Error("Can only set raw "+r+" value of a "+r+" node");e.dom().nodeValue=n}}}(tn,"text"),Pt=["img","br"],Mt=function(e,i){var u=function(e){for(var n=Ce(e),t=n.length-1;0<=t;t--){var r=n[t];if(i(r))return Me.some(r);var o=u(r);if(o.isSome())return o}return Me.none()};return u(e)},Wt={cellOperations:function(i,e,u){return{row:Nt(e),cell:function(e){var n=he(e.element()),t=on.fromTag(en(e.element()),n.dom()),r=u.getOr(["strong","em","b","i","span","font","h1","h2","h3","h4","h5","h6","p","div"]),o=0=e.startCol()&&o<=e.finishRow()&&i>=e.startRow()},Lt=function(e,n){for(var t=!0,r=b(kt,n),o=n.startRow();o<=n.finishRow();o++)for(var i=n.startCol();i<=n.finishCol();i++)t=t&&mt.getAt(e,o,i).exists(r);return t?Me.some(n):Me.none()},jt=It,zt=function(n,e,t){return It(n,e,t).bind(function(e){return Lt(n,e)})},Ht=function(r,e,o,i){return mt.findItem(r,e,In).bind(function(e){var n=0=n.length-1)return Me.none();var e=n[t].fold(function(){var e=E(n.slice(0,t));return bo(e,function(e,n){return e.map(function(e){return{value:e,delta:n+1}})})},function(e){return Me.some({value:e,delta:0})}),r=n[t+1].fold(function(){var e=n.slice(t+1);return bo(e,function(e,n){return e.map(function(e){return{value:e,delta:n+1}})})},function(e){return Me.some({value:e,delta:1})});return e.bind(function(t){return r.map(function(e){var n=e.delta+t.delta;return Math.abs(e.value-t.value)/n})})}function Eo(e){var n=e.replace(/\./g,"-");return{resolve:function(e){return n+"-"+e}}}function No(e){var n=Be(e.parent(),"."+iu);p(n,Wn)}function ko(t,e,r){var o=t.origin();p(e,function(e,n){e.each(function(e){var n=r(o,e);Ro(n,iu),Mn(t.parent(),n)})})}function Io(e,n,t,r,o,i){var u=Ur(n);!function(e,n,r,o){ko(e,n,function(e,n){var t=ou(n.row(),r.left()-e.left(),n.y()-e.top(),o,7);return Ro(t,uu),t})}(e,0',r.insertBefore(o,r.firstChild)),""===u.align?Nc(t,r):Ac(t,r,u.align),t.focus(),t.addVisual()})}function Vi(n){return function(e){return Me.from(e.dom.getParent(e.selection.getStart(),n)).map(on.fromDom)}}function Gi(e){function n(){e.stopPropagation()}function t(){e.preventDefault()}var r=on.fromDom(e.target),o=O(t,n);return function(e,n,t,r,o,i,u){return{target:D(e),x:D(n),y:D(t),stop:r,prevent:o,kill:i,raw:D(u)}}(r,e.clientX,e.clientY,n,t,o,e)}function Yi(e,n,t,r,o){var i=function(n,t){return function(e){n(e)&&t(Gi(e))}}(t,r);return e.dom().addEventListener(n,i,o),{unbind:b(sa,e,n,i,o)}}function Ki(e,n,t){return function(e,n,t,r){return Yi(e,n,t,r,!1)}(e,n,da,t)}var Xi,$i=function(e){var n=ft(e);return mt.generate(n).grid()},Ji=function(o,e){function n(e,n){0=n.length||e.column()>pu.cellLength(n[0]))return Cu.error("invalid start address out of table bounds, row: "+e.row()+", column: "+e.column());var r=n.slice(e.row()),o=r[0].cells().slice(e.column()),i=pu.cellLength(t[0]),u=t.length;return Cu.value({rowDelta:D(r.length-u),colDelta:D(o.length-i)})},xu=function(e,n){var t=pu.cellLength(e[0]),r=pu.cellLength(n[0]);return{rowDelta:D(0),colDelta:D(t-r)}},Ru=function(e,n,t){var r=n.colDelta()<0?Vo:o;return(n.rowDelta()<0?qo:o)(r(e,Math.abs(n.colDelta()),t),Math.abs(n.rowDelta()),t)},Tu=function(e,n,t,r){if(0===e.length)return e;for(var o=n.startRow();o<=n.finishRow();o++)for(var i=n.startCol();i<=n.finishCol();i++)pu.mutateCell(e[o],i,Un(r(),!1));return e},Ou=function(e,n,t,r){for(var o=!0,i=0;i=e.left&&n<=e.right&&t>=e.top&&t<=e.bottom}function ka(t,r,e,n,o){function i(e){var n=t.dom().createRange();return n.setStart(r.dom(),e),n.collapse(!0),n}var u=ht(r).length,c=function(e,n,t,r,o){if(0===o)return 0;if(n===r)return o-1;for(var i=r,u=1;un.right()}(t,e)})})}function dl(n,t,e){var r=n.move(e,5),o=wf(t,n,e,r,100).getOr(r);return function(e,n,t){return e.point(n)>t.getInnerHeight()?Me.some(e.point(n)-t.getInnerHeight()):e.point(n)<0?Me.some(-e.point(n)):Me.none()}(n,o,t).fold(function(){return t.situsFromPoint(o.left(),n.point(o))},function(e){return t.scrollBy(0,e),t.situsFromPoint(o.left(),n.point(o)-e)})}function ml(e,n){return function(e,n,t){return $n(e,n,t).isSome()}(e,function(e){return ve(e).exists(function(e){return In(e,n)})})}function gl(n,r,o,e,i){return et(e,"td,th",r).bind(function(t){return et(t,"table",r).bind(function(e){return ml(i,e)?Of(n,r,o).bind(function(n){return et(n.finish(),"td,th",r).map(function(e){return{start:D(t),finish:D(e),range:D(n)}})}):Me.none()})})}function pl(e,n){return et(e,"td,th",n)}var hl=function(n,t,e){function r(){l.stop(),u.isOn()&&(u.off(),i.trigger.stop())}var o=!1,i=fa.create({start:la([]),stop:la([])}),u=wa(),c=function(t,r){var o=null;return{cancel:function(){null!==o&&(f.clearTimeout(o),o=null)},throttle:function(){for(var e=[],n=0;nr.left&&o.left ("+e.right()+", "+e.bottom()+")"}},gf=function(e,n,t){return nn(n)?fl(e,n).map(ll):tn(n)?function(e,n,t){return 0<=t&&to.bottom()?hf.retry(i):t.top()===o.bottom()?hf.retry(mf.moveDown(o,1)):sl(e,n,o)?hf.retry(mf.translate(i,5,0)):hf.none()},move:mf.moveDown,gather:il},wf=function(t,r,o,i,u){return 0===u?Me.some(i):function(e,n,t){return e.elementFromPoint(n,t).filter(function(e){return"table"===en(e)}).isSome()}(t,i.left(),r.point(i))?function(e,n,t,r,o){return wf(e,n,t,n.move(r,5),o)}(t,r,o,i,u-1):t.situsFromPoint(i.left(),r.point(i)).bind(function(e){return e.start().fold(Me.none,function(n){return pf(t,n).bind(function(e){return r.adjuster(t,n,e,o,i).fold(Me.none,function(e){return wf(t,r,o,e,u-1)})}).orThunk(function(){return Me.some(i)})},Me.none)})},yf={tryUp:b(dl,vf),tryDown:b(dl,bf),ieTryUp:function(e,n){return e.situsFromPoint(n.left(),n.top()-5)},ieTryDown:function(e,n){return e.situsFromPoint(n.left(),n.bottom()+5)},getJumpSize:D(5)},Cf=me(),Sf=function(r,o,i,u,c,a){return 0===a?Me.none():Tf(r,o,i,u,c).bind(function(e){var n=r.fromSitus(e),t=uf.verify(r,i,u,n.finish(),n.foffset(),c.failure,o);return uf.cata(t,function(){return Me.none()},function(){return Me.some(e)},function(e){return In(i,e)&&0===u?xf(r,i,u,mf.moveUp,c):Sf(r,o,e,0,c,a-1)},function(e){return In(i,e)&&u===wt(e)?xf(r,i,u,mf.moveDown,c):Sf(r,o,e,wt(e),c,a-1)})})},xf=function(n,e,t,r,o){return gf(n,e,t).bind(function(e){return Rf(n,o,r(e,yf.getJumpSize()))})},Rf=function(e,n,t){return Cf.browser.isChrome()||Cf.browser.isSafari()||Cf.browser.isFirefox()||Cf.browser.isEdge()?n.otherRetry(e,t):Cf.browser.isIE()?n.ieRetry(e,t):Me.none()},Tf=function(n,e,t,r,o){return gf(n,t,r).bind(function(e){return Rf(n,o,e)})},Of=function(n,t,r){return function(o,i,u){return o.getSelection().bind(function(r){return ff(i,r.finish(),r.foffset(),u).fold(function(){return Me.some(rf(r.finish(),r.foffset()))},function(e){var n=o.fromSitus(e),t=uf.verify(o,r.finish(),r.foffset(),n.finish(),n.foffset(),u.failure,i);return sf(t)})})}(n,t,r).bind(function(e){return Sf(n,t,e.element(),e.offset(),r,20).map(n.fromSitus)})},Df=me(),Af=function(e,n,t,r,o,i){return Df.browser.isIE()?Me.none():i(r,n).orThunk(function(){return gl(e,n,t,r,o).map(function(e){var n=e.range();return Hl.create(Me.some(Ul.makeSitus(n.start(),n.soffset(),n.finish(),n.foffset())),!0)})})},Ef=function(e,n,t,r,o,i,u){return gl(e,t,r,o,i).bind(function(e){return Vl.detect(n,t,e.start(),e.finish(),u)})},Nf=function(e,r){return et(e,"tr",r).bind(function(t){return et(t,"table",r).bind(function(e){var n=Be(e,"tr");return In(t,n[0])?function(e,n,t){return ef(tf,e,n,t)}(e,function(e){return St(e).isSome()},r).map(function(e){var n=wt(e);return Hl.create(Me.some(Ul.makeSitus(e,n,e,n)),!0)}):Me.none()})})},kf=function(e,r){return et(e,"tr",r).bind(function(t){return et(t,"table",r).bind(function(e){var n=Be(e,"tr");return In(t,n[n.length-1])?function(e,n,t){return nf(tf,e,n,t)}(e,function(e){return Ct(e).isSome()},r).map(function(e){return Hl.create(Me.some(Ul.makeSitus(e,0,e,0)),!0)}):Me.none()})})};function If(n){return function(e){return e===n}}function Bf(c){return{elementFromPoint:function(e,n){return on.fromPoint(on.fromDom(c.document),e,n)},getRect:function(e){return e.dom().getBoundingClientRect()},getRangedRect:function(e,n,t,r){var o=kl.exact(e,n,t,r);return $a(c,o).map(jf)},getSelection:function(){return Xa(c).map(function(e){return Ul.convertToRange(c,e)})},fromSitus:function(e){var n=kl.relative(e.start(),e.finish());return Ul.convertToRange(c,n)},situsFromPoint:function(e,n){return Ja(c,e,n).map(function(e){return Fl(e.start(),e.soffset(),e.finish(),e.foffset())})},clearSelection:function(){!function(e){e.getSelection().removeAllRanges()}(c)},collapseSelection:function(u){void 0===u&&(u=!1),Xa(c).each(function(e){return e.fold(function(e){return e.collapse(u)},function(e,n){var t=u?e:n;Va(c,t,t)},function(e,n,t,r){var o=u?e:t,i=u?n:r;qa(c,o,i,o,i)})})},setSelection:function(e){qa(c,e.start(),e.soffset(),e.finish(),e.foffset())},setRelativeSelection:function(e,n){Va(c,e,n)},selectContents:function(e){Ka(c,e)},getInnerHeight:function(){return c.innerHeight},getScrollY:function(){return function(e){var n=e!==undefined?e.dom():f.document,t=n.body.scrollLeft||n.documentElement.scrollLeft,r=n.body.scrollTop||n.documentElement.scrollTop;return lo(t,r)}(on.fromDom(c.document)).top()},scrollBy:function(e,n){!function(e,n,t){(t!==undefined?t.dom():f.document).defaultView.scrollBy(e,n)}(e,n,on.fromDom(c.document))}}}function Pf(n,e){p(e,function(e){!function(e,n){Co(e)?e.dom().classList.remove(n):xo(e,n);To(e)}(n,e)})}var Mf={down:{traverse:ye,gather:il,relative:El.before,otherRetry:yf.tryDown,ieRetry:yf.ieTryDown,failure:uf.failedDown},up:{traverse:we,gather:ol,relative:El.before,otherRetry:yf.tryUp,ieRetry:yf.ieTryUp,failure:uf.failedUp}},Wf=If(38),_f=If(40),Lf={ltr:{isBackward:If(37),isForward:If(39)},rtl:{isBackward:If(39),isForward:If(37)},isUp:Wf,isDown:_f,isNavigation:function(e){return 37<=e&&e<=40}},jf=function(e){return{left:e.left(),top:e.top(),right:e.right(),bottom:e.bottom(),width:e.width(),height:e.height()}},zf=(me().browser.isSafari(),B("rows","cols")),Hf={mouse:function(e,n,t,r){var o=function c(o,i,n,u){function t(){r=Me.none()}var r=Me.none();return{mousedown:function(e){u.clear(i),r=pl(e.target(),n)},mouseover:function(e){r.each(function(r){u.clearBeforeUpdate(i),pl(e.target(),n).each(function(t){dr(r,t,n).each(function(e){var n=e.boxes().getOr([]);(1