mirror of
https://github.com/documize/community.git
synced 2025-07-22 06:39:43 +02:00
1 line
No EOL
125 KiB
JavaScript
1 line
No EOL
125 KiB
JavaScript
!function(){"use strict";function n(t,e,r,o){if("TD"===e.tagName||"TH"===e.tagName)t.setStyle(e,r,o);else if(e.children)for(var i=0;i<e.children.length;i++)n(t,e.children[i],r,o)}function t(n,t,e){function r(n,t,e){e&&i.setAttrib(n,t,e)}var o,i=n.dom;Ia.updateStyleField(n,e),o=e.control.rootControl.toJSON(),n.undoManager.transact(function(){Na.each(t,function(e){r(e,"scope",o.scope),r(e,"style",o.style),r(e,"class",o["class"]),function(n,t,e){e&&i.setStyle(n,t,e)}(e,"height",xa.addSizeSuffix(o.height)),o.type!==e.parentNode.nodeName.toLowerCase()&&_a(n.dom,e,o.type),1===t.length&&Ba.unApplyAlign(n,e),o.align&&Ba.applyAlign(n,e,o.align)}),n.focus()})}var e=tinymce.util.Tools.resolve("tinymce.PluginManager"),r=function(n){return function(){return n}},o={noop:function(){},noarg:function(n){return function(){return n()}},compose:function(n,t){return function(){return n(t.apply(null,arguments))}},constant:r,identity:function(n){return n},tripleEquals:function(n,t){return n===t},curry:function(n){for(var t=new Array(arguments.length-1),e=1;e<arguments.length;e++)t[e-1]=arguments[e];return function(){for(var e=new Array(arguments.length),r=0;r<e.length;r++)e[r]=arguments[r];var o=t.concat(e);return n.apply(null,o)}},not:function(n){return function(){return!n.apply(null,arguments)}},die:function(n){return function(){throw new Error(n)}},apply:function(n){return n()},call:function(n){n()},never:r(!1),always:r(!0)},i=o.never,u=o.always,a=function(){return c},c=function(){var n=function(n){return n.isNone()},t=function(n){return n()},e=function(n){return n},r={fold:function(n,t){return n()},is:i,isSome:i,isNone:u,getOr:e,getOrThunk:t,getOrDie:function(n){throw new Error(n||"error: getOrDie called on none.")},or:e,orThunk:t,map:a,ap:a,each:function(){},bind:a,flatten:a,exists:i,forall:u,filter:a,equals:n,equals_:n,toArray:function(){return[]},toString:o.constant("none()")};return Object.freeze&&Object.freeze(r),r}(),l=function(n){var t=function(){return n},e=function(){return o},r=function(t){return t(n)},o={fold:function(t,e){return e(n)},is:function(t){return n===t},isSome:u,isNone:i,getOr:t,getOrThunk:t,getOrDie:t,or:e,orThunk:e,map:function(t){return l(t(n))},ap:function(t){return t.fold(a,function(t){return l(t(n))})},each:function(t){t(n)},bind:r,flatten:t,exists:r,forall:r,filter:function(t){return t(n)?o:c},equals:function(t){return t.is(n)},equals_:function(t,e){return t.fold(i,function(t){return e(n,t)})},toArray:function(){return[n]},toString:function(){return"some("+n+")"}};return o},f={some:l,none:a,from:function(n){return null===n||n===undefined?c:l(n)}},s=function(){var n=Array.prototype.indexOf;return n===undefined?function(n,t){return b(n,t)}:function(t,e){return n.call(t,e)}}(),d=function(n,t){return s(n,t)>-1},m=function(n,t){for(var e=n.length,r=new Array(e),o=0;o<e;o++){var i=n[o];r[o]=t(i,o,n)}return r},g=function(n,t){for(var e=0,r=n.length;e<r;e++){t(n[e],e,n)}},p=function(n,t){for(var e=n.length-1;e>=0;e--){t(n[e],e,n)}},h=function(n,t){for(var e=[],r=0,o=n.length;r<o;r++){var i=n[r];t(i,r,n)&&e.push(i)}return e},v=function(n,t){for(var e=0,r=n.length;e<r;e++){if(t(n[e],e,n))return f.some(e)}return f.none()},b=function(n,t){for(var e=0,r=n.length;e<r;++e)if(n[e]===t)return e;return-1},w=Array.prototype.push,y=function(n){for(var t=[],e=0,r=n.length;e<r;++e){if(!Array.prototype.isPrototypeOf(n[e]))throw new Error("Arr.flatten item "+e+" was not an array, input: "+n);w.apply(t,n[e])}return t},x=function(n,t){for(var e=0,r=n.length;e<r;++e){if(!0!==t(n[e],e,n))return!1}return!0},C=Array.prototype.slice,S={map:m,each:g,eachr:p,partition:function(n,t){for(var e=[],r=[],o=0,i=n.length;o<i;o++){var u=n[o];(t(u,o,n)?e:r).push(u)}return{pass:e,fail:r}},filter:h,groupBy:function(n,t){if(0===n.length)return[];for(var e=t(n[0]),r=[],o=[],i=0,u=n.length;i<u;i++){var a=n[i],c=t(a);c!==e&&(r.push(o),o=[]),e=c,o.push(a)}return 0!==o.length&&r.push(o),r},indexOf:function(n,t){var e=s(n,t);return-1===e?f.none():f.some(e)},foldr:function(n,t,e){return p(n,function(n){e=t(e,n)}),e},foldl:function(n,t,e){return g(n,function(n){e=t(e,n)}),e},find:function(n,t){for(var e=0,r=n.length;e<r;e++){var o=n[e];if(t(o,e,n))return f.some(o)}return f.none()},findIndex:v,flatten:y,bind:function(n,t){var e=m(n,t);return y(e)},forall:x,exists:function(n,t){return v(n,t).isSome()},contains:d,equal:function(n,t){return n.length===t.length&&x(n,function(n,e){return n===t[e]})},reverse:function(n){var t=C.call(n,0);return t.reverse(),t},chunk:function(n,t){for(var e=[],r=0;r<n.length;r+=t){var o=n.slice(r,r+t);e.push(o)}return e},difference:function(n,t){return h(n,function(n){return!d(t,n)})},mapToObject:function(n,t){for(var e={},r=0,o=n.length;r<o;r++){var i=n[r];e[String(i)]=t(i,r)}return e},pure:function(n){return[n]},sort:function(n,t){var e=C.call(n,0);return e.sort(t),e},range:function(n,t){for(var e=[],r=0;r<n;r++)e.push(t(r));return e},head:function(n){return 0===n.length?f.none():f.some(n[0])},last:function(n){return 0===n.length?f.none():f.some(n[n.length-1])}},R=function(){var n=Object.keys;return n===undefined?function(n){var t=[];for(var e in n)n.hasOwnProperty(e)&&t.push(e);return t}:n}(),T=function(n,t){for(var e=R(n),r=0,o=e.length;r<o;r++){var i=e[r];t(n[i],i,n)}},D=function(n,t){var e={};return T(n,function(r,o){var i=t(r,o,n);e[i.k]=i.v}),e},A=function(n,t){var e=[];return T(n,function(n,r){e.push(t(n,r))}),e},k=function(n){return A(n,function(n){return n})},N={bifilter:function(n,t){var e={},r={};return T(n,function(n,o){(t(n,o)?e:r)[o]=n}),{t:e,f:r}},each:T,map:function(n,t){return D(n,function(n,e,r){return{k:e,v:t(n,e,r)}})},mapToArray:A,tupleMap:D,find:function(n,t){for(var e=R(n),r=0,o=e.length;r<o;r++){var i=e[r],u=n[i];if(t(u,i,n))return f.some(u)}return f.none()},keys:R,values:k,size:function(n){return k(n).length}},O=function(n){return function(t){return function(n){if(null===n)return"null";var t=typeof n;return"object"===t&&Array.prototype.isPrototypeOf(n)?"array":"object"===t&&String.prototype.isPrototypeOf(n)?"string":t}(t)===n}},B={isString:O("string"),isObject:O("object"),isArray:O("array"),isNull:O("null"),isBoolean:O("boolean"),isUndefined:O("undefined"),isFunction:O("function"),isNumber:O("number")},E=function(n){return n.slice(0).sort()},I=function(n,t){throw new Error("All required keys ("+E(n).join(", ")+") were not specified. Specified keys were: "+E(t).join(", ")+".")},P=function(n){throw new Error("Unsupported keys for object: "+E(n).join(", "))},W=function(n,t){if(!B.isArray(t))throw new Error("The "+n+" fields must be an array. Was: "+t+".");S.each(t,function(t){if(!B.isString(t))throw new Error("The value "+t+" in the "+n+" fields was not a string.")})},_=function(n,t){throw new Error("All values need to be of type: "+t+". Keys ("+E(n).join(", ")+") were not.")},M=function(n){var t=E(n);S.find(t,function(n,e){return e<t.length-1&&n===t[e+1]}).each(function(n){throw new Error("The field: "+n+" occurs more than once in the combined fields: ["+t.join(", ")+"].")})},L={immutable:function(){var n=arguments;return function(){for(var t=new Array(arguments.length),e=0;e<t.length;e++)t[e]=arguments[e];if(n.length!==t.length)throw new Error('Wrong number of arguments to struct. Expected "['+n.length+']", got '+t.length+" arguments");var r={};return S.each(n,function(n,e){r[n]=o.constant(t[e])}),r}},immutableBag:function(n,t){var e=n.concat(t);if(0===e.length)throw new Error("You must specify at least one required or optional field.");return W("required",n),W("optional",t),M(e),function(r){var i=N.keys(r);S.forall(n,function(n){return S.contains(i,n)})||I(n,i);var u=S.filter(i,function(n){return!S.contains(e,n)});u.length>0&&P(u);var a={};return S.each(n,function(n){a[n]=o.constant(r[n])}),S.each(t,function(n){a[n]=o.constant(Object.prototype.hasOwnProperty.call(r,n)?f.some(r[n]):f.none())}),a}}},q=L.immutable("width","height"),z=L.immutable("rows","columns"),F=L.immutable("row","column"),j=L.immutable("x","y"),H=L.immutable("element","rowspan","colspan"),V=L.immutable("element","rowspan","colspan","isNew"),U={dimensions:q,grid:z,address:F,coords:j,extended:L.immutable("element","rowspan","colspan","row","column"),detail:H,detailnew:V,rowdata:L.immutable("element","cells","section"),elementnew:L.immutable("element","isNew"),rowdatanew:L.immutable("element","cells","section","isNew"),rowcells:L.immutable("cells","section"),rowdetails:L.immutable("details","section"),bounds:L.immutable("startRow","startCol","finishRow","finishCol")},G=function(n){if(null===n||n===undefined)throw new Error("Node cannot be null or undefined");return{dom:o.constant(n)}},X={fromHtml:function(n,t){var e=(t||document).createElement("div");if(e.innerHTML=n,!e.hasChildNodes()||e.childNodes.length>1)throw console.error("HTML does not have a single root node",n),"HTML must have a single root node";return G(e.childNodes[0])},fromTag:function(n,t){var e=(t||document).createElement(n);return G(e)},fromText:function(n,t){var e=(t||document).createTextNode(n);return G(e)},fromDom:G,fromPoint:function(n,t,e){return f.from(n.dom().elementFromPoint(t,e)).map(G)}},Y=8,$=9,K=1,J=3,Q=K,Z=$,nn=function(n){return n.nodeType!==Q&&n.nodeType!==Z||0===n.childElementCount},tn=function(n,t){var e=t===undefined?document:t.dom();return nn(e)?[]:S.map(e.querySelectorAll(n),X.fromDom)},en=function(n,t){var e=n.dom();if(e.nodeType!==Q)return!1;if(e.matches!==undefined)return e.matches(t);if(e.msMatchesSelector!==undefined)return e.msMatchesSelector(t);if(e.webkitMatchesSelector!==undefined)return e.webkitMatchesSelector(t);if(e.mozMatchesSelector!==undefined)return e.mozMatchesSelector(t);throw new Error("Browser lacks native selectors")},rn=function(n,t){var e=t===undefined?document:t.dom();return nn(e)?f.none():f.from(e.querySelector(n)).map(X.fromDom)},on=function(n,t){var e=[],r=function(n){return e.push(n),t(n)},o=t(n);do{o=o.bind(r)}while(o.isSome());return e},un="undefined"!=typeof window?window:Function("return this;")(),an=function(n,t){for(var e=t!==undefined&&null!==t?t:un,r=0;r<n.length&&e!==undefined&&null!==e;++r)e=e[n[r]];return e},cn=function(n,t){var e=n.split(".");return an(e,t)},ln=function(n,t){var e=function(n,t){return cn(n,t)}(n,t);if(e===undefined||null===e)throw n+" not available on this browser";return e},fn=function(){return ln("Node")},sn=function(n,t,e){return 0!=(n.compareDocumentPosition(t)&e)},dn=function(n,t){return sn(n,t,fn().DOCUMENT_POSITION_CONTAINED_BY)},mn=function(n){var t,e=!1;return function(){return e||(e=!0,t=n.apply(null,arguments)),t}},gn=function(n,t){var e=function(n,t){for(var e=0;e<n.length;e++){var r=n[e];if(r.test(t))return r}return undefined}(n,t);if(!e)return{major:0,minor:0};var r=function(n){return Number(t.replace(e,"$"+n))};return hn(r(1),r(2))},pn=function(){return hn(0,0)},hn=function(n,t){return{major:n,minor:t}},vn={nu:hn,detect:function(n,t){var e=String(t).toLowerCase();return 0===n.length?pn():gn(n,e)},unknown:pn},bn=function(n,t){return function(){return t===n}},wn=function(n){var t=n.current;return{current:t,version:n.version,isEdge:bn("Edge",t),isChrome:bn("Chrome",t),isIE:bn("IE",t),isOpera:bn("Opera",t),isFirefox:bn("Firefox",t),isSafari:bn("Safari",t)}},yn={unknown:function(){return wn({current:undefined,version:vn.unknown()})},nu:wn,edge:o.constant("Edge"),chrome:o.constant("Chrome"),ie:o.constant("IE"),opera:o.constant("Opera"),firefox:o.constant("Firefox"),safari:o.constant("Safari")},xn=function(n,t){return function(){return t===n}},Cn=function(n){var t=n.current;return{current:t,version:n.version,isWindows:xn("Windows",t),isiOS:xn("iOS",t),isAndroid:xn("Android",t),isOSX:xn("OSX",t),isLinux:xn("Linux",t),isSolaris:xn("Solaris",t),isFreeBSD:xn("FreeBSD",t)}},Sn={unknown:function(){return Cn({current:undefined,version:vn.unknown()})},nu:Cn,windows:o.constant("Windows"),ios:o.constant("iOS"),android:o.constant("Android"),linux:o.constant("Linux"),osx:o.constant("OSX"),solaris:o.constant("Solaris"),freebsd:o.constant("FreeBSD")},Rn=function(n,t){var e=String(t).toLowerCase();return S.find(n,function(n){return n.search(e)})},Tn=function(n,t){return Rn(n,t).map(function(n){var e=vn.detect(n.versionRegexes,t);return{current:n.name,version:e}})},Dn=function(n,t){return Rn(n,t).map(function(n){var e=vn.detect(n.versionRegexes,t);return{current:n.name,version:e}})},An=function(n,t){return t+n},kn=function(n,t){return n+t},Nn=function(n,t){return n.substring(t)},On=function(n,t){return n.substring(0,n.length-t)},Bn=function(n){return""===n?f.none():f.some(n.substr(0,1))},En=function(n){return""===n?f.none():f.some(n.substring(1))},In=function(n,t,e){if(""===t)return!0;if(n.length<t.length)return!1;return n.substr(e,e+t.length)===t},Pn=function(n,t){return In(n,t,0)},Wn=function(n,t){return In(n,t,n.length-t.length)},_n={supplant:function(n,t){return n.replace(/\${([^{}]*)}/g,function(n,e){var r=t[e];return function(n){var t=typeof n;return"string"===t||"number"===t}(r)?r:n})},startsWith:Pn,removeLeading:function(n,t){return Pn(n,t)?Nn(n,t.length):n},removeTrailing:function(n,t){return Wn(n,t)?On(n,t.length):n},ensureLeading:function(n,t){return Pn(n,t)?n:An(n,t)},ensureTrailing:function(n,t){return Wn(n,t)?n:kn(n,t)},endsWith:Wn,contains:function(n,t){return-1!==n.indexOf(t)},trim:function(n){return n.replace(/^\s+|\s+$/g,"")},lTrim:function(n){return n.replace(/^\s+/g,"")},rTrim:function(n){return n.replace(/\s+$/g,"")},capitalize:function(n){return Bn(n).bind(function(t){return En(n).map(function(n){return t.toUpperCase()+n})}).getOr(n)}},Mn=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,Ln=function(n){return function(t){return _n.contains(t,n)}},qn=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:function(n){return _n.contains(n,"edge/")&&_n.contains(n,"chrome")&&_n.contains(n,"safari")&&_n.contains(n,"applewebkit")}},{name:"Chrome",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,Mn],search:function(n){return _n.contains(n,"chrome")&&!_n.contains(n,"chromeframe")}},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:function(n){return _n.contains(n,"msie")||_n.contains(n,"trident")}},{name:"Opera",versionRegexes:[Mn,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:Ln("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:Ln("firefox")},{name:"Safari",versionRegexes:[Mn,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:function(n){return(_n.contains(n,"safari")||_n.contains(n,"mobile/"))&&_n.contains(n,"applewebkit")}}],zn=[{name:"Windows",search:Ln("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:function(n){return _n.contains(n,"iphone")||_n.contains(n,"ipad")},versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:Ln("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"OSX",search:Ln("os x"),versionRegexes:[/.*?os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:Ln("linux"),versionRegexes:[]},{name:"Solaris",search:Ln("sunos"),versionRegexes:[]},{name:"FreeBSD",search:Ln("freebsd"),versionRegexes:[]}],Fn={browsers:o.constant(qn),oses:o.constant(zn)},jn=function(n){var t=Fn.browsers(),e=Fn.oses(),r=Tn(t,n).fold(yn.unknown,yn.nu),i=Dn(e,n).fold(Sn.unknown,Sn.nu);return{browser:r,os:i,deviceType:function(n,t,e){var r=n.isiOS()&&!0===/ipad/i.test(e),i=n.isiOS()&&!r,u=n.isAndroid()&&3===n.version.major,a=n.isAndroid()&&4===n.version.major,c=r||u||a&&!0===/mobile/i.test(e),l=n.isiOS()||n.isAndroid(),f=l&&!c,s=t.isSafari()&&n.isiOS()&&!1===/safari/i.test(e);return{isiPad:o.constant(r),isiPhone:o.constant(i),isTablet:o.constant(c),isPhone:o.constant(f),isTouch:o.constant(l),isAndroid:n.isAndroid,isiOS:n.isiOS,isWebView:o.constant(s)}}(i,r,n)}},Hn={detect:mn(function(){var n=navigator.userAgent;return jn(n)})},Vn=function(n,t){return n.dom()===t.dom()},Un=Hn.detect().browser.isIE()?function(n,t){return dn(n.dom(),t.dom())}:function(n,t){var e=n.dom(),r=t.dom();return e!==r&&e.contains(r)},Gn={eq:Vn,isEqualNode:function(n,t){return n.dom().isEqualNode(t.dom())},member:function(n,t){return S.exists(t,o.curry(Vn,n))},contains:Un,is:en},Xn=function(n){return X.fromDom(n.dom().ownerDocument)},Yn=function(n){var t=n.dom();return f.from(t.parentNode).map(X.fromDom)},$n=function(n){var t=n.dom();return f.from(t.previousSibling).map(X.fromDom)},Kn=function(n){var t=n.dom();return f.from(t.nextSibling).map(X.fromDom)},Jn=function(n){var t=n.dom();return S.map(t.childNodes,X.fromDom)},Qn=function(n,t){var e=n.dom().childNodes;return f.from(e[t]).map(X.fromDom)},Zn=L.immutable("element","offset"),nt={owner:Xn,defaultView:function(n){var t=n.dom().ownerDocument.defaultView;return X.fromDom(t)},documentElement:function(n){var t=Xn(n);return X.fromDom(t.dom().documentElement)},parent:Yn,findIndex:function(n){return Yn(n).bind(function(t){var e=Jn(t);return S.findIndex(e,function(t){return Gn.eq(n,t)})})},parents:function(n,t){for(var e=B.isFunction(t)?t:o.constant(!1),r=n.dom(),i=[];null!==r.parentNode&&r.parentNode!==undefined;){var u=r.parentNode,a=X.fromDom(u);if(i.push(a),!0===e(a))break;r=u}return i},siblings:function(n){return Yn(n).map(Jn).map(function(t){return S.filter(t,function(t){return!Gn.eq(n,t)})}).getOr([])},prevSibling:$n,offsetParent:function(n){var t=n.dom();return f.from(t.offsetParent).map(X.fromDom)},prevSiblings:function(n){return S.reverse(on(n,$n))},nextSibling:Kn,nextSiblings:function(n){return on(n,Kn)},children:Jn,child:Qn,firstChild:function(n){return Qn(n,0)},lastChild:function(n){return Qn(n,n.dom().childNodes.length-1)},childNodesCount:function(n){return n.dom().childNodes.length},hasChildNodes:function(n){return n.dom().hasChildNodes()},leaf:function(n,t){var e=Jn(n);return e.length>0&&t<e.length?Zn(e[t],0):Zn(n,t)}},tt=function(n,t,e){return S.bind(nt.children(n),function(n){return en(n,t)?e(n)?[n]:[]:tt(n,t,e)})},et={firstLayer:function(n,t){return tt(n,t,o.constant(!0))},filterFirstLayer:tt},rt=function(n){return n.dom().nodeName.toLowerCase()},ot=function(n){return n.dom().nodeType},it=function(n){return function(t){return ot(t)===n}},ut=it(K),at=it(J),ct=it($),lt={name:rt,type:ot,value:function(n){return n.dom().nodeValue},isElement:ut,isText:at,isDocument:ct,isComment:function(n){return ot(n)===Y||"#comment"===rt(n)}},ft=function(n,t,e){if(!(B.isString(e)||B.isBoolean(e)||B.isNumber(e)))throw console.error("Invalid call to Attr.set. Key ",t,":: Value ",e,":: Element ",n),new Error("Attribute value was not simple");n.setAttribute(t,e+"")},st=function(n,t,e){ft(n.dom(),t,e)},dt=function(n,t){var e=n.dom().getAttribute(t);return null===e?undefined:e},mt=function(n,t){var e=n.dom();return!(!e||!e.hasAttribute)&&e.hasAttribute(t)},gt=function(n){return S.foldl(n.dom().attributes,function(n,t){return n[t.name]=t.value,n},{})},pt=st,ht=function(n,t){var e=n.dom();N.each(t,function(n,t){ft(e,t,n)})},vt=dt,bt=mt,wt=function(n,t){n.dom().removeAttribute(t)},yt=mn(function(){return xt(X.fromDom(document))}),xt=function(n){var t=n.dom().body;if(null===t||t===undefined)throw"Body is not available yet";return X.fromDom(t)},Ct={body:yt,getBody:xt,inBody:function(n){var t=lt.isText(n)?n.dom().parentNode:n.dom();return t!==undefined&&null!==t&&t.ownerDocument.body.contains(t)}},St=function(n,t){var e=[];return S.each(nt.children(n),function(n){t(n)&&(e=e.concat([n])),e=e.concat(St(n,t))}),e},Rt={all:function(n){return St(Ct.body(),n)},ancestors:function(n,t,e){return S.filter(nt.parents(n,e),t)},siblings:function(n,t){return S.filter(nt.siblings(n),t)},children:function(n,t){return S.filter(nt.children(n),t)},descendants:St},Tt=function(n,t,e){return Rt.ancestors(n,function(n){return en(n,t)},e)},Dt=function(n,t){return Rt.children(n,function(n){return en(n,t)})},At=function(n,t){return tn(t,n)},kt=function(n,t,e,r,o){return n(e,r)?f.some(e):B.isFunction(o)&&o(e)?f.none():t(e,r,o)},Nt=function(n,t,e){for(var r=n.dom(),i=B.isFunction(e)?e:o.constant(!1);r.parentNode;){r=r.parentNode;var u=X.fromDom(r);if(t(u))return f.some(u);if(i(u))break}return f.none()},Ot=function(n,t){return S.find(n.dom().childNodes,o.compose(t,X.fromDom)).map(X.fromDom)},Bt=function(n,t){var e=function(n){for(var r=0;r<n.childNodes.length;r++){if(t(X.fromDom(n.childNodes[r])))return f.some(X.fromDom(n.childNodes[r]));var o=e(n.childNodes[r]);if(o.isSome())return o}return f.none()};return e(n.dom())},Et={first:function(n){return Bt(Ct.body(),n)},ancestor:Nt,closest:function(n,t,e){return kt(function(n){return t(n)},Nt,n,t,e)},sibling:function(n,t){var e=n.dom();return e.parentNode?Ot(X.fromDom(e.parentNode),function(e){return!Gn.eq(n,e)&&t(e)}):f.none()},child:Ot,descendant:Bt},It=function(n,t,e){return Et.ancestor(n,function(n){return en(n,t)},e)},Pt=It,Wt=function(n,t){return Et.child(n,function(n){return en(n,t)})},_t=function(n,t){return rn(t,n)},Mt=function(n,t,e){return kt(en,It,n,t,e)},Lt=function(n,t,e){var r=e!==undefined?e:o.constant(!1);if(r(t))return f.none();if(S.contains(n,lt.name(t)))return f.some(t);return Pt(t,n.join(","),function(n){return en(n,"table")||r(n)})},qt=function(n,t){return nt.parent(t).map(function(t){return Dt(t,n)})},zt=function(n,t){return Lt(["td","th"],n,t)},Ft=function(n){return et.firstLayer(n,"th,td")},jt=(o.curry(qt,"th,td"),function(n,t){return Mt(n,"table",t)}),Ht=function(n){return et.firstLayer(n,"tr")},Vt=(o.curry(qt,"tr"),function(n){var t=Ht(n);return S.map(t,function(n){var t=n,e=nt.parent(t).bind(function(n){var t=lt.name(n);return"tfoot"===t||"thead"===t||"tbody"===t?t:"tbody"}),r=S.map(Ft(n),function(n){var t=bt(n,"rowspan")?parseInt(vt(n,"rowspan"),10):1,e=bt(n,"colspan")?parseInt(vt(n,"colspan"),10):1;return U.detail(n,t,e)});return U.rowdata(t,r,e)})}),Ut=function(n,t){return S.map(n,function(n){var e=S.map(Ft(n),function(n){var t=bt(n,"rowspan")?parseInt(vt(n,"rowspan"),10):1,e=bt(n,"colspan")?parseInt(vt(n,"colspan"),10):1;return U.detail(n,t,e)});return U.rowdata(n,e,t.section())})},Gt=function(n,t){return n+","+t},Xt=function(n,t){var e=S.bind(n.all(),function(n){return n.cells()});return S.filter(e,t)},Yt={generate:function(n){var t={},e=[],r=n.length,i=0;S.each(n,function(n,r){var o=[];S.each(n.cells(),function(n,e){for(var u=0;t[Gt(r,u)]!==undefined;)u++;for(var a=U.extended(n.element(),n.rowspan(),n.colspan(),r,u),c=0;c<n.colspan();c++)for(var l=0;l<n.rowspan();l++){var f=u+c,s=Gt(r+l,f);t[s]=a,i=Math.max(i,f+1)}o.push(a)}),e.push(U.rowdata(n.element(),o,n.section()))});var u=U.grid(r,i);return{grid:o.constant(u),access:o.constant(t),all:o.constant(e)}},getAt:function(n,t,e){var r=n.access()[Gt(t,e)];return r!==undefined?f.some(r):f.none()},findItem:function(n,t,e){var r=Xt(n,function(n){return e(t,n.element())});return r.length>0?f.some(r[0]):f.none()},filterItems:Xt,justCells:function(n){var t=S.map(n.all(),function(n){return n.cells()});return S.flatten(t)}},$t=function(n){return n.style!==undefined},Kt=function(n,t,e){if(!B.isString(e))throw console.error("Invalid call to CSS.set. Property ",t,":: Value ",e,":: Element ",n),new Error("CSS value must be a string: "+e);$t(n)&&n.style.setProperty(t,e)},Jt=function(n,t){$t(n)&&n.style.removeProperty(t)},Qt=function(n,t,e){var r=n.dom();Kt(r,t,e)},Zt=function(n,t){return $t(n)?n.style.getPropertyValue(t):""},ne=function(n,t){var e=n.dom(),r=Zt(e,t);return f.from(r).filter(function(n){return n.length>0})},te=function(n,t){var e=n.dom(),r=t.dom();$t(e)&&$t(r)&&(r.style.cssText=e.style.cssText)},ee=Qt,re=function(n,t){var e=n.dom();N.each(t,function(n,t){Kt(e,t,n)})},oe=function(n,t){var e=n.dom();Jt(e,t),bt(n,"style")&&""===_n.trim(vt(n,"style"))&&wt(n,"style")},ie=function(n,t){var e=n.dom(),r=window.getComputedStyle(e).getPropertyValue(t),o=""!==r||Ct.inBody(n)?r:Zt(e,t);return null===o?undefined:o},ue=ne,ae=function(n,t){nt.parent(n).each(function(e){e.dom().insertBefore(t.dom(),n.dom())})},ce=function(n,t){n.dom().appendChild(t.dom())},le={before:ae,after:function(n,t){nt.nextSibling(n).fold(function(){nt.parent(n).each(function(n){ce(n,t)})},function(n){ae(n,t)})},prepend:function(n,t){nt.firstChild(n).fold(function(){ce(n,t)},function(e){n.dom().insertBefore(t.dom(),e.dom())})},append:ce,appendAt:function(n,t,e){nt.child(n,e).fold(function(){ce(n,t)},function(n){ae(n,t)})},wrap:function(n,t){ae(n,t),ce(t,n)}},fe=function(n,t){S.each(t,function(t){le.before(n,t)})},se=function(n,t){S.each(t,function(e,r){var o=0===r?n:t[r-1];le.after(o,e)})},de=function(n,t){S.each(t,function(t){le.append(n,t)})},me=function(n){var t=n.dom();null!==t.parentNode&&t.parentNode.removeChild(t)},ge={empty:function(n){n.dom().textContent="",S.each(nt.children(n),function(n){me(n)})},remove:me,unwrap:function(n){var t=nt.children(n);t.length>0&&fe(n,t),me(n)}},pe=L.immutable("minRow","minCol","maxRow","maxCol"),he=function(n,t,e){var r=n[e].element(),o=X.fromTag("td");le.append(o,X.fromTag("br"));(t?le.append:le.prepend)(r,o)},ve=function(n,t){var e=function(n){return en(n.element(),t)},r=Vt(n),o=Yt.generate(r),i=function(n,t){var e=n.grid().columns(),r=n.grid().rows(),o=e,i=0,u=0;return N.each(n.access(),function(n){if(t(n)){var e=n.row(),a=e+n.rowspan()-1,c=n.column(),l=c+n.colspan()-1;e<r?r=e:a>i&&(i=a),c<o?o=c:l>u&&(u=l)}}),pe(r,o,i,u)}(o,e),u="th:not("+t+"),td:not("+t+")",a=et.filterFirstLayer(n,"th,td",function(n){return en(n,u)});return S.each(a,ge.remove),function(n,t,e,r){for(var o=t.grid().columns(),i=t.grid().rows(),u=0;u<i;u++)for(var a=!1,c=0;c<o;c++)u<e.minRow()||u>e.maxRow()||c<e.minCol()||c>e.maxCol()||(Yt.getAt(t,u,c).filter(r).isNone()?he(n,a,u):a=!0)}(r,o,i,e),function(n,t){var e=S.filter(et.firstLayer(n,"tr"),function(n){return 0===n.dom().childElementCount});S.each(e,ge.remove),t.minCol()!==t.maxCol()&&t.minRow()!==t.maxRow()||S.each(et.firstLayer(n,"th,td"),function(n){wt(n,"rowspan"),wt(n,"colspan")}),wt(n,"width"),wt(n,"height"),oe(n,"width"),oe(n,"height")}(n,i),n},be=function(n,t){return X.fromDom(n.dom().cloneNode(t))},we=function(n){return be(n,!0)},ye=function(n,t){var e=X.fromTag(t),r=gt(n);return ht(e,r),e},xe=function(n){return be(n,!1)},Ce=we,Se=function(n,t){var e=ye(n,t),r=nt.children(we(n));return de(e,r),e},Re=function(n,t){var e=function(t){return n(t)?f.from(t.dom().nodeValue):f.none()},r=Hn.detect().browser,o=r.isIE()&&10===r.version.major?function(n){try{return e(n)}catch(t){return f.none()}}:e;return{get:function(e){if(!n(e))throw new Error("Can only get "+t+" value of a "+t+" node");return o(e).getOr("")},getOption:o,set:function(e,r){if(!n(e))throw new Error("Can only set raw "+t+" value of a "+t+" node");e.dom().nodeValue=r}}}(lt.isText,"text"),Te=function(n){return Re.get(n)},De=function(n){return Re.getOption(n)},Ae=function(n,t){Re.set(n,t)},ke=function(n){return"img"===lt.name(n)?1:De(n).fold(function(){return nt.children(n).length},function(n){return n.length})},Ne=["img","br"],Oe=ke,Be=function(n){return function(n){return De(n).filter(function(n){return 0!==n.trim().length||n.indexOf("\xa0")>-1}).isSome()}(n)||S.contains(Ne,lt.name(n))},Ee=function(n,t){var e=function(n){for(var r=nt.children(n),o=r.length-1;o>=0;o--){var i=r[o];if(t(i))return f.some(i);var u=e(i);if(u.isSome())return u}return f.none()};return e(n)},Ie=function(n){return Et.descendant(n,Be)},Pe=function(n){return Ee(n,Be)},We=function(){var n=X.fromTag("td");return le.append(n,X.fromTag("br")),n},_e=function(n,t,e){var r=Se(n,t);return N.each(e,function(n,t){null===n?wt(r,t):pt(r,t,n)}),r},Me=function(n){return n},Le=function(n){return function(){return X.fromTag("tr",n.dom())}},qe=function(n,t,e){return{row:Le(t),cell:function(t){var r=nt.owner(t.element()),o=X.fromTag(lt.name(t.element()),r.dom()),i=e.getOr(["strong","em","b","i","span","font","h1","h2","h3","h4","h5","h6","p","div"]),u=i.length>0?function(n,t,e){return Ie(n).map(function(r){var o=e.join(","),i=Tt(r,o,function(t){return Gn.eq(t,n)});return S.foldr(i,function(n,t){var e=xe(t);return le.append(n,e),e},t)}).getOr(t)}(t.element(),o,i):o;return le.append(u,X.fromTag("br")),te(t.element(),o),oe(o,"height"),1!==t.colspan()&&oe(t.element(),"width"),n(t.element(),o),o},replace:_e,gap:We}},ze=function(n){return{row:Le(n),cell:We,replace:Me,gap:We}},Fe=function(n,t){var e=(t||document).createElement("div");return e.innerHTML=n,nt.children(X.fromDom(e))},je=["body","p","div","article","aside","figcaption","figure","footer","header","nav","section","ol","ul","li","table","thead","tbody","tfoot","caption","tr","td","th","h1","h2","h3","h4","h5","h6","blockquote","pre","address"],He=function(){return{up:o.constant({selector:Pt,closest:Mt,predicate:Et.ancestor,all:nt.parents}),down:o.constant({selector:At,predicate:Rt.descendants}),styles:o.constant({get:ie,getRaw:ue,set:ee,remove:oe}),attrs:o.constant({get:vt,set:pt,remove:wt,copyTo:function(n,t){var e=gt(n);ht(t,e)}}),insert:o.constant({before:le.before,after:le.after,afterAll:se,append:le.append,appendAll:de,prepend:le.prepend,wrap:le.wrap}),remove:o.constant({unwrap:ge.unwrap,remove:ge.remove}),create:o.constant({nu:X.fromTag,clone:function(n){return X.fromDom(n.dom().cloneNode(!1))},text:X.fromText}),query:o.constant({comparePosition:function(n,t){return n.dom().compareDocumentPosition(t.dom())},prevSibling:nt.prevSibling,nextSibling:nt.nextSibling}),property:o.constant({children:nt.children,name:lt.name,parent:nt.parent,isText:lt.isText,isComment:lt.isComment,isElement:lt.isElement,getText:Te,setText:Ae,isBoundary:function(n){return!!lt.isElement(n)&&("body"===lt.name(n)||S.contains(je,lt.name(n)))},isEmptyTag:function(n){return!!lt.isElement(n)&&S.contains(["br","img","hr","input"],lt.name(n))}}),eq:Gn.eq,is:Gn.is}},Ve=(L.immutable("left","right"),function(n,t,e,r){var o=t(n,e);return S.foldr(r,function(e,r){var o=t(n,r);return Ue(n,e,o)},o)}),Ue=function(n,t,e){return t.bind(function(t){return e.filter(o.curry(n.eq,t))})},Ge=function(n,t,e){return e.length>0?function(n,t,e,r){return r(n,t,e[0],e.slice(1))}(n,t,e,Ve):f.none()},Xe=function(n,t){return o.curry(n.eq,t)},Ye=function(n,t,e,r){var i=r!==undefined?r:o.constant(!1),u=[t].concat(n.up().all(t)),a=[e].concat(n.up().all(e)),c=function(n){return S.findIndex(n,i).fold(function(){return n},function(t){return n.slice(0,t+1)})},l=c(u),f=c(a),s=S.find(l,function(t){return S.exists(f,Xe(n,t))});return{firstpath:o.constant(l),secondpath:o.constant(f),shared:o.constant(s)}},$e=Ye,Ke=function(n,t,e){return Ge(n,t,e)},Je=function(n,t,e,r){return $e(n,t,e,r)},Qe=He(),Ze=function(n,t){return Ke(Qe,function(t,e){return n(e)},t)},nr=function(n,t,e){return Je(Qe,n,t,e)},tr=function(n,t){return t.column()>=n.startCol()&&t.column()+t.colspan()-1<=n.finishCol()&&t.row()>=n.startRow()&&t.row()+t.rowspan()-1<=n.finishRow()},er=function(n,t){var e=t.column(),r=t.column()+t.colspan()-1,o=t.row(),i=t.row()+t.rowspan()-1;return e<=n.finishCol()&&r>=n.startCol()&&o<=n.finishRow()&&i>=n.startRow()},rr=function(n,t){for(var e=!0,r=o.curry(tr,t),i=t.startRow();i<=t.finishRow();i++)for(var u=t.startCol();u<=t.finishCol();u++)e=e&&Yt.getAt(n,i,u).exists(r);return e?f.some(t):f.none()},or=function(n,t,e){var r=Yt.findItem(n,t,Gn.eq),o=Yt.findItem(n,e,Gn.eq);return r.bind(function(n){return o.map(function(t){return function(n,t){return U.bounds(Math.min(n.row(),t.row()),Math.min(n.column(),t.column()),Math.max(n.row()+n.rowspan()-1,t.row()+t.rowspan()-1),Math.max(n.column()+n.colspan()-1,t.column()+t.colspan()-1))}(n,t)})})},ir=or,ur=function(n,t,e){return or(n,t,e).bind(function(t){return rr(n,t)})},ar=function(n,t,e,r){return Yt.findItem(n,t,Gn.eq).bind(function(t){var o=e>0?t.row()+t.rowspan()-1:t.row(),i=r>0?t.column()+t.colspan()-1:t.column();return Yt.getAt(n,o+e,i+r).map(function(n){return n.element()})})},cr=function(n,t,e){return ir(n,t,e).map(function(t){var e=Yt.filterItems(n,o.curry(er,t));return S.map(e,function(n){return n.element()})})},lr=function(n,t){return Yt.findItem(n,t,function(n,t){return Gn.contains(t,n)}).bind(function(n){return n.element()})},fr=function(n){var t=Vt(n);return Yt.generate(t)},sr=function(n,t,e){return jt(n).bind(function(r){var o=fr(r);return ar(o,n,t,e)})},dr=function(n,t,e){var r=fr(n);return cr(r,t,e)},mr=function(n,t,e,r,o){var i=fr(n),u=Gn.eq(n,e)?t:lr(i,t),a=Gn.eq(n,o)?r:lr(i,r);return cr(i,u,a)},gr=function(n,t,e){var r=fr(n);return ur(r,t,e)},pr=function(n,t){return Pt(n,"table")},hr=L.immutableBag(["boxes","start","finish"],[]),vr=function(n,t,e){var r=function(n){return function(t){return e(t)||Gn.eq(t,n)}};return Gn.eq(n,t)?f.some(hr({boxes:f.some([n]),start:n,finish:t})):pr(n).bind(function(o){return pr(t).bind(function(i){if(Gn.eq(o,i))return f.some(hr({boxes:dr(o,n,t),start:n,finish:t}));if(Gn.contains(o,i)){var u=(a=Tt(t,"td,th",r(o))).length>0?a[a.length-1]:t;return f.some(hr({boxes:mr(o,n,o,t,i),start:n,finish:u}))}if(Gn.contains(i,o)){var a,c=(a=Tt(n,"td,th",r(i))).length>0?a[a.length-1]:n;return f.some(hr({boxes:mr(i,n,o,t,i),start:n,finish:c}))}return nr(n,t).shared().bind(function(u){return Mt(u,"table",e).bind(function(e){var u=Tt(t,"td,th",r(e)),a=u.length>0?u[u.length-1]:t,c=Tt(n,"td,th",r(e)),l=c.length>0?c[c.length-1]:n;return f.some(hr({boxes:mr(e,n,o,t,i),start:l,finish:a}))})})})})},br=vr,wr=function(n,t){var e=At(n,t);return e.length>0?f.some(e):f.none()},yr=function(n,t,e,r,i){return function(n,t){return S.find(n,function(n){return en(n,t)})}(n,i).bind(function(n){return sr(n,t,e).bind(function(n){return function(n,t){return Pt(n,"table").bind(function(e){return _t(e,t).bind(function(t){return vr(t,n).bind(function(n){return n.boxes().map(function(t){return{boxes:o.constant(t),start:o.constant(n.start()),finish:o.constant(n.finish())}})})})})}(n,r)})})},xr=function(n,t,e){return _t(n,t).bind(function(t){return _t(n,e).bind(function(n){return Ze(pr,[t,n]).map(function(e){return{first:o.constant(t),last:o.constant(n),table:o.constant(e)}})})})},Cr=function(n,t){return wr(n,t)},Sr=function(n,t,e){return xr(n,t,e).bind(function(t){var e=function(t){return Gn.eq(n,t)},r=Pt(t.first(),"thead,tfoot,tbody,table",e),o=Pt(t.last(),"thead,tfoot,tbody,table",e);return r.bind(function(n){return o.bind(function(e){return Gn.eq(n,e)?gr(t.table(),t.first(),t.last()):f.none()})})})},Rr="data-mce-selected",Tr="data-mce-first-selected",Dr="data-mce-last-selected",Ar={selected:o.constant(Rr),selectedSelector:o.constant("td[data-mce-selected],th[data-mce-selected]"),attributeSelector:o.constant("[data-mce-selected]"),firstSelected:o.constant(Tr),firstSelectedSelector:o.constant("td[data-mce-first-selected],th[data-mce-first-selected]"),lastSelected:o.constant(Dr),lastSelectedSelector:o.constant("td[data-mce-last-selected],th[data-mce-last-selected]")},kr=function(n){if(!B.isArray(n))throw new Error("cases must be an array");if(0===n.length)throw new Error("there must be at least one case");var t=[],e={};return S.each(n,function(r,o){var i=N.keys(r);if(1!==i.length)throw new Error("one and only one name per case");var u=i[0],a=r[u];if(e[u]!==undefined)throw new Error("duplicate key detected:"+u);if("cata"===u)throw new Error("cannot have a case named cata (sorry)");if(!B.isArray(a))throw new Error("case arguments must be an array");t.push(u),e[u]=function(){var e=arguments.length;if(e!==a.length)throw new Error("Wrong number of arguments to case "+u+". Expected "+a.length+" ("+a+"), got "+e);for(var r=new Array(e),i=0;i<r.length;i++)r[i]=arguments[i];return{fold:function(){if(arguments.length!==n.length)throw new Error("Wrong number of arguments to fold. Expected "+n.length+", got "+arguments.length);return arguments[o].apply(null,r)},match:function(n){var e=N.keys(n);if(t.length!==e.length)throw new Error("Wrong number of arguments to match. Expected: "+t.join(",")+"\nActual: "+e.join(","));if(!S.forall(t,function(n){return S.contains(e,n)}))throw new Error("Not all branches were specified when using match. Specified: "+e.join(", ")+"\nRequired: "+t.join(", "));return n[u].apply(null,r)},log:function(n){console.log(n,{constructors:t,constructor:u,params:r})}}}}),e},Nr=kr([{none:[]},{multiple:["elements"]},{single:["selection"]}]),Or={cata:function(n,t,e,r){return n.fold(t,e,r)},none:Nr.none,multiple:Nr.multiple,single:Nr.single},Br=function(n,t){return Or.cata(t.get(),o.constant([]),o.identity,o.constant([n]))},Er=function(n,t){return Or.cata(t.get(),f.none,function(t,e){return 0===t.length?f.none():Sr(n,Ar.firstSelectedSelector(),Ar.lastSelectedSelector()).bind(function(n){return t.length>1?f.some({bounds:o.constant(n),cells:o.constant(t)}):f.none()})},f.none)},Ir=function(n,t){var e=Br(n,t);return e.length>0&&S.forall(e,function(n){return bt(n,"rowspan")&&parseInt(vt(n,"rowspan"),10)>1||bt(n,"colspan")&&parseInt(vt(n,"colspan"),10)>1})?f.some(e):f.none()},Pr=Br,Wr=function(n){return{element:o.constant(n),mergable:f.none,unmergable:f.none,selection:o.constant([n])}},_r=L.immutable("element","clipboard","generators"),Mr={noMenu:Wr,forMenu:function(n,t,e){return{element:o.constant(e),mergable:o.constant(Er(t,n)),unmergable:o.constant(Ir(e,n)),selection:o.constant(Pr(e,n))}},notCell:function(n){return Wr(n)},paste:_r,pasteRows:function(n,t,e,r,i){return{element:o.constant(e),mergable:f.none,unmergable:f.none,selection:o.constant(Pr(e,n)),clipboard:o.constant(r),generators:o.constant(i)}}},Lr={registerEvents:function(n,t,e,r){n.on("BeforeGetContent",function(e){!0===e.selection&&Or.cata(t.get(),o.noop,function(t){e.preventDefault(),function(n){return jt(n[0]).map(Ce).map(function(n){return[ve(n,Ar.attributeSelector())]})}(t).each(function(t){e.content=S.map(t,function(t){return function(n,t){return n.selection.serializer.serialize(t.dom(),{})}(n,t)}).join("")})},o.noop)}),n.on("BeforeSetContent",function(t){!0===t.selection&&!0===t.paste&&f.from(n.dom.getParent(n.selection.getStart(),"th,td")).each(function(o){var i=X.fromDom(o);jt(i).bind(function(o){var u=S.filter(Fe(t.content),function(n){return"meta"!==lt.name(n)});if(1===u.length&&"table"===lt.name(u[0])){t.preventDefault();var a=X.fromDom(n.getDoc()),c=ze(a),l=Mr.paste(i,u[0],c);e.pasteCells(o,l).each(function(t){n.selection.setRng(t),n.focus(),r.clear(o)})}})})})}},qr=function(){return X.fromTag("tr")},zr=function(){return X.fromTag("th")},Fr=function(){return X.fromTag("td")},jr={render:function(n,t,e,r){var o=X.fromTag("table");re(o,{"border-collapse":"collapse",width:"100%"}),pt(o,"border","1");var i=X.fromTag("tbody");le.append(o,i);for(var u=[],a=0;a<n;a++){for(var c=qr(),l=0;l<t;l++){var f=a<e||l<r?zr():Fr();l<r&&pt(f,"scope","row"),a<e&&pt(f,"scope","col"),le.append(f,X.fromTag("br")),ee(f,"width",100/t+"%"),le.append(c,f)}u.push(c)}return de(i,u),o}},Hr=function(n){return n.dom().innerHTML},Vr=function(n){var t=X.fromTag("div"),e=X.fromDom(n.dom().cloneNode(!0));return le.append(t,e),Hr(t)},Ur=function(n,t){n.selection.select(t.dom(),!0),n.selection.collapse(!0)},Gr={insert:function(n,t,e){var r,i=jr.render(e,t,0,0);pt(i,"id","__mce");var u=Vr(i);return n.insertContent(u),r=n.dom.get("__mce"),n.dom.setAttrib(r,"id",null),n.$("tr",r).each(function(t,e){n.fire("newrow",{node:e}),n.$("th,td",e).each(function(t,e){n.fire("newcell",{node:e})})}),n.dom.setAttribs(r,n.settings.table_default_attributes||{}),n.dom.setStyles(r,n.settings.table_default_styles||{}),function(n,t){_t(t,"td,th").each(o.curry(Ur,n))}(n,X.fromDom(r)),r}},Xr=function(n,t){var e=function(e){var r=t(e);if(r<=0||null===r){var o=ie(e,n);return parseFloat(o)||0}return r},r=function(n,t){return S.foldl(t,function(t,e){var r=ie(n,e),o=r===undefined?0:parseInt(r,10);return isNaN(o)?t:t+o},0)};return{set:function(t,e){if(!B.isNumber(e)&&!e.match(/^[0-9]+$/))throw n+".set accepts only positive integer values. Value was "+e;var r=t.dom();$t(r)&&(r.style[n]=e+"px")},get:e,getOuter:e,aggregate:r,max:function(n,t,e){var o=r(n,e);return t>o?t-o:0}}},Yr=Xr("height",function(n){return Ct.inBody(n)?n.dom().getBoundingClientRect().height:n.dom().offsetHeight}),$r=function(n){return Yr.get(n)},Kr=function(n){return Yr.getOuter(n)},Jr=Xr("width",function(n){return n.dom().offsetWidth}),Qr=function(n){return Jr.get(n)},Zr=function(n){return Jr.getOuter(n)},no=Hn.detect(),to=function(n,t,e){return function(n,t){var e=parseFloat(n);return isNaN(e)?t:e}(ie(n,t),e)},eo=function(n){return no.browser.isIE()||no.browser.isEdge()?function(n){var t=to(n,"padding-top",0),e=to(n,"padding-bottom",0),r=to(n,"border-top-width",0),o=to(n,"border-bottom-width",0),i=n.dom().getBoundingClientRect().height;return"border-box"===ie(n,"box-sizing")?i:i-t-e-(r+o)}(n):to(n,"height",$r(n))},ro=/(\d+(\.\d+)?)(\w|%)*/,oo=/(\d+(\.\d+)?)%/,io=/(\d+(\.\d+)?)px|em/,uo=function(n,t){ee(n,"height",t+"px")},ao=function(n,t,e,r){var o=parseInt(n,10);return _n.endsWith(n,"%")&&"table"!==lt.name(t)?function(n,t,e,r){var o=jt(n).map(function(n){var r=e(n);return Math.floor(t/100*r)}).getOr(t);return r(n,o),o}(t,o,e,r):o},co=function(n){var t=function(n){return ue(n,"height").getOrThunk(function(){return eo(n)+"px"})}(n);return t?ao(t,n,$r,uo):$r(n)},lo=function(n,t){return bt(n,t)?parseInt(vt(n,t),10):1},fo=function(n){return ue(n,"width").fold(function(){return f.from(vt(n,"width"))},function(n){return f.some(n)})},so=function(n,t){return n/t.pixelWidth()*100},mo={percentageBasedSizeRegex:o.constant(oo),pixelBasedSizeRegex:o.constant(io),setPixelWidth:function(n,t){ee(n,"width",t+"px")},setPercentageWidth:function(n,t){ee(n,"width",t+"%")},setHeight:uo,getPixelWidth:function(n,t){return fo(n).fold(function(){var t=Qr(n);return parseInt(t,10)},function(e){return function(n,t,e){if(io.test(t)){var r=io.exec(t);return parseInt(r[1],10)}if(oo.test(t)){var o=oo.exec(t);return function(n,t){return n/100*t.pixelWidth()}(parseFloat(o[1]),e)}var i=Qr(n);return parseInt(i,10)}(n,e,t)})},getPercentageWidth:function(n,t){return fo(n).fold(function(){var e=Qr(n),r=parseInt(e,10);return so(r,t)},function(e){return function(n,t,e){if(oo.test(t)){var r=oo.exec(t);return parseFloat(r[1])}var o=Qr(n),i=parseInt(o,10);return so(i,e)}(n,e,t)})},getGenericWidth:function(n){return fo(n).bind(function(n){if(ro.test(n)){var t=ro.exec(n);return f.some({width:o.constant(t[1]),unit:o.constant(t[3])})}return f.none()})},setGenericWidth:function(n,t,e){ee(n,"width",t+e)},getHeight:function(n){return function(n,t,e){return e(n)/lo(n,t)}(n,"rowspan",co)},getRawWidth:fo},go=function(n,t){mo.getGenericWidth(n).each(function(e){var r=e.width()/2;mo.setGenericWidth(n,r,e.unit()),mo.setGenericWidth(t,r,e.unit())})},po=function(n,t){var e=t||X.fromDom(document.documentElement);return Et.ancestor(n,o.curry(Gn.eq,e)).isSome()},ho=function(n){var t=n.dom();return t===t.window?n:lt.isDocument(n)?t.defaultView||t.parentWindow:null},vo=function(n,t){return{left:o.constant(n),top:o.constant(t),translate:function(e,r){return vo(n+e,t+r)}}},bo=function(n,t){return n!==undefined?n:t!==undefined?t:0},wo=function(n){var t=n.dom(),e=t.ownerDocument,r=e.body,o=X.fromDom(e.documentElement);return r===t?vo(r.offsetLeft,r.offsetTop):po(n,o)?function(n){var t=n.getBoundingClientRect();return vo(t.left,t.top)}(t):vo(0,0)},yo=function(n){var t=n.dom().ownerDocument,e=t.body,r=ho(X.fromDom(t)),o=t.documentElement,i=bo(r.pageYOffset,o.scrollTop),u=bo(r.pageXOffset,o.scrollLeft),a=bo(o.clientTop,e.clientTop),c=bo(o.clientLeft,e.clientLeft);return wo(n).translate(u-c,i-a)},xo=L.immutable("row","y"),Co=L.immutable("col","x"),So=function(n){return yo(n).left()+Zr(n)},Ro=function(n){return yo(n).left()},To=function(n,t){return Co(n,Ro(t))},Do=function(n,t){return Co(n,So(t))},Ao=function(n){return yo(n).top()},ko=function(n,t,e){if(0===e.length)return[];var r=S.map(e.slice(1),function(t,e){return t.map(function(t){return n(e,t)})}),o=e[e.length-1].map(function(n){return t(e.length-1,n)});return r.concat([o])},No={delta:o.identity,positions:o.curry(ko,function(n,t){return xo(n,Ao(t))},function(n,t){return xo(n,Ao(t)+Kr(t))}),edge:Ao},Oo={delta:o.identity,edge:Ro,positions:o.curry(ko,To,Do)},Bo={height:No,rtl:{delta:function(n,t){return-n},edge:So,positions:o.curry(ko,Do,To)},ltr:Oo},Eo={ltr:Bo.ltr,rtl:Bo.rtl},Io=function(n){var t=function(t){return n(t).isRtl()?Eo.rtl:Eo.ltr};return{delta:function(n,e){return t(e).delta(n,e)},edge:function(n){return t(n).edge(n)},positions:function(n,e){return t(e).positions(n,e)}}},Po=function(n){var t=Vt(n);return Yt.generate(t).grid()},Wo=function(n){var t=n,e=function(){return t};return{get:e,set:function(n){t=n},clone:function(){return Wo(e())}}},_o=function(n,t){return Mo(n,t,{validate:B.isFunction,label:"function"})},Mo=function(n,t,e){if(0===t.length)throw new Error("You must specify at least one required field.");return W("required",t),M(t),function(r){var o=N.keys(r);S.forall(t,function(n){return S.contains(o,n)})||I(t,o),n(t,o);var i=S.filter(t,function(n){return!e.validate(r[n],n)});return i.length>0&&_(i,e.label),r}},Lo=o.noop,qo={exactly:o.curry(_o,function(n,t){var e=S.filter(t,function(t){return!S.contains(n,t)});e.length>0&&P(e)}),ensure:o.curry(_o,Lo),ensureWith:o.curry(Mo,Lo)},zo=function(n){var t=bt(n,"colspan")?parseInt(vt(n,"colspan"),10):1,e=bt(n,"rowspan")?parseInt(vt(n,"rowspan"),10):1;return{element:o.constant(n),colspan:o.constant(t),rowspan:o.constant(e)}},Fo=qo.exactly(["cell","row","replace","gap"]),jo=function(n,t){Fo(n);var e=Wo(f.none()),r=t!==undefined?t:zo,o=function(t){return function(t){return n.cell(t)}(r(t))},i=function(n){var t=o(n);return e.get().isNone()&&e.set(f.some(t)),u=f.some({item:n,replacement:t}),t},u=f.none();return{getOrInit:function(n,t){return u.fold(function(){return i(n)},function(e){return t(n,e.item)?e.replacement:i(n)})},cursor:e.get}},Ho=function(n,t){return function(e){var r=Wo(f.none());Fo(e);var o=[],i=function(i){var u=e.replace(i,t,{scope:n});return o.push({item:i,sub:u}),r.get().isNone()&&r.set(f.some(u)),u};return{replaceOrInit:function(n,t){return function(n,t){return S.find(o,function(e){return t(e.item,n)})}(n,t).fold(function(){return i(n)},function(e){return t(n,e.item)?e.sub:i(n)})},cursor:r.get}}},Vo=function(n){Fo(n);var t=Wo(f.none());return{combine:function(e){return t.get().isNone()&&t.set(f.some(e)),function(){var t=n.cell({element:o.constant(e),colspan:o.constant(1),rowspan:o.constant(1)});return oe(t,"width"),oe(e,"width"),t}},cursor:t.get}},Uo=["body","p","div","article","aside","figcaption","figure","footer","header","nav","section","ol","ul","table","thead","tfoot","tbody","caption","tr","td","th","h1","h2","h3","h4","h5","h6","blockquote","pre","address"],Go=function(n,t){var e=n.property().name(t);return S.contains(Uo,e)},Xo=function(n,t){return S.contains(["br","img","hr","input"],n.property().name(t))},Yo=Go,$o=function(n,t){var e=n.property().name(t);return S.contains(["ol","ul"],e)},Ko=Xo,Jo=He(),Qo=function(n){return Yo(Jo,n)},Zo=function(n){return $o(Jo,n)},ni=function(n){return Ko(Jo,n)},ti=function(n){var t=function(n){return"br"===lt.name(n)},e=function(n){return Pe(n).bind(function(e){var r=function(n){return nt.nextSibling(n).map(function(n){return!!Qo(n)||(ni(n)?"img"!==lt.name(n):void 0)}).getOr(!1)}(e);return nt.parent(e).map(function(o){return!0===r||function(n){return"li"===lt.name(n)||Et.ancestor(n,Zo).isSome()}(o)||t(e)||Qo(o)&&!Gn.eq(n,o)?[]:[X.fromTag("br")]})}).getOr([])},r=function(){var r=S.bind(n,function(n){var r=nt.children(n);return function(n){return S.forall(n,function(n){return t(n)||lt.isText(n)&&0===Te(n).trim().length})}(r)?[]:r.concat(e(n))});return 0===r.length?[X.fromTag("br")]:r}();ge.empty(n[0]),de(n[0],r)},ei=function(n){return function(){for(var t=new Array(arguments.length),e=0;e<t.length;e++)t[e]=arguments[e];if(0===t.length)throw new Error("Can't merge zero objects");for(var r={},o=0;o<t.length;o++){var i=t[o];for(var u in i)i.hasOwnProperty(u)&&(r[u]=n(r[u],i[u]))}return r}},ri=ei(function(n,t){return B.isObject(n)&&B.isObject(t)?ri(n,t):t}),oi=ei(function(n,t){return t}),ii={deepMerge:ri,merge:oi},ui=function(n){for(var t=[],e=function(n){t.push(n)},r=0;r<n.length;r++)n[r].each(e);return t},ai=function(n,t){for(var e=0;e<n.length;e++){var r=t(n[e],e);if(r.isSome())return r}return f.none()},ci=function(n,t){return U.rowcells(t,n.section())},li=function(n,t){return n.cells()[t]},fi={addCell:function(n,t,e){var r=n.cells(),o=r.slice(0,t),i=r.slice(t),u=o.concat([e]).concat(i);return ci(n,u)},setCells:ci,mutateCell:function(n,t,e){n.cells()[t]=e},getCell:li,getCellElement:function(n,t){return li(n,t).element()},mapCells:function(n,t){var e=n.cells(),r=S.map(e,t);return U.rowcells(r,n.section())},cellLength:function(n){return n.cells().length}},si=function(n,t){if(0===n.length)return 0;var e=n[0];return S.findIndex(n,function(n){return!t(e.element(),n.element())}).fold(function(){return n.length},function(n){return n})},di=function(n,t,e,r){var i=function(n,t){return n[t]}(n,t).cells().slice(e),u=si(i,r),a=function(n,t){return S.map(n,function(n){return fi.getCell(n,t)})}(n,e).slice(t),c=si(a,r);return{colspan:o.constant(u),rowspan:o.constant(c)}},mi=function(n,t){var e=S.map(n,function(n,t){return S.map(n.cells(),function(n,t){return!1})});return S.map(n,function(r,o){var i=S.bind(r.cells(),function(r,i){if(!1===e[o][i]){var u=di(n,o,i,t);return function(n,t,r,o){for(var i=n;i<n+r;i++)for(var u=t;u<t+o;u++)e[i][u]=!0}(o,i,u.rowspan(),u.colspan()),[U.detailnew(r.element(),u.rowspan(),u.colspan(),r.isNew())]}return[]});return U.rowdetails(i,r.section())})},gi=function(n,t,e){for(var r=[],o=0;o<n.grid().rows();o++){for(var i=[],u=0;u<n.grid().columns();u++){var a=Yt.getAt(n,o,u).map(function(n){return U.elementnew(n.element(),e)}).getOrThunk(function(){return U.elementnew(t.gap(),!0)});i.push(a)}var c=U.rowcells(i,n.all()[o].section());r.push(c)}return r},pi=function(n,t,e,r){e===r?wt(n,t):pt(n,t,e)},hi=function(n,t){var e=[],r=[],i=function(t,o){t.length>0?function(t,o){var i=Wt(n,o).getOrThunk(function(){var t=X.fromTag(o,nt.owner(n).dom());return le.append(n,t),t});ge.empty(i);var u=S.map(t,function(n){n.isNew()&&e.push(n.element());var t=n.element();return ge.empty(t),S.each(n.cells(),function(n){n.isNew()&&r.push(n.element()),pi(n.element(),"colspan",n.colspan(),1),pi(n.element(),"rowspan",n.rowspan(),1),le.append(t,n.element())}),t});de(i,u)}(t,o):function(t){Wt(n,t).bind(ge.remove)}(o)},u=[],a=[],c=[];return S.each(t,function(n){switch(n.section()){case"thead":u.push(n);break;case"tbody":a.push(n);break;case"tfoot":c.push(n)}}),i(u,"thead"),i(a,"tbody"),i(c,"tfoot"),{newRows:o.constant(e),newCells:o.constant(r)}},vi=function(n){return S.map(n,function(n){var t=xe(n.element());return S.each(n.cells(),function(n){var e=Ce(n.element());pi(e,"colspan",n.colspan(),1),pi(e,"rowspan",n.rowspan(),1),le.append(t,e)}),t})},bi=function(n,t){for(var e=[],r=0;r<n;r++)e.push(t(r));return e},wi=function(n,t){for(var e=[],r=n;r<t;r++)e.push(r);return e},yi=function(n,t){if(t<0||t>=n.length-1)return f.none();var e=n[t].fold(function(){var e=S.reverse(n.slice(0,t));return ai(e,function(n,t){return n.map(function(n){return{value:n,delta:t+1}})})},function(n){return f.some({value:n,delta:0})}),r=n[t+1].fold(function(){var e=n.slice(t+1);return ai(e,function(n,t){return n.map(function(n){return{value:n,delta:t+1}})})},function(n){return f.some({value:n,delta:1})});return e.bind(function(n){return r.map(function(t){var e=t.delta+n.delta;return Math.abs(t.value-n.value)/e})})},xi=function(n,t,e){var r=n();return S.find(r,t).orThunk(function(){return f.from(r[0]).orThunk(e)}).map(function(n){return n.element()})},Ci=function(n){var t=n.grid(),e=wi(0,t.columns()),r=wi(0,t.rows());return S.map(e,function(t){return xi(function(){return S.bind(r,function(e){return Yt.getAt(n,e,t).filter(function(n){return n.column()===t}).fold(o.constant([]),function(n){return[n]})})},function(n){return 1===n.colspan()},function(){return Yt.getAt(n,0,t)})})},Si=function(n){var t=n.grid(),e=wi(0,t.rows()),r=wi(0,t.columns());return S.map(e,function(t){return xi(function(){return S.bind(r,function(e){return Yt.getAt(n,t,e).filter(function(n){return n.row()===t}).fold(o.constant([]),function(n){return[n]})})},function(n){return 1===n.rowspan()},function(){return Yt.getAt(n,t,0)})})},Ri=function(n,t,e,r,o){var i=X.fromTag("div");return re(i,{position:"absolute",left:t-r/2+"px",top:e+"px",height:o+"px",width:r+"px"}),ht(i,{"data-column":n,role:"presentation"}),i},Ti=function(n,t,e,r,o){var i=X.fromTag("div");return re(i,{position:"absolute",left:t+"px",top:e-o/2+"px",height:o+"px",width:r+"px"}),ht(i,{"data-row":n,role:"presentation"}),i},Di=function(n){var t=n.replace(/\./g,"-");return{resolve:function(n){return t+"-"+n}}},Ai={resolve:Di("ephox-snooker").resolve},ki=function(n,t){var e=vt(n,t);return e===undefined||""===e?[]:e.split(" ")},Ni=ki,Oi=function(n,t,e){var r=ki(n,t).concat([e]);pt(n,t,r.join(" "))},Bi=function(n,t,e){var r=S.filter(ki(n,t),function(n){return n!==e});r.length>0?pt(n,t,r.join(" ")):wt(n,t)},Ei=function(n){return Ni(n,"class")},Ii=function(n,t){return Oi(n,"class",t)},Pi=function(n,t){return Bi(n,"class",t)},Wi=Ei,_i=Ii,Mi=Pi,Li=function(n,t){S.contains(Ei(n),t)?Pi(n,t):Ii(n,t)},qi=function(n){return n.dom().classList!==undefined},zi=function(n,t){return qi(n)&&n.dom().classList.contains(t)},Fi={add:function(n,t){qi(n)?n.dom().classList.add(t):_i(n,t)},remove:function(n,t){qi(n)?n.dom().classList.remove(t):Mi(n,t);!function(n){0===(qi(n)?n.dom().classList:Wi(n)).length&&wt(n,"class")}(n)},toggle:function(n,t){return qi(n)?n.dom().classList.toggle(t):Li(n,t)},toggler:function(n,t){var e=qi(n),r=n.dom().classList;return function(n,t,e){var r=e||!1,o=function(){t(),r=!0},i=function(){n(),r=!1};return{on:o,off:i,toggle:function(){(r?i:o)()},isOn:function(){return r}}}(function(){e?r.remove(t):Mi(n,t)},function(){e?r.add(t):_i(n,t)},zi(n,t))},has:zi},ji=Ai.resolve("resizer-bar"),Hi=Ai.resolve("resizer-rows"),Vi=Ai.resolve("resizer-cols"),Ui=function(n){var t=At(n.parent(),"."+ji);S.each(t,ge.remove)},Gi=function(n,t,e){var r=n.origin();S.each(t,function(t,o){t.each(function(t){var o=e(r,t);Fi.add(o,ji),le.append(n.parent(),o)})})},Xi=function(n,t,e,r,o,i){var u=yo(t);!function(n,t,e,r){Gi(n,t,function(n,t){var o=Ti(t.row(),e.left()-n.left(),t.y()-n.top(),r,7);return Fi.add(o,Hi),o})}(n,e.length>0?o.positions(e,t):[],u,Zr(t));!function(n,t,e,r){Gi(n,t,function(n,t){var o=Ri(t.col(),t.x()-n.left(),e.top()-n.top(),7,r);return Fi.add(o,Vi),o})}(n,r.length>0?i.positions(r,t):[],u,Kr(t))},Yi=function(n,t){var e=At(n.parent(),"."+ji);S.each(e,t)},$i=function(n,t,e,r){Ui(n);var o=Vt(t),i=Yt.generate(o),u=Si(i),a=Ci(i);Xi(n,t,u,a,e,r)},Ki=function(n){Yi(n,function(n){ee(n,"display","none")})},Ji=function(n){Yi(n,function(n){ee(n,"display","block")})},Qi=Ui,Zi=function(n){return Fi.has(n,Hi)},nu=function(n){return Fi.has(n,Vi)},tu=function(n,t){return S.map(n,function(n){var e=function(n){return ai(n,function(n){return nt.parent(n.element()).map(function(n){var t=nt.parent(n).isNone();return U.elementnew(n,t)})}).getOrThunk(function(){return U.elementnew(t.row(),!0)})}(n.details());return U.rowdatanew(e.element(),n.details(),n.section(),e.isNew())})},eu=function(n,t){var e=mi(n,Gn.eq);return tu(e,t)},ru=function(n,t){var e=S.flatten(S.map(n.all(),function(n){return n.cells()}));return S.find(e,function(n){return Gn.eq(t,n.element())})},ou=function(n,t,e,r,i){return function(u,a,c,l,s){var d=Vt(a),m=Yt.generate(d);return t(m,c).map(function(t){var e=function(n,t){return gi(n,t,!1)}(m,l),r=n(e,t,Gn.eq,i(l)),u=eu(r.grid(),l);return{grid:o.constant(u),cursor:r.cursor}}).fold(function(){return f.none()},function(n){var t=hi(a,n.grid());return e(a,n.grid(),s),r(a),$i(u,a,Bo.height,s),f.some({cursor:n.cursor,newRows:t.newRows,newCells:t.newCells})})}},iu=eu,uu=function(n,t){return zt(t.element()).bind(function(t){return ru(n,t)})},au=function(n,t){var e=S.map(t.selection(),function(t){return zt(t).bind(function(t){return ru(n,t)})}),r=ui(e);return r.length>0?f.some(r):f.none()},cu=function(n,t){return zt(t.element()).bind(function(e){return ru(n,e).map(function(n){return ii.merge(n,{generators:t.generators,clipboard:t.clipboard})})})},lu=function(n,t){var e=S.map(t.selection(),function(t){return zt(t).bind(function(t){return ru(n,t)})}),r=ui(e);return r.length>0?f.some(ii.merge({cells:r},{generators:t.generators,clipboard:t.clipboard})):f.none()},fu=function(n,t){return t.mergable()},su=function(n,t){return t.unmergable()},du=function(n){return{is:function(t){return n===t},isValue:o.constant(!0),isError:o.constant(!1),getOr:o.constant(n),getOrThunk:o.constant(n),getOrDie:o.constant(n),or:function(t){return du(n)},orThunk:function(t){return du(n)},fold:function(t,e){return e(n)},map:function(t){return du(t(n))},each:function(t){t(n)},bind:function(t){return t(n)},exists:function(t){return t(n)},forall:function(t){return t(n)},toOption:function(){return f.some(n)}}},mu=function(n){return{is:o.constant(!1),isValue:o.constant(!1),isError:o.constant(!0),getOr:o.identity,getOrThunk:function(n){return n()},getOrDie:function(){return o.die(n)()},or:function(n){return n},orThunk:function(n){return n()},fold:function(t,e){return t(n)},map:function(t){return mu(n)},each:o.noop,bind:function(t){return mu(n)},exists:o.constant(!1),forall:o.constant(!0),toOption:f.none}},gu={value:du,error:mu},pu=function(n,t){return S.map(n,function(){return U.elementnew(t.cell(),!0)})},hu=function(n,t,e){return n.concat(bi(t,function(t){return fi.setCells(n[n.length-1],pu(n[n.length-1].cells(),e))}))},vu=function(n,t,e){return S.map(n,function(n){return fi.setCells(n,n.cells().concat(pu(wi(0,t),e)))})},bu=function(n,t,e){if(n.row()>=t.length||n.column()>fi.cellLength(t[0]))return gu.error("invalid start address out of table bounds, row: "+n.row()+", column: "+n.column());var r=t.slice(n.row()),i=r[0].cells().slice(n.column()),u=fi.cellLength(e[0]),a=e.length;return gu.value({rowDelta:o.constant(r.length-a),colDelta:o.constant(i.length-u)})},wu=function(n,t){var e=fi.cellLength(n[0]),r=fi.cellLength(t[0]);return{rowDelta:o.constant(0),colDelta:o.constant(e-r)}},yu=function(n,t,e){var r=t.colDelta()<0?vu:o.identity;return(t.rowDelta()<0?hu:o.identity)(r(n,Math.abs(t.colDelta()),e),Math.abs(t.rowDelta()),e)},xu=function(n,t,e,r){if(0===n.length)return n;for(var o=t.startRow();o<=t.finishRow();o++)for(var i=t.startCol();i<=t.finishCol();i++)fi.mutateCell(n[o],i,U.elementnew(r(),!1));return n},Cu=function(n,t,e,r){for(var o=!0,i=0;i<n.length;i++)for(var u=0;u<fi.cellLength(n[0]);u++){var a=e(fi.getCellElement(n[i],u),t);!0===a&&!1===o?fi.mutateCell(n[i],u,U.elementnew(r(),!0)):!0===a&&(o=!1)}return n},Su=function(n,t,e,r){if(t>0&&t<n.length){var o=function(n,t){return S.foldl(n,function(n,e){return S.exists(n,function(n){return t(n.element(),e.element())})?n:n.concat([e])},[])}(n[t-1].cells(),e);S.each(o,function(o){for(var i=f.none(),u=t;u<n.length;u++)for(var a=0;a<fi.cellLength(n[0]);a++){var c=n[u].cells()[a];e(c.element(),o.element())&&(i.isNone()&&(i=f.some(r())),i.each(function(t){fi.mutateCell(n[u],a,U.elementnew(t,!0))}))}})}return n},Ru=function(n,t,e,r){var i=fi.getCell(n[t],e),u=o.curry(r,i.element()),a=n[t];return n.length>1&&fi.cellLength(a)>1&&(e>0&&u(fi.getCellElement(a,e-1))||e<a.length-1&&u(fi.getCellElement(a,e+1))||t>0&&u(fi.getCellElement(n[t-1],e))||t<n.length-1&&u(fi.getCellElement(n[t+1],e)))},Tu=function(n,t,e,r,o){return bu(n,t,e).map(function(i){var u=yu(t,i,r);return function(n,t,e,r,o){for(var i=n.row(),u=n.column(),a=i+e.length,c=u+fi.cellLength(e[0]),l=i;l<a;l++)for(var f=u;f<c;f++){Ru(t,l,f,o)&&Cu(t,fi.getCellElement(t[l],f),o,r.cell);var s=fi.getCellElement(e[l-i],f-u),d=r.replace(s);fi.mutateCell(t[l],f,U.elementnew(d,!0))}return t}(n,u,e,r,o)})},Du=function(n,t,e,r,o){Su(t,n,o,r.cell);var i=wu(e,t),u=yu(e,i,r),a=wu(t,u),c=yu(t,a,r);return c.slice(0,n).concat(u).concat(c.slice(n,c.length))},Au=function(n,t,e,r,o){var i=n.slice(0,t),u=n.slice(t),a=fi.mapCells(n[e],function(e,i){return t>0&&t<n.length&&r(fi.getCellElement(n[t-1],i),fi.getCellElement(n[t],i))?fi.getCell(n[t],i):U.elementnew(o(e.element(),r),!0)});return i.concat([a]).concat(u)},ku=function(n,t,e,r,o){return S.map(n,function(n){var i=t>0&&t<fi.cellLength(n)&&r(fi.getCellElement(n,t-1),fi.getCellElement(n,t))?fi.getCell(n,t):U.elementnew(o(fi.getCellElement(n,e),r),!0);return fi.addCell(n,t,i)})},Nu=function(n,t,e,r,o){var i=e+1;return S.map(n,function(n,u){var a=u===t?U.elementnew(o(fi.getCellElement(n,e),r),!0):fi.getCell(n,e);return fi.addCell(n,i,a)})},Ou=function(n,t,e,r,o){var i=t+1,u=n.slice(0,i),a=n.slice(i),c=fi.mapCells(n[t],function(n,t){return t===e?U.elementnew(o(n.element(),r),!0):n});return u.concat([c]).concat(a)},Bu=function(n,t,e){return n.slice(0,t).concat(n.slice(e+1))},Eu=function(n,t,e){var r=S.map(n,function(n){var r=n.cells().slice(0,t).concat(n.cells().slice(e+1));return U.rowcells(r,n.section())});return S.filter(r,function(n){return n.cells().length>0})},Iu=function(n,t,e,r){return S.map(n,function(n){return fi.mapCells(n,function(n){return function(n){return S.exists(t,function(t){return e(n.element(),t.element())})}(n)?U.elementnew(r(n.element(),e),!0):n})})},Pu=function(n,t,e,r){return fi.getCellElement(n[t],e)!==undefined&&t>0&&r(fi.getCellElement(n[t-1],e),fi.getCellElement(n[t],e))},Wu=function(n,t,e){return t>0&&e(fi.getCellElement(n,t-1),fi.getCellElement(n,t))},_u=function(n,t,e,r){var o=S.bind(n,function(r,o){return Pu(n,o,t,e)||Wu(r,t,e)?[]:[fi.getCell(r,t)]});return Iu(n,o,e,r)},Mu=function(n,t,e,r){var o=n[t],i=S.bind(o.cells(),function(r,i){return Pu(n,t,i,e)||Wu(o,i,e)?[]:[r]});return Iu(n,i,e,r)},Lu=function(n){return{fold:n}},qu=function(){return Lu(function(n,t,e,r,o){return n()})},zu=function(n){return Lu(function(t,e,r,o,i){return e(n)})},Fu=function(n,t){return Lu(function(e,r,o,i,u){return o(n,t)})},ju=function(n,t,e){return Lu(function(r,o,i,u,a){return u(n,t,e)})},Hu=function(n,t){return Lu(function(e,r,o,i,u){return u(n,t)})},Vu=function(n,t,e,r){var i=n.slice(0),u=function(n,t){return 0===n.length?qu():1===n.length?zu(0):0===t?Fu(0,1):t===n.length-1?Hu(t-1,t):t>0&&t<n.length-1?ju(t-1,t,t+1):qu()}(n,t),a=function(n){return S.map(n,o.constant(0))},c=o.constant(a(i)),l=function(n,t){if(e>=0){var o=Math.max(r.minCellWidth(),i[t]-e);return a(i.slice(0,n)).concat([e,o-i[t]]).concat(a(i.slice(t+1)))}var u=Math.max(r.minCellWidth(),i[n]+e),c=i[n]-u;return a(i.slice(0,n)).concat([u-i[n],c]).concat(a(i.slice(t+1)))},f=l;return u.fold(c,function(n){return r.singleColumnWidth(i[n],e)},f,function(n,t,e){return l(t,e)},function(n,t){if(e>=0)return a(i.slice(0,t)).concat([e]);var o=Math.max(r.minCellWidth(),i[t]+e);return a(i.slice(0,t)).concat([o-i[t]])})},Uu=function(n,t){return bt(n,t)&&parseInt(vt(n,t),10)>1},Gu={hasColspan:function(n){return Uu(n,"colspan")},hasRowspan:function(n){return Uu(n,"rowspan")},minWidth:o.constant(10),minHeight:o.constant(10),getInt:function(n,t){return parseInt(ie(n,t),10)}},Xu=function(n,t,e,r,i){var u=Ci(n),a=S.map(u,function(n){return n.map(t.edge)});return S.map(u,function(n,t){return n.filter(o.not(Gu.hasColspan)).fold(function(){var n=yi(a,t);return r(n)},function(n){return e(n,i)})})},Yu=function(n,t,e,r){var i=Si(n),u=S.map(i,function(n){return n.map(t.edge)});return S.map(i,function(n,t){return n.filter(o.not(Gu.hasRowspan)).fold(function(){var n=yi(u,t);return r(n)},function(n){return e(n)})})},$u=function(n,t,e){return Xu(n,t,mo.getPixelWidth,function(n){return n.getOrThunk(e.minCellWidth)},e)},Ku=function(n,t,e){return Xu(n,t,mo.getPercentageWidth,function(n){return n.fold(function(){return e.minCellWidth()},function(n){return n/e.pixelWidth()*100})},e)},Ju=function(n,t){return Yu(n,t,mo.getHeight,function(n){return n.getOrThunk(Gu.minHeight)})},Qu=function(n,t,e){for(var r=0,o=n;o<t;o++)r+=e[o]!==undefined?e[o]:0;return r},Zu=function(n,t){var e=Yt.justCells(n);return S.map(e,function(n){var e=Qu(n.column(),n.column()+n.colspan(),t);return{element:n.element,width:o.constant(e),colspan:n.colspan}})},na=function(n,t){var e=Yt.justCells(n);return S.map(e,function(n){var e=Qu(n.row(),n.row()+n.rowspan(),t);return{element:n.element,height:o.constant(e),rowspan:n.rowspan}})},ta=function(n,t){return S.map(n.all(),function(n,e){return{element:n.element,height:o.constant(t[e])}})},ea=function(n){var t=parseInt(n,10),e=o.identity;return{width:o.constant(t),pixelWidth:o.constant(t),getWidths:$u,getCellDelta:e,singleColumnWidth:function(n,t){return[Math.max(Gu.minWidth(),n+t)-n]},minCellWidth:Gu.minWidth,setElementWidth:mo.setPixelWidth,setTableWidth:function(n,t,e){var r=S.foldr(t,function(n,t){return n+t},0);mo.setPixelWidth(n,r)}}},ra=function(n,t){if(mo.percentageBasedSizeRegex().test(t)){return function(n,t){var e=parseFloat(n),r=Qr(t);return{width:o.constant(e),pixelWidth:o.constant(r),getWidths:Ku,getCellDelta:function(n){return n/r*100},singleColumnWidth:function(n,t){return[100-n]},minCellWidth:function(){return Gu.minWidth()/r*100},setElementWidth:mo.setPercentageWidth,setTableWidth:function(n,t,r){var o=e+r;mo.setPercentageWidth(n,o)}}}(mo.percentageBasedSizeRegex().exec(t)[1],n)}if(mo.pixelBasedSizeRegex().test(t)){var e=mo.pixelBasedSizeRegex().exec(t);return ea(e[1])}var r=Qr(n);return ea(r)},oa=function(n){return mo.getRawWidth(n).fold(function(){var t=Qr(n);return ea(t)},function(t){return ra(n,t)})},ia=function(n){return Yt.generate(n)},ua=function(n){var t=Vt(n);return ia(t)},aa=function(n,t,e,r){var o=oa(n),i=o.getCellDelta(t),u=ua(n),a=o.getWidths(u,r,o),c=Vu(a,e,i,o),l=S.map(c,function(n,t){return n+a[t]}),f=Zu(u,l);S.each(f,function(n){o.setElementWidth(n.element(),n.width())}),e===u.grid().columns()-1&&o.setTableWidth(n,l,i)},ca=function(n,t,e,r){var o=ua(n),i=Ju(o,r),u=S.map(i,function(n,r){return e===r?Math.max(t+n,Gu.minHeight()):n}),a=na(o,u),c=ta(o,u);S.each(c,function(n){mo.setHeight(n.element(),n.height())}),S.each(a,function(n){mo.setHeight(n.element(),n.height())});var l=function(n){return S.foldr(n,function(n,t){return n+t},0)}(u);mo.setHeight(n,l)},la=function(n,t,e){var r=oa(n),o=ia(t),i=r.getWidths(o,e,r),u=Zu(o,i);S.each(u,function(n){r.setElementWidth(n.element(),n.width())});var a=S.foldr(i,function(n,t){return t+n},0);u.length>0&&r.setElementWidth(n,a)},fa=function(n){0===Ft(n).length&&ge.remove(n)},sa=L.immutable("grid","cursor"),da=function(n,t,e){return ma(n,t,e).orThunk(function(){return ma(n,0,0)})},ma=function(n,t,e){return f.from(n[t]).bind(function(n){return f.from(n.cells()[e]).bind(function(n){return f.from(n.element())})})},ga=function(n,t,e){return sa(n,ma(n,t,e))},pa=function(n){return S.foldl(n,function(n,t){return S.exists(n,function(n){return n.row()===t.row()})?n:n.concat([t])},[]).sort(function(n,t){return n.row()-t.row()})},ha=function(n){return S.foldl(n,function(n,t){return S.exists(n,function(n){return n.column()===t.column()})?n:n.concat([t])},[]).sort(function(n,t){return n.column()-t.column()})},va=function(n,t,e){var r=Ut(n,e),o=Yt.generate(r);return gi(o,t,!0)},ba=la,wa={insertRowBefore:ou(function(n,t,e,r){var o=t.row(),i=t.row(),u=Au(n,i,o,e,r.getOrInit);return ga(u,i,t.column())},uu,o.noop,o.noop,jo),insertRowsBefore:ou(function(n,t,e,r){var o=t[0].row(),i=t[0].row(),u=pa(t),a=S.foldl(u,function(n,t){return Au(n,i,o,e,r.getOrInit)},n);return ga(a,i,t[0].column())},au,o.noop,o.noop,jo),insertRowAfter:ou(function(n,t,e,r){var o=t.row(),i=t.row()+t.rowspan(),u=Au(n,i,o,e,r.getOrInit);return ga(u,i,t.column())},uu,o.noop,o.noop,jo),insertRowsAfter:ou(function(n,t,e,r){var o=pa(t),i=o[o.length-1].row(),u=o[o.length-1].row()+o[o.length-1].rowspan(),a=S.foldl(o,function(n,t){return Au(n,u,i,e,r.getOrInit)},n);return ga(a,u,t[0].column())},au,o.noop,o.noop,jo),insertColumnBefore:ou(function(n,t,e,r){var o=t.column(),i=t.column(),u=ku(n,i,o,e,r.getOrInit);return ga(u,t.row(),i)},uu,ba,o.noop,jo),insertColumnsBefore:ou(function(n,t,e,r){var o=ha(t),i=o[0].column(),u=o[0].column(),a=S.foldl(o,function(n,t){return ku(n,u,i,e,r.getOrInit)},n);return ga(a,t[0].row(),u)},au,ba,o.noop,jo),insertColumnAfter:ou(function(n,t,e,r){var o=t.column(),i=t.column()+t.colspan(),u=ku(n,i,o,e,r.getOrInit);return ga(u,t.row(),i)},uu,ba,o.noop,jo),insertColumnsAfter:ou(function(n,t,e,r){var o=t[t.length-1].column(),i=t[t.length-1].column()+t[t.length-1].colspan(),u=ha(t),a=S.foldl(u,function(n,t){return ku(n,i,o,e,r.getOrInit)},n);return ga(a,t[0].row(),i)},au,ba,o.noop,jo),splitCellIntoColumns:ou(function(n,t,e,r){var o=Nu(n,t.row(),t.column(),e,r.getOrInit);return ga(o,t.row(),t.column())},uu,ba,o.noop,jo),splitCellIntoRows:ou(function(n,t,e,r){var o=Ou(n,t.row(),t.column(),e,r.getOrInit);return ga(o,t.row(),t.column())},uu,o.noop,o.noop,jo),eraseColumns:ou(function(n,t,e,r){var o=ha(t),i=Eu(n,o[0].column(),o[o.length-1].column()),u=da(i,t[0].row(),t[0].column());return sa(i,u)},au,ba,fa,jo),eraseRows:ou(function(n,t,e,r){var o=pa(t),i=Bu(n,o[0].row(),o[o.length-1].row()),u=da(i,t[0].row(),t[0].column());return sa(i,u)},au,o.noop,fa,jo),makeColumnHeader:ou(function(n,t,e,r){var o=_u(n,t.column(),e,r.replaceOrInit);return ga(o,t.row(),t.column())},uu,o.noop,o.noop,Ho("row","th")),unmakeColumnHeader:ou(function(n,t,e,r){var o=_u(n,t.column(),e,r.replaceOrInit);return ga(o,t.row(),t.column())},uu,o.noop,o.noop,Ho(null,"td")),makeRowHeader:ou(function(n,t,e,r){var o=Mu(n,t.row(),e,r.replaceOrInit);return ga(o,t.row(),t.column())},uu,o.noop,o.noop,Ho("col","th")),unmakeRowHeader:ou(function(n,t,e,r){var o=Mu(n,t.row(),e,r.replaceOrInit);return ga(o,t.row(),t.column())},uu,o.noop,o.noop,Ho(null,"td")),mergeCells:ou(function(n,t,e,r){var i=t.cells();ti(i);var u=xu(n,t.bounds(),e,o.constant(i[0]));return sa(u,f.from(i[0]))},fu,o.noop,o.noop,Vo),unmergeCells:ou(function(n,t,e,r){var o=S.foldr(t,function(n,t){return Cu(n,t,e,r.combine(t))},n);return sa(o,f.from(t[0]))},su,ba,o.noop,Vo),pasteCells:ou(function(n,t,e,r){var o=function(n,t){var e=Vt(n),r=Yt.generate(e);return gi(r,t,!0)}(t.clipboard(),t.generators()),i=U.address(t.row(),t.column());return Tu(i,n,o,t.generators(),e).fold(function(){return sa(n,f.some(t.element()))},function(n){var e=da(n,t.row(),t.column());return sa(n,e)})},cu,ba,o.noop,jo),pasteRowsBefore:ou(function(n,t,e,r){var o=n[t.cells[0].row()],i=t.cells[0].row(),u=va(t.clipboard(),t.generators(),o),a=Du(i,n,u,t.generators(),e),c=da(a,t.cells[0].row(),t.cells[0].column());return sa(a,c)},lu,o.noop,o.noop,jo),pasteRowsAfter:ou(function(n,t,e,r){var o=n[t.cells[0].row()],i=t.cells[t.cells.length-1].row()+t.cells[t.cells.length-1].rowspan(),u=va(t.clipboard(),t.generators(),o),a=Du(i,n,u,t.generators(),e),c=da(a,t.cells[0].row(),t.cells[0].column());return sa(a,c)},lu,o.noop,o.noop,jo)},ya=function(n){return X.fromDom(n.getBody())},xa={getBody:ya,getIsRoot:function(n){return function(t){return Gn.eq(t,ya(n))}},addSizeSuffix:function(n){return/^[0-9]+$/.test(n)&&(n+="px"),n},removePxSuffix:function(n){return n?n.replace(/px$/,""):""}},Ca=function(n){return"rtl"===ie(n,"direction")?"rtl":"ltr"},Sa={onDirection:function(n,t){return function(e){return"rtl"===Ca(e)?t:n}},getDirection:Ca},Ra={isRtl:o.constant(!1)},Ta={isRtl:o.constant(!0)},Da=function(n){return"rtl"===Sa.getDirection(n)?Ta:Ra},Aa=function(n,t){var e,r=function(n){return"table"===lt.name(xa.getBody(n))};!1!==n.settings.table_clone_elements&&("string"==typeof n.settings.table_clone_elements?e=n.settings.table_clone_elements.split(/[ ,]/):Array.isArray(n.settings.table_clone_elements)&&(e=n.settings.table_clone_elements));var i=f.from(e),u=function(t,e,r,o){return function(u,a){var c=At(u,"td[data-mce-style],th[data-mce-style]");S.each(c,function(n){wt(n,"data-mce-style")});var l=o(),s=X.fromDom(n.getDoc()),d=Io(Da),m=qe(r,s,i);return e(u)?t(l,u,a,m,d).bind(function(t){return S.each(t.newRows(),function(t){!function(t){n.fire("newrow",{node:t.dom()}),t.dom()}(t)}),S.each(t.newCells(),function(t){!function(t){n.fire("newcell",{node:t.dom()}),t.dom()}(t)}),t.cursor().map(function(t){var e=n.dom.createRng();return e.setStart(t.dom(),0),e.setEnd(t.dom(),0),e})}):f.none()}};return{deleteRow:u(wa.eraseRows,function(t){var e=Po(t);return!1===r(n)||e.rows()>1},o.noop,t),deleteColumn:u(wa.eraseColumns,function(t){var e=Po(t);return!1===r(n)||e.columns()>1},o.noop,t),insertRowsBefore:u(wa.insertRowsBefore,o.always,o.noop,t),insertRowsAfter:u(wa.insertRowsAfter,o.always,o.noop,t),insertColumnsBefore:u(wa.insertColumnsBefore,o.always,go,t),insertColumnsAfter:u(wa.insertColumnsAfter,o.always,go,t),mergeCells:u(wa.mergeCells,o.always,o.noop,t),unmergeCells:u(wa.unmergeCells,o.always,o.noop,t),pasteRowsBefore:u(wa.pasteRowsBefore,o.always,o.noop,t),pasteRowsAfter:u(wa.pasteRowsAfter,o.always,o.noop,t),pasteCells:u(wa.pasteCells,o.always,o.noop,t)}},ka=function(n,t,e){var r=Vt(n),o=Yt.generate(r);return au(o,t).map(function(n){var t=gi(o,e,!1).slice(n[0].row(),n[n.length-1].row()+n[n.length-1].rowspan()),r=iu(t,e);return vi(r)})},Na=tinymce.util.Tools.resolve("tinymce.util.Tools"),Oa=tinymce.util.Tools.resolve("tinymce.Env"),Ba={applyAlign:function(n,t,e){e&&n.formatter.apply("align"+e,{},t)},applyVAlign:function(n,t,e){e&&n.formatter.apply("valign"+e,{},t)},unApplyAlign:function(n,t){Na.each("left center right".split(" "),function(e){n.formatter.remove("align"+e,{},t)})},unApplyVAlign:function(n,t){Na.each("top middle bottom".split(" "),function(e){n.formatter.remove("valign"+e,{},t)})},getTDTHOverallStyle:function(n,t,e){var r;return r=function(t,r){for(var o=0;o<r.length;o++){var i=n.getStyle(r[o],e);if(void 0===t&&(t=i),t!==i)return""}return t}(r,n.select("td,th",t))}},Ea=function(n,t){var e=n.dom,r=t.control.rootControl,o=r.toJSON(),i=e.parseStyle(o.style);"style"===t.control.name()?(r.find("#borderStyle").value(i["border-style"]||"")[0].fire("select"),r.find("#borderColor").value(i["border-color"]||"")[0].fire("change"),r.find("#backgroundColor").value(i["background-color"]||"")[0].fire("change"),r.find("#width").value(i.width||"").fire("change"),r.find("#height").value(i.height||"").fire("change")):(i["border-style"]=o.borderStyle,i["border-color"]=o.borderColor,i["background-color"]=o.backgroundColor,i.width=o.width?xa.addSizeSuffix(o.width):"",i.height=o.height?xa.addSizeSuffix(o.height):""),r.find("#style").value(e.serializeStyle(e.parseStyle(e.serializeStyle(i))))},Ia={createStyleForm:function(n){var t=function(){var t=n.settings.color_picker_callback;if(t)return function(e){return t.call(n,function(n){e.control.value(n).fire("change")},e.control.value())}};return{title:"Advanced",type:"form",defaults:{onchange:o.curry(Ea,n)},items:[{label:"Style",name:"style",type:"textbox"},{type:"form",padding:0,formItemDefaults:{layout:"grid",alignH:["start","right"]},defaults:{size:7},items:[{label:"Border style",type:"listbox",name:"borderStyle",width:90,onselect:o.curry(Ea,n),values:[{text:"Select...",value:""},{text:"Solid",value:"solid"},{text:"Dotted",value:"dotted"},{text:"Dashed",value:"dashed"},{text:"Double",value:"double"},{text:"Groove",value:"groove"},{text:"Ridge",value:"ridge"},{text:"Inset",value:"inset"},{text:"Outset",value:"outset"},{text:"None",value:"none"},{text:"Hidden",value:"hidden"}]},{label:"Border color",type:"colorbox",name:"borderColor",onaction:t()},{label:"Background color",type:"colorbox",name:"backgroundColor",onaction:t()}]}]}},buildListItems:function(n,t,e){var r=function(n,e){return e=e||[],Na.each(n,function(n){var o={text:n.text||n.title};n.menu?o.menu=r(n.menu):(o.value=n.value,t&&t(o)),e.push(o)}),e};return r(n,e||[])},updateStyleField:Ea,extractAdvancedStyles:function(n,t){var e=n.parseStyle(n.getAttrib(t,"style")),r={};return e["border-style"]&&(r.borderStyle=e["border-style"]),e["border-color"]&&(r.borderColor=e["border-color"]),e["background-color"]&&(r.backgroundColor=e["background-color"]),r.style=n.serializeStyle(e),r}},Pa=function(t,e,r){var o,i,u=t.dom;Ia.updateStyleField(t,r),!1===(i=r.control.rootControl.toJSON())["class"]&&delete i["class"],t.undoManager.transact(function(){e||(e=Gr.insert(t,i.cols||1,i.rows||1)),function(t,e,r){var o=t.dom,i={},u={};if(i["class"]=r["class"],u.height=xa.addSizeSuffix(r.height),o.getAttrib(e,"width")&&!t.settings.table_style_by_css?i.width=xa.removePxSuffix(r.width):u.width=xa.addSizeSuffix(r.width),t.settings.table_style_by_css?(u["border-width"]=xa.addSizeSuffix(r.border),u["border-spacing"]=xa.addSizeSuffix(r.cellspacing),Na.extend(i,{"data-mce-border-color":r.borderColor,"data-mce-cell-padding":r.cellpadding,"data-mce-border":r.border})):Na.extend(i,{border:r.border,cellpadding:r.cellpadding,cellspacing:r.cellspacing}),t.settings.table_style_by_css&&e.children)for(var a=0;a<e.children.length;a++)n(o,e.children[a],{"border-width":xa.addSizeSuffix(r.border),"border-color":r.borderColor,padding:xa.addSizeSuffix(r.cellpadding)});r.style?Na.extend(u,o.parseStyle(r.style)):u=Na.extend({},o.parseStyle(o.getAttrib(e,"style")),u),i.style=o.serializeStyle(u),o.setAttribs(e,i)}(t,e,i),(o=u.select("caption",e)[0])&&!i.caption&&u.remove(o),!o&&i.caption&&((o=u.create("caption")).innerHTML=Oa.ie?"\xa0":'<br data-mce-bogus="1"/>',e.insertBefore(o,e.firstChild)),Ba.unApplyAlign(t,e),i.align&&Ba.applyAlign(t,e,i.align),t.focus(),t.addVisual()})},Wa=function(n,t){var e,r,i,u,a,c=n.dom,l={};!0===t?(e=c.getParent(n.selection.getStart(),"table"))&&(l=function(n,t){var e=n.dom,r={width:e.getStyle(t,"width")||e.getAttrib(t,"width"),height:e.getStyle(t,"height")||e.getAttrib(t,"height"),cellspacing:e.getStyle(t,"border-spacing")||e.getAttrib(t,"cellspacing"),cellpadding:e.getAttrib(t,"data-mce-cell-padding")||e.getAttrib(t,"cellpadding")||Ba.getTDTHOverallStyle(n.dom,t,"padding"),border:e.getAttrib(t,"data-mce-border")||e.getAttrib(t,"border")||Ba.getTDTHOverallStyle(n.dom,t,"border"),borderColor:e.getAttrib(t,"data-mce-border-color"),caption:!!e.select("caption",t)[0],"class":e.getAttrib(t,"class")};return Na.each("left center right".split(" "),function(e){n.formatter.matchNode(t,"align"+e)&&(r.align=e)}),!1!==n.settings.table_advtab&&Na.extend(r,Ia.extractAdvancedStyles(e,t)),r}(n,e)):(r={label:"Cols",name:"cols"},i={label:"Rows",name:"rows"}),n.settings.table_class_list&&(l["class"]&&(l["class"]=l["class"].replace(/\s*mce\-item\-table\s*/g,"")),u={name:"class",type:"listbox",label:"Class",values:Ia.buildListItems(n.settings.table_class_list,function(t){t.value&&(t.textStyle=function(){return n.formatter.getCssText({block:"table",classes:[t.value]})})})}),a={type:"form",layout:"flex",direction:"column",labelGapCalc:"children",padding:0,items:[{type:"form",labelGapCalc:!1,padding:0,layout:"grid",columns:2,defaults:{type:"textbox",maxWidth:50},items:!1!==n.settings.table_appearance_options?[r,i,{label:"Width",name:"width",onchange:o.curry(Ia.updateStyleField,n)},{label:"Height",name:"height",onchange:o.curry(Ia.updateStyleField,n)},{label:"Cell spacing",name:"cellspacing"},{label:"Cell padding",name:"cellpadding"},{label:"Border",name:"border"},{label:"Caption",name:"caption",type:"checkbox"}]:[r,i,{label:"Width",name:"width",onchange:o.curry(Ia.updateStyleField,n)},{label:"Height",name:"height",onchange:o.curry(Ia.updateStyleField,n)}]},{label:"Alignment",name:"align",type:"listbox",text:"None",values:[{text:"None",value:""},{text:"Left",value:"left"},{text:"Center",value:"center"},{text:"Right",value:"right"}]},u]},!1!==n.settings.table_advtab?n.windowManager.open({title:"Table properties",data:l,bodyType:"tabpanel",body:[{title:"General",type:"form",items:a},Ia.createStyleForm(n)],onsubmit:o.curry(Pa,n,e)}):n.windowManager.open({title:"Table properties",data:l,body:a,onsubmit:o.curry(Pa,n,e)})},_a=function(n,t,e){var r=n.getParent(t,"table"),o=t.parentNode,i=n.select(e,r)[0];i||(i=n.create(e),r.firstChild?"CAPTION"===r.firstChild.nodeName?n.insertAfter(i,r.firstChild):r.insertBefore(i,r.firstChild):r.appendChild(i)),i.appendChild(t),o.hasChildNodes()||n.remove(o)},Ma=function(n){var e,r,i,u,a,c,l=n.dom,f=[];e=n.dom.getParent(n.selection.getStart(),"table"),r=n.dom.getParent(n.selection.getStart(),"td,th"),Na.each(e.rows,function(n){Na.each(n.cells,function(t){if(l.getAttrib(t,"data-mce-selected")||t===r)return f.push(n),!1})}),(i=f[0])&&(a=f.length>1?{height:"",scope:"","class":"",align:"",type:i.parentNode.nodeName.toLowerCase()}:function(n,t){var e=n.dom,r={height:e.getStyle(t,"height")||e.getAttrib(t,"height"),scope:e.getAttrib(t,"scope"),"class":e.getAttrib(t,"class")};return r.type=t.parentNode.nodeName.toLowerCase(),Na.each("left center right".split(" "),function(e){n.formatter.matchNode(t,"align"+e)&&(r.align=e)}),!1!==n.settings.table_row_advtab&&Na.extend(r,Ia.extractAdvancedStyles(e,t)),r}(n,i),n.settings.table_row_class_list&&(u={name:"class",type:"listbox",label:"Class",values:Ia.buildListItems(n.settings.table_row_class_list,function(t){t.value&&(t.textStyle=function(){return n.formatter.getCssText({block:"tr",classes:[t.value]})})})}),c={type:"form",columns:2,padding:0,defaults:{type:"textbox"},items:[{type:"listbox",name:"type",label:"Row type",text:"Header",maxWidth:null,values:[{text:"Header",value:"thead"},{text:"Body",value:"tbody"},{text:"Footer",value:"tfoot"}]},{type:"listbox",name:"align",label:"Alignment",text:"None",maxWidth:null,values:[{text:"None",value:""},{text:"Left",value:"left"},{text:"Center",value:"center"},{text:"Right",value:"right"}]},{label:"Height",name:"height"},u]},!1!==n.settings.table_row_advtab?n.windowManager.open({title:"Row properties",data:a,bodyType:"tabpanel",body:[{title:"General",type:"form",items:c},Ia.createStyleForm(l)],onsubmit:o.curry(t,n,f)}):n.windowManager.open({title:"Row properties",data:a,body:c,onsubmit:o.curry(t,n,f)}))},La=function(n,t,e){function r(n,t,e){e&&u.setAttrib(n,t,e)}function o(n,t,e){e&&u.setStyle(n,t,e)}var i,u=n.dom;Ia.updateStyleField(n,e),i=e.control.rootControl.toJSON(),n.undoManager.transact(function(){Na.each(t,function(e){r(e,"scope",i.scope),1===t.length?r(e,"style",i.style):function(n,t){n.style.cssText+=";"+t}(e,i.style),r(e,"class",i["class"]),o(e,"width",xa.addSizeSuffix(i.width)),o(e,"height",xa.addSizeSuffix(i.height)),i.type&&e.nodeName.toLowerCase()!==i.type&&(e=u.rename(e,i.type)),1===t.length&&(Ba.unApplyAlign(n,e),Ba.unApplyVAlign(n,e)),i.align&&Ba.applyAlign(n,e,i.align),i.valign&&Ba.applyVAlign(n,e,i.valign)}),n.focus()})},qa=function(n){var t,e,r,i=[];if(i=n.dom.select("td[data-mce-selected],th[data-mce-selected]"),t=n.dom.getParent(n.selection.getStart(),"td,th"),!i.length&&t&&i.push(t),t=t||i[0]){e=i.length>1?{width:"",height:"",scope:"","class":"",align:"",style:"",type:t.nodeName.toLowerCase()}:function(n,t){var e=n.dom,r={width:e.getStyle(t,"width")||e.getAttrib(t,"width"),height:e.getStyle(t,"height")||e.getAttrib(t,"height"),scope:e.getAttrib(t,"scope"),"class":e.getAttrib(t,"class")};return r.type=t.nodeName.toLowerCase(),Na.each("left center right".split(" "),function(e){n.formatter.matchNode(t,"align"+e)&&(r.align=e)}),Na.each("top middle bottom".split(" "),function(e){n.formatter.matchNode(t,"valign"+e)&&(r.valign=e)}),!1!==n.settings.table_cell_advtab&&Na.extend(r,Ia.extractAdvancedStyles(e,t)),r}(n,t),n.settings.table_cell_class_list&&(r={name:"class",type:"listbox",label:"Class",values:Ia.buildListItems(n.settings.table_cell_class_list,function(t){t.value&&(t.textStyle=function(){return n.formatter.getCssText({block:"td",classes:[t.value]})})})});var u={type:"form",layout:"flex",direction:"column",labelGapCalc:"children",padding:0,items:[{type:"form",layout:"grid",columns:2,labelGapCalc:!1,padding:0,defaults:{type:"textbox",maxWidth:50},items:[{label:"Width",name:"width",onchange:o.curry(Ia.updateStyleField,n)},{label:"Height",name:"height",onchange:o.curry(Ia.updateStyleField,n)},{label:"Cell type",name:"type",type:"listbox",text:"None",minWidth:90,maxWidth:null,values:[{text:"Cell",value:"td"},{text:"Header cell",value:"th"}]},{label:"Scope",name:"scope",type:"listbox",text:"None",minWidth:90,maxWidth:null,values:[{text:"None",value:""},{text:"Row",value:"row"},{text:"Column",value:"col"},{text:"Row group",value:"rowgroup"},{text:"Column group",value:"colgroup"}]},{label:"H Align",name:"align",type:"listbox",text:"None",minWidth:90,maxWidth:null,values:[{text:"None",value:""},{text:"Left",value:"left"},{text:"Center",value:"center"},{text:"Right",value:"right"}]},{label:"V Align",name:"valign",type:"listbox",text:"None",minWidth:90,maxWidth:null,values:[{text:"None",value:""},{text:"Top",value:"top"},{text:"Middle",value:"middle"},{text:"Bottom",value:"bottom"}]}]},r]};!1!==n.settings.table_cell_advtab?n.windowManager.open({title:"Cell properties",bodyType:"tabpanel",data:e,body:[{title:"General",type:"form",items:u},Ia.createStyleForm(n)],onsubmit:o.curry(La,n,i)}):n.windowManager.open({title:"Cell properties",data:e,body:u,onsubmit:o.curry(La,n,i)})}},za=Na.each,Fa=f.none(),ja={registerCommands:function(n,t,e,r){var i=xa.getIsRoot(n),u=function(){return X.fromDom(n.dom.getParent(n.selection.getStart(),"th,td"))},a=function(n){return jt(n,i)},c=function(t){var o=u();a(o).each(function(i){var u=Mr.forMenu(r,i,o);t(i,u).each(function(t){n.selection.setRng(t),n.focus(),e.clear(i)})})},l=function(t){var e=u();return a(e).bind(function(t){var i=X.fromDom(n.getDoc()),u=Mr.forMenu(r,t,e),a=qe(o.noop,i,f.none());return ka(t,u,a)})},s=function(t){Fa.each(function(o){var i=S.map(o,function(n){return Ce(n)}),c=u();a(c).bind(function(o){var u=X.fromDom(n.getDoc()),a=ze(u),l=Mr.pasteRows(r,o,c,i,a);t(o,l).each(function(t){n.selection.setRng(t),n.focus(),e.clear(o)})})})};za({mceTableSplitCells:function(){c(t.unmergeCells)},mceTableMergeCells:function(){c(t.mergeCells)},mceTableInsertRowBefore:function(){c(t.insertRowsBefore)},mceTableInsertRowAfter:function(){c(t.insertRowsAfter)},mceTableInsertColBefore:function(){c(t.insertColumnsBefore)},mceTableInsertColAfter:function(){c(t.insertColumnsAfter)},mceTableDeleteCol:function(){c(t.deleteColumn)},mceTableDeleteRow:function(){c(t.deleteRow)},mceTableCutRow:function(n){Fa=l(),c(t.deleteRow)},mceTableCopyRow:function(n){Fa=l()},mceTablePasteRowBefore:function(n){s(t.pasteRowsBefore)},mceTablePasteRowAfter:function(n){s(t.pasteRowsAfter)},mceTableDelete:function(){var t=X.fromDom(n.dom.getParent(n.selection.getStart(),"th,td"));jt(t,i).filter(o.not(i)).each(function(t){var e=X.fromText("");le.after(t,e),ge.remove(t);var r=n.dom.createRng();r.setStart(e.dom(),0),r.setEnd(e.dom(),0),n.selection.setRng(r)})}},function(t,e){n.addCommand(e,t)}),za({mceInsertTable:o.curry(Wa,n),mceTableProps:o.curry(Wa,n,!0),mceTableRowProps:o.curry(Ma,n),mceTableCellProps:o.curry(qa,n)},function(t,e){n.addCommand(e,function(n,e){t(e)})})},getClipboardRows:function(){return Fa.fold(function(){},function(n){return S.map(n,function(n){return n.dom()})})},setClipboardRows:function(n){var t=S.map(n,X.fromDom);Fa=f.from(t)}},Ha=function(n){var t=f.from(n.dom().documentElement).map(X.fromDom).getOr(n);return{parent:o.constant(t),view:o.constant(n),origin:o.constant(vo(0,0))}},Va=function(n,t){return{parent:o.constant(t),view:o.constant(n),origin:o.constant(vo(0,0))}},Ua=function(n){var t=L.immutable.apply(null,n),e=[];return{bind:function(n){if(n===undefined)throw"Event bind error: undefined handler";e.push(n)},unbind:function(n){e=S.filter(e,function(t){return t!==n})},trigger:function(){var n=t.apply(null,arguments);S.each(e,function(t){t(n)})}}},Ga=function(n){return{registry:N.map(n,function(n){return{bind:n.bind,unbind:n.unbind}}),trigger:N.map(n,function(n){return n.trigger})}},Xa={mode:qo.exactly(["compare","extract","mutate","sink"]),sink:qo.exactly(["element","start","stop","destroy"]),api:qo.exactly(["forceDrop","drop","move","delayDrop"])},Ya={resolve:Di("ephox-dragster").resolve},$a=function(n,t){return function(e){if(n(e)){var r=X.fromDom(e.target),i=function(){e.stopPropagation()},u=function(){e.preventDefault()},a=o.compose(u,i),c=function(n,t,e,r,i,u,a){return{target:o.constant(n),x:o.constant(t),y:o.constant(e),stop:r,prevent:i,kill:u,raw:o.constant(a)}}(r,e.clientX,e.clientY,i,u,a,e);t(c)}}},Ka=function(n,t,e,r,i){var u=$a(e,r);return n.dom().addEventListener(t,u,i),{unbind:o.curry(Ja,n,t,u,i)}},Ja=function(n,t,e,r){n.dom().removeEventListener(t,e,r)},Qa=function(n,t,e,r){return Ka(n,t,e,r,!1)},Za=o.constant(!0),nc=function(n,t,e){return Qa(n,t,Za,e)},tc=Xa.mode({compare:function(n,t){return vo(t.left()-n.left(),t.top()-n.top())},extract:function(n){return f.some(vo(n.x(),n.y()))},sink:function(n,t){var e=function(n){var t=ii.merge({layerClass:Ya.resolve("blocker")},n),e=X.fromTag("div");return pt(e,"role","presentation"),re(e,{position:"fixed",left:"0px",top:"0px",width:"100%",height:"100%"}),Fi.add(e,Ya.resolve("blocker")),Fi.add(e,t.layerClass),{element:function(){return e},destroy:function(){ge.remove(e)}}}(t),r=nc(e.element(),"mousedown",n.forceDrop),o=nc(e.element(),"mouseup",n.drop),i=nc(e.element(),"mousemove",n.move),u=nc(e.element(),"mouseout",n.delayDrop);return Xa.sink({element:e.element,start:function(n){le.append(n,e.element())},stop:function(){ge.remove(e.element())},destroy:function(){e.destroy(),o.unbind(),i.unbind(),u.unbind(),r.unbind()}})},mutate:function(n,t){n.mutate(t.left(),t.top())}}),ec=function(){var n=f.none(),t=Ga({move:Ua(["info"])});return{onEvent:function(e,r){r.extract(e).each(function(e){(function(t,e){var r=n.map(function(n){return t.compare(n,e)});return n=f.some(e),r})(r,e).each(function(n){t.trigger.move(n)})})},reset:function(){n=f.none()},events:t.registry}},rc=function(){var n={onEvent:function(n,t){},reset:o.noop},t=ec(),e=n;return{on:function(){e.reset(),e=t},off:function(){e.reset(),e=n},isOn:function(){return e===t},onEvent:function(n,t){e.onEvent(n,t)},events:t.events}},oc=function(n,t){var e=null;return{cancel:function(){null!==e&&(clearTimeout(e),e=null)},throttle:function(){var r=arguments;null!==e&&clearTimeout(e),e=setTimeout(function(){n.apply(null,r),e=null,r=null},t)}}},ic=function(n,t,e){var r=!1,o=Ga({start:Ua([]),stop:Ua([])}),i=rc(),u=function(){l.stop(),i.isOn()&&(i.off(),o.trigger.stop())},a=oc(u,200);i.events.move.bind(function(e){t.mutate(n,e.info())});var c=function(n){return function(){var t=Array.prototype.slice.call(arguments,0);if(r)return n.apply(null,t)}},l=t.sink(Xa.api({forceDrop:u,drop:c(u),move:c(function(n,e){a.cancel(),i.onEvent(n,t)}),delayDrop:c(a.throttle)}),e);return{element:l.element,go:function(n){l.start(n),i.on(),o.trigger.start()},on:function(){r=!0},off:function(){r=!1},destroy:function(){l.destroy()},events:o.registry}},uc=function(n,t){var e=t!==undefined?t:{},r=e.mode!==undefined?e.mode:tc;return ic(n,r,t)},ac=function(){var n=Ga({drag:Ua(["xDelta","yDelta","target"])}),t=f.none(),e=function(){var n=Ga({drag:Ua(["xDelta","yDelta"])});return{mutate:function(t,e){n.trigger.drag(t,e)},events:n.registry}}();e.events.drag.bind(function(e){t.each(function(t){n.trigger.drag(e.xDelta(),e.yDelta(),t)})});return{assign:function(n){t=f.some(n)},get:function(){return t},mutate:e.mutate,events:n.registry}},cc=function(n,t,e){return Pt(n,t,e).isSome()},lc=Ai.resolve("resizer-bar-dragging"),fc=function(n,t){var e=Bo.height,r=function(n,t,e){var r=ac(),i=uc(r,{}),u=f.none(),a=function(n,t){return f.from(vt(n,t))};r.events.drag.bind(function(n){a(n.target(),"data-row").each(function(t){var e=Gu.getInt(n.target(),"top");ee(n.target(),"top",e+n.yDelta()+"px")}),a(n.target(),"data-column").each(function(t){var e=Gu.getInt(n.target(),"left");ee(n.target(),"left",e+n.xDelta()+"px")})});var c=function(n,t){return Gu.getInt(n,t)-parseInt(vt(n,"data-initial-"+t),10)};i.events.stop.bind(function(){r.get().each(function(r){u.each(function(o){a(r,"data-row").each(function(n){var t=c(r,"top");wt(r,"data-initial-top"),g.trigger.adjustHeight(o,t,parseInt(n,10))}),a(r,"data-column").each(function(n){var t=c(r,"left");wt(r,"data-initial-left"),g.trigger.adjustWidth(o,t,parseInt(n,10))}),$i(n,o,e,t)})})});var l=function(t,e){g.trigger.startAdjust(),r.assign(t),pt(t,"data-initial-"+e,parseInt(ie(t,e),10)),Fi.add(t,lc),ee(t,"opacity","0.2"),i.go(n.parent())},s=nc(n.parent(),"mousedown",function(n){Zi(n.target())&&l(n.target(),"top"),nu(n.target())&&l(n.target(),"left")}),d=function(t){return Gn.eq(t,n.view())},m=nc(n.view(),"mouseover",function(r){"table"===lt.name(r.target())||cc(r.target(),"table",d)?(u="table"===lt.name(r.target())?f.some(r.target()):Pt(r.target(),"table",d)).each(function(r){$i(n,r,e,t)}):Ct.inBody(r.target())&&Qi(n)}),g=Ga({adjustHeight:Ua(["table","delta","row"]),adjustWidth:Ua(["table","delta","column"]),startAdjust:Ua([])});return{destroy:function(){s.unbind(),m.unbind(),i.destroy(),Qi(n)},refresh:function(r){$i(n,r,e,t)},on:i.on,off:i.off,hideBars:o.curry(Ki,n),showBars:o.curry(Ji,n),events:g.registry}}(n,t,e),i=Ga({beforeResize:Ua(["table"]),afterResize:Ua(["table"]),startDrag:Ua([])});return r.events.adjustHeight.bind(function(n){i.trigger.beforeResize(n.table());var t=e.delta(n.delta(),n.table());ca(n.table(),t,n.row(),e),i.trigger.afterResize(n.table())}),r.events.startAdjust.bind(function(n){i.trigger.startDrag()}),r.events.adjustWidth.bind(function(n){i.trigger.beforeResize(n.table());var e=t.delta(n.delta(),n.table());aa(n.table(),e,n.column(),t),i.trigger.afterResize(n.table())}),{on:r.on,off:r.off,hideBars:r.hideBars,showBars:r.showBars,destroy:r.destroy,events:i.registry}},sc=function(n,t){return n.inline?Va(xa.getBody(n),function(){var n=X.fromTag("div");return re(n,{position:"static",height:"0",width:"0",padding:"0",margin:"0",border:"0"}),le.append(Ct.body(),n),n}()):Ha(X.fromDom(n.getDoc()))},dc=function(n,t){n.inline&&ge.remove(t.parent())},mc=function(n){var t,e,r=f.none(),o=f.none(),i=f.none(),u=/(\d+(\.\d+)?)%/,a=function(n){return"TABLE"===n.nodeName};return n.on("init",function(){var t=Io(Da),e=sc(n);if(i=f.some(e),n.settings.object_resizing&&!1!==n.settings.table_resize_bars&&(!0===n.settings.object_resizing||"table"===n.settings.object_resizing)){var u=fc(e,t);u.on(),u.events.startDrag.bind(function(t){r=f.some(n.selection.getRng())}),u.events.afterResize.bind(function(t){var e=t.table(),o=At(e,"td[data-mce-style],th[data-mce-style]");S.each(o,function(n){wt(n,"data-mce-style")}),r.each(function(t){n.selection.setRng(t),n.focus()}),n.undoManager.add()}),o=f.some(u)}}),n.on("ObjectResizeStart",function(r){a(r.target)&&(t=r.width,e=function(t){return n.dom.getStyle(t,"width")||n.dom.getAttrib(t,"width")}(r.target))}),n.on("ObjectResized",function(r){if(a(r.target)){var o=r.target;if(u.test(e)){var i=parseFloat(u.exec(e)[1]),c=r.width*i/t;n.dom.setStyle(o,"width",c+"%")}else{var l=[];Na.each(o.rows,function(t){Na.each(t.cells,function(t){var e=n.dom.getStyle(t,"width",!0);l.push({cell:t,width:e})})}),Na.each(l,function(t){n.dom.setStyle(t.cell,"width",t.width),n.dom.setAttrib(t.cell,"width",null)})}}}),{lazyResize:function(){return o},lazyWire:function(){return i.getOr(Ha(X.fromDom(n.getBody())))},destroy:function(){o.each(function(n){n.destroy()}),i.each(function(t){dc(n,t)})}}},gc=function(n){return{fold:n}},pc=function(n){return gc(function(t,e,r,o){return t(n)})},hc=function(n){return gc(function(t,e,r,o){return e(n)})},vc=function(n,t){return gc(function(e,r,o,i){return o(n,t)})},bc=function(n){return gc(function(t,e,r,o){return o(n)})},wc=function(n,t){return jt(n,t).bind(function(t){var e=Ft(t);return S.findIndex(e,function(t){return Gn.eq(n,t)}).map(function(n){return{index:o.constant(n),all:o.constant(e)}})})},yc=function(n,t){return wc(n,t).fold(function(){return pc(n)},function(t){return t.index()+1<t.all().length?vc(n,t.all()[t.index()+1]):bc(n)})},xc=function(n,t){return wc(n,t).fold(function(){return pc()},function(t){return t.index()-1>=0?vc(n,t.all()[t.index()-1]):hc(n)})},Cc=kr([{before:["element"]},{on:["element","offset"]},{after:["element"]}]),Sc={before:Cc.before,on:Cc.on,after:Cc.after,cata:function(n,t,e,r){return n.fold(t,e,r)},getStart:function(n){return n.fold(o.identity,o.identity,o.identity)}},Rc=kr([{domRange:["rng"]},{relative:["startSitu","finishSitu"]},{exact:["start","soffset","finish","foffset"]}]),Tc=L.immutable("start","soffset","finish","foffset"),Dc={domRange:Rc.domRange,relative:Rc.relative,exact:Rc.exact,exactFromRange:function(n){return Rc.exact(n.start(),n.soffset(),n.finish(),n.foffset())},range:Tc,getWin:function(n){var t=function(n){return n.match({domRange:function(n){return X.fromDom(n.startContainer)},relative:function(n,t){return Sc.getStart(n)},exact:function(n,t,e,r){return n}})}(n);return nt.defaultView(t)}},Ac=function(n,t,e,r){var o=nt.owner(n).dom().createRange();return o.setStart(n.dom(),t),o.setEnd(e.dom(),r),o},kc=function(n,t,e,r){var o=Ac(n,t,e,r),i=Gn.eq(n,e)&&t===r;return o.collapsed&&!i},Nc=function(n,t){n.selectNodeContents(t.dom())},Oc=function(n){n.deleteContents()},Bc=function(n){return{left:o.constant(n.left),top:o.constant(n.top),right:o.constant(n.right),bottom:o.constant(n.bottom),width:o.constant(n.width),height:o.constant(n.height)}},Ec={create:function(n){return n.document.createRange()},replaceWith:function(n,t){Oc(n),n.insertNode(t.dom())},selectNodeContents:function(n,t){var e=n.document.createRange();return Nc(e,t),e},selectNodeContentsUsing:Nc,relativeToNative:function(n,t,e){var r=n.document.createRange();return function(n,t){t.fold(function(t){n.setStartBefore(t.dom())},function(t,e){n.setStart(t.dom(),e)},function(t){n.setStartAfter(t.dom())})}(r,t),function(n,t){t.fold(function(t){n.setEndBefore(t.dom())},function(t,e){n.setEnd(t.dom(),e)},function(t){n.setEndAfter(t.dom())})}(r,e),r},exactToNative:function(n,t,e,r,o){var i=n.document.createRange();return i.setStart(t.dom(),e),i.setEnd(r.dom(),o),i},deleteContents:Oc,cloneFragment:function(n){var t=n.cloneContents();return X.fromDom(t)},getFirstRect:function(n){var t=n.getClientRects(),e=t.length>0?t[0]:n.getBoundingClientRect();return e.width>0||e.height>0?f.some(e).map(Bc):f.none()},getBounds:function(n){var t=n.getBoundingClientRect();return t.width>0||t.height>0?f.some(t).map(Bc):f.none()},isWithin:function(n,t){return t.compareBoundaryPoints(n.END_TO_START,n)<1&&t.compareBoundaryPoints(n.START_TO_END,n)>-1},toString:function(n){return n.toString()}},Ic=kr([{ltr:["start","soffset","finish","foffset"]},{rtl:["start","soffset","finish","foffset"]}]),Pc=function(n,t,e){return t(X.fromDom(e.startContainer),e.startOffset,X.fromDom(e.endContainer),e.endOffset)},Wc=function(n,t){return function(n,t){var e=t.ltr();if(e.collapsed)return t.rtl().filter(function(n){return!1===n.collapsed}).map(function(n){return Ic.rtl(X.fromDom(n.endContainer),n.endOffset,X.fromDom(n.startContainer),n.startOffset)}).getOrThunk(function(){return Pc(0,Ic.ltr,e)});return Pc(0,Ic.ltr,e)}(0,function(n,t){return t.match({domRange:function(n){return{ltr:o.constant(n),rtl:f.none}},relative:function(t,e){return{ltr:mn(function(){return Ec.relativeToNative(n,t,e)}),rtl:mn(function(){return f.some(Ec.relativeToNative(n,e,t))})}},exact:function(t,e,r,o){return{ltr:mn(function(){return Ec.exactToNative(n,t,e,r,o)}),rtl:mn(function(){return f.some(Ec.exactToNative(n,r,o,t,e))})}}})}(n,t))},_c=(Ic.ltr,Ic.rtl,Wc),Mc=function(n,t){return Wc(n,t).match({ltr:function(t,e,r,o){var i=n.document.createRange();return i.setStart(t.dom(),e),i.setEnd(r.dom(),o),i},rtl:function(t,e,r,o){var i=n.document.createRange();return i.setStart(r.dom(),o),i.setEnd(t.dom(),e),i}})},Lc=function(n,t,e){return t>=n.left&&t<=n.right&&e>=n.top&&e<=n.bottom},qc=function(n,t,e,r,o){if(0===o)return 0;if(t===r)return o-1;for(var i=r,u=1;u<o;u++){var a=n(u),c=Math.abs(t-a.left);if(e>a.bottom);else{if(e<a.top||c>i)return u-1;i=c}}return 0},zc=function(n,t,e,r){var o=n.dom().createRange();o.selectNode(t.dom());var i=o.getClientRects();return ai(i,function(n){return Lc(n,e,r)?f.some(n):f.none()}).map(function(o){return function(n,t,e,r,o){var i=function(e){var r=n.dom().createRange();return r.setStart(t.dom(),e),r.collapse(!0),r},u=Te(t).length,a=qc(function(n){return i(n).getBoundingClientRect()},e,r,o.right,u);return i(a)}(n,t,e,r,o)})},Fc=function(n,t,e,r){var o=n.dom().createRange(),i=nt.children(t);return ai(i,function(t){return o.selectNode(t.dom()),Lc(o.getBoundingClientRect(),e,r)?jc(n,t,e,r):f.none()})},jc=function(n,t,e,r){return(lt.isText(t)?zc:Fc)(n,t,e,r)},Hc=function(n,t,e,r){var o=n.dom().createRange();o.selectNode(t.dom());var i=o.getBoundingClientRect(),u=Math.max(i.left,Math.min(i.right,e)),a=Math.max(i.top,Math.min(i.bottom,r));return jc(n,t,u,a)},Vc=function(n,t){return t-n.left<n.right-t},Uc=function(n,t,e){var r=n.dom().createRange();return r.selectNode(t.dom()),r.collapse(e),r},Gc=function(n,t,e){var r=n.dom().createRange();r.selectNode(t.dom());var o=r.getBoundingClientRect(),i=Vc(o,e);return(!0===i?Ie:Pe)(t).map(function(t){return Uc(n,t,i)})},Xc=function(n,t,e){var r=t.dom().getBoundingClientRect(),o=Vc(r,e);return f.some(Uc(n,t,o))},Yc=function(n,t,e){return(0===nt.children(t).length?Xc:Gc)(n,t,e)},$c=document.caretPositionFromPoint?function(n,t,e){return f.from(n.dom().caretPositionFromPoint(t,e)).bind(function(t){if(null===t.offsetNode)return f.none();var e=n.dom().createRange();return e.setStart(t.offsetNode,t.offset),e.collapse(),f.some(e)})}:document.caretRangeFromPoint?function(n,t,e){return f.from(n.dom().caretRangeFromPoint(t,e))}:function(n,t,e){return X.fromPoint(n,t,e).bind(function(r){var o=function(){return Yc(n,r,t)};return 0===nt.children(r).length?o():function(n,t,e,r){var o=n.dom().createRange();o.selectNode(t.dom());var i=o.getBoundingClientRect(),u=Math.max(i.left,Math.min(i.right,e)),a=Math.max(i.top,Math.min(i.bottom,r));return Hc(n,t,u,a)}(n,r,t,e).orThunk(o)})},Kc=function(n,t,e){var r=X.fromDom(n.document);return $c(r,t,e).map(function(n){return Dc.range(X.fromDom(n.startContainer),n.startOffset,X.fromDom(n.endContainer),n.endOffset)})},Jc=function(n,t){var e=lt.name(n);return"input"===e?Sc.after(n):S.contains(["br","img"],e)?0===t?Sc.before(n):Sc.after(n):Sc.on(n,t)},Qc=function(n,t){var e=n.fold(Sc.before,Jc,Sc.after),r=t.fold(Sc.before,Jc,Sc.after);return Dc.relative(e,r)},Zc=function(n,t,e,r){var o=Jc(n,t),i=Jc(e,r);return Dc.relative(o,i)},nl=function(n){return n.match({domRange:function(n){var t=X.fromDom(n.startContainer),e=X.fromDom(n.endContainer);return Zc(t,n.startOffset,e,n.endOffset)},relative:Qc,exact:Zc})},tl=Qc,el=Zc,rl=function(n,t){f.from(n.getSelection()).each(function(n){n.removeAllRanges(),n.addRange(t)})},ol=function(n,t,e,r,o){var i=Ec.exactToNative(n,t,e,r,o);rl(n,i)},il=function(n,t){return _c(n,t).match({ltr:function(t,e,r,o){ol(n,t,e,r,o)},rtl:function(t,e,r,o){var i=n.getSelection();i.extend?(i.collapse(t.dom(),e),i.extend(r.dom(),o)):ol(n,r,o,t,e)}})},ul=function(n){var t=X.fromDom(n.anchorNode),e=X.fromDom(n.focusNode);return kc(t,n.anchorOffset,e,n.focusOffset)?f.some(Dc.range(X.fromDom(n.anchorNode),n.anchorOffset,X.fromDom(n.focusNode),n.focusOffset)):function(n){if(n.rangeCount>0){var t=n.getRangeAt(0),e=n.getRangeAt(n.rangeCount-1);return f.some(Dc.range(X.fromDom(t.startContainer),t.startOffset,X.fromDom(e.endContainer),e.endOffset))}return f.none()}(n)},al=function(n){var t=n.getSelection();return t.rangeCount>0?ul(t):f.none()},cl=function(n,t,e,r,o){var i=el(t,e,r,o);il(n,i)},ll=function(n){return al(n).map(function(n){return Dc.exact(n.start(),n.soffset(),n.finish(),n.foffset())})},fl=function(n,t,e){var r=tl(t,e);il(n,r)},sl=function(n){var t=Dc.getWin(n).dom(),e=function(n,e,r,o){return Ec.exactToNative(t,n,e,r,o)},r=nl(n);return _c(t,r).match({ltr:e,rtl:e})},dl=function(n,t){var e=Ec.selectNodeContents(n,t);rl(n,e)},ml=function(n){n.getSelection().removeAllRanges()},gl=function(n,t){var e=Mc(n,t);return Ec.getFirstRect(e)},pl=function(n,t,e){return Kc(n,t,e)},hl=tinymce.util.Tools.resolve("tinymce.util.VK"),vl=function(n,t,e,r){return yl(n,t,yc(e),r)},bl=function(n,t,e,r){return yl(n,t,xc(e),r)},wl=function(n,t){var e=Dc.exact(t,0,t,0);return sl(e)},yl=function(n,t,e,r,o){return e.fold(f.none,f.none,function(n,t){return Ie(t).map(function(n){return wl(0,n)})},function(e){return jt(e,t).bind(function(t){var o=Mr.noMenu(e);return n.undoManager.transact(function(){r.insertRowsAfter(t,o)}),function(n,t){var e=At(t,"tr");return S.last(e).bind(function(n){return _t(n,"td,th").map(function(n){return wl(0,n)})})}(0,t)})})},xl=["table","li","dl"],Cl={handle:function(n,t,e,r){if(n.keyCode===hl.TAB){var o=xa.getBody(t),i=function(n){var t=lt.name(n);return Gn.eq(n,o)||S.contains(xl,t)},u=t.selection.getRng();if(u.collapsed){var a=X.fromDom(u.startContainer);zt(a,i).each(function(o){n.preventDefault(),(n.shiftKey?bl:vl)(t,i,o,e,r).each(function(n){t.selection.setRng(n)})})}}}},Sl={response:L.immutable("selection","kill")},Rl=function(n){return function(t){return t===n}},Tl=Rl(38),Dl=Rl(40),Al={ltr:{isBackward:Rl(37),isForward:Rl(39)},rtl:{isBackward:Rl(39),isForward:Rl(37)},isUp:Tl,isDown:Dl,isNavigation:function(n){return n>=37&&n<=40}},kl=function(n,t){var e=Mc(n,t);return{start:o.constant(X.fromDom(e.startContainer)),soffset:o.constant(e.startOffset),finish:o.constant(X.fromDom(e.endContainer)),foffset:o.constant(e.endOffset)}},Nl=function(n,t,e,r){return{start:o.constant(Sc.on(n,t)),finish:o.constant(Sc.on(e,r))}},Ol=(Hn.detect().browser.isSafari(),function(n){var t=n!==undefined?n.dom():document,e=t.body.scrollLeft||t.documentElement.scrollLeft,r=t.body.scrollTop||t.documentElement.scrollTop;return vo(e,r)}),Bl=Ol,El=function(n,t,e){(e!==undefined?e.dom():document).defaultView.scrollBy(n,t)},Il=function(n){return{elementFromPoint:function(t,e){return f.from(n.document.elementFromPoint(t,e)).map(X.fromDom)},getRect:function(n){return n.dom().getBoundingClientRect()},getRangedRect:function(t,e,r,i){var u=Dc.exact(t,e,r,i);return gl(n,u).map(function(n){return N.map(n,o.apply)})},getSelection:function(){return ll(n).map(function(t){return kl(n,t)})},fromSitus:function(t){var e=Dc.relative(t.start(),t.finish());return kl(n,e)},situsFromPoint:function(t,e){return pl(n,t,e).map(function(n){return{start:o.constant(Sc.on(n.start(),n.soffset())),finish:o.constant(Sc.on(n.finish(),n.foffset()))}})},clearSelection:function(){ml(n)},setSelection:function(t){cl(n,t.start(),t.soffset(),t.finish(),t.foffset())},setRelativeSelection:function(t,e){fl(n,t,e)},selectContents:function(t){dl(n,t)},getInnerHeight:function(){return n.innerHeight},getScrollY:function(){return Bl(X.fromDom(n.document)).top()},scrollBy:function(t,e){El(t,e,X.fromDom(n.document))}}},Pl=function(n,t,e,r,o){if(!Gn.eq(e,r))return br(e,r,t).bind(function(t){var r=t.boxes().getOr([]);return r.length>0?(o(n,r,t.start(),t.finish()),f.some(Sl.response(f.some(Nl(e,0,e,Oe(e))),!0))):f.none()})},Wl={sync:function(n,t,e,r,o,i,u){return Gn.eq(e,o)&&r===i?f.none():Mt(e,"td,th",t).bind(function(e){return Mt(o,"td,th",t).bind(function(r){return Pl(n,t,e,r,u)})})},detect:Pl,update:function(n,t,e,r,o){return yr(r,n,t,o.firstSelectedSelector(),o.lastSelectedSelector()).map(function(n){return o.clear(e),o.selectRange(e,n.boxes(),n.start(),n.finish()),n.boxes()})}},_l=L.immutableBag(["left","top","right","bottom"],[]),Ml={nu:_l,moveUp:function(n,t){return _l({left:n.left(),top:n.top()-t,right:n.right(),bottom:n.bottom()-t})},moveDown:function(n,t){return _l({left:n.left(),top:n.top()+t,right:n.right(),bottom:n.bottom()+t})},moveBottomTo:function(n,t){var e=n.bottom()-n.top();return _l({left:n.left(),top:t-e,right:n.right(),bottom:t})},moveTopTo:function(n,t){var e=n.bottom()-n.top();return _l({left:n.left(),top:t,right:n.right(),bottom:t+e})},getTop:function(n){return n.top()},getBottom:function(n){return n.bottom()},translate:function(n,t,e){return _l({left:n.left()+t,top:n.top()+e,right:n.right()+t,bottom:n.bottom()+e})},toString:function(n){return"("+n.left()+", "+n.top()+") -> ("+n.right()+", "+n.bottom()+")"}},Ll=function(n){return Ml.nu({left:n.left,top:n.top,right:n.right,bottom:n.bottom})},ql=function(n,t){return f.some(n.getRect(t))},zl=function(n,t,e){return lt.isElement(t)?ql(n,t).map(Ll):lt.isText(t)?function(n,t,e){return e>=0&&e<Oe(t)?n.getRangedRect(t,e,t,e+1):e>0?n.getRangedRect(t,e-1,t,e):f.none()}(n,t,e).map(Ll):f.none()},Fl=function(n,t){return lt.isElement(t)?ql(n,t).map(Ll):lt.isText(t)?n.getRangedRect(t,0,t,Oe(t)).map(Ll):f.none()},jl=L.immutable("item","mode"),Hl=function(n,t,e,r){var o=r!==undefined?r:Vl;return n.property().parent(t).map(function(n){return jl(n,o)})},Vl=function(n,t,e,r){var o=r!==undefined?r:Ul;return e.sibling(n,t).map(function(n){return jl(n,o)})},Ul=function(n,t,e,r){var o=r!==undefined?r:Ul,i=n.property().children(t);return e.first(i).map(function(n){return jl(n,o)})},Gl=[{current:Hl,next:Vl,fallback:f.none()},{current:Vl,next:Ul,fallback:f.some(Hl)},{current:Ul,next:Ul,fallback:f.some(Vl)}],Xl=function(n,t,e,r,o){o=o!==undefined?o:Gl;return S.find(o,function(n){return n.current===e}).bind(function(e){return e.current(n,t,r,e.next).orThunk(function(){return e.fallback.bind(function(e){return Xl(n,t,e,r)})})})},Yl={backtrack:Hl,sidestep:Vl,advance:Ul,go:Xl},$l=function(){return{sibling:function(n,t){return n.query().prevSibling(t)},first:function(n){return n.length>0?f.some(n[n.length-1]):f.none()}}},Kl=function(){return{sibling:function(n,t){return n.query().nextSibling(t)},first:function(n){return n.length>0?f.some(n[0]):f.none()}}},Jl=function(n,t,e,r,o,i){return Yl.go(n,t,r,o).bind(function(t){return i(t.item())?f.none():e(t.item())?f.some(t.item()):Jl(n,t.item(),e,t.mode(),o,i)})},Ql=function(n,t,e,r){return Jl(n,t,e,Yl.sidestep,$l(),r)},Zl=function(n,t,e,r){return Jl(n,t,e,Yl.sidestep,Kl(),r)},nf=function(n,t){return 0===n.property().children(t).length},tf=function(n,t,e,r){return Ql(n,t,e,r)},ef=function(n,t,e,r){return Zl(n,t,e,r)},rf={before:function(n,t,e){return tf(n,t,o.curry(nf,n),e)},after:function(n,t,e){return ef(n,t,o.curry(nf,n),e)},seekLeft:tf,seekRight:ef,walkers:function(){return{left:$l,right:Kl}},walk:function(n,t,e,r,o){return Yl.go(n,t,e,r,o)},backtrack:Yl.backtrack,sidestep:Yl.sidestep,advance:Yl.advance},of=He(),uf=function(n,t){return rf.before(of,n,t)},af=function(n,t){return rf.after(of,n,t)},cf=function(n,t,e){return rf.seekLeft(of,n,t,e)},lf=function(n,t,e){return rf.seekRight(of,n,t,e)},ff=kr([{none:[]},{retry:["caret"]}]),sf=function(n,t,e){return Et.closest(t,Qo).fold(o.constant(!1),function(t){return Fl(n,t).exists(function(n){return function(n,t){return n.left()<t.left()||Math.abs(t.right()-n.left())<1||n.left()>t.right()}(e,n)})})},df={point:Ml.getTop,adjuster:function(n,t,e,r,o){var i=Ml.moveUp(o,5);return Math.abs(e.top()-r.top())<1?ff.retry(i):e.bottom()<o.top()?ff.retry(i):e.bottom()===o.top()?ff.retry(Ml.moveUp(o,1)):sf(n,t,o)?ff.retry(Ml.translate(i,5,0)):ff.none()},move:Ml.moveUp,gather:uf},mf={point:Ml.getBottom,adjuster:function(n,t,e,r,o){var i=Ml.moveDown(o,5);return Math.abs(e.bottom()-r.bottom())<1?ff.retry(i):e.top()>o.bottom()?ff.retry(i):e.top()===o.bottom()?ff.retry(Ml.moveDown(o,1)):sf(n,t,o)?ff.retry(Ml.translate(i,5,0)):ff.none()},move:Ml.moveDown,gather:af},gf=function(n,t,e,r,o){return 0===o?f.some(r):function(n,t,e){return n.elementFromPoint(t,e).filter(function(n){return"table"===lt.name(n)}).isSome()}(n,r.left(),t.point(r))?function(n,t,e,r,o){return gf(n,t,e,t.move(r,5),o)}(n,t,e,r,o-1):n.situsFromPoint(r.left(),t.point(r)).bind(function(i){return i.start().fold(f.none,function(i,u){return Fl(n,i,u).bind(function(u){return t.adjuster(n,i,u,e,r).fold(f.none,function(r){return gf(n,t,e,r,o-1)})}).orThunk(function(){return f.some(r)})},f.none)})},pf=function(n,t,e){var r=n.move(e,5),o=gf(t,n,e,r,100).getOr(r);return function(n,t,e){return n.point(t)>e.getInnerHeight()?f.some(n.point(t)-e.getInnerHeight()):n.point(t)<0?f.some(-n.point(t)):f.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)})},hf={tryUp:o.curry(pf,df),tryDown:o.curry(pf,mf),ieTryUp:function(n,t){return n.situsFromPoint(t.left(),t.top()-5)},ieTryDown:function(n,t){return n.situsFromPoint(t.left(),t.bottom()+5)},getJumpSize:o.constant(5)},vf=kr([{none:["message"]},{success:[]},{failedUp:["cell"]},{failedDown:["cell"]}]),bf=function(n){return Mt(n,"tr")},wf={verify:function(n,t,e,r,o,i,u){return Mt(r,"td,th",u).bind(function(e){return Mt(t,"td,th",u).map(function(t){return Gn.eq(e,t)?Gn.eq(r,e)&&Oe(e)===o?i(t):vf.none("in same cell"):Ze(bf,[e,t]).fold(function(){return function(n,t,e){var r=n.getRect(t),o=n.getRect(e);return o.right>r.left&&o.left<r.right}(n,t,e)?vf.success():i(t)},function(n){return i(t)})})}).getOr(vf.none("default"))},cata:function(n,t,e,r,o){return n.fold(t,e,r,o)},adt:vf},yf={point:L.immutable("element","offset"),delta:L.immutable("element","deltaOffset"),range:L.immutable("element","start","finish"),points:L.immutable("begin","end"),text:L.immutable("element","text")},xf=(L.immutable("ancestor","descendants","element","index"),L.immutable("parent","children","element","index")),Cf=function(n,t){return S.findIndex(n,o.curry(Gn.eq,t))},Sf=function(n){return nt.parent(n).bind(function(t){var e=nt.children(t);return Cf(e,n).map(function(r){return xf(t,e,n,r)})})},Rf=function(n){return"br"===lt.name(n)},Tf=function(n,t,e){return t(n,e).bind(function(n){return lt.isText(n)&&0===Te(n).trim().length?Tf(n,t,e):f.some(n)})},Df=function(n,t,e,r){return function(n,t){return nt.child(n,t).filter(Rf).orThunk(function(){return nt.child(n,t-1).filter(Rf)})}(t,e).bind(function(t){return r.traverse(t).fold(function(){return Tf(t,r.gather,n).map(r.relative)},function(n){return Sf(n).map(function(n){return Sc.on(n.parent(),n.index())})})})},Af=function(n,t,e,r){return(Rf(t)?function(n,t,e){return e.traverse(t).orThunk(function(){return Tf(t,e.gather,n)}).map(e.relative)}(n,t,r):Df(n,t,e,r)).map(function(n){return{start:o.constant(n),finish:o.constant(n)}})},kf=function(n){return wf.cata(n,function(n){return f.none("BR ADT: none")},function(){return f.none()},function(n){return f.some(yf.point(n,0))},function(n){return f.some(yf.point(n,Oe(n)))})},Nf=Hn.detect(),Of=function(n,t,e,r,o,i){return 0===i?f.none():If(n,t,e,r,o).bind(function(u){var a=n.fromSitus(u),c=wf.verify(n,e,r,a.finish(),a.foffset(),o.failure,t);return wf.cata(c,function(){return f.none()},function(){return f.some(u)},function(u){return Gn.eq(e,u)&&0===r?Bf(n,e,r,Ml.moveUp,o):Of(n,t,u,0,o,i-1)},function(u){return Gn.eq(e,u)&&r===Oe(u)?Bf(n,e,r,Ml.moveDown,o):Of(n,t,u,Oe(u),o,i-1)})})},Bf=function(n,t,e,r,o){return zl(n,t,e).bind(function(t){return Ef(n,o,r(t,hf.getJumpSize()))})},Ef=function(n,t,e){return Nf.browser.isChrome()||Nf.browser.isSafari()||Nf.browser.isFirefox()||Nf.browser.isEdge()?t.otherRetry(n,e):Nf.browser.isIE()?t.ieRetry(n,e):f.none()},If=function(n,t,e,r,o){return zl(n,e,r).bind(function(t){return Ef(n,o,t)})},Pf=function(n,t,e){return function(n,t,e){return n.getSelection().bind(function(r){return Af(t,r.finish(),r.foffset(),e).fold(function(){return f.some(yf.point(r.finish(),r.foffset()))},function(o){var i=n.fromSitus(o),u=wf.verify(n,r.finish(),r.foffset(),i.finish(),i.foffset(),e.failure,t);return kf(u)})})}(n,t,e).bind(function(r){return Of(n,t,r.element(),r.offset(),e,20).map(n.fromSitus)})},Wf=function(n,t,e){return Et.ancestor(n,t,e).isSome()},_f=Hn.detect(),Mf=function(n,t,e,r,i){return Mt(r,"td,th",t).bind(function(r){return Mt(r,"table",t).bind(function(u){return function(n,t){return Wf(n,function(n){return nt.parent(n).exists(function(n){return Gn.eq(n,t)})})}(i,u)?Pf(n,t,e).bind(function(n){return Mt(n.finish(),"td,th",t).map(function(t){return{start:o.constant(r),finish:o.constant(t),range:o.constant(n)}})}):f.none()})})},Lf=function(n,t,e,r,o,i){return _f.browser.isIE()?f.none():i(r,t).orThunk(function(){return Mf(n,t,e,r,o).map(function(n){var t=n.range();return Sl.response(f.some(Nl(t.start(),t.soffset(),t.finish(),t.foffset())),!0)})})},qf=function(n,t,e,r,o,i,u){return Mf(n,e,r,o,i).bind(function(n){return Wl.detect(t,e,n.start(),n.finish(),u)})},zf=function(n,t){return Mt(n,"tr",t).bind(function(n){return Mt(n,"table",t).bind(function(e){var r=At(e,"tr");return Gn.eq(n,r[0])?cf(e,function(n){return Pe(n).isSome()},t).map(function(n){var t=Oe(n);return Sl.response(f.some(Nl(n,t,n,t)),!0)}):f.none()})})},Ff=function(n,t){return Mt(n,"tr",t).bind(function(n){return Mt(n,"table",t).bind(function(e){var r=At(e,"tr");return Gn.eq(n,r[r.length-1])?lf(e,function(n){return Ie(n).isSome()},t).map(function(n){return Sl.response(f.some(Nl(n,0,n,0)),!0)}):f.none()})})},jf=function(n,t){return Mt(n,"td,th",t)},Hf={down:{traverse:nt.nextSibling,gather:af,relative:Sc.before,otherRetry:hf.tryDown,ieRetry:hf.ieTryDown,failure:wf.adt.failedDown},up:{traverse:nt.prevSibling,gather:uf,relative:Sc.before,otherRetry:hf.tryUp,ieRetry:hf.ieTryUp,failure:wf.adt.failedUp}},Vf=L.immutable("rows","cols"),Uf=function(n,t,e,r){var o=function(n,t,e,r){var o=f.none(),i=function(){o=f.none()};return{mousedown:function(n){r.clear(t),o=jf(n.target(),e)},mouseover:function(i){o.each(function(o){r.clear(t),jf(i.target(),e).each(function(i){br(o,i,e).each(function(e){var u=e.boxes().getOr([]);(u.length>1||1===u.length&&!Gn.eq(o,i))&&(r.selectRange(t,u,e.start(),e.finish()),n.selectContents(i))})})})},mouseup:function(){o.each(i)}}}(Il(n),t,e,r);return{mousedown:o.mousedown,mouseover:o.mouseover,mouseup:o.mouseup}},Gf=function(n,t,e,r){var i=Il(n),u=function(){return r.clear(t),f.none()};return{keydown:function(n,a,c,l,s,d){var m=n.raw().which,g=!0===n.raw().shiftKey;return wr(t,r.selectedSelector()).fold(function(){return Al.isDown(m)&&g?o.curry(qf,i,t,e,Hf.down,l,a,r.selectRange):Al.isUp(m)&&g?o.curry(qf,i,t,e,Hf.up,l,a,r.selectRange):Al.isDown(m)?o.curry(Lf,i,e,Hf.down,l,a,Ff):Al.isUp(m)?o.curry(Lf,i,e,Hf.up,l,a,zf):f.none},function(n){var e=function(e){return function(){return ai(e,function(e){return Wl.update(e.rows(),e.cols(),t,n,r)}).fold(function(){return xr(t,r.firstSelectedSelector(),r.lastSelectedSelector()).map(function(n){var e=Al.isDown(m)||d.isForward(m)?Sc.after:Sc.before;return i.setRelativeSelection(Sc.on(n.first(),0),e(n.table())),r.clear(t),Sl.response(f.none(),!0)})},function(n){return f.some(Sl.response(f.none(),!0))})}};return Al.isDown(m)&&g?e([Vf(1,0)]):Al.isUp(m)&&g?e([Vf(-1,0)]):d.isBackward(m)&&g?e([Vf(0,-1),Vf(-1,0)]):d.isForward(m)&&g?e([Vf(0,1),Vf(1,0)]):Al.isNavigation(m)&&!1===g?u:f.none})()},keyup:function(n,o,i,u,a){return wr(t,r.selectedSelector()).fold(function(){var c=n.raw().which;return 0==(!0===n.raw().shiftKey)?f.none():Al.isNavigation(c)?Wl.sync(t,e,o,i,u,a,r.selectRange):f.none()},f.none)}}},Xf=function(n){var t=function(t){wt(t,n.selected()),wt(t,n.firstSelected()),wt(t,n.lastSelected())},e=function(t){pt(t,n.selected(),"1")},r=function(e){var r=At(e,n.selectedSelector());S.each(r,t)};return{clear:r,selectRange:function(t,o,i,u){r(t),S.each(o,e),pt(i,n.firstSelected(),"1"),pt(u,n.lastSelected(),"1")},selectedSelector:n.selectedSelector,firstSelectedSelector:n.firstSelectedSelector,lastSelectedSelector:n.lastSelectedSelector}},Yf=function(n,t){var e=L.immutableBag(["mousedown","mouseover","mouseup","keyup","keydown"],[]),r=f.none(),i=Xf(Ar);n.on("init",function(u){var a=n.getWin(),c=xa.getBody(n),l=xa.getIsRoot(n),s=Uf(a,c,l,i),d=Gf(a,c,l,i),m=function(t,e){e.kill()&&t.kill(),e.selection().each(function(t){var e=Dc.relative(t.start(),t.finish()),r=Mc(a,e);n.selection.setRng(r)})},g=function(t){var e=v(t);if(e.raw().shiftKey&&Al.isNavigation(e.raw().which)){var r=n.selection.getRng(),o=X.fromDom(r.startContainer),i=X.fromDom(r.endContainer);d.keyup(e,o,r.startOffset,i,r.endOffset).each(function(n){m(e,n)})}},p=function(n){return!(bt(n,"data-mce-bogus")||"br"===lt.name(n)||lt.isText(n)&&0===Te(n).length)},h=function(e){var r=v(e);t().each(function(n){n.hideBars()}),40===e.which&&function(){var t=X.fromDom(n.getBody()),e=function(n){return nt.prevSibling(n).bind(function(n){return p(n)?f.some(n):e(n)})};return nt.lastChild(t).bind(function(n){return p(n)?f.some(n):e(n)})}().each(function(t){"table"===lt.name(t)&&(n.settings.forced_root_block?n.dom.add(n.getBody(),n.settings.forced_root_block,n.settings.forced_root_block_attrs,"<br/>"):n.dom.add(n.getBody(),"br"))});var o=n.selection.getRng(),i=X.fromDom(n.selection.getStart()),u=X.fromDom(o.startContainer),a=X.fromDom(o.endContainer),c=Da(i).isRtl()?Al.rtl:Al.ltr;d.keydown(r,u,o.startOffset,a,o.endOffset,c).each(function(n){m(r,n)}),t().each(function(n){n.showBars()})},v=function(n){var t=X.fromDom(n.target),e=function(){n.stopPropagation()},r=function(){n.preventDefault()},i=o.compose(r,e);return{target:o.constant(t),x:o.constant(n.x),y:o.constant(n.y),stop:e,prevent:r,kill:i,raw:o.constant(n)}},b=function(n){return 0===n.button},w=function(n){b(n)&&s.mousedown(v(n))},y=function(n){(function(n){return n.buttons===undefined||0!=(1&n.buttons)})(n)&&s.mouseover(v(n))},x=function(n){b&&s.mouseup(v(n))};n.on("mousedown",w),n.on("mouseover",y),n.on("mouseup",x),n.on("keyup",g),n.on("keydown",h),n.on("nodechange",function(){var t=n.selection,e=X.fromDom(t.getStart()),r=X.fromDom(t.getEnd()),u=jt(e),a=jt(r);u.bind(function(n){return a.bind(function(t){return Gn.eq(n,t)?f.some(!0):f.none()})}).fold(function(){i.clear(c)},o.noop)}),r=f.some(e({mousedown:w,mouseover:y,mouseup:x,keyup:g,keydown:h}))});return{clear:i.clear,destroy:function(){r.each(function(n){})}}},$f=function(n){return{get:function(){var t=xa.getBody(n);return Cr(t,Ar.selectedSelector()).fold(function(){return n.selection.getStart()===undefined?Or.none():Or.single(n.selection)},function(n){return Or.multiple(n)})}}},Kf=Na.each,Jf={addButtons:function(n){function t(t){return function(){n.execCommand(t)}}var e=[];Kf("inserttable tableprops deletetable | cell row column".split(" "),function(t){"|"===t?e.push({text:"-"}):e.push(n.menuItems[t])}),n.addButton("table",{type:"menubutton",title:"Table",menu:e}),n.addButton("tableprops",{title:"Table properties",onclick:o.curry(Wa,n,!0),icon:"table"}),n.addButton("tabledelete",{title:"Delete table",onclick:t("mceTableDelete")}),n.addButton("tablecellprops",{title:"Cell properties",onclick:t("mceTableCellProps")}),n.addButton("tablemergecells",{title:"Merge cells",onclick:t("mceTableMergeCells")}),n.addButton("tablesplitcells",{title:"Split cell",onclick:t("mceTableSplitCells")}),n.addButton("tableinsertrowbefore",{title:"Insert row before",onclick:t("mceTableInsertRowBefore")}),n.addButton("tableinsertrowafter",{title:"Insert row after",onclick:t("mceTableInsertRowAfter")}),n.addButton("tabledeleterow",{title:"Delete row",onclick:t("mceTableDeleteRow")}),n.addButton("tablerowprops",{title:"Row properties",onclick:t("mceTableRowProps")}),n.addButton("tablecutrow",{title:"Cut row",onclick:t("mceTableCutRow")}),n.addButton("tablecopyrow",{title:"Copy row",onclick:t("mceTableCopyRow")}),n.addButton("tablepasterowbefore",{title:"Paste row before",onclick:t("mceTablePasteRowBefore")}),n.addButton("tablepasterowafter",{title:"Paste row after",onclick:t("mceTablePasteRowAfter")}),n.addButton("tableinsertcolbefore",{title:"Insert column before",onclick:t("mceTableInsertColBefore")}),n.addButton("tableinsertcolafter",{title:"Insert column after",onclick:t("mceTableInsertColAfter")}),n.addButton("tabledeletecol",{title:"Delete column",onclick:t("mceTableDeleteCol")})},addToolbars:function(n){var t=n.settings.table_toolbar;""!==t&&!1!==t&&(t||(t="tableprops tabledelete | tableinsertrowbefore tableinsertrowafter tabledeleterow | tableinsertcolbefore tableinsertcolafter tabledeletecol"),n.addContextToolbar(function(t){return n.dom.is(t,"table")&&n.getBody().contains(t)},t))}},Qf={addMenuItems:function(n,t){function e(t){return function(){n.execCommand(t)}}var r=f.none(),i=[],u=[],a=[],c=[],l=function(n){n.disabled(!0)},s=function(n){n.disabled(!1)},d=function(){var n=this;i.push(n),r.fold(function(){l(n)},function(t){s(n)})},m=function(){var n=this;u.push(n),r.fold(function(){l(n)},function(t){s(n)})};n.on("init",function(){n.on("nodechange",function(e){var o=f.from(n.dom.getParent(n.selection.getStart(),"th,td"));(r=o.bind(function(n){var e=X.fromDom(n);return jt(e).map(function(n){return Mr.forMenu(t,n,e)})})).fold(function(){S.each(i,l),S.each(u,l),S.each(a,l),S.each(c,l)},function(n){S.each(i,s),S.each(u,s),S.each(a,function(t){t.disabled(n.mergable().isNone())}),S.each(c,function(t){t.disabled(n.unmergable().isNone())})})})});var g=function(n,t,e,r){var o,i,u,a,c,l=r.getEl().getElementsByTagName("table")[0],f=r.isRtl()||"tl-tr"===r.parent().rel;for(l.nextSibling.innerHTML=t+1+" x "+(e+1),f&&(t=9-t),i=0;i<10;i++)for(o=0;o<10;o++)a=l.rows[i].childNodes[o].firstChild,c=(f?o>=t:o<=t)&&i<=e,n.dom.toggleClass(a,"mce-active",c),c&&(u=a);return u.parentNode},p=!1===n.settings.table_grid?{text:"Table",icon:"table",context:"table",onclick:o.curry(Wa,n)}:{text:"Table",icon:"table",context:"table",ariaHideMenu:!0,onclick:function(t){t.aria&&(this.parent().hideAll(),t.stopImmediatePropagation(),Wa(n))},onshow:function(){g(n,0,0,this.menu.items()[0])},onhide:function(){var t=this.menu.items()[0].getEl().getElementsByTagName("a");n.dom.removeClass(t,"mce-active"),n.dom.addClass(t[0],"mce-active")},menu:[{type:"container",html:function(){var n="";n='<table role="grid" class="mce-grid mce-grid-border" aria-readonly="true">';for(var t=0;t<10;t++){n+="<tr>";for(var e=0;e<10;e++)n+='<td role="gridcell" tabindex="-1"><a id="mcegrid'+(10*t+e)+'" href="#" data-mce-x="'+e+'" data-mce-y="'+t+'"></a></td>';n+="</tr>"}return n+="</table>",n+='<div class="mce-text-center" role="presentation">1 x 1</div>'}(),onPostRender:function(){this.lastX=this.lastY=0},onmousemove:function(t){var e,r,o=t.target;"A"===o.tagName.toUpperCase()&&(e=parseInt(o.getAttribute("data-mce-x"),10),r=parseInt(o.getAttribute("data-mce-y"),10),(this.isRtl()||"tl-tr"===this.parent().rel)&&(e=9-e),e===this.lastX&&r===this.lastY||(g(n,e,r,t.control),this.lastX=e,this.lastY=r))},onclick:function(t){var e=this;"A"===t.target.tagName.toUpperCase()&&(t.preventDefault(),t.stopPropagation(),e.parent().cancel(),n.undoManager.transact(function(){Gr.insert(n,e.lastX+1,e.lastY+1)}),n.addVisual())}}]},h={text:"Table properties",context:"table",onPostRender:d,onclick:o.curry(Wa,n,!0)},v={text:"Delete table",context:"table",onPostRender:d,cmd:"mceTableDelete"},b={text:"Row",context:"table",menu:[{text:"Insert row before",onclick:e("mceTableInsertRowBefore"),onPostRender:m},{text:"Insert row after",onclick:e("mceTableInsertRowAfter"),onPostRender:m},{text:"Delete row",onclick:e("mceTableDeleteRow"),onPostRender:m},{text:"Row properties",onclick:e("mceTableRowProps"),onPostRender:m},{text:"-"},{text:"Cut row",onclick:e("mceTableCutRow"),onPostRender:m},{text:"Copy row",onclick:e("mceTableCopyRow"),onPostRender:m},{text:"Paste row before",onclick:e("mceTablePasteRowBefore"),onPostRender:m},{text:"Paste row after",onclick:e("mceTablePasteRowAfter"),onPostRender:m}]},w={text:"Column",context:"table",menu:[{text:"Insert column before",onclick:e("mceTableInsertColBefore"),onPostRender:m},{text:"Insert column after",onclick:e("mceTableInsertColAfter"),onPostRender:m},{text:"Delete column",onclick:e("mceTableDeleteCol"),onPostRender:m}]},y={separator:"before",text:"Cell",context:"table",menu:[{text:"Cell properties",onclick:e("mceTableCellProps"),onPostRender:m},{text:"Merge cells",onclick:e("mceTableMergeCells"),onPostRender:function(){var n=this;a.push(n),r.fold(function(){l(n)},function(t){n.disabled(t.mergable().isNone())})}},{text:"Split cell",onclick:e("mceTableSplitCells"),onPostRender:function(){var n=this;c.push(n),r.fold(function(){l(n)},function(t){n.disabled(t.unmergable().isNone())})}}]};n.addMenuItem("inserttable",p),n.addMenuItem("tableprops",h),n.addMenuItem("deletetable",v),n.addMenuItem("row",b),n.addMenuItem("column",w),n.addMenuItem("cell",y)}};e.add("table",function(n){var t=mc(n),e=Yf(n,t.lazyResize),r=Aa(n,t.lazyWire),o=$f(n);ja.registerCommands(n,r,e,o),Lr.registerEvents(n,o,r,e),Qf.addMenuItems(n,o),Jf.addButtons(n),Jf.addToolbars(n),n.on("PreInit",function(){n.serializer.addTempAttr(Ar.firstSelected()),n.serializer.addTempAttr(Ar.lastSelected())}),!1!==n.settings.table_tab_navigation&&n.on("keydown",function(e){Cl.handle(e,n,r,t.lazyWire)}),n.on("remove",function(){t.destroy(),e.destroy()}),this.insertTable=function(t,e){return Gr.insert(n,t,e)},this.setClipboardRows=ja.setClipboardRows,this.getClipboardRows=ja.getClipboardRows})}(); |