!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()||(Gt.getAt(t,l,f).filter(r).isNone()?(o=s,i=e[l].element(),u=Y.fromTag("td"),nn.append(u,Y.fromTag("br")),(o?nn.append:nn.prepend)(i,u)):s=!0)}(m,g,p,d),o=e,s=p,f=E.filter(it.firstLayer(o,"tr"),function(e){return 0===e.dom().childElementCount}),E.each(f,un.remove),s.minCol()!==s.maxCol()&&s.minRow()!==s.maxRow()||E.each(it.firstLayer(o,"th,td"),function(e){vt.remove(e,"rowspan"),vt.remove(e,"colspan")}),vt.remove(o,"width"),vt.remove(o,"height"),Zt.remove(o,"width"),Zt.remove(o,"height"),e},ln=function(e,t){return Y.fromDom(e.dom().cloneNode(t))},sn=function(e){return ln(e,!0)},fn=function(e,t){var n=Y.fromTag(t),r=vt.clone(e);return vt.setAll(n,r),n},dn=function(e){return ln(e,!1)},mn=sn,gn=function(e,t){var n=fn(e,t),r=rt.children(sn(e));return rn.append(n,r),n},pn=(Tt=dt.isText,At="text",Dt=function(e){return Tt(e)?x.from(e.dom().nodeValue):x.none()},kt=Ge.detect().browser,{get:function(e){if(!Tt(e))throw new Error("Can only get "+At+" value of a "+At+" node");return Nt(e).getOr("")},getOption:Nt=kt.isIE()&&10===kt.version.major?function(e){try{return Dt(e)}catch(t){return x.none()}}:Dt,set:function(e,t){if(!Tt(e))throw new Error("Can only set raw "+At+" value of a "+At+" node");e.dom().nodeValue=t}}),hn={get:function(e){return pn.get(e)},getOption:function(e){return pn.getOption(e)},set:function(e,t){pn.set(e,t)}},vn=function(e){return"img"===dt.name(e)?1:hn.getOption(e).fold(function(){return rt.children(e).length},function(e){return e.length})},bn=["img","br"],wn=vn,yn=function(e){var t;return t=e,hn.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()},Vn=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()},Un=function(e,t){for(var n=!0,r=y.curry(Hn,t),o=t.startRow();o<=t.finishRow();o++)for(var i=t.startCol();i<=t.finishCol();i++)n=n&&Gt.getAt(e,o,i).exists(r);return n?x.some(t):x.none()},Gn=function(e,t,n){var r=Gt.findItem(e,t,Ke.eq),o=Gt.findItem(e,n,Ke.eq);return r.bind(function(r){return o.map(function(e){return t=r,n=e,G.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})})},Xn=Gn,Yn=function(t,e,n){return Gn(t,e,n).bind(function(e){return Un(t,e)})},Kn=function(r,e,o,i){return Gt.findItem(r,e,Ke.eq).bind(function(e){var t=0=t.length-1)return x.none();var e=t[n].fold(function(){var e=E.reverse(t.slice(0,n));return qo(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 qo(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})})},Qo=function(e,t,n){var r=e();return E.find(r,t).orThunk(function(){return x.from(r[0]).orThunk(n)}).map(function(e){return e.element()})},Zo=function(n){var e=n.grid(),t=$o(0,e.columns()),r=$o(0,e.rows());return E.map(t,function(t){return Qo(function(){return E.bind(r,function(e){return Gt.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 Gt.getAt(n,0,t)})})},ei=function(n){var e=n.grid(),t=$o(0,e.rows()),r=$o(0,e.columns());return E.map(t,function(t){return Qo(function(){return E.bind(r,function(e){return Gt.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 Gt.getAt(n,t,0)})})},ti=function(e,t,n,r,o){var i=Y.fromTag("div");return Zt.setAll(i,{position:"absolute",left:t-r/2+"px",top:n+"px",height:o+"px",width:r+"px"}),vt.setAll(i,{"data-column":e,role:"presentation"}),i},ni=function(e,t,n,r,o){var i=Y.fromTag("div");return Zt.setAll(i,{position:"absolute",left:t+"px",top:n-o/2+"px",height:o+"px",width:r+"px"}),vt.setAll(i,{"data-row":e,role:"presentation"}),i},ri=function(e){var t=e.replace(/\./g,"-");return{resolve:function(e){return t+"-"+e}}},oi={resolve:ri("ephox-snooker").resolve},ii=function(e,t){var n=vt.get(e,t);return n===undefined||""===n?[]:n.split(" ")},ui=ii,ai=function(e,t,n){var r=ii(e,t).concat([n]);vt.set(e,t,r.join(" "))},ci=function(e,t,n){var r=E.filter(ii(e,t),function(e){return e!==n});0=t.length||e.column()>zo.cellLength(t[0]))return ji.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=zo.cellLength(n[0]),u=n.length;return ji.value({rowDelta:y.constant(r.length-u),colDelta:y.constant(o.length-i)})},Ui=function(e,t){var n=zo.cellLength(e[0]),r=zo.cellLength(t[0]);return{rowDelta:y.constant(0),colDelta:y.constant(n-r)}},Gi=function(e,t,n){var r=t.colDelta()<0?Hi:y.identity;return(t.rowDelta()<0?_i:y.identity)(r(e,Math.abs(t.colDelta()),n),Math.abs(t.rowDelta()),n)},Xi=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++)zo.mutateCell(e[o],i,G.elementnew(r(),!1));return e},Yi=function(e,t,n,r){for(var o=!0,i=0;i',t.insertBefore(r,t.firstChild)),pa.unApplyAlign(e,t),o.align&&pa.applyAlign(e,t,o.align),e.focus(),e.addVisual()})},Ba=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")||pa.getTDTHOverallStyle(a.dom,c,"padding"),border:l.getAttrib(c,"data-mce-border")||l.getAttrib(c,"border")||pa.getTDTHOverallStyle(a.dom,c,"border"),borderColor:l.getAttrib(c,"data-mce-border-color"),caption:!!l.select("caption",c)[0],"class":l.getAttrib(c,"class")},ga.each("left center right".split(" "),function(e){a.formatter.matchNode(c,"align"+e)&&(s.align=e)}),oa(a)&&ga.extend(s,va.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},Bc=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&&wl(e,!1)},setToElement:function(e,t){var n=$r(t),r=Y.fromDom(e.document);bl(n.left(),n.top(),r)},scrollBarWidth:function(){var e=Y.fromHtml('
');nn.after(yt.body(),e);var t=e.dom().offsetWidth-e.dom().clientWidth;return un.remove(e),t}};function xl(i){return{elementFromPoint:function(e,t){return x.from(i.document.elementFromPoint(e,t)).map(Y.fromDom)},getRect:function(e){return e.dom().getBoundingClientRect()},getRangedRect:function(e,t,n,r){var o=wc.exact(e,t,n,r);return nl.getFirstRect(i,o).map(function(e){return M.map(e,y.apply)})},getSelection:function(){return nl.get(i).map(function(e){return pl.convertToRange(i,e)})},fromSitus:function(e){var t=wc.relative(e.start(),e.finish());return pl.convertToRange(i,t)},situsFromPoint:function(e,t){return nl.getAtPoint(i,e,t).map(function(e){return{start:y.constant(hc.on(e.start(),e.soffset())),finish:y.constant(hc.on(e.finish(),e.foffset()))}})},clearSelection:function(){nl.clear(i)},setSelection:function(e){nl.setExact(i,e.start(),e.soffset(),e.finish(),e.foffset())},setRelativeSelection:function(e,t){nl.setRelative(i,e,t)},selectContents:function(e){nl.setToElement(i,e)},getInnerHeight:function(){return i.innerHeight},getScrollY:function(){return yl.get(Y.fromDom(i.document)).top()},scrollBy:function(e,t){yl.by(e,t,Y.fromDom(i.document))}}}var Sl=function(n,e,r,t,o){return Ke.eq(r,t)?x.none():ur.identify(r,t,e).bind(function(e){var t=e.boxes().getOr([]);return 0 ("+e.right()+", "+e.bottom()+")"}},Al=function(e){return Tl.nu({left:e.left,top:e.top,right:e.right,bottom:e.bottom})},Dl=function(e,t){return x.some(e.getRect(t))},kl=function(e,t,n){return dt.isElement(t)?Dl(e,t).map(Al):dt.isText(t)?(r=e,o=t,i=n,0<=i&&in.right();var t,n})})},Kl={point:Tl.getTop,adjuster:function(e,t,n,r,o){var i=Tl.moveUp(o,5);return Math.abs(n.top()-r.top())<1?Xl.retry(i):n.bottom()o.bottom()?Xl.retry(i):n.top()===o.bottom()?Xl.retry(Tl.moveDown(o,1)):Yl(e,t,o)?Xl.retry(Tl.translate(i,5,0)):Xl.none()},move:Tl.moveDown,gather:Gl.after},Jl=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"===dt.name(e)}).isSome()?(t=i,a=u-1,Jl(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 Nl(n,t,e).bind(function(e){return r.adjuster(n,t,e,o,i).fold(x.none,function(e){return Jl(n,r,o,e,u-1)})}).orThunk(function(){return x.some(i)})},x.none)}));var e,t,a,c,l,s},Ql=function(t,n,e){var r,o,i,u=t.move(e,5),a=Jl(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)})},Zl={tryUp:y.curry(Ql,Kl),tryDown:y.curry(Ql,$l),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)},es=mr([{none:["message"]},{success:[]},{failedUp:["cell"]},{failedDown:["cell"]}]),ts=function(e){return Wt.closest(e,"tr")},ns={verify:function(a,e,t,n,r,c,o){return Wt.closest(n,"td,th",o).bind(function(u){return Wt.closest(e,"td,th",o).map(function(i){return Ke.eq(u,i)?Ke.eq(n,u)&&wn(u)===r?c(i):es.none("in same cell"):zn(ts,[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(){Na(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(Ba,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)}},qs=function(n,o){return{insertTable:function(e,t){return Na(n,e,t)},setClipboardRows:function(e){return t=e,n=o,r=E.map(t,Y.fromDom),void n.set(x.from(r));var t,n,r},getClipboardRows:function(){return o.get().fold(function(){},function(e){return E.map(e,function(e){return e.dom()})})}}};u.add("table",function(t){var n=uc(t),e=Ps(t,n.lazyResize),r=da(t,n.lazyWire),o=Is(t),i=fo(x.none());return Ia.registerCommands(t,r,e,o,i),Cr.registerEvents(t,o,r,e),Ls.addMenuItems(t,o),Ms.addButtons(t),Ms.addToolbars(t),t.on("PreInit",function(){t.serializer.addTempAttr(dr.firstSelected()),t.serializer.addTempAttr(dr.lastSelected())}),ta(t)&&t.on("keydown",function(e){ll.handle(e,t,r,n.lazyWire)}),t.on("remove",function(){n.destroy(),e.destroy()}),qs(t,i)})}();