!function(){"use strict";var e,t,n,r,o,i,u=tinymce.util.Tools.resolve("tinymce.PluginManager"),a=function(e){return function(){return e}},y={noop:function(){for(var e=[],t=0;tn.maxRow()||fn.maxCol()||(Ut.getAt(t,l,f).filter(r).isNone()?(o=s,i=e[l].element(),u=X.fromTag("td"),tn.append(u,X.fromTag("br")),(o?tn.append:tn.prepend)(i,u)):s=!0)}(m,g,p,d),o=e,s=p,f=A.filter(ot.firstLayer(o,"tr"),function(e){return 0===e.dom().childElementCount}),A.each(f,on.remove),s.minCol()!==s.maxCol()&&s.minRow()!==s.maxRow()||A.each(ot.firstLayer(o,"th,td"),function(e){ht.remove(e,"rowspan"),ht.remove(e,"colspan")}),ht.remove(o,"width"),ht.remove(o,"height"),Qt.remove(o,"width"),Qt.remove(o,"height"),e},cn=function(e,t){return X.fromDom(e.dom().cloneNode(t))},ln=function(e){return cn(e,!0)},sn=function(e,t){var n=X.fromTag(t),r=ht.clone(e);return ht.setAll(n,r),n},fn=function(e){return cn(e,!1)},dn=ln,mn=function(e,t){var n=sn(e,t),r=nt.children(ln(e));return nn.append(n,r),n},gn=(Rt=ft.isText,Tt="text",Dt=function(e){return Rt(e)?x.from(e.dom().nodeValue):x.none()},At=Ue.detect().browser,{get:function(e){if(!Rt(e))throw new Error("Can only get "+Tt+" value of a "+Tt+" node");return kt(e).getOr("")},getOption:kt=At.isIE()&&10===At.version.major?function(e){try{return Dt(e)}catch(t){return x.none()}}:Dt,set:function(e,t){if(!Rt(e))throw new Error("Can only set raw "+Tt+" value of a "+Tt+" node");e.dom().nodeValue=t}}),pn={get:function(e){return gn.get(e)},getOption:function(e){return gn.getOption(e)},set:function(e,t){gn.set(e,t)}},hn=function(e){return"img"===ft.name(e)?1:pn.getOption(e).fold(function(){return nt.children(e).length},function(e){return e.length})},vn=["img","br"],bn=hn,wn=function(e){var t;return t=e,pn.getOption(t).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()},Hn=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()},Vn=function(e,t){for(var n=!0,r=y.curry(_n,t),o=t.startRow();o<=t.finishRow();o++)for(var i=t.startCol();i<=t.finishCol();i++)n=n&&Ut.getAt(e,o,i).exists(r);return n?x.some(t):x.none()},Un=function(e,t,n){var r=Ut.findItem(e,t,Ye.eq),o=Ut.findItem(e,n,Ye.eq);return r.bind(function(r){return o.map(function(e){return t=r,n=e,U.bounds(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})})},Gn=Un,Xn=function(t,e,n){return Un(t,e,n).bind(function(e){return Vn(t,e)})},Yn=function(r,e,o,i){return Ut.findItem(r,e,Ye.eq).bind(function(e){var t=0=t.length-1)return x.none();var e=t[n].fold(function(){var e=A.reverse(t.slice(0,n));return Lo(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 Lo(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})})},Jo=function(e,t,n){var r=e();return A.find(r,t).orThunk(function(){return x.from(r[0]).orThunk(n)}).map(function(e){return e.element()})},Qo=function(n){var e=n.grid(),t=Ko(0,e.columns()),r=Ko(0,e.rows());return A.map(t,function(t){return Jo(function(){return A.bind(r,function(e){return Ut.getAt(n,e,t).filter(function(e){return e.column()===t}).fold(y.constant([]),function(e){return[e]})})},function(e){return 1===e.colspan()},function(){return Ut.getAt(n,0,t)})})},Zo=function(n){var e=n.grid(),t=Ko(0,e.rows()),r=Ko(0,e.columns());return A.map(t,function(t){return Jo(function(){return A.bind(r,function(e){return Ut.getAt(n,t,e).filter(function(e){return e.row()===t}).fold(y.constant([]),function(e){return[e]})})},function(e){return 1===e.rowspan()},function(){return Ut.getAt(n,t,0)})})},ei=function(e,t,n,r,o){var i=X.fromTag("div");return Qt.setAll(i,{position:"absolute",left:t-r/2+"px",top:n+"px",height:o+"px",width:r+"px"}),ht.setAll(i,{"data-column":e,role:"presentation"}),i},ti=function(e,t,n,r,o){var i=X.fromTag("div");return Qt.setAll(i,{position:"absolute",left:t+"px",top:n-o/2+"px",height:o+"px",width:r+"px"}),ht.setAll(i,{"data-row":e,role:"presentation"}),i},ni=function(e){var t=e.replace(/\./g,"-");return{resolve:function(e){return t+"-"+e}}},ri={resolve:ni("ephox-snooker").resolve},oi=function(e,t){var n=ht.get(e,t);return n===undefined||""===n?[]:n.split(" ")},ii=oi,ui=function(e,t,n){var r=oi(e,t).concat([n]);ht.set(e,t,r.join(" "))},ai=function(e,t,n){var r=A.filter(oi(e,t),function(e){return e!==n});0=t.length||e.column()>jo.cellLength(t[0]))return Fi.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=jo.cellLength(n[0]),u=n.length;return Fi.value({rowDelta:y.constant(r.length-u),colDelta:y.constant(o.length-i)})},Vi=function(e,t){var n=jo.cellLength(e[0]),r=jo.cellLength(t[0]);return{rowDelta:y.constant(0),colDelta:y.constant(n-r)}},Ui=function(e,t,n){var r=t.colDelta()<0?_i:y.identity;return(t.rowDelta()<0?zi:y.identity)(r(e,Math.abs(t.colDelta()),n),Math.abs(t.rowDelta()),n)},Gi=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++)jo.mutateCell(e[o],i,U.elementnew(r(),!1));return e},Xi=function(e,t,n,r){for(var o=!0,i=0;i',t.insertBefore(r,t.firstChild)),ga.unApplyAlign(e,t),o.align&&ga.applyAlign(e,t,o.align),e.focus(),e.addVisual()})},Oa=function(t,e){var n,r,o,i,u,a,c,l,s,f,d=t.dom,m={};!0===e?(n=d.getParent(t.selection.getStart(),"table"))&&(c=n,l=(a=t).dom,s={width:l.getStyle(c,"width")||l.getAttrib(c,"width"),height:l.getStyle(c,"height")||l.getAttrib(c,"height"),cellspacing:l.getStyle(c,"border-spacing")||l.getAttrib(c,"cellspacing"),cellpadding:l.getAttrib(c,"data-mce-cell-padding")||l.getAttrib(c,"cellpadding")||ga.getTDTHOverallStyle(a.dom,c,"padding"),border:l.getAttrib(c,"data-mce-border")||l.getAttrib(c,"border")||ga.getTDTHOverallStyle(a.dom,c,"border"),borderColor:l.getAttrib(c,"data-mce-border-color"),caption:!!l.select("caption",c)[0],"class":l.getAttrib(c,"class")},ma.each("left center right".split(" "),function(e){a.formatter.matchNode(c,"align"+e)&&(s.align=e)}),ra(a)&&ma.extend(s,ha.extractAdvancedStyles(l,c)),m=s):(r={label:"Cols",name:"cols"},o={label:"Rows",name:"rows"}),0=e.left&&t<=e.right&&n>=e.top&&n<=e.bottom},Oc=function(e,t,n,r,o){if(0===o)return 0;if(t===r)return o-1;for(var i=r,u=1;ua.bottom);else{if(nn.bottom&&bl(e,!1)},setToElement:function(e,t){var n=Kr(t),r=X.fromDom(e.document);vl(n.left(),n.top(),r)},scrollBarWidth:function(){var e=X.fromHtml('
');tn.after(wt.body(),e);var t=e.dom().offsetWidth-e.dom().clientWidth;return on.remove(e),t}};function yl(i){return{elementFromPoint:function(e,t){return x.from(i.document.elementFromPoint(e,t)).map(X.fromDom)},getRect:function(e){return e.dom().getBoundingClientRect()},getRangedRect:function(e,t,n,r){var o=bc.exact(e,t,n,r);return tl.getFirstRect(i,o).map(function(e){return P.map(e,y.apply)})},getSelection:function(){return tl.get(i).map(function(e){return gl.convertToRange(i,e)})},fromSitus:function(e){var t=bc.relative(e.start(),e.finish());return gl.convertToRange(i,t)},situsFromPoint:function(e,t){return tl.getAtPoint(i,e,t).map(function(e){return{start:y.constant(pc.on(e.start(),e.soffset())),finish:y.constant(pc.on(e.finish(),e.foffset()))}})},clearSelection:function(){tl.clear(i)},setSelection:function(e){tl.setExact(i,e.start(),e.soffset(),e.finish(),e.foffset())},setRelativeSelection:function(e,t){tl.setRelative(i,e,t)},selectContents:function(e){tl.setToElement(i,e)},getInnerHeight:function(){return i.innerHeight},getScrollY:function(){return wl.get(X.fromDom(i.document)).top()},scrollBy:function(e,t){wl.by(e,t,X.fromDom(i.document))}}}var xl=function(n,e,r,t,o){return Ye.eq(r,t)?x.none():ir.identify(r,t,e).bind(function(e){var t=e.boxes().getOr([]);return 0 ("+e.right()+", "+e.bottom()+")"}},Tl=function(e){return Rl.nu({left:e.left,top:e.top,right:e.right,bottom:e.bottom})},Dl=function(e,t){return x.some(e.getRect(t))},Al=function(e,t,n){return ft.isElement(t)?Dl(e,t).map(Tl):ft.isText(t)?(r=e,o=t,i=n,0<=i&&in.right();var t,n})})},Yl={point:Rl.getTop,adjuster:function(e,t,n,r,o){var i=Rl.moveUp(o,5);return Math.abs(n.top()-r.top())<1?Gl.retry(i):n.bottom()o.bottom()?Gl.retry(i):n.top()===o.bottom()?Gl.retry(Rl.moveDown(o,1)):Xl(e,t,o)?Gl.retry(Rl.translate(i,5,0)):Gl.none()},move:Rl.moveDown,gather:Ul.after},$l=function(n,r,o,i,u){return 0===u?x.some(i):(c=n,l=i.left(),s=r.point(i),c.elementFromPoint(l,s).filter(function(e){return"table"===ft.name(e)}).isSome()?(t=i,a=u-1,$l(n,e=r,o,e.move(t,5),a)):n.situsFromPoint(i.left(),r.point(i)).bind(function(e){return e.start().fold(x.none,function(t,e){return kl(n,t,e).bind(function(e){return r.adjuster(n,t,e,o,i).fold(x.none,function(e){return $l(n,r,o,e,u-1)})}).orThunk(function(){return x.some(i)})},x.none)}));var e,t,a,c,l,s},Jl=function(t,n,e){var r,o,i,u=t.move(e,5),a=$l(n,t,e,u,100).getOr(u);return(r=t,o=a,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(a.left(),t.point(a))},function(e){return n.scrollBy(0,e),n.situsFromPoint(a.left(),t.point(a)-e)})},Ql={tryUp:y.curry(Jl,Yl),tryDown:y.curry(Jl,Kl),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:y.constant(5)},Zl=dr([{none:["message"]},{success:[]},{failedUp:["cell"]},{failedDown:["cell"]}]),es=function(e){return It.closest(e,"tr")},ts={verify:function(a,e,t,n,r,c,o){return It.closest(n,"td,th",o).bind(function(u){return It.closest(e,"td,th",o).map(function(i){return Ye.eq(u,i)?Ye.eq(n,u)&&bn(u)===r?c(i):Zl.none("in same cell"):jn(es,[u,i]).fold(function(){return t=i,n=u,r=(e=a).getRect(t),(o=e.getRect(n)).right>r.left&&o.left";for(var n=0;n<10;n++)e+='';e+=""}return e+="",e+=''}(),onPostRender:function(){this.lastX=this.lastY=0},onmousemove:function(e){var t,n,r=e.target;"A"===r.tagName.toUpperCase()&&(t=parseInt(r.getAttribute("data-mce-x"),10),n=parseInt(r.getAttribute("data-mce-y"),10),(this.isRtl()||"tl-tr"===this.parent().rel)&&(t=9-t),t===this.lastX&&n===this.lastY||(f(o,t,n,e.control),this.lastX=t,this.lastY=n))},onclick:function(e){var t=this;"A"===e.target.tagName.toUpperCase()&&(e.preventDefault(),e.stopPropagation(),t.parent().cancel(),o.undoManager.transact(function(){ka(o,t.lastX+1,t.lastY+1)}),o.addVisual())}}]};function m(e){return function(){o.execCommand(e)}}var g={text:"Table properties",context:"table",onPostRender:e,onclick:y.curry(Oa,o,!0)},p={text:"Delete table",context:"table",onPostRender:e,cmd:"mceTableDelete"},h={text:"Row",context:"table",menu:[{text:"Insert row before",onclick:m("mceTableInsertRowBefore"),onPostRender:t},{text:"Insert row after",onclick:m("mceTableInsertRowAfter"),onPostRender:t},{text:"Delete row",onclick:m("mceTableDeleteRow"),onPostRender:t},{text:"Row properties",onclick:m("mceTableRowProps"),onPostRender:t},{text:"-"},{text:"Cut row",onclick:m("mceTableCutRow"),onPostRender:t},{text:"Copy row",onclick:m("mceTableCopyRow"),onPostRender:t},{text:"Paste row before",onclick:m("mceTablePasteRowBefore"),onPostRender:t},{text:"Paste row after",onclick:m("mceTablePasteRowAfter"),onPostRender:t}]},v={text:"Column",context:"table",menu:[{text:"Insert column before",onclick:m("mceTableInsertColBefore"),onPostRender:t},{text:"Insert column after",onclick:m("mceTableInsertColAfter"),onPostRender:t},{text:"Delete column",onclick:m("mceTableDeleteCol"),onPostRender:t}]},b={separator:"before",text:"Cell",context:"table",menu:[{text:"Cell properties",onclick:m("mceTableCellProps"),onPostRender:t},{text:"Merge cells",onclick:m("mceTableMergeCells"),onPostRender:function(){var t=this;a.push(t),r.fold(function(){l(t)},function(e){t.disabled(e.mergable().isNone())})}},{text:"Split cell",onclick:m("mceTableSplitCells"),onPostRender:function(){var t=this;c.push(t),r.fold(function(){l(t)},function(e){t.disabled(e.unmergable().isNone())})}}]};o.addMenuItem("inserttable",d),o.addMenuItem("tableprops",g),o.addMenuItem("deletetable",p),o.addMenuItem("row",h),o.addMenuItem("column",v),o.addMenuItem("cell",b)}},Ls=function(n,o){return{insertTable:function(e,t){return ka(n,e,t)},setClipboardRows:function(e){return t=e,n=o,r=A.map(t,X.fromDom),void n.set(x.from(r));var t,n,r},getClipboardRows:function(){return o.get().fold(function(){},function(e){return A.map(e,function(e){return e.dom()})})}}};u.add("table",function(t){var n=ic(t),e=Bs(t,n.lazyResize),r=fa(t,n.lazyWire),o=Ps(t),i=so(x.none());return Pa.registerCommands(t,r,e,o,i),Sr.registerEvents(t,o,r,e),Ms.addMenuItems(t,o),Ws.addButtons(t),Ws.addToolbars(t),t.on("PreInit",function(){t.serializer.addTempAttr(fr.firstSelected()),t.serializer.addTempAttr(fr.lastSelected())}),ea(t)&&t.on("keydown",function(e){cl.handle(e,t,r,n.lazyWire)}),t.on("remove",function(){n.destroy(),e.destroy()}),Ls(t,i)})}();