45219 lines
1.8 MiB
Vendored
45219 lines
1.8 MiB
Vendored
/**
|
|
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
|
|
* Licensed under the LGPL or a commercial license.
|
|
* For LGPL see License.txt in the project root for license information.
|
|
* For commercial licenses see https://www.tiny.cloud/
|
|
*
|
|
* Version: 5.3.1 (2020-05-27)
|
|
*/
|
|
!function(V){"use strict";var r=function(e){if(null===e)return"null";if(e===undefined)return"undefined";var t=typeof e;return"object"==t&&(Array.prototype.isPrototypeOf(e)||e.constructor&&"Array"===e.constructor.name)?"array":"object"==t&&(String.prototype.isPrototypeOf(e)||e.constructor&&"String"===e.constructor.name)?"string":t},t=function(e){return{eq:e}},s=t(function(e,t){return e===t}),i=function(o){return t(function(e,t){if(e.length!==t.length)return!1;for(var n=e.length,r=0;r<n;r++)if(!o.eq(e[r],t[r]))return!1;return!0})},c=function(e,r){return n=i(e),o=function(e){return t=e,n=r,Array.prototype.slice.call(t).sort(n);var t,n},t(function(e,t){return n.eq(o(e),o(t))});var n,o},u=function(u){return t(function(e,t){var n=Object.keys(e),r=Object.keys(t);if(!c(s).eq(n,r))return!1;for(var o=n.length,i=0;i<o;i++){var a=n[i];if(!u.eq(e[a],t[a]))return!1}return!0})},l=t(function(e,t){if(e===t)return!0;var n=r(e);return n===r(t)&&(-1!==["undefined","boolean","number","string","function","xml","null"].indexOf(n)?e===t:"array"===n?i(l).eq(e,t):"object"===n&&u(l).eq(e,t))}),f=function(){},a=function(n,r){return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return n(r.apply(null,e))}},x=function(e){return function(){return e}},d=function(e){return e};function N(r){for(var o=[],e=1;e<arguments.length;e++)o[e-1]=arguments[e];return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];var n=o.concat(e);return r.apply(null,n)}}var e,n,o,m=function(t){return function(e){return!t(e)}},p=function(e){return function(){throw new Error(e)}},g=x(!1),h=x(!0),v=function(){return y},y=(e=function(e){return e.isNone()},{fold:function(e,t){return e()},is:g,isSome:g,isNone:h,getOr:o=function(e){return e},getOrThunk:n=function(e){return e()},getOrDie:function(e){throw new Error(e||"error: getOrDie called on none.")},getOrNull:x(null),getOrUndefined:x(undefined),or:o,orThunk:n,map:v,each:f,bind:v,exists:g,forall:h,filter:v,equals:e,equals_:e,toArray:function(){return[]},toString:x("none()")}),b=function(n){var e=x(n),t=function(){return o},r=function(e){return e(n)},o={fold:function(e,t){return t(n)},is:function(e){return n===e},isSome:h,isNone:g,getOr:e,getOrThunk:e,getOrDie:e,getOrNull:e,getOrUndefined:e,or:t,orThunk:t,map:function(e){return b(e(n))},each:function(e){e(n)},bind:r,exists:r,forall:r,filter:function(e){return e(n)?o:y},toArray:function(){return[n]},toString:function(){return"some("+n+")"},equals:function(e){return e.is(n)},equals_:function(e,t){return e.fold(g,function(e){return t(n,e)})}};return o},R={some:b,none:v,from:function(e){return null===e||e===undefined?y:b(e)}},C=function(r){return function(e){return n=typeof(t=e),(null===t?"null":"object"==n&&(Array.prototype.isPrototypeOf(t)||t.constructor&&"Array"===t.constructor.name)?"array":"object"==n&&(String.prototype.isPrototypeOf(t)||t.constructor&&"String"===t.constructor.name)?"string":n)===r;var t,n}},w=function(t){return function(e){return typeof e===t}},S=function(t){return function(e){return t===e}},q=C("string"),E=C("object"),k=C("array"),_=S(null),T=w("boolean"),A=S(undefined),D=w("function"),O=w("number"),B=Array.prototype.slice,P=Array.prototype.indexOf,L=Array.prototype.push,I=function(e,t){return P.call(e,t)},M=function(e,t){return-1<I(e,t)},F=function(e,t){for(var n=0,r=e.length;n<r;n++){if(t(e[n],n))return!0}return!1},U=function(e,t){for(var n=e.length,r=new Array(n),o=0;o<n;o++){var i=e[o];r[o]=t(i,o)}return r},z=function(e,t){for(var n=0,r=e.length;n<r;n++){t(e[n],n)}},j=function(e,t){for(var n=[],r=[],o=0,i=e.length;o<i;o++){var a=e[o];(t(a,o)?n:r).push(a)}return{pass:n,fail:r}},H=function(e,t){for(var n=[],r=0,o=e.length;r<o;r++){var i=e[r];t(i,r)&&n.push(i)}return n},$=function(e,t,n){return function(e,t){for(var n=e.length-1;0<=n;n--){t(e[n],n)}}(e,function(e){n=t(n,e)}),n},W=function(e,t,n){return z(e,function(e){n=t(n,e)}),n},K=function(e,t){return function(e,t,n){for(var r=0,o=e.length;r<o;r++){var i=e[r];if(t(i,r))return R.some(i);if(n(i,r))break}return R.none()}(e,t,g)},X=function(e,t){for(var n=0,r=e.length;n<r;n++){if(t(e[n],n))return R.some(n)}return R.none()},Y=function(e,t){return function(e){for(var t=[],n=0,r=e.length;n<r;++n){if(!k(e[n]))throw new Error("Arr.flatten item "+n+" was not an array, input: "+e);L.apply(t,e[n])}return t}(U(e,t))},G=function(e,t){for(var n=0,r=e.length;n<r;++n){if(!0!==t(e[n],n))return!1}return!0},J=function(e){var t=B.call(e,0);return t.reverse(),t},Q=function(e,t){return H(e,function(e){return!M(t,e)})},Z=function(e){return 0===e.length?R.none():R.some(e[0])},ee=function(e){return 0===e.length?R.none():R.some(e[e.length-1])},te=D(Array.from)?Array.from:function(e){return B.call(e)},ne=Object.keys,re=Object.hasOwnProperty,oe=function(e,t){for(var n=ne(e),r=0,o=n.length;r<o;r++){var i=n[r];t(e[i],i)}},ie=function(e,n){return ae(e,function(e,t){return{k:t,v:n(e,t)}})},ae=function(e,r){var o={};return oe(e,function(e,t){var n=r(e,t);o[n.k]=n.v}),o},ue=function(n){return function(e,t){n[t]=e}},se=function(e,n,r,o){return oe(e,function(e,t){(n(e,t)?r:o)(e,t)}),{}},ce=function(e,t){var n={},r={};return se(e,t,ue(n),ue(r)),{t:n,f:r}},le=function(e,t){var n={};return se(e,t,ue(n),f),n},fe=function(e){return n=function(e){return e},r=[],oe(e,function(e,t){r.push(n(e,t))}),r;var n,r},de=function(e,t){return me(e,t)?R.from(e[t]):R.none()},me=function(e,t){return re.call(e,t)},pe=function(){return(pe=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function ge(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,u=i.length;a<u;a++,o++)r[o]=i[a];return r}var he,ve,ye,be,Ce,we,xe,Se=function(e){if(null===e||e===undefined)throw new Error("Node cannot be null or undefined");return{dom:x(e)}},Ne={fromHtml:function(e,t){var n=(t||V.document).createElement("div");if(n.innerHTML=e,!n.hasChildNodes()||1<n.childNodes.length)throw V.console.error("HTML does not have a single root node",e),new Error("HTML must have a single root node");return Se(n.childNodes[0])},fromTag:function(e,t){var n=(t||V.document).createElement(e);return Se(n)},fromText:function(e,t){var n=(t||V.document).createTextNode(e);return Se(n)},fromDom:Se,fromPoint:function(e,t,n){var r=e.dom();return R.from(r.elementFromPoint(t,n)).map(Se)}},Ee=function(e,t){var n=function(e,t){for(var n=0;n<e.length;n++){var r=e[n];if(r.test(t))return r}return undefined}(e,t);if(!n)return{major:0,minor:0};var r=function(e){return Number(t.replace(n,"$"+e))};return _e(r(1),r(2))},ke=function(){return _e(0,0)},_e=function(e,t){return{major:e,minor:t}},Re={nu:_e,detect:function(e,t){var n=String(t).toLowerCase();return 0===e.length?ke():Ee(e,n)},unknown:ke},Te="Firefox",Ae=function(e){var t=e.current,n=e.version,r=function(e){return function(){return t===e}};return{current:t,version:n,isEdge:r("Edge"),isChrome:r("Chrome"),isIE:r("IE"),isOpera:r("Opera"),isFirefox:r(Te),isSafari:r("Safari")}},De={unknown:function(){return Ae({current:undefined,version:Re.unknown()})},nu:Ae,edge:x("Edge"),chrome:x("Chrome"),ie:x("IE"),opera:x("Opera"),firefox:x(Te),safari:x("Safari")},Oe="Windows",Be="Android",Pe="Solaris",Le="FreeBSD",Ie="ChromeOS",Me=function(e){var t=e.current,n=e.version,r=function(e){return function(){return t===e}};return{current:t,version:n,isWindows:r(Oe),isiOS:r("iOS"),isAndroid:r(Be),isOSX:r("OSX"),isLinux:r("Linux"),isSolaris:r(Pe),isFreeBSD:r(Le),isChromeOS:r(Ie)}},Fe={unknown:function(){return Me({current:undefined,version:Re.unknown()})},nu:Me,windows:x(Oe),ios:x("iOS"),android:x(Be),linux:x("Linux"),osx:x("OSX"),solaris:x(Pe),freebsd:x(Le),chromeos:x(Ie)},Ue=function(e,t){var n=String(t).toLowerCase();return K(e,function(e){return e.search(n)})},ze=function(e,n){return Ue(e,n).map(function(e){var t=Re.detect(e.versionRegexes,n);return{current:e.name,version:t}})},je=function(e,n){return Ue(e,n).map(function(e){var t=Re.detect(e.versionRegexes,n);return{current:e.name,version:t}})},He=function(e,t){return-1!==e.indexOf(t)},Ve=function(e,t){return n=e,o=0,""===(r=t)||n.length>=r.length&&n.substr(o,o+r.length)===r;var n,r,o},qe=function(t){return function(e){return e.replace(t,"")}},$e=qe(/^\s+|\s+$/g),We=qe(/^\s+/g),Ke=qe(/\s+$/g),Xe=/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,Ye=function(t){return function(e){return He(e,t)}},Ge=[{name:"Edge",versionRegexes:[/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],search:function(e){return He(e,"edge/")&&He(e,"chrome")&&He(e,"safari")&&He(e,"applewebkit")}},{name:"Chrome",versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/,Xe],search:function(e){return He(e,"chrome")&&!He(e,"chromeframe")}},{name:"IE",versionRegexes:[/.*?msie\ ?([0-9]+)\.([0-9]+).*/,/.*?rv:([0-9]+)\.([0-9]+).*/],search:function(e){return He(e,"msie")||He(e,"trident")}},{name:"Opera",versionRegexes:[Xe,/.*?opera\/([0-9]+)\.([0-9]+).*/],search:Ye("opera")},{name:"Firefox",versionRegexes:[/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],search:Ye("firefox")},{name:"Safari",versionRegexes:[Xe,/.*?cpu os ([0-9]+)_([0-9]+).*/],search:function(e){return(He(e,"safari")||He(e,"mobile/"))&&He(e,"applewebkit")}}],Je=[{name:"Windows",search:Ye("win"),versionRegexes:[/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]},{name:"iOS",search:function(e){return He(e,"iphone")||He(e,"ipad")},versionRegexes:[/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,/.*cpu os ([0-9]+)_([0-9]+).*/,/.*cpu iphone os ([0-9]+)_([0-9]+).*/]},{name:"Android",search:Ye("android"),versionRegexes:[/.*?android\ ?([0-9]+)\.([0-9]+).*/]},{name:"OSX",search:Ye("mac os x"),versionRegexes:[/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]},{name:"Linux",search:Ye("linux"),versionRegexes:[]},{name:"Solaris",search:Ye("sunos"),versionRegexes:[]},{name:"FreeBSD",search:Ye("freebsd"),versionRegexes:[]},{name:"ChromeOS",search:Ye("cros"),versionRegexes:[/.*?chrome\/([0-9]+)\.([0-9]+).*/]}],Qe={browsers:x(Ge),oses:x(Je)},Ze=function(e,t){var n,r,o,i,a,u,s,c,l,f,d,m,p=Qe.browsers(),g=Qe.oses(),h=ze(p,e).fold(De.unknown,De.nu),v=je(g,e).fold(Fe.unknown,Fe.nu);return{browser:h,os:v,deviceType:(r=h,o=e,i=t,a=(n=v).isiOS()&&!0===/ipad/i.test(o),u=n.isiOS()&&!a,s=n.isiOS()||n.isAndroid(),c=s||i("(pointer:coarse)"),l=a||!u&&s&&i("(min-device-width:768px)"),f=u||s&&!l,d=r.isSafari()&&n.isiOS()&&!1===/safari/i.test(o),m=!f&&!l&&!d,{isiPad:x(a),isiPhone:x(u),isTablet:x(l),isPhone:x(f),isTouch:x(c),isAndroid:n.isAndroid,isiOS:n.isiOS,isWebView:x(d),isDesktop:x(m)})}},et=function(e){return V.window.matchMedia(e).matches},tt=(ye=!(he=function(){return Ze(V.navigator.userAgent,et)}),function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return ye||(ye=!0,ve=he.apply(null,e)),ve}),nt=function(){return tt()},rt=function(e,t){for(var n=[],r=function(e){return n.push(e),t(e)},o=t(e);(o=o.bind(r)).isSome(););return n},ot=function(e,t){var n=e.dom();if(1!==n.nodeType)return!1;var r=n;if(r.matches!==undefined)return r.matches(t);if(r.msMatchesSelector!==undefined)return r.msMatchesSelector(t);if(r.webkitMatchesSelector!==undefined)return r.webkitMatchesSelector(t);if(r.mozMatchesSelector!==undefined)return r.mozMatchesSelector(t);throw new Error("Browser lacks native selectors")},it=function(e){return 1!==e.nodeType&&9!==e.nodeType||0===e.childElementCount},at=function(e,t){return e.dom()===t.dom()},ut=function(e,t){return n=e.dom(),r=t.dom(),o=n,i=r,a=V.Node.DOCUMENT_POSITION_CONTAINED_BY,0!=(o.compareDocumentPosition(i)&a);var n,r,o,i,a},st=function(e,t){return nt().browser.isIE()?ut(e,t):(n=t,r=e.dom(),o=n.dom(),r!==o&&r.contains(o));var n,r,o},ct=function(e){return Ne.fromDom(e.dom().ownerDocument)},lt=function(e){return Ne.fromDom(e.dom().ownerDocument.defaultView)},ft=function(e){return R.from(e.dom().parentNode).map(Ne.fromDom)},dt=function(e){return R.from(e.dom().previousSibling).map(Ne.fromDom)},mt=function(e){return R.from(e.dom().nextSibling).map(Ne.fromDom)},pt=function(e){return J(rt(e,dt))},gt=function(e){return rt(e,mt)},ht=function(e){return U(e.dom().childNodes,Ne.fromDom)},vt=function(e,t){var n=e.dom().childNodes;return R.from(n[t]).map(Ne.fromDom)},yt=function(e){return vt(e,0)},bt=function(e){return vt(e,e.dom().childNodes.length-1)},Ct=function(t,n){ft(t).each(function(e){e.dom().insertBefore(n.dom(),t.dom())})},wt=function(e,t){mt(e).fold(function(){ft(e).each(function(e){St(e,t)})},function(e){Ct(e,t)})},xt=function(t,n){yt(t).fold(function(){St(t,n)},function(e){t.dom().insertBefore(n.dom(),e.dom())})},St=function(e,t){e.dom().appendChild(t.dom())},Nt=function(t,e){z(e,function(e){St(t,e)})},Et=function(e){e.dom().textContent="",z(ht(e),function(e){kt(e)})},kt=function(e){var t=e.dom();null!==t.parentNode&&t.parentNode.removeChild(t)},_t=function(e){var t,n=ht(e);0<n.length&&(t=e,z(n,function(e){Ct(t,e)})),kt(e)},Rt=("undefined"!=typeof V.window?V.window:Function("return this;")(),function(e){return e.dom().nodeName.toLowerCase()}),Tt=function(e){return e.dom().nodeType},At=function(t){return function(e){return Tt(e)===t}},Dt=At(1),Ot=At(3),Bt=function(e){var t=Ot(e)?e.dom().parentNode:e.dom();return t!==undefined&&null!==t&&t.ownerDocument.body.contains(t)},Pt=function(n,r){return{left:x(n),top:x(r),translate:function(e,t){return Pt(n+e,r+t)}}},Lt=Pt,It=function(e,t){return e!==undefined?e:t!==undefined?t:0},Mt=function(e){var t,n=e.dom(),r=n.ownerDocument.body;return r===n?Lt(r.offsetLeft,r.offsetTop):Bt(e)?(t=n.getBoundingClientRect(),Lt(t.left,t.top)):Lt(0,0)},Ft=function(e){var t=e!==undefined?e.dom():V.document,n=t.body.scrollLeft||t.documentElement.scrollLeft,r=t.body.scrollTop||t.documentElement.scrollTop;return Lt(n,r)},Ut=function(e,t,n){(n!==undefined?n.dom():V.document).defaultView.scrollTo(e,t)},zt=function(e,t){nt().browser.isSafari()&&D(e.dom().scrollIntoViewIfNeeded)?e.dom().scrollIntoViewIfNeeded(!1):e.dom().scrollIntoView(t)},jt=function(e,t,n,r){return{x:e,y:t,width:n,height:r,right:e+n,bottom:t+r}},Ht=function(e){var t,n,r=e===undefined?V.window:e,o=r.document,i=Ft(Ne.fromDom(o));return n=(t=r)===undefined?V.window:t,R.from(n.visualViewport).fold(function(){var e=r.document.documentElement,t=e.clientWidth,n=e.clientHeight;return jt(i.left(),i.top(),t,n)},function(e){return jt(Math.max(e.pageLeft,i.left()),Math.max(e.pageTop,i.top()),e.width,e.height)})},Vt=function(t){return function(e){return!!e&&e.nodeType===t}},qt=function(e){return!!e&&!Object.getPrototypeOf(e)},$t=Vt(1),Wt=function(e){var n=e.map(function(e){return e.toLowerCase()});return function(e){if(e&&e.nodeName){var t=e.nodeName.toLowerCase();return M(n,t)}return!1}},Kt=function(r,e){var o=e.toLowerCase().split(" ");return function(e){var t;if($t(e))for(t=0;t<o.length;t++){var n=e.ownerDocument.defaultView.getComputedStyle(e,null);if((n?n.getPropertyValue(r):null)===o[t])return!0}return!1}},Xt=function(t){return function(e){return $t(e)&&e.hasAttribute(t)}},Yt=function(e){return $t(e)&&e.hasAttribute("data-mce-bogus")},Gt=function(e){return $t(e)&&"TABLE"===e.tagName},Jt=function(t){return function(e){if($t(e)){if(e.contentEditable===t)return!0;if(e.getAttribute("data-mce-contenteditable")===t)return!0}return!1}},Qt=Wt(["textarea","input"]),Zt=Vt(3),en=Vt(8),tn=Vt(9),nn=Vt(11),rn=Wt(["br"]),on=Jt("true"),an=Jt("false"),un=function(e){return e.style!==undefined&&D(e.style.getPropertyValue)},sn=function(e,t,n){if(!(q(n)||T(n)||O(n)))throw V.console.error("Invalid call to Attr.set. Key ",t,":: Value ",n,":: Element ",e),new Error("Attribute value was not simple");e.setAttribute(t,n+"")},cn=function(e,t,n){sn(e.dom(),t,n)},ln=function(e,t){var n=e.dom();oe(t,function(e,t){sn(n,t,e)})},fn=function(e,t){var n=e.dom().getAttribute(t);return null===n?undefined:n},dn=function(e,t){e.dom().removeAttribute(t)},mn=function(e,t){var n=e.dom(),r=V.window.getComputedStyle(n).getPropertyValue(t);return""!==r||Bt(e)?r:pn(n,t)},pn=function(e,t){return un(e)?e.style.getPropertyValue(t):""},gn=function(e,t){var n=e.dom(),r=pn(n,t);return R.from(r).filter(function(e){return 0<e.length})},hn=nt().browser,vn=function(e){return K(e,Dt)},yn=function(e,t){return e.children&&M(e.children,t)},bn=function(e,t,n){var r,o,i,a=0,u=0,s=e.ownerDocument;if(n=n||e,t){if(n===e&&t.getBoundingClientRect&&"static"===mn(Ne.fromDom(e),"position"))return{x:a=(o=t.getBoundingClientRect()).left+(s.documentElement.scrollLeft||e.scrollLeft)-s.documentElement.clientLeft,y:u=o.top+(s.documentElement.scrollTop||e.scrollTop)-s.documentElement.clientTop};for(r=t;r&&r!==n&&r.nodeType&&!yn(r,n);)a+=r.offsetLeft||0,u+=r.offsetTop||0,r=r.offsetParent;for(r=t.parentNode;r&&r!==n&&r.nodeType&&!yn(r,n);)a-=r.scrollLeft||0,u-=r.scrollTop||0,r=r.parentNode;u+=(i=Ne.fromDom(t),hn.isFirefox()&&"table"===Rt(i)?vn(ht(i)).filter(function(e){return"caption"===Rt(e)}).bind(function(o){return vn(gt(o)).map(function(e){var t=e.dom().offsetTop,n=o.dom().offsetTop,r=o.dom().offsetHeight;return t<=n?-r:0})}).getOr(0):0)}return{x:a,y:u}},Cn={},wn={exports:Cn};be=undefined,Ce=Cn,we=wn,xe=undefined,function(e){if("object"==typeof Ce&&void 0!==we)we.exports=e();else if("function"==typeof be&&be.amd)be([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).EphoxContactWrapper=e()}}(function(){return function l(i,a,u){function s(t,e){if(!a[t]){if(!i[t]){var n="function"==typeof xe&&xe;if(!e&&n)return n(t,!0);if(c)return c(t,!0);var r=new Error("Cannot find module '"+t+"'");throw r.code="MODULE_NOT_FOUND",r}var o=a[t]={exports:{}};i[t][0].call(o.exports,function(e){return s(i[t][1][e]||e)},o,o.exports,l,i,a,u)}return a[t].exports}for(var c="function"==typeof xe&&xe,e=0;e<u.length;e++)s(u[e]);return s}({1:[function(e,t,n){var r,o,i=t.exports={};function a(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function s(e){if(r===setTimeout)return setTimeout(e,0);if((r===a||!r)&&setTimeout)return r=setTimeout,setTimeout(e,0);try{return r(e,0)}catch(t){try{return r.call(null,e,0)}catch(t){return r.call(this,e,0)}}}!function(){try{r="function"==typeof setTimeout?setTimeout:a}catch(e){r=a}try{o="function"==typeof clearTimeout?clearTimeout:u}catch(e){o=u}}();var c,l=[],f=!1,d=-1;function m(){f&&c&&(f=!1,c.length?l=c.concat(l):d=-1,l.length&&p())}function p(){if(!f){var e=s(m);f=!0;for(var t=l.length;t;){for(c=l,l=[];++d<t;)c&&c[d].run();d=-1,t=l.length}c=null,f=!1,function n(e){if(o===clearTimeout)return clearTimeout(e);if((o===u||!o)&&clearTimeout)return o=clearTimeout,clearTimeout(e);try{return o(e)}catch(t){try{return o.call(null,e)}catch(t){return o.call(this,e)}}}(e)}}function g(e,t){this.fun=e,this.array=t}function h(){}i.nextTick=function(e){var t=new Array(arguments.length-1);if(1<arguments.length)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];l.push(new g(e,t)),1!==l.length||f||s(p)},g.prototype.run=function(){this.fun.apply(null,this.array)},i.title="browser",i.browser=!0,i.env={},i.argv=[],i.version="",i.versions={},i.on=h,i.addListener=h,i.once=h,i.off=h,i.removeListener=h,i.removeAllListeners=h,i.emit=h,i.prependListener=h,i.prependOnceListener=h,i.listeners=function(e){return[]},i.binding=function(e){throw new Error("process.binding is not supported")},i.cwd=function(){return"/"},i.chdir=function(e){throw new Error("process.chdir is not supported")},i.umask=function(){return 0}},{}],2:[function(e,f,t){(function(t){function r(){}function i(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=undefined,this._deferreds=[],l(e,this)}function o(r,o){for(;3===r._state;)r=r._value;0!==r._state?(r._handled=!0,i._immediateFn(function(){var e=1===r._state?o.onFulfilled:o.onRejected;if(null!==e){var t;try{t=e(r._value)}catch(n){return void u(o.promise,n)}a(o.promise,t)}else(1===r._state?a:u)(o.promise,r._value)})):r._deferreds.push(o)}function a(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var n=t.then;if(t instanceof i)return e._state=3,e._value=t,void s(e);if("function"==typeof n)return void l(function r(e,t){return function(){e.apply(t,arguments)}}(n,t),e)}e._state=1,e._value=t,s(e)}catch(o){u(e,o)}}function u(e,t){e._state=2,e._value=t,s(e)}function s(e){2===e._state&&0===e._deferreds.length&&i._immediateFn(function(){e._handled||i._unhandledRejectionFn(e._value)});for(var t=0,n=e._deferreds.length;t<n;t++)o(e,e._deferreds[t]);e._deferreds=null}function c(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function l(e,t){var n=!1;try{e(function(e){n||(n=!0,a(t,e))},function(e){n||(n=!0,u(t,e))})}catch(r){if(n)return;n=!0,u(t,r)}}var e,n;e=this,n=setTimeout,i.prototype["catch"]=function(e){return this.then(null,e)},i.prototype.then=function(e,t){var n=new this.constructor(r);return o(this,new c(e,t,n)),n},i.all=function(e){var s=Array.prototype.slice.call(e);return new i(function(o,i){if(0===s.length)return o([]);var a=s.length;function u(t,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void n.call(e,function(e){u(t,e)},i)}s[t]=e,0==--a&&o(s)}catch(r){i(r)}}for(var e=0;e<s.length;e++)u(e,s[e])})},i.resolve=function(t){return t&&"object"==typeof t&&t.constructor===i?t:new i(function(e){e(t)})},i.reject=function(n){return new i(function(e,t){t(n)})},i.race=function(o){return new i(function(e,t){for(var n=0,r=o.length;n<r;n++)o[n].then(e,t)})},i._immediateFn="function"==typeof t?function(e){t(e)}:function(e){n(e,0)},i._unhandledRejectionFn=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)},i._setImmediateFn=function(e){i._immediateFn=e},i._setUnhandledRejectionFn=function(e){i._unhandledRejectionFn=e},void 0!==f&&f.exports?f.exports=i:e.Promise||(e.Promise=i)}).call(this,e("timers").setImmediate)},{timers:3}],3:[function(s,e,c){(function(e,t){var r=s("process/browser.js").nextTick,n=Function.prototype.apply,o=Array.prototype.slice,i={},a=0;function u(e,t){this._id=e,this._clearFn=t}c.setTimeout=function(){return new u(n.call(setTimeout,window,arguments),clearTimeout)},c.setInterval=function(){return new u(n.call(setInterval,window,arguments),clearInterval)},c.clearTimeout=c.clearInterval=function(e){e.close()},u.prototype.unref=u.prototype.ref=function(){},u.prototype.close=function(){this._clearFn.call(window,this._id)},c.enroll=function(e,t){clearTimeout(e._idleTimeoutId),e._idleTimeout=t},c.unenroll=function(e){clearTimeout(e._idleTimeoutId),e._idleTimeout=-1},c._unrefActive=c.active=function(e){clearTimeout(e._idleTimeoutId);var t=e._idleTimeout;0<=t&&(e._idleTimeoutId=setTimeout(function(){e._onTimeout&&e._onTimeout()},t))},c.setImmediate="function"==typeof e?e:function(e){var t=a++,n=!(arguments.length<2)&&o.call(arguments,1);return i[t]=!0,r(function(){i[t]&&(n?e.apply(null,n):e.call(null),c.clearImmediate(t))}),t},c.clearImmediate="function"==typeof t?t:function(e){delete i[e]}}).call(this,s("timers").setImmediate,s("timers").clearImmediate)},{"process/browser.js":1,timers:3}],4:[function(e,t,n){var r=e("promise-polyfill"),o="undefined"!=typeof window?window:Function("return this;")();t.exports={boltExport:o.Promise||r}},{"promise-polyfill":2}]},{},[4])(4)});var xn,Sn,Nn,En,kn=wn.exports.boltExport,_n=function(e){var n=R.none(),t=[],r=function(e){o()?a(e):t.push(e)},o=function(){return n.isSome()},i=function(e){z(e,a)},a=function(t){n.each(function(e){V.setTimeout(function(){t(e)},0)})};return e(function(e){n=R.some(e),i(t),t=[]}),{get:r,map:function(n){return _n(function(t){r(function(e){t(n(e))})})},isReady:o}},Rn={nu:_n,pure:function(t){return _n(function(e){e(t)})}},Tn=function(e){V.setTimeout(function(){throw e},0)},An=function(n){var e=function(e){n().then(e,Tn)};return{map:function(e){return An(function(){return n().then(e)})},bind:function(t){return An(function(){return n().then(function(e){return t(e).toPromise()})})},anonBind:function(e){return An(function(){return n().then(function(){return e.toPromise()})})},toLazy:function(){return Rn.nu(e)},toCached:function(){var e=null;return An(function(){return null===e&&(e=n()),e})},toPromise:n,get:e}},Dn={nu:function(e){return An(function(){return new kn(e)})},pure:function(e){return An(function(){return kn.resolve(e)})}},On=function(a,e){return e(function(r){var o=[],i=0;0===a.length?r([]):z(a,function(e,t){var n;e.get((n=t,function(e){o[n]=e,++i>=a.length&&r(o)}))})})},Bn=function(e){return On(e,Dn.nu)},Pn=function(n){return{is:function(e){return n===e},isValue:h,isError:g,getOr:x(n),getOrThunk:x(n),getOrDie:x(n),or:function(e){return Pn(n)},orThunk:function(e){return Pn(n)},fold:function(e,t){return t(n)},map:function(e){return Pn(e(n))},mapError:function(e){return Pn(n)},each:function(e){e(n)},bind:function(e){return e(n)},exists:function(e){return e(n)},forall:function(e){return e(n)},toOption:function(){return R.some(n)}}},Ln=function(n){return{is:g,isValue:g,isError:h,getOr:d,getOrThunk:function(e){return e()},getOrDie:function(){return p(String(n))()},or:function(e){return e},orThunk:function(e){return e()},fold:function(e,t){return e(n)},map:function(e){return Ln(n)},mapError:function(e){return Ln(e(n))},each:f,bind:function(e){return Ln(n)},exists:g,forall:h,toOption:R.none}},In={value:Pn,error:Ln,fromOption:function(e,t){return e.fold(function(){return Ln(t)},Pn)}},Mn=window.Promise?window.Promise:(xn=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)},Nn=(Sn=function(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],qn(e,Fn(zn,this),Fn(jn,this))}).immediateFn||"function"==typeof V.setImmediate&&V.setImmediate||function(e){V.setTimeout(e,1)},Sn.prototype["catch"]=function(e){return this.then(null,e)},Sn.prototype.then=function(n,r){var o=this;return new Sn(function(e,t){Un.call(o,new Vn(n,r,e,t))})},Sn.all=function(){var s=Array.prototype.slice.call(1===arguments.length&&xn(arguments[0])?arguments[0]:arguments);return new Sn(function(o,i){if(0===s.length)return o([]);var a=s.length;function u(t,e){try{if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void n.call(e,function(e){u(t,e)},i)}s[t]=e,0==--a&&o(s)}catch(r){i(r)}}for(var e=0;e<s.length;e++)u(e,s[e])})},Sn.resolve=function(t){return t&&"object"==typeof t&&t.constructor===Sn?t:new Sn(function(e){e(t)})},Sn.reject=function(n){return new Sn(function(e,t){t(n)})},Sn.race=function(o){return new Sn(function(e,t){for(var n=0,r=o.length;n<r;n++)o[n].then(e,t)})},Sn);function Fn(e,t){return function(){e.apply(t,arguments)}}function Un(r){var o=this;null!==this._state?Nn(function(){var e=o._state?r.onFulfilled:r.onRejected;if(null!==e){var t;try{t=e(o._value)}catch(n){return void r.reject(n)}r.resolve(t)}else(o._state?r.resolve:r.reject)(o._value)}):this._deferreds.push(r)}function zn(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var t=e.then;if("function"==typeof t)return void qn(Fn(t,e),Fn(zn,this),Fn(jn,this))}this._state=!0,this._value=e,Hn.call(this)}catch(n){jn.call(this,n)}}function jn(e){this._state=!1,this._value=e,Hn.call(this)}function Hn(){for(var e=0,t=this._deferreds.length;e<t;e++)Un.call(this,this._deferreds[e]);this._deferreds=null}function Vn(e,t,n,r){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.resolve=n,this.reject=r}function qn(e,t,n){var r=!1;try{e(function(e){r||(r=!0,t(e))},function(e){r||(r=!0,n(e))})}catch(o){if(r)return;r=!0,n(o)}}var $n=function(e,t){return"number"!=typeof t&&(t=0),V.setTimeout(e,t)},Wn=function(e,t){return"number"!=typeof t&&(t=1),V.setInterval(e,t)},Kn=function(n,r){var o,e;return(e=function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];V.clearTimeout(o),o=$n(function(){n.apply(this,e)},r)}).stop=function(){V.clearTimeout(o)},e},Xn={requestAnimationFrame:function(e,t){En?En.then(e):En=new Mn(function(e){!function(e,t){var n,r=V.window.requestAnimationFrame,o=["ms","moz","webkit"];for(n=0;n<o.length&&!r;n++)r=V.window[o[n]+"RequestAnimationFrame"];(r=r||function(e){V.window.setTimeout(e,0)})(e,t)}(e,t=t||V.document.body)}).then(e)},setTimeout:$n,setInterval:Wn,setEditorTimeout:function(e,t,n){return $n(function(){e.removed||t()},n)},setEditorInterval:function(e,t,n){var r;return r=Wn(function(){e.removed?V.clearInterval(r):t()},n)},debounce:Kn,throttle:Kn,clearInterval:function(e){return V.clearInterval(e)},clearTimeout:function(e){return V.clearTimeout(e)}},Yn=V.navigator.userAgent,Gn=nt(),Jn=Gn.browser,Qn=Gn.os,Zn=Gn.deviceType,er=/WebKit/.test(Yn)&&!Jn.isEdge(),tr="FormData"in V.window&&"FileReader"in V.window&&"URL"in V.window&&!!V.URL.createObjectURL,nr=-1!==Yn.indexOf("Windows Phone"),rr={opera:Jn.isOpera(),webkit:er,ie:!(!Jn.isIE()&&!Jn.isEdge())&&Jn.version.major,gecko:Jn.isFirefox(),mac:Qn.isOSX()||Qn.isiOS(),iOS:Zn.isiPad()||Zn.isiPhone(),android:Qn.isAndroid(),contentEditable:!0,transparentSrc:"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",caretAfter:!0,range:V.window.getSelection&&"Range"in V.window,documentMode:Jn.isIE()?V.document.documentMode||7:10,fileApi:tr,ceFalse:!0,cacheSuffix:null,container:null,experimentalShadowDom:!1,canHaveCSP:!Jn.isIE(),desktop:Zn.isDesktop(),windowsPhone:nr,browser:{current:Jn.current,version:Jn.version,isChrome:Jn.isChrome,isEdge:Jn.isEdge,isFirefox:Jn.isFirefox,isIE:Jn.isIE,isOpera:Jn.isOpera,isSafari:Jn.isSafari},os:{current:Qn.current,version:Qn.version,isAndroid:Qn.isAndroid,isChromeOS:Qn.isChromeOS,isFreeBSD:Qn.isFreeBSD,isiOS:Qn.isiOS,isLinux:Qn.isLinux,isOSX:Qn.isOSX,isSolaris:Qn.isSolaris,isWindows:Qn.isWindows},deviceType:{isDesktop:Zn.isDesktop,isiPad:Zn.isiPad,isiPhone:Zn.isiPhone,isPhone:Zn.isPhone,isTablet:Zn.isTablet,isTouch:Zn.isTouch,isWebView:Zn.isWebView}},or=Array.isArray,ir=function(e,t,n){var r,o;if(!e)return 0;if(n=n||e,e.length!==undefined){for(r=0,o=e.length;r<o;r++)if(!1===t.call(n,e[r],r,e))return 0}else for(r in e)if(e.hasOwnProperty(r)&&!1===t.call(n,e[r],r,e))return 0;return 1},ar=function(n,r){var o=[];return ir(n,function(e,t){o.push(r(e,t,n))}),o},ur=function(n,r){var o=[];return ir(n,function(e,t){r&&!r(e,t,n)||o.push(e)}),o},sr=function(e,t){var n,r;if(e)for(n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1},cr=function(e,t,n,r){var o=0;for(arguments.length<3&&(n=e[0]);o<e.length;o++)n=t.call(r,n,e[o],o);return n},lr=function(e,t,n){var r,o;for(r=0,o=e.length;r<o;r++)if(t.call(n,e[r],r,e))return r;return-1},fr=function(e){return e[e.length-1]},dr=/^\s*|\s*$/g,mr=function(e){return null===e||e===undefined?"":(""+e).replace(dr,"")},pr=function(e,t){return t?!("array"!==t||!or(e))||typeof e===t:e!==undefined},gr=function(e,n,r,o){o=o||this,e&&(r&&(e=e[r]),ir(e,function(e,t){if(!1===n.call(o,e,t,r))return!1;gr(e,n,r,o)}))},hr={trim:mr,isArray:or,is:pr,toArray:function(e){var t,n,r=e;if(!or(e))for(r=[],t=0,n=e.length;t<n;t++)r[t]=e[t];return r},makeMap:function(e,t,n){var r;for(t=t||",","string"==typeof(e=e||[])&&(e=e.split(t)),n=n||{},r=e.length;r--;)n[e[r]]={};return n},each:ir,map:ar,grep:ur,inArray:sr,hasOwn:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},extend:function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];for(var r=0;r<t.length;r++){var o=t[r];for(var i in o)if(o.hasOwnProperty(i)){var a=o[i];a!==undefined&&(e[i]=a)}}return e},create:function(e,t,n){var r,o,i,a,u,s=this,c=0;if(e=/^((static) )?([\w.]+)(:([\w.]+))?/.exec(e),i=e[3].match(/(^|\.)(\w+)$/i)[2],!(o=s.createNS(e[3].replace(/\.\w+$/,""),n))[i]){if("static"===e[2])return o[i]=t,void(this.onCreate&&this.onCreate(e[2],e[3],o[i]));t[i]||(t[i]=function(){},c=1),o[i]=t[i],s.extend(o[i].prototype,t),e[5]&&(r=s.resolve(e[5]).prototype,a=e[5].match(/\.(\w+)$/i)[1],u=o[i],o[i]=c?function(){return r[a].apply(this,arguments)}:function(){return this.parent=r[a],u.apply(this,arguments)},o[i].prototype[i]=o[i],s.each(r,function(e,t){o[i].prototype[t]=r[t]}),s.each(t,function(e,t){r[t]?o[i].prototype[t]=function(){return this.parent=r[t],e.apply(this,arguments)}:t!==i&&(o[i].prototype[t]=e)})),s.each(t["static"],function(e,t){o[i][t]=e})}},walk:gr,createNS:function(e,t){var n,r;for(t=t||V.window,e=e.split("."),n=0;n<e.length;n++)t[r=e[n]]||(t[r]={}),t=t[r];return t},resolve:function(e,t){var n,r;for(t=t||V.window,n=0,r=(e=e.split(".")).length;n<r&&(t=t[e[n]]);n++);return t},explode:function(e,t){return!e||pr(e,"array")?e:ar(e.split(t||","),mr)},_addCacheSuffix:function(e){var t=rr.cacheSuffix;return t&&(e+=(-1===e.indexOf("?")?"?":"&")+t),e}};function vr(p,g){void 0===g&&(g={});var h,v=0,y={};h=g.maxLoadTime||5e3;var b=function(e){p.getElementsByTagName("head")[0].appendChild(e)},n=function(e,t,n){var o,r,i,a,u=function(e){a.status=e,a.passed=[],a.failed=[],o&&(o.onload=null,o.onerror=null,o=null)},s=function(){for(var e=a.passed,t=e.length;t--;)e[t]();u(2)},c=function(){for(var e=a.failed,t=e.length;t--;)e[t]();u(3)},l=function(e,t){e()||((new Date).getTime()-i<h?Xn.setTimeout(t):c())},f=function(){l(function(){for(var e,t,n=p.styleSheets,r=n.length;r--;)if((t=(e=n[r]).ownerNode?e.ownerNode:e.owningElement)&&t.id===o.id)return s(),1},f)},d=function(){l(function(){try{var e=r.sheet.cssRules;return s(),e}catch(t){}},d)};if(e=hr._addCacheSuffix(e),y[e]?a=y[e]:(a={passed:[],failed:[]},y[e]=a),t&&a.passed.push(t),n&&a.failed.push(n),1!==a.status)if(2!==a.status)if(3!==a.status){if(a.status=1,(o=p.createElement("link")).rel="stylesheet",o.type="text/css",o.id="u"+v++,o.async=!1,o.defer=!1,i=(new Date).getTime(),g.contentCssCors&&(o.crossOrigin="anonymous"),g.referrerPolicy&&cn(Ne.fromDom(o),"referrerpolicy",g.referrerPolicy),"onload"in o&&!((m=V.navigator.userAgent.match(/WebKit\/(\d*)/))&&parseInt(m[1],10)<536))o.onload=f,o.onerror=c;else{if(0<V.navigator.userAgent.indexOf("Firefox"))return(r=p.createElement("style")).textContent='@import "'+e+'"',d(),void b(r);f()}var m;b(o),o.href=e}else c();else s()},t=function(t){return Dn.nu(function(e){n(t,a(e,x(In.value(t))),a(e,x(In.error(t))))})},o=function(e){return e.fold(d,d)};return{load:n,loadAll:function(e,n,r){Bn(U(e,t)).get(function(e){var t=j(e,function(e){return e.isValue()});0<t.fail.length?r(t.fail.map(o)):n(t.pass.map(o))})},_setReferrerPolicy:function(e){g.referrerPolicy=e}}}var yr,br,Cr,wr=function(t){var n;return function(e){return(n=n||function(e,t){for(var n={},r=0,o=e.length;r<o;r++){var i=e[r];n[String(i)]=t(i,r)}return n}(t,x(!0))).hasOwnProperty(Rt(e))}},xr=wr(["h1","h2","h3","h4","h5","h6"]),Sr=wr(["article","aside","details","div","dt","figcaption","footer","form","fieldset","header","hgroup","html","main","nav","section","summary","body","p","dl","multicol","dd","figure","address","center","blockquote","h1","h2","h3","h4","h5","h6","listing","xmp","pre","plaintext","menu","dir","ul","ol","li","hr","table","tbody","thead","tfoot","th","tr","td","caption"]),Nr=function(e){return Dt(e)&&!Sr(e)},Er=function(e){return Dt(e)&&"br"===Rt(e)},kr=wr(["h1","h2","h3","h4","h5","h6","p","div","address","pre","form","blockquote","center","dir","fieldset","header","footer","article","section","hgroup","aside","nav","figure"]),_r=wr(["ul","ol","dl"]),Rr=wr(["li","dd","dt"]),Tr=wr(["area","base","basefont","br","col","frame","hr","img","input","isindex","link","meta","param","embed","source","wbr","track"]),Ar=wr(["thead","tbody","tfoot"]),Dr=wr(["td","th"]),Or=wr(["pre","script","textarea","style"]),Br=function(e){return e&&"SPAN"===e.tagName&&"bookmark"===e.getAttribute("data-mce-type")},Pr=function(e,t){var n,r=t.childNodes;if(!$t(t)||!Br(t)){for(n=r.length-1;0<=n;n--)Pr(e,r[n]);if(!1===tn(t)){if(Zt(t)&&0<t.nodeValue.length){var o=hr.trim(t.nodeValue).length;if(e.isBlock(t.parentNode)||0<o)return;if(0===o&&(a=(i=t).previousSibling&&"SPAN"===i.previousSibling.nodeName,u=i.nextSibling&&"SPAN"===i.nextSibling.nodeName,a&&u))return}else if($t(t)&&(1===(r=t.childNodes).length&&Br(r[0])&&t.parentNode.insertBefore(r[0],t),r.length||Tr(Ne.fromDom(t))))return;e.remove(t)}var i,a,u;return t}},Lr=hr.makeMap,Ir=/[&<>\"\u0060\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,Mr=/[<>&\u007E-\uD7FF\uE000-\uFFEF]|[\uD800-\uDBFF][\uDC00-\uDFFF]/g,Fr=/[<>&\"\']/g,Ur=/&#([a-z0-9]+);?|&([a-z0-9]+);/gi,zr={128:"\u20ac",130:"\u201a",131:"\u0192",132:"\u201e",133:"\u2026",134:"\u2020",135:"\u2021",136:"\u02c6",137:"\u2030",138:"\u0160",139:"\u2039",140:"\u0152",142:"\u017d",145:"\u2018",146:"\u2019",147:"\u201c",148:"\u201d",149:"\u2022",150:"\u2013",151:"\u2014",152:"\u02dc",153:"\u2122",154:"\u0161",155:"\u203a",156:"\u0153",158:"\u017e",159:"\u0178"};br={'"':""","'":"'","<":"<",">":">","&":"&","`":"`"},Cr={"<":"<",">":">","&":"&",""":'"',"'":"'"};var jr=function(e,t){var n,r,o,i={};if(e){for(e=e.split(","),t=t||10,n=0;n<e.length;n+=2)r=String.fromCharCode(parseInt(e[n],t)),br[r]||(o="&"+e[n+1]+";",i[r]=o,i[o]=r);return i}};yr=jr("50,nbsp,51,iexcl,52,cent,53,pound,54,curren,55,yen,56,brvbar,57,sect,58,uml,59,copy,5a,ordf,5b,laquo,5c,not,5d,shy,5e,reg,5f,macr,5g,deg,5h,plusmn,5i,sup2,5j,sup3,5k,acute,5l,micro,5m,para,5n,middot,5o,cedil,5p,sup1,5q,ordm,5r,raquo,5s,frac14,5t,frac12,5u,frac34,5v,iquest,60,Agrave,61,Aacute,62,Acirc,63,Atilde,64,Auml,65,Aring,66,AElig,67,Ccedil,68,Egrave,69,Eacute,6a,Ecirc,6b,Euml,6c,Igrave,6d,Iacute,6e,Icirc,6f,Iuml,6g,ETH,6h,Ntilde,6i,Ograve,6j,Oacute,6k,Ocirc,6l,Otilde,6m,Ouml,6n,times,6o,Oslash,6p,Ugrave,6q,Uacute,6r,Ucirc,6s,Uuml,6t,Yacute,6u,THORN,6v,szlig,70,agrave,71,aacute,72,acirc,73,atilde,74,auml,75,aring,76,aelig,77,ccedil,78,egrave,79,eacute,7a,ecirc,7b,euml,7c,igrave,7d,iacute,7e,icirc,7f,iuml,7g,eth,7h,ntilde,7i,ograve,7j,oacute,7k,ocirc,7l,otilde,7m,ouml,7n,divide,7o,oslash,7p,ugrave,7q,uacute,7r,ucirc,7s,uuml,7t,yacute,7u,thorn,7v,yuml,ci,fnof,sh,Alpha,si,Beta,sj,Gamma,sk,Delta,sl,Epsilon,sm,Zeta,sn,Eta,so,Theta,sp,Iota,sq,Kappa,sr,Lambda,ss,Mu,st,Nu,su,Xi,sv,Omicron,t0,Pi,t1,Rho,t3,Sigma,t4,Tau,t5,Upsilon,t6,Phi,t7,Chi,t8,Psi,t9,Omega,th,alpha,ti,beta,tj,gamma,tk,delta,tl,epsilon,tm,zeta,tn,eta,to,theta,tp,iota,tq,kappa,tr,lambda,ts,mu,tt,nu,tu,xi,tv,omicron,u0,pi,u1,rho,u2,sigmaf,u3,sigma,u4,tau,u5,upsilon,u6,phi,u7,chi,u8,psi,u9,omega,uh,thetasym,ui,upsih,um,piv,812,bull,816,hellip,81i,prime,81j,Prime,81u,oline,824,frasl,88o,weierp,88h,image,88s,real,892,trade,89l,alefsym,8cg,larr,8ch,uarr,8ci,rarr,8cj,darr,8ck,harr,8dl,crarr,8eg,lArr,8eh,uArr,8ei,rArr,8ej,dArr,8ek,hArr,8g0,forall,8g2,part,8g3,exist,8g5,empty,8g7,nabla,8g8,isin,8g9,notin,8gb,ni,8gf,prod,8gh,sum,8gi,minus,8gn,lowast,8gq,radic,8gt,prop,8gu,infin,8h0,ang,8h7,and,8h8,or,8h9,cap,8ha,cup,8hb,int,8hk,there4,8hs,sim,8i5,cong,8i8,asymp,8j0,ne,8j1,equiv,8j4,le,8j5,ge,8k2,sub,8k3,sup,8k4,nsub,8k6,sube,8k7,supe,8kl,oplus,8kn,otimes,8l5,perp,8m5,sdot,8o8,lceil,8o9,rceil,8oa,lfloor,8ob,rfloor,8p9,lang,8pa,rang,9ea,loz,9j0,spades,9j3,clubs,9j5,hearts,9j6,diams,ai,OElig,aj,oelig,b0,Scaron,b1,scaron,bo,Yuml,m6,circ,ms,tilde,802,ensp,803,emsp,809,thinsp,80c,zwnj,80d,zwj,80e,lrm,80f,rlm,80j,ndash,80k,mdash,80o,lsquo,80p,rsquo,80q,sbquo,80s,ldquo,80t,rdquo,80u,bdquo,810,dagger,811,Dagger,81g,permil,81p,lsaquo,81q,rsaquo,85c,euro",32);var Hr=function(e,t){return e.replace(t?Ir:Mr,function(e){return br[e]||e})},Vr=function(e,t){return e.replace(t?Ir:Mr,function(e){return 1<e.length?"&#"+(1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320)+65536)+";":br[e]||"&#"+e.charCodeAt(0)+";"})},qr=function(e,t,n){return n=n||yr,e.replace(t?Ir:Mr,function(e){return br[e]||n[e]||e})},$r={encodeRaw:Hr,encodeAllRaw:function(e){return(""+e).replace(Fr,function(e){return br[e]||e})},encodeNumeric:Vr,encodeNamed:qr,getEncodeFunc:function(e,t){var n=jr(t)||yr,r=Lr(e.replace(/\+/g,","));return r.named&&r.numeric?function(e,t){return e.replace(t?Ir:Mr,function(e){return br[e]!==undefined?br[e]:n[e]!==undefined?n[e]:1<e.length?"&#"+(1024*(e.charCodeAt(0)-55296)+(e.charCodeAt(1)-56320)+65536)+";":"&#"+e.charCodeAt(0)+";"})}:r.named?t?function(e,t){return qr(e,t,n)}:qr:r.numeric?Vr:Hr},decode:function(e){return e.replace(Ur,function(e,t){return t?65535<(t="x"===t.charAt(0).toLowerCase()?parseInt(t.substr(1),16):parseInt(t,10))?(t-=65536,String.fromCharCode(55296+(t>>10),56320+(1023&t))):zr[t]||String.fromCharCode(t):Cr[e]||yr[e]||(n=e,(r=Ne.fromTag("div").dom()).innerHTML=n,r.textContent||r.innerText||n);var n,r})}},Wr={},Kr={},Xr=hr.makeMap,Yr=hr.each,Gr=hr.extend,Jr=hr.explode,Qr=hr.inArray,Zr=function(e,t){return(e=hr.trim(e))?e.split(t||" "):[]},eo=function(e){var u,t,n,r,o,i,s={},a=function(e,t,n){var r,o,i,a=function(e,t){var n,r,o={};for(n=0,r=e.length;n<r;n++)o[e[n]]=t||{};return o};for(t=t||"","string"==typeof(n=n||[])&&(n=Zr(n)),r=(e=Zr(e)).length;r--;)i={attributes:a(o=Zr([u,t].join(" "))),attributesOrder:o,children:a(n,Kr)},s[e[r]]=i},c=function(e,t){var n,r,o,i;for(n=(e=Zr(e)).length,t=Zr(t);n--;)for(r=s[e[n]],o=0,i=t.length;o<i;o++)r.attributes[t[o]]={},r.attributesOrder.push(t[o])};return Wr[e]?Wr[e]:(u="id accesskey class dir lang style tabindex title role",t="address blockquote div dl fieldset form h1 h2 h3 h4 h5 h6 hr menu ol p pre table ul",n="a abbr b bdo br button cite code del dfn em embed i iframe img input ins kbd label map noscript object q s samp script select small span strong sub sup textarea u var #text #comment","html4"!==e&&(u+=" contenteditable contextmenu draggable dropzone hidden spellcheck translate",t+=" article aside details dialog figure main header footer hgroup section nav",n+=" audio canvas command datalist mark meter output picture progress time wbr video ruby bdi keygen"),"html5-strict"!==e&&(u+=" xml:lang",n=[n,i="acronym applet basefont big font strike tt"].join(" "),Yr(Zr(i),function(e){a(e,"",n)}),t=[t,o="center dir isindex noframes"].join(" "),r=[t,n].join(" "),Yr(Zr(o),function(e){a(e,"",r)})),r=r||[t,n].join(" "),a("html","manifest","head body"),a("head","","base command link meta noscript script style title"),a("title hr noscript br"),a("base","href target"),a("link","href rel media hreflang type sizes hreflang"),a("meta","name http-equiv content charset"),a("style","media type scoped"),a("script","src async defer type charset"),a("body","onafterprint onbeforeprint onbeforeunload onblur onerror onfocus onhashchange onload onmessage onoffline ononline onpagehide onpageshow onpopstate onresize onscroll onstorage onunload",r),a("address dt dd div caption","",r),a("h1 h2 h3 h4 h5 h6 pre p abbr code var samp kbd sub sup i b u bdo span legend em strong small s cite dfn","",n),a("blockquote","cite",r),a("ol","reversed start type","li"),a("ul","","li"),a("li","value",r),a("dl","","dt dd"),a("a","href target rel media hreflang type",n),a("q","cite",n),a("ins del","cite datetime",r),a("img","src sizes srcset alt usemap ismap width height"),a("iframe","src name width height",r),a("embed","src type width height"),a("object","data type typemustmatch name usemap form width height",[r,"param"].join(" ")),a("param","name value"),a("map","name",[r,"area"].join(" ")),a("area","alt coords shape href target rel media hreflang type"),a("table","border","caption colgroup thead tfoot tbody tr"+("html4"===e?" col":"")),a("colgroup","span","col"),a("col","span"),a("tbody thead tfoot","","tr"),a("tr","","td th"),a("td","colspan rowspan headers",r),a("th","colspan rowspan headers scope abbr",r),a("form","accept-charset action autocomplete enctype method name novalidate target",r),a("fieldset","disabled form name",[r,"legend"].join(" ")),a("label","form for",n),a("input","accept alt autocomplete checked dirname disabled form formaction formenctype formmethod formnovalidate formtarget height list max maxlength min multiple name pattern readonly required size src step type value width"),a("button","disabled form formaction formenctype formmethod formnovalidate formtarget name type value","html4"===e?r:n),a("select","disabled form multiple name required size","option optgroup"),a("optgroup","disabled label","option"),a("option","disabled label selected value"),a("textarea","cols dirname disabled form maxlength name readonly required rows wrap"),a("menu","type label",[r,"li"].join(" ")),a("noscript","",r),"html4"!==e&&(a("wbr"),a("ruby","",[n,"rt rp"].join(" ")),a("figcaption","",r),a("mark rt rp summary bdi","",n),a("canvas","width height",r),a("video","src crossorigin poster preload autoplay mediagroup loop muted controls width height buffered",[r,"track source"].join(" ")),a("audio","src crossorigin preload autoplay mediagroup loop muted controls buffered volume",[r,"track source"].join(" ")),a("picture","","img source"),a("source","src srcset type media sizes"),a("track","kind src srclang label default"),a("datalist","",[n,"option"].join(" ")),a("article section nav aside main header footer","",r),a("hgroup","","h1 h2 h3 h4 h5 h6"),a("figure","",[r,"figcaption"].join(" ")),a("time","datetime",n),a("dialog","open",r),a("command","type label icon disabled checked radiogroup command"),a("output","for form name",n),a("progress","value max",n),a("meter","value min max low high optimum",n),a("details","open",[r,"summary"].join(" ")),a("keygen","autofocus challenge disabled form keytype name")),"html5-strict"!==e&&(c("script","language xml:space"),c("style","xml:space"),c("object","declare classid code codebase codetype archive standby align border hspace vspace"),c("embed","align name hspace vspace"),c("param","valuetype type"),c("a","charset name rev shape coords"),c("br","clear"),c("applet","codebase archive code object alt name width height align hspace vspace"),c("img","name longdesc align border hspace vspace"),c("iframe","longdesc frameborder marginwidth marginheight scrolling align"),c("font basefont","size color face"),c("input","usemap align"),c("select"),c("textarea"),c("h1 h2 h3 h4 h5 h6 div p legend caption","align"),c("ul","type compact"),c("li","type"),c("ol dl menu dir","compact"),c("pre","width xml:space"),c("hr","align noshade size width"),c("isindex","prompt"),c("table","summary width frame rules cellspacing cellpadding align bgcolor"),c("col","width align char charoff valign"),c("colgroup","width align char charoff valign"),c("thead","align char charoff valign"),c("tr","align char charoff valign bgcolor"),c("th","axis align char charoff valign nowrap bgcolor width height"),c("form","accept"),c("td","abbr axis scope align char charoff valign nowrap bgcolor width height"),c("tfoot","align char charoff valign"),c("tbody","align char charoff valign"),c("area","nohref"),c("body","background bgcolor text link vlink alink")),"html4"!==e&&(c("input button select textarea","autofocus"),c("input textarea","placeholder"),c("a","download"),c("link script img","crossorigin"),c("img","loading"),c("iframe","sandbox seamless allowfullscreen loading")),Yr(Zr("a form meter progress dfn"),function(e){s[e]&&delete s[e].children[e]}),delete s.caption.children.table,delete s.script,Wr[e]=s)},to=function(e,n){var r;return e&&(r={},"string"==typeof e&&(e={"*":e}),Yr(e,function(e,t){r[t]=r[t.toUpperCase()]=("map"===n?Xr:Jr)(e,/[, ]/)})),r};function no(i){var e,t,n,r,o,a,u,s,c,l,f,d,m,x={},p={},S=[],g={},h={},v=function(e,t,n){var r=i[e];return r?r=Xr(r,/[, ]/,Xr(r.toUpperCase(),/[, ]/)):(r=Wr[e])||(r=Xr(t," ",Xr(t.toUpperCase()," ")),r=Gr(r,n),Wr[e]=r),r};n=eo((i=i||{}).schema),!1===i.verify_html&&(i.valid_elements="*[*]"),e=to(i.valid_styles),t=to(i.invalid_styles,"map"),s=to(i.valid_classes,"map"),r=v("whitespace_elements","pre script noscript style textarea video audio iframe object code"),o=v("self_closing_elements","colgroup dd dt li option p td tfoot th thead tr"),a=v("short_ended_elements","area base basefont br col frame hr img input isindex link meta param embed source wbr track"),u=v("boolean_attributes","checked compact declare defer disabled ismap multiple nohref noresize noshade nowrap readonly selected autoplay loop controls"),l=v("non_empty_elements","td th iframe video audio object script pre code",a),f=v("move_caret_before_on_enter_elements","table",l),d=v("text_block_elements","h1 h2 h3 h4 h5 h6 p div address pre form blockquote center dir fieldset header footer article section hgroup aside main nav figure"),c=v("block_elements","hr table tbody thead tfoot th tr td li ol ul caption dl dt dd noscript menu isindex option datalist select optgroup figcaption details summary",d),m=v("text_inline_elements","span strong b em i font strike u var cite dfn code mark q sup sub samp"),Yr((i.special||"script noscript noframes noembed title style textarea xmp").split(" "),function(e){h[e]=new RegExp("</"+e+"[^>]*>","gi")});var N=function(e){return new RegExp("^"+e.replace(/([?+*])/g,".$1")+"$")},y=function(e){var t,n,r,o,i,a,u,s,c,l,f,d,m,p,g,h,v,y,b=/^([#+\-])?([^\[!\/]+)(?:\/([^\[!]+))?(?:(!?)\[([^\]]+)\])?$/,C=/^([!\-])?(\w+[\\:]:\w+|[^=:<]+)?(?:([=:<])(.*))?$/,w=/[*?+]/;if(e)for(e=Zr(e,","),x["@"]&&(h=x["@"].attributes,v=x["@"].attributesOrder),t=0,n=e.length;t<n;t++)if(i=b.exec(e[t])){if(p=i[1],c=i[2],g=i[3],s=i[5],a={attributes:d={},attributesOrder:m=[]},"#"===p&&(a.paddEmpty=!0),"-"===p&&(a.removeEmpty=!0),"!"===i[4]&&(a.removeEmptyAttrs=!0),h&&(oe(h,function(e,t){d[t]=e}),m.push.apply(m,v)),s)for(r=0,o=(s=Zr(s,"|")).length;r<o;r++)if(i=C.exec(s[r])){if(u={},f=i[1],l=i[2].replace(/[\\:]:/g,":"),p=i[3],y=i[4],"!"===f&&(a.attributesRequired=a.attributesRequired||[],a.attributesRequired.push(l),u.required=!0),"-"===f){delete d[l],m.splice(Qr(m,l),1);continue}p&&("="===p&&(a.attributesDefault=a.attributesDefault||[],a.attributesDefault.push({name:l,value:y}),u.defaultValue=y),":"===p&&(a.attributesForced=a.attributesForced||[],a.attributesForced.push({name:l,value:y}),u.forcedValue=y),"<"===p&&(u.validValues=Xr(y,"?"))),w.test(l)?(a.attributePatterns=a.attributePatterns||[],u.pattern=N(l),a.attributePatterns.push(u)):(d[l]||m.push(l),d[l]=u)}h||"@"!==c||(h=d,v=m),g&&(a.outputName=c,x[g]=a),w.test(c)?(a.pattern=N(c),S.push(a)):x[c]=a}},b=function(e){x={},S=[],y(e),Yr(n,function(e,t){p[t]=e.children})},C=function(e){var a=/^(~)?(.+)$/;e&&(Wr.text_block_elements=Wr.block_elements=null,Yr(Zr(e,","),function(e){var t=a.exec(e),n="~"===t[1],r=n?"span":"div",o=t[2];if(p[o]=p[r],g[o]=r,n||(c[o.toUpperCase()]={},c[o]={}),!x[o]){var i=x[r];delete(i=Gr({},i)).removeEmptyAttrs,delete i.removeEmpty,x[o]=i}Yr(p,function(e,t){e[r]&&(p[t]=e=Gr({},p[t]),e[o]=e[r])})}))},w=function(e){var o=/^([+\-]?)(\w+)\[([^\]]+)\]$/;Wr[i.schema]=null,e&&Yr(Zr(e,","),function(e){var t,n,r=o.exec(e);r&&(n=r[1],t=n?p[r[2]]:p[r[2]]={"#comment":{}},t=p[r[2]],Yr(Zr(r[3],"|"),function(e){"-"===n?delete t[e]:t[e]={}}))})},E=function(e){var t,n=x[e];if(n)return n;for(t=S.length;t--;)if((n=S[t]).pattern.test(e))return n};i.valid_elements?b(i.valid_elements):(Yr(n,function(e,t){x[t]={attributes:e.attributes,attributesOrder:e.attributesOrder},p[t]=e.children}),"html5"!==i.schema&&Yr(Zr("strong/b em/i"),function(e){e=Zr(e,"/"),x[e[1]].outputName=e[0]}),Yr(Zr("ol ul sub sup blockquote span font a table tbody tr strong em b i"),function(e){x[e]&&(x[e].removeEmpty=!0)}),Yr(Zr("p h1 h2 h3 h4 h5 h6 th td pre div address caption li"),function(e){x[e].paddEmpty=!0}),Yr(Zr("span"),function(e){x[e].removeEmptyAttrs=!0})),C(i.custom_elements),w(i.valid_children),y(i.extended_valid_elements),w("+ol[ul|ol],+ul[ul|ol]"),Yr({dd:"dl",dt:"dl",li:"ul ol",td:"tr",th:"tr",tr:"tbody thead tfoot",tbody:"table",thead:"table",tfoot:"table",legend:"fieldset",area:"map",param:"video audio object"},function(e,t){x[t]&&(x[t].parentsRequired=Zr(e))}),i.invalid_elements&&Yr(Jr(i.invalid_elements),function(e){x[e]&&delete x[e]}),E("span")||y("span[!data-mce-type|*]");return{children:p,elements:x,getValidStyles:function(){return e},getValidClasses:function(){return s},getBlockElements:function(){return c},getInvalidStyles:function(){return t},getShortEndedElements:function(){return a},getTextBlockElements:function(){return d},getTextInlineElements:function(){return m},getBoolAttrs:function(){return u},getElementRule:E,getSelfClosingElements:function(){return o},getNonEmptyElements:function(){return l},getMoveCaretBeforeOnEnterElements:function(){return f},getWhiteSpaceElements:function(){return r},getSpecialElements:function(){return h},isValidChild:function(e,t){var n=p[e.toLowerCase()];return!(!n||!n[t.toLowerCase()])},isValid:function(e,t){var n,r,o=E(e);if(o){if(!t)return!0;if(o.attributes[t])return!0;if(n=o.attributePatterns)for(r=n.length;r--;)if(n[r].pattern.test(e))return!0}return!1},getCustomElements:function(){return g},addValidElements:y,setValidElements:b,addCustomElements:C,addValidChildren:w}}var ro="\ufeff",oo="\xa0",io=function(e,t,n,r){var o=function(e){return 1<(e=parseInt(e,10).toString(16)).length?e:"0"+e};return"#"+o(t)+o(n)+o(r)},ao=function(b,e){var C,t,s,c,w=/rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\s*\)/gi,x=/(?:url(?:(?:\(\s*\"([^\"]+)\"\s*\))|(?:\(\s*\'([^\']+)\'\s*\))|(?:\(\s*([^)\s]+)\s*\))))|(?:\'([^\']+)\')|(?:\"([^\"]+)\")/gi,S=/\s*([^:]+):\s*([^;]+);?/g,N=/\s+$/,E={},k=ro;for(b=b||{},e&&(s=e.getValidStyles(),c=e.getInvalidStyles()),t=("\\\" \\' \\; \\: ; : "+k).split(" "),C=0;C<t.length;C++)E[t[C]]=k+C,E[k+C]=t[C];return{toHex:function(e){return e.replace(w,io)},parse:function(e){var t,n,r,o,i,a,u,s,c={},l=b.url_converter,f=b.url_converter_scope||this,d=function(e,t,n){var r,o,i,a;if((r=c[e+"-top"+t])&&(o=c[e+"-right"+t])&&(i=c[e+"-bottom"+t])&&(a=c[e+"-left"+t])){var u=[r,o,i,a];for(C=u.length-1;C--&&u[C]===u[C+1];);-1<C&&n||(c[e+t]=-1===C?u[0]:u.join(" "),delete c[e+"-top"+t],delete c[e+"-right"+t],delete c[e+"-bottom"+t],delete c[e+"-left"+t])}},m=function(e){var t,n=c[e];if(n){for(t=(n=n.split(" ")).length;t--;)if(n[t]!==n[0])return!1;return c[e]=n[0],!0}},p=function(e){return o=!0,E[e]},g=function(e,t){return o&&(e=e.replace(/\uFEFF[0-9]/g,function(e){return E[e]})),t||(e=e.replace(/\\([\'\";:])/g,"$1")),e},h=function(e){return String.fromCharCode(parseInt(e.slice(1),16))},v=function(e){return e.replace(/\\[0-9a-f]+/gi,h)},y=function(e,t,n,r,o,i){if(o=o||i)return"'"+(o=g(o)).replace(/\'/g,"\\'")+"'";if(t=g(t||n||r),!b.allow_script_urls){var a=t.replace(/[\s\r\n]+/g,"");if(/(java|vb)script:/i.test(a))return"";if(!b.allow_svg_data_urls&&/^data:image\/svg/i.test(a))return""}return l&&(t=l.call(f,t,"style")),"url('"+t.replace(/\'/g,"\\'")+"')"};if(e){for(e=(e=e.replace(/[\u0000-\u001F]/g,"")).replace(/\\[\"\';:\uFEFF]/g,p).replace(/\"[^\"]+\"|\'[^\']+\'/g,function(e){return e.replace(/[;:]/g,p)});t=S.exec(e);)if(S.lastIndex=t.index+t[0].length,n=t[1].replace(N,"").toLowerCase(),r=t[2].replace(N,""),n&&r){if(n=v(n),r=v(r),-1!==n.indexOf(k)||-1!==n.indexOf('"'))continue;if(!b.allow_script_urls&&("behavior"===n||/expression\s*\(|\/\*|\*\//.test(r)))continue;"font-weight"===n&&"700"===r?r="bold":"color"!==n&&"background-color"!==n||(r=r.toLowerCase()),r=(r=r.replace(w,io)).replace(x,y),c[n]=o?g(r,!0):r}d("border","",!0),d("border","-width"),d("border","-color"),d("border","-style"),d("padding",""),d("margin",""),i="border",u="border-style",s="border-color",m(a="border-width")&&m(u)&&m(s)&&(c[i]=c[a]+" "+c[u]+" "+c[s],delete c[a],delete c[u],delete c[s]),"medium none"===c.border&&delete c.border,"none"===c["border-image"]&&delete c["border-image"]}return c},serialize:function(i,a){var u="",e=function(e){var t,n,r,o;if(t=s[e])for(n=0,r=t.length;n<r;n++)e=t[n],(o=i[e])&&(u+=(0<u.length?" ":"")+e+": "+o+";")};return a&&s?(e("*"),e(a)):oe(i,function(e,t){var n,r,o;!e||c&&(n=t,r=a,(o=c["*"])&&o[n]||(o=c[r])&&o[n])||(u+=(0<u.length?" ":"")+t+": "+e+";")}),u}}},uo=/^(?:mouse|contextmenu)|click/,so={keyLocation:1,layerX:1,layerY:1,returnValue:1,webkitMovementX:1,webkitMovementY:1,keyIdentifier:1,mozPressure:1},co=function(){return!1},lo=function(){return!0},fo=function(e,t,n,r){e.addEventListener?e.addEventListener(t,n,r||!1):e.attachEvent&&e.attachEvent("on"+t,n)},mo=function(e,t,n,r){e.removeEventListener?e.removeEventListener(t,n,r||!1):e.detachEvent&&e.detachEvent("on"+t,n)},po=function(e,t){var n,r,o=t||{};for(n in e)so[n]||(o[n]=e[n]);if(o.target||(o.target=o.srcElement||V.document),rr.experimentalShadowDom&&(o.target=function(e,t){if(e.composedPath){var n=e.composedPath();if(n&&0<n.length)return n[0]}return t}(e,o.target)),e&&uo.test(e.type)&&e.pageX===undefined&&e.clientX!==undefined){var i=o.target.ownerDocument||V.document,a=i.documentElement,u=i.body;o.pageX=e.clientX+(a&&a.scrollLeft||u&&u.scrollLeft||0)-(a&&a.clientLeft||u&&u.clientLeft||0),o.pageY=e.clientY+(a&&a.scrollTop||u&&u.scrollTop||0)-(a&&a.clientTop||u&&u.clientTop||0)}return o.preventDefault=function(){o.isDefaultPrevented=lo,e&&(e.preventDefault?e.preventDefault():e.returnValue=!1)},o.stopPropagation=function(){o.isPropagationStopped=lo,e&&(e.stopPropagation?e.stopPropagation():e.cancelBubble=!0)},!(o.stopImmediatePropagation=function(){o.isImmediatePropagationStopped=lo,o.stopPropagation()})==((r=o).isDefaultPrevented===lo||r.isDefaultPrevented===co)&&(o.isDefaultPrevented=co,o.isPropagationStopped=co,o.isImmediatePropagationStopped=co),"undefined"==typeof o.metaKey&&(o.metaKey=!1),o},go=function(e,t,n){var r=e.document,o={type:"ready"};if(n.domLoaded)t(o);else{var i=function(){mo(e,"DOMContentLoaded",i),mo(e,"load",i),n.domLoaded||(n.domLoaded=!0,t(o))};"complete"===r.readyState||"interactive"===r.readyState&&r.body?i():fo(e,"DOMContentLoaded",i),fo(e,"load",i)}},ho=(vo.prototype.bind=function(e,t,n,r){var o,i,a,u,s,c,l,f=this,d=V.window,m=function(e){f.executeHandlers(po(e||d.event),o)};if(e&&3!==e.nodeType&&8!==e.nodeType){e[f.expando]?o=e[f.expando]:(o=f.count++,e[f.expando]=o,f.events[o]={}),r=r||e;var p=t.split(" ");for(a=p.length;a--;)c=m,s=l=!1,"DOMContentLoaded"===(u=p[a])&&(u="ready"),f.domLoaded&&"ready"===u&&"complete"===e.readyState?n.call(r,po({type:u})):(f.hasMouseEnterLeave||(s=f.mouseEnterLeave[u])&&(c=function(e){var t,n;if(t=e.currentTarget,(n=e.relatedTarget)&&t.contains)n=t.contains(n);else for(;n&&n!==t;)n=n.parentNode;n||((e=po(e||d.event)).type="mouseout"===e.type?"mouseleave":"mouseenter",e.target=t,f.executeHandlers(e,o))}),f.hasFocusIn||"focusin"!==u&&"focusout"!==u||(l=!0,s="focusin"===u?"focus":"blur",c=function(e){(e=po(e||d.event)).type="focus"===e.type?"focusin":"focusout",f.executeHandlers(e,o)}),(i=f.events[o][u])?"ready"===u&&f.domLoaded?n(po({type:u})):i.push({func:n,scope:r}):(f.events[o][u]=i=[{func:n,scope:r}],i.fakeName=s,i.capture=l,i.nativeHandler=c,"ready"===u?go(e,c,f):fo(e,s||u,c,l)));return e=i=0,n}},vo.prototype.unbind=function(n,e,t){var r,o,i,a,u,s;if(!n||3===n.nodeType||8===n.nodeType)return this;if(r=n[this.expando]){if(s=this.events[r],e){var c=e.split(" ");for(i=c.length;i--;)if(o=s[u=c[i]]){if(t)for(a=o.length;a--;)if(o[a].func===t){var l=o.nativeHandler,f=o.fakeName,d=o.capture;(o=o.slice(0,a).concat(o.slice(a+1))).nativeHandler=l,o.fakeName=f,o.capture=d,s[u]=o}t&&0!==o.length||(delete s[u],mo(n,o.fakeName||u,o.nativeHandler,o.capture))}}else oe(s,function(e,t){mo(n,e.fakeName||t,e.nativeHandler,e.capture)}),s={};for(u in s)if(me(s,u))return this;delete this.events[r];try{delete n[this.expando]}catch(m){n[this.expando]=null}}return this},vo.prototype.fire=function(e,t,n){var r;if(!e||3===e.nodeType||8===e.nodeType)return this;var o=po(null,n);for(o.type=t,o.target=e;(r=e[this.expando])&&this.executeHandlers(o,r),(e=e.parentNode||e.ownerDocument||e.defaultView||e.parentWindow)&&!o.isPropagationStopped(););return this},vo.prototype.clean=function(e){var t,n;if(!e||3===e.nodeType||8===e.nodeType)return this;if(e[this.expando]&&this.unbind(e),e.getElementsByTagName||(e=e.document),e&&e.getElementsByTagName)for(this.unbind(e),t=(n=e.getElementsByTagName("*")).length;t--;)(e=n[t])[this.expando]&&this.unbind(e);return this},vo.prototype.destroy=function(){this.events={}},vo.prototype.cancel=function(e){return e&&(e.preventDefault(),e.stopImmediatePropagation()),!1},vo.prototype.executeHandlers=function(e,t){var n,r,o,i,a=this.events[t];if(n=a&&a[e.type])for(r=0,o=n.length;r<o;r++)if((i=n[r])&&!1===i.func.call(i.scope,e)&&e.preventDefault(),e.isImmediatePropagationStopped())return},vo.Event=new vo,vo);function vo(){this.domLoaded=!1,this.events={},this.count=1,this.expando="mce-data-"+(+new Date).toString(32),this.hasMouseEnterLeave="onmouseenter"in V.document.documentElement,this.hasFocusIn="onfocusin"in V.document.documentElement,this.count=1}var yo,bo,Co,wo,xo,So,No,Eo,ko,_o,Ro,To,Ao,Do,Oo,Bo,Po,Lo="sizzle"+-new Date,Io=V.window.document,Mo=0,Fo=0,Uo=vi(),zo=vi(),jo=vi(),Ho=function(e,t){return e===t&&(_o=!0),0},Vo=typeof undefined,qo={}.hasOwnProperty,$o=[],Wo=$o.pop,Ko=$o.push,Xo=$o.push,Yo=$o.slice,Go=$o.indexOf||function(e){for(var t=0,n=this.length;t<n;t++)if(this[t]===e)return t;return-1},Jo="[\\x20\\t\\r\\n\\f]",Qo="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",Zo="\\["+Jo+"*("+Qo+")(?:"+Jo+"*([*^$|!~]?=)"+Jo+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+Qo+"))|)"+Jo+"*\\]",ei=":("+Qo+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+Zo+")*)|.*)\\)|)",ti=new RegExp("^"+Jo+"+|((?:^|[^\\\\])(?:\\\\.)*)"+Jo+"+$","g"),ni=new RegExp("^"+Jo+"*,"+Jo+"*"),ri=new RegExp("^"+Jo+"*([>+~]|"+Jo+")"+Jo+"*"),oi=new RegExp("="+Jo+"*([^\\]'\"]*?)"+Jo+"*\\]","g"),ii=new RegExp(ei),ai=new RegExp("^"+Qo+"$"),ui={ID:new RegExp("^#("+Qo+")"),CLASS:new RegExp("^\\.("+Qo+")"),TAG:new RegExp("^("+Qo+"|[*])"),ATTR:new RegExp("^"+Zo),PSEUDO:new RegExp("^"+ei),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+Jo+"*(even|odd|(([+-]|)(\\d*)n|)"+Jo+"*(?:([+-]|)"+Jo+"*(\\d+)|))"+Jo+"*\\)|)","i"),bool:new RegExp("^(?:checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)$","i"),needsContext:new RegExp("^"+Jo+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+Jo+"*((?:-\\d)?\\d*)"+Jo+"*\\)|)(?=[^-]|$)","i")},si=/^(?:input|select|textarea|button)$/i,ci=/^h\d$/i,li=/^[^{]+\{\s*\[native \w/,fi=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,di=/[+~]/,mi=/'|\\/g,pi=new RegExp("\\\\([\\da-f]{1,6}"+Jo+"?|("+Jo+")|.)","ig"),gi=function(e,t,n){var r="0x"+t-65536;return r!=r||n?t:r<0?String.fromCharCode(65536+r):String.fromCharCode(r>>10|55296,1023&r|56320)};try{Xo.apply($o=Yo.call(Io.childNodes),Io.childNodes),$o[Io.childNodes.length].nodeType}catch(pE){Xo={apply:$o.length?function(e,t){Ko.apply(e,Yo.call(t))}:function(e,t){for(var n=e.length,r=0;e[n++]=t[r++];);e.length=n-1}}}var hi=function(e,t,n,r){var o,i,a,u,s,c,l,f,d,m;if((t?t.ownerDocument||t:Io)!==To&&Ro(t),n=n||[],!e||"string"!=typeof e)return n;if(1!==(u=(t=t||To).nodeType)&&9!==u)return[];if(Do&&!r){if(o=fi.exec(e))if(a=o[1]){if(9===u){if(!(i=t.getElementById(a))||!i.parentNode)return n;if(i.id===a)return n.push(i),n}else if(t.ownerDocument&&(i=t.ownerDocument.getElementById(a))&&Po(t,i)&&i.id===a)return n.push(i),n}else{if(o[2])return Xo.apply(n,t.getElementsByTagName(e)),n;if((a=o[3])&&yo.getElementsByClassName)return Xo.apply(n,t.getElementsByClassName(a)),n}if(yo.qsa&&(!Oo||!Oo.test(e))){if(f=l=Lo,d=t,m=9===u&&e,1===u&&"object"!==t.nodeName.toLowerCase()){for(c=xo(e),(l=t.getAttribute("id"))?f=l.replace(mi,"\\$&"):t.setAttribute("id",f),f="[id='"+f+"'] ",s=c.length;s--;)c[s]=f+Si(c[s]);d=di.test(e)&&wi(t.parentNode)||t,m=c.join(",")}if(m)try{return Xo.apply(n,d.querySelectorAll(m)),n}catch(p){}finally{l||t.removeAttribute("id")}}}return No(e.replace(ti,"$1"),t,n,r)};function vi(){var n=[];function r(e,t){return n.push(e+" ")>bo.cacheLength&&delete r[n.shift()],r[e+" "]=t}return r}function yi(e){return e[Lo]=!0,e}function bi(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||1<<31)-(~e.sourceIndex||1<<31);if(r)return r;if(n)for(;n=n.nextSibling;)if(n===t)return-1;return e?1:-1}function Ci(a){return yi(function(i){return i=+i,yi(function(e,t){for(var n,r=a([],e.length,i),o=r.length;o--;)e[n=r[o]]&&(e[n]=!(t[n]=e[n]))})})}function wi(e){return e&&typeof e.getElementsByTagName!=Vo&&e}function xi(){}function Si(e){for(var t=0,n=e.length,r="";t<n;t++)r+=e[t].value;return r}function Ni(a,e,t){var u=e.dir,s=t&&"parentNode"===u,c=Fo++;return e.first?function(e,t,n){for(;e=e[u];)if(1===e.nodeType||s)return a(e,t,n)}:function(e,t,n){var r,o,i=[Mo,c];if(n){for(;e=e[u];)if((1===e.nodeType||s)&&a(e,t,n))return!0}else for(;e=e[u];)if(1===e.nodeType||s){if((r=(o=e[Lo]||(e[Lo]={}))[u])&&r[0]===Mo&&r[1]===c)return i[2]=r[2];if((o[u]=i)[2]=a(e,t,n))return!0}}}function Ei(o){return 1<o.length?function(e,t,n){for(var r=o.length;r--;)if(!o[r](e,t,n))return!1;return!0}:o[0]}function ki(e,t,n,r,o){for(var i,a=[],u=0,s=e.length,c=null!=t;u<s;u++)(i=e[u])&&(n&&!n(i,r,o)||(a.push(i),c&&t.push(u)));return a}function _i(p,g,h,v,y,e){return v&&!v[Lo]&&(v=_i(v)),y&&!y[Lo]&&(y=_i(y,e)),yi(function(e,t,n,r){var o,i,a,u=[],s=[],c=t.length,l=e||function m(e,t,n){for(var r=0,o=t.length;r<o;r++)hi(e,t[r],n);return n}(g||"*",n.nodeType?[n]:n,[]),f=!p||!e&&g?l:ki(l,u,p,n,r),d=h?y||(e?p:c||v)?[]:t:f;if(h&&h(f,d,n,r),v)for(o=ki(d,s),v(o,[],n,r),i=o.length;i--;)(a=o[i])&&(d[s[i]]=!(f[s[i]]=a));if(e){if(y||p){if(y){for(o=[],i=d.length;i--;)(a=d[i])&&o.push(f[i]=a);y(null,d=[],o,r)}for(i=d.length;i--;)(a=d[i])&&-1<(o=y?Go.call(e,a):u[i])&&(e[o]=!(t[o]=a))}}else d=ki(d===t?d.splice(c,d.length):d),y?y(null,t,d,r):Xo.apply(t,d)})}function Ri(e){for(var r,t,n,o=e.length,i=bo.relative[e[0].type],a=i||bo.relative[" "],u=i?1:0,s=Ni(function(e){return e===r},a,!0),c=Ni(function(e){return-1<Go.call(r,e)},a,!0),l=[function(e,t,n){return!i&&(n||t!==Eo)||((r=t).nodeType?s:c)(e,t,n)}];u<o;u++)if(t=bo.relative[e[u].type])l=[Ni(Ei(l),t)];else{if((t=bo.filter[e[u].type].apply(null,e[u].matches))[Lo]){for(n=++u;n<o&&!bo.relative[e[n].type];n++);return _i(1<u&&Ei(l),1<u&&Si(e.slice(0,u-1).concat({value:" "===e[u-2].type?"*":""})).replace(ti,"$1"),t,u<n&&Ri(e.slice(u,n)),n<o&&Ri(e=e.slice(n)),n<o&&Si(e))}l.push(t)}return Ei(l)}yo=hi.support={},wo=hi.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return!!t&&"HTML"!==t.nodeName},Ro=hi.setDocument=function(e){var t,s=e?e.ownerDocument||e:Io,n=s.defaultView;return s!==To&&9===s.nodeType&&s.documentElement?(Ao=(To=s).documentElement,Do=!wo(s),n&&n!==function r(e){try{return e.top}catch(t){}return null}(n)&&(n.addEventListener?n.addEventListener("unload",function(){Ro()},!1):n.attachEvent&&n.attachEvent("onunload",function(){Ro()})),yo.attributes=!0,yo.getElementsByTagName=!0,yo.getElementsByClassName=li.test(s.getElementsByClassName),yo.getById=!0,bo.find.ID=function(e,t){if(typeof t.getElementById!=Vo&&Do){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},bo.filter.ID=function(e){var t=e.replace(pi,gi);return function(e){return e.getAttribute("id")===t}},bo.find.TAG=yo.getElementsByTagName?function(e,t){if(typeof t.getElementsByTagName!=Vo)return t.getElementsByTagName(e)}:function(e,t){var n,r=[],o=0,i=t.getElementsByTagName(e);if("*"!==e)return i;for(;n=i[o++];)1===n.nodeType&&r.push(n);return r},bo.find.CLASS=yo.getElementsByClassName&&function(e,t){if(Do)return t.getElementsByClassName(e)},Bo=[],Oo=[],yo.disconnectedMatch=!0,Oo=Oo.length&&new RegExp(Oo.join("|")),Bo=Bo.length&&new RegExp(Bo.join("|")),t=li.test(Ao.compareDocumentPosition),Po=t||li.test(Ao.contains)?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)for(;t=t.parentNode;)if(t===e)return!0;return!1},Ho=t?function(e,t){if(e===t)return _o=!0,0;var n=!e.compareDocumentPosition-!t.compareDocumentPosition;return n||(1&(n=(e.ownerDocument||e)===(t.ownerDocument||t)?e.compareDocumentPosition(t):1)||!yo.sortDetached&&t.compareDocumentPosition(e)===n?e===s||e.ownerDocument===Io&&Po(Io,e)?-1:t===s||t.ownerDocument===Io&&Po(Io,t)?1:ko?Go.call(ko,e)-Go.call(ko,t):0:4&n?-1:1)}:function(e,t){if(e===t)return _o=!0,0;var n,r=0,o=e.parentNode,i=t.parentNode,a=[e],u=[t];if(!o||!i)return e===s?-1:t===s?1:o?-1:i?1:ko?Go.call(ko,e)-Go.call(ko,t):0;if(o===i)return bi(e,t);for(n=e;n=n.parentNode;)a.unshift(n);for(n=t;n=n.parentNode;)u.unshift(n);for(;a[r]===u[r];)r++;return r?bi(a[r],u[r]):a[r]===Io?-1:u[r]===Io?1:0},s):To},hi.matches=function(e,t){return hi(e,null,null,t)},hi.matchesSelector=function(e,t){if((e.ownerDocument||e)!==To&&Ro(e),t=t.replace(oi,"='$1']"),yo.matchesSelector&&Do&&(!Bo||!Bo.test(t))&&(!Oo||!Oo.test(t)))try{var n=(void 0).call(e,t);if(n||yo.disconnectedMatch||e.document&&11!==e.document.nodeType)return n}catch(pE){}return 0<hi(t,To,null,[e]).length},hi.contains=function(e,t){return(e.ownerDocument||e)!==To&&Ro(e),Po(e,t)},hi.attr=function(e,t){(e.ownerDocument||e)!==To&&Ro(e);var n=bo.attrHandle[t.toLowerCase()],r=n&&qo.call(bo.attrHandle,t.toLowerCase())?n(e,t,!Do):undefined;return r!==undefined?r:yo.attributes||!Do?e.getAttribute(t):(r=e.getAttributeNode(t))&&r.specified?r.value:null},hi.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)},hi.uniqueSort=function(e){var t,n=[],r=0,o=0;if(_o=!yo.detectDuplicates,ko=!yo.sortStable&&e.slice(0),e.sort(Ho),_o){for(;t=e[o++];)t===e[o]&&(r=n.push(o));for(;r--;)e.splice(n[r],1)}return ko=null,e},Co=hi.getText=function(e){var t,n="",r=0,o=e.nodeType;if(o){if(1===o||9===o||11===o){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=Co(e)}else if(3===o||4===o)return e.nodeValue}else for(;t=e[r++];)n+=Co(t);return n},(bo=hi.selectors={cacheLength:50,createPseudo:yi,match:ui,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(pi,gi),e[3]=(e[3]||e[4]||e[5]||"").replace(pi,gi),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||hi.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&hi.error(e[0]),e},PSEUDO:function(e){var t,n=!e[6]&&e[2];return ui.CHILD.test(e[0])?null:(e[3]?e[2]=e[4]||e[5]||"":n&&ii.test(n)&&(t=xo(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(pi,gi).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=Uo[e+" "];return t||(t=new RegExp("(^|"+Jo+")"+e+"("+Jo+"|$)"))&&Uo(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!=Vo&&e.getAttribute("class")||"")})},ATTR:function(n,r,o){return function(e){var t=hi.attr(e,n);return null==t?"!="===r:!r||(t+="","="===r?t===o:"!="===r?t!==o:"^="===r?o&&0===t.indexOf(o):"*="===r?o&&-1<t.indexOf(o):"$="===r?o&&t.slice(-o.length)===o:"~="===r?-1<(" "+t+" ").indexOf(o):"|="===r&&(t===o||t.slice(0,o.length+1)===o+"-"))}},CHILD:function(m,e,t,p,g){var h="nth"!==m.slice(0,3),v="last"!==m.slice(-4),y="of-type"===e;return 1===p&&0===g?function(e){return!!e.parentNode}:function(e,t,n){var r,o,i,a,u,s,c=h!=v?"nextSibling":"previousSibling",l=e.parentNode,f=y&&e.nodeName.toLowerCase(),d=!n&&!y;if(l){if(h){for(;c;){for(i=e;i=i[c];)if(y?i.nodeName.toLowerCase()===f:1===i.nodeType)return!1;s=c="only"===m&&!s&&"nextSibling"}return!0}if(s=[v?l.firstChild:l.lastChild],v&&d){for(u=(r=(o=l[Lo]||(l[Lo]={}))[m]||[])[0]===Mo&&r[1],a=r[0]===Mo&&r[2],i=u&&l.childNodes[u];i=++u&&i&&i[c]||(a=u=0)||s.pop();)if(1===i.nodeType&&++a&&i===e){o[m]=[Mo,u,a];break}}else if(d&&(r=(e[Lo]||(e[Lo]={}))[m])&&r[0]===Mo)a=r[1];else for(;(i=++u&&i&&i[c]||(a=u=0)||s.pop())&&((y?i.nodeName.toLowerCase()!==f:1!==i.nodeType)||!++a||(d&&((i[Lo]||(i[Lo]={}))[m]=[Mo,a]),i!==e)););return(a-=g)===p||a%p==0&&0<=a/p}}},PSEUDO:function(e,i){var t,a=bo.pseudos[e]||bo.setFilters[e.toLowerCase()]||hi.error("unsupported pseudo: "+e);return a[Lo]?a(i):1<a.length?(t=[e,e,"",i],bo.setFilters.hasOwnProperty(e.toLowerCase())?yi(function(e,t){for(var n,r=a(e,i),o=r.length;o--;)e[n=Go.call(e,r[o])]=!(t[n]=r[o])}):function(e){return a(e,0,t)}):a}},pseudos:{not:yi(function(e){var r=[],o=[],u=So(e.replace(ti,"$1"));return u[Lo]?yi(function(e,t,n,r){for(var o,i=u(e,null,r,[]),a=e.length;a--;)(o=i[a])&&(e[a]=!(t[a]=o))}):function(e,t,n){return r[0]=e,u(r,null,n,o),!o.pop()}}),has:yi(function(t){return function(e){return 0<hi(t,e).length}}),contains:yi(function(t){return t=t.replace(pi,gi),function(e){return-1<(e.textContent||e.innerText||Co(e)).indexOf(t)}}),lang:yi(function(n){return ai.test(n||"")||hi.error("unsupported lang: "+n),n=n.replace(pi,gi).toLowerCase(),function(e){var t;do{if(t=Do?e.lang:e.getAttribute("xml:lang")||e.getAttribute("lang"))return(t=t.toLowerCase())===n||0===t.indexOf(n+"-")}while((e=e.parentNode)&&1===e.nodeType);return!1}}),target:function(e){var t=V.window.location&&V.window.location.hash;return t&&t.slice(1)===e.id},root:function(e){return e===Ao},focus:function(e){return e===To.activeElement&&(!To.hasFocus||To.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return!1===e.disabled},disabled:function(e){return!0===e.disabled},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,!0===e.selected},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeType<6)return!1;return!0},parent:function(e){return!bo.pseudos.empty(e)},header:function(e){return ci.test(e.nodeName)},input:function(e){return si.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||"text"===t.toLowerCase())},first:Ci(function(){return[0]}),last:Ci(function(e,t){return[t-1]}),eq:Ci(function(e,t,n){return[n<0?n+t:n]}),even:Ci(function(e,t){for(var n=0;n<t;n+=2)e.push(n);return e}),odd:Ci(function(e,t){for(var n=1;n<t;n+=2)e.push(n);return e}),lt:Ci(function(e,t,n){for(var r=n<0?n+t:n;0<=--r;)e.push(r);return e}),gt:Ci(function(e,t,n){for(var r=n<0?n+t:n;++r<t;)e.push(r);return e})}}).pseudos.nth=bo.pseudos.eq,z(["radio","checkbox","file","password","image"],function(e){bo.pseudos[e]=function n(t){return function(e){return"input"===e.nodeName.toLowerCase()&&e.type===t}}(e)}),z(["submit","reset"],function(e){bo.pseudos[e]=function t(n){return function(e){var t=e.nodeName.toLowerCase();return("input"===t||"button"===t)&&e.type===n}}(e)}),xi.prototype=bo.filters=bo.pseudos,bo.setFilters=new xi,xo=hi.tokenize=function(e,t){var n,r,o,i,a,u,s,c=zo[e+" "];if(c)return t?0:c.slice(0);for(a=e,u=[],s=bo.preFilter;a;){for(i in n&&!(r=ni.exec(a))||(r&&(a=a.slice(r[0].length)||a),u.push(o=[])),n=!1,(r=ri.exec(a))&&(n=r.shift(),o.push({value:n,type:r[0].replace(ti," ")}),a=a.slice(n.length)),bo.filter)bo.filter.hasOwnProperty(i)&&(!(r=ui[i].exec(a))||s[i]&&!(r=s[i](r))||(n=r.shift(),o.push({value:n,type:i,matches:r}),a=a.slice(n.length)));if(!n)break}return t?a.length:a?hi.error(e):zo(e,u).slice(0)},So=hi.compile=function(e,t){var n,r=[],o=[],i=jo[e+" "];if(!i){for(n=(t=t||xo(e)).length;n--;)(i=Ri(t[n]))[Lo]?r.push(i):o.push(i);(i=jo(e,function a(h,v){var y=0<v.length,b=0<h.length,e=function(e,t,n,r,o){var i,a,u,s=0,c="0",l=e&&[],f=[],d=Eo,m=e||b&&bo.find.TAG("*",o),p=Mo+=null==d?1:Math.random()||.1,g=m.length;for(o&&(Eo=t!==To&&t);c!==g&&null!=(i=m[c]);c++){if(b&&i){for(a=0;u=h[a++];)if(u(i,t,n)){r.push(i);break}o&&(Mo=p)}y&&((i=!u&&i)&&s--,e&&l.push(i))}if(s+=c,y&&c!==s){for(a=0;u=v[a++];)u(l,f,t,n);if(e){if(0<s)for(;c--;)l[c]||f[c]||(f[c]=Wo.call(r));f=ki(f)}Xo.apply(r,f),o&&!e&&0<f.length&&1<s+v.length&&hi.uniqueSort(r)}return o&&(Mo=p,Eo=d),l};return y?yi(e):e}(o,r))).selector=e}return i},No=hi.select=function(e,t,n,r){var o,i,a,u,s,c="function"==typeof e&&e,l=!r&&xo(e=c.selector||e);if(n=n||[],1===l.length){if(2<(i=l[0]=l[0].slice(0)).length&&"ID"===(a=i[0]).type&&yo.getById&&9===t.nodeType&&Do&&bo.relative[i[1].type]){if(!(t=(bo.find.ID(a.matches[0].replace(pi,gi),t)||[])[0]))return n;c&&(t=t.parentNode),e=e.slice(i.shift().value.length)}for(o=ui.needsContext.test(e)?0:i.length;o--&&(a=i[o],!bo.relative[u=a.type]);)if((s=bo.find[u])&&(r=s(a.matches[0].replace(pi,gi),di.test(i[0].type)&&wi(t.parentNode)||t))){if(i.splice(o,1),!(e=r.length&&Si(i)))return Xo.apply(n,r),n;break}}return(c||So(e,l))(r,t,!Do,n,di.test(e)&&wi(t.parentNode)||t),n},yo.sortStable=Lo.split("").sort(Ho).join("")===Lo,yo.detectDuplicates=!!_o,Ro(),yo.sortDetached=!0;var Ti=V.document,Ai=Array.prototype.push,Di=Array.prototype.slice,Oi=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,Bi=ho.Event,Pi=hr.makeMap("children,contents,next,prev"),Li=function(e){return void 0!==e},Ii=function(e){return"string"==typeof e},Mi=function(e,t){var n,r,o;for(o=(t=t||Ti).createElement("div"),n=t.createDocumentFragment(),o.innerHTML=e;r=o.firstChild;)n.appendChild(r);return n},Fi=function(e,t,n,r){var o;if(Ii(t))t=Mi(t,Qi(e[0]));else if(t.length&&!t.nodeType){if(t=na.makeArray(t),r)for(o=t.length-1;0<=o;o--)Fi(e,t[o],n,r);else for(o=0;o<t.length;o++)Fi(e,t[o],n,r);return e}if(t.nodeType)for(o=e.length;o--;)n.call(e[o],t);return e},Ui=function(e,t){return e&&t&&-1!==(" "+e.className+" ").indexOf(" "+t+" ")},zi=function(e,t,n){var r,o;return t=na(t)[0],e.each(function(){n&&r===this.parentNode||(r=this.parentNode,o=t.cloneNode(!1),this.parentNode.insertBefore(o,this)),o.appendChild(this)}),e},ji=hr.makeMap("fillOpacity fontWeight lineHeight opacity orphans widows zIndex zoom"," "),Hi=hr.makeMap("checked compact declare defer disabled ismap multiple nohref noshade nowrap readonly selected"," "),Vi={"for":"htmlFor","class":"className",readonly:"readOnly"},qi={"float":"cssFloat"},$i={},Wi={},Ki=function(e,t){return new na.fn.init(e,t)},Xi=/^\s*|\s*$/g,Yi=function(e){return null===e||e===undefined?"":(""+e).replace(Xi,"")},Gi=function(e,t){var n,r,o,i;if(e)if((n=e.length)===undefined){for(r in e)if(e.hasOwnProperty(r)&&(i=e[r],!1===t.call(i,r,i)))break}else for(o=0;o<n&&(i=e[o],!1!==t.call(i,o,i));o++);return e},Ji=function(e,n){var r=[];return Gi(e,function(e,t){n(t,e)&&r.push(t)}),r},Qi=function(e){return e?9===e.nodeType?e:e.ownerDocument:Ti};Ki.fn=Ki.prototype={constructor:Ki,selector:"",context:null,length:0,init:function(e,t){var n,r,o=this;if(!e)return o;if(e.nodeType)return o.context=o[0]=e,o.length=1,o;if(t&&t.nodeType)o.context=t;else{if(t)return na(e).attr(t);o.context=t=V.document}if(Ii(e)){if(!(n="<"===(o.selector=e).charAt(0)&&">"===e.charAt(e.length-1)&&3<=e.length?[null,e,null]:Oi.exec(e)))return na(t).find(e);if(n[1])for(r=Mi(e,Qi(t)).firstChild;r;)Ai.call(o,r),r=r.nextSibling;else{if(!(r=Qi(t).getElementById(n[2])))return o;if(r.id!==n[2])return o.find(e);o.length=1,o[0]=r}}else this.add(e,!1);return o},toArray:function(){return hr.toArray(this)},add:function(e,t){var n,r;if(Ii(e))return this.add(na(e));if(!1!==t)for(n=na.unique(this.toArray().concat(na.makeArray(e))),this.length=n.length,r=0;r<n.length;r++)this[r]=n[r];else Ai.apply(this,na.makeArray(e));return this},attr:function(t,n){var e,r=this;if("object"==typeof t)Gi(t,function(e,t){r.attr(e,t)});else{if(!Li(n)){if(r[0]&&1===r[0].nodeType){if((e=$i[t])&&e.get)return e.get(r[0],t);if(Hi[t])return r.prop(t)?t:undefined;null===(n=r[0].getAttribute(t,2))&&(n=undefined)}return n}this.each(function(){var e;if(1===this.nodeType){if((e=$i[t])&&e.set)return void e.set(this,n);null===n?this.removeAttribute(t,2):this.setAttribute(t,n,2)}})}return r},removeAttr:function(e){return this.attr(e,null)},prop:function(e,t){var n=this;if("object"==typeof(e=Vi[e]||e))Gi(e,function(e,t){n.prop(e,t)});else{if(!Li(t))return n[0]&&n[0].nodeType&&e in n[0]?n[0][e]:t;this.each(function(){1===this.nodeType&&(this[e]=t)})}return n},css:function(n,r){var e,o,i=this,t=function(e){return e.replace(/-(\D)/g,function(e,t){return t.toUpperCase()})},a=function(e){return e.replace(/[A-Z]/g,function(e){return"-"+e})};if("object"==typeof n)Gi(n,function(e,t){i.css(e,t)});else if(Li(r))n=t(n),"number"!=typeof r||ji[n]||(r=r.toString()+"px"),i.each(function(){var e=this.style;if((o=Wi[n])&&o.set)o.set(this,r);else{try{this.style[qi[n]||n]=r}catch(t){}null!==r&&""!==r||(e.removeProperty?e.removeProperty(a(n)):e.removeAttribute(n))}});else{if(e=i[0],(o=Wi[n])&&o.get)return o.get(e);if(!e.ownerDocument.defaultView)return e.currentStyle?e.currentStyle[t(n)]:"";try{return e.ownerDocument.defaultView.getComputedStyle(e,null).getPropertyValue(a(n))}catch(u){return undefined}}return i},remove:function(){for(var e,t=this.length;t--;)e=this[t],Bi.clean(e),e.parentNode&&e.parentNode.removeChild(e);return this},empty:function(){for(var e,t=this.length;t--;)for(e=this[t];e.firstChild;)e.removeChild(e.firstChild);return this},html:function(e){var t;if(Li(e)){t=this.length;try{for(;t--;)this[t].innerHTML=e}catch(n){na(this[t]).empty().append(e)}return this}return this[0]?this[0].innerHTML:""},text:function(e){var t;if(Li(e)){for(t=this.length;t--;)"innerText"in this[t]?this[t].innerText=e:this[0].textContent=e;return this}return this[0]?this[0].innerText||this[0].textContent:""},append:function(){return Fi(this,arguments,function(e){(1===this.nodeType||this.host&&1===this.host.nodeType)&&this.appendChild(e)})},prepend:function(){return Fi(this,arguments,function(e){(1===this.nodeType||this.host&&1===this.host.nodeType)&&this.insertBefore(e,this.firstChild)},!0)},before:function(){return this[0]&&this[0].parentNode?Fi(this,arguments,function(e){this.parentNode.insertBefore(e,this)}):this},after:function(){return this[0]&&this[0].parentNode?Fi(this,arguments,function(e){this.parentNode.insertBefore(e,this.nextSibling)},!0):this},appendTo:function(e){return na(e).append(this),this},prependTo:function(e){return na(e).prepend(this),this},replaceWith:function(e){return this.before(e).remove()},wrap:function(e){return zi(this,e)},wrapAll:function(e){return zi(this,e,!0)},wrapInner:function(e){return this.each(function(){na(this).contents().wrapAll(e)}),this},unwrap:function(){return this.parent().each(function(){na(this).replaceWith(this.childNodes)})},clone:function(){var e=[];return this.each(function(){e.push(this.cloneNode(!0))}),na(e)},addClass:function(e){return this.toggleClass(e,!0)},removeClass:function(e){return this.toggleClass(e,!1)},toggleClass:function(o,i){var e=this;return"string"!=typeof o||(-1!==o.indexOf(" ")?Gi(o.split(" "),function(){e.toggleClass(this,i)}):e.each(function(e,t){var n,r;(r=Ui(t,o))!==i&&(n=t.className,r?t.className=Yi((" "+n+" ").replace(" "+o+" "," ")):t.className+=n?" "+o:o)})),e},hasClass:function(e){return Ui(this[0],e)},each:function(e){return Gi(this,e)},on:function(e,t){return this.each(function(){Bi.bind(this,e,t)})},off:function(e,t){return this.each(function(){Bi.unbind(this,e,t)})},trigger:function(e){return this.each(function(){"object"==typeof e?Bi.fire(this,e.type,e):Bi.fire(this,e)})},show:function(){return this.css("display","")},hide:function(){return this.css("display","none")},slice:function(){return new na(Di.apply(this,arguments))},eq:function(e){return-1===e?this.slice(e):this.slice(e,+e+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},find:function(e){var t,n,r=[];for(t=0,n=this.length;t<n;t++)na.find(e,this[t],r);return na(r)},filter:function(n){return na("function"==typeof n?Ji(this.toArray(),function(e,t){return n(t,e)}):na.filter(n,this.toArray()))},closest:function(n){var r=[];return n instanceof na&&(n=n[0]),this.each(function(e,t){for(;t;){if("string"==typeof n&&na(t).is(n)){r.push(t);break}if(t===n){r.push(t);break}t=t.parentNode}}),na(r)},offset:function(e){var t,n,r,o,i=0,a=0;return e?this.css(e):((t=this[0])&&(r=(n=t.ownerDocument).documentElement,t.getBoundingClientRect&&(i=(o=t.getBoundingClientRect()).left+(r.scrollLeft||n.body.scrollLeft)-r.clientLeft,a=o.top+(r.scrollTop||n.body.scrollTop)-r.clientTop)),{left:i,top:a})},push:Ai,sort:Array.prototype.sort,splice:Array.prototype.splice},hr.extend(Ki,{extend:hr.extend,makeArray:function(e){return(t=e)&&t===t.window||e.nodeType?[e]:hr.toArray(e);var t},inArray:function(e,t){var n;if(t.indexOf)return t.indexOf(e);for(n=t.length;n--;)if(t[n]===e)return n;return-1},isArray:hr.isArray,each:Gi,trim:Yi,grep:Ji,find:hi,expr:hi.selectors,unique:hi.uniqueSort,text:hi.getText,contains:hi.contains,filter:function(e,t,n){var r=t.length;for(n&&(e=":not("+e+")");r--;)1!==t[r].nodeType&&t.splice(r,1);return t=1===t.length?na.find.matchesSelector(t[0],e)?[t[0]]:[]:na.find.matches(e,t)}});var Zi=function(e,t,n){var r=[],o=e[t];for("string"!=typeof n&&n instanceof na&&(n=n[0]);o&&9!==o.nodeType;){if(n!==undefined){if(o===n)break;if("string"==typeof n&&na(o).is(n))break}1===o.nodeType&&r.push(o),o=o[t]}return r},ea=function(e,t,n,r){var o=[];for(r instanceof na&&(r=r[0]);e;e=e[t])if(!n||e.nodeType===n){if(r!==undefined){if(e===r)break;if("string"==typeof r&&na(e).is(r))break}o.push(e)}return o},ta=function(e,t,n){for(e=e[t];e;e=e[t])if(e.nodeType===n)return e;return null};Gi({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return Zi(e,"parentNode")},next:function(e){return ta(e,"nextSibling",1)},prev:function(e){return ta(e,"previousSibling",1)},children:function(e){return ea(e.firstChild,"nextSibling",1)},contents:function(e){return hr.toArray(("iframe"===e.nodeName?e.contentDocument||e.contentWindow.document:e).childNodes)}},function(r,o){Ki.fn[r]=function(t){var n=[];this.each(function(){var e=o.call(n,this,t,n);e&&(na.isArray(e)?n.push.apply(n,e):n.push(e))}),1<this.length&&(Pi[r]||(n=na.unique(n)),0===r.indexOf("parents")&&(n=n.reverse()));var e=na(n);return t?e.filter(t):e}}),Gi({parentsUntil:function(e,t){return Zi(e,"parentNode",t)},nextUntil:function(e,t){return ea(e,"nextSibling",1,t).slice(1)},prevUntil:function(e,t){return ea(e,"previousSibling",1,t).slice(1)}},function(o,i){Ki.fn[o]=function(t,e){var n=[];this.each(function(){var e=i.call(n,this,t,n);e&&(na.isArray(e)?n.push.apply(n,e):n.push(e))}),1<this.length&&(n=na.unique(n),0!==o.indexOf("parents")&&"prevUntil"!==o||(n=n.reverse()));var r=na(n);return e?r.filter(e):r}}),Ki.fn.is=function(e){return!!e&&0<this.filter(e).length},Ki.fn.init.prototype=Ki.fn,Ki.overrideDefaults=function(n){var r,o=function(e,t){return r=r||n(),0===arguments.length&&(e=r.element),t=t||r.context,new o.fn.init(e,t)};return na.extend(o,this),o},Ki.attrHooks=$i,Ki.cssHooks=Wi;var na=Ki,ra=(oa.prototype.current=function(){return this.node},oa.prototype.next=function(e){return this.node=this.findSibling(this.node,"firstChild","nextSibling",e),this.node},oa.prototype.prev=function(e){return this.node=this.findSibling(this.node,"lastChild","previousSibling",e),this.node},oa.prototype.prev2=function(e){return this.node=this.findPreviousNode(this.node,"lastChild","previousSibling",e),this.node},oa.prototype.findSibling=function(e,t,n,r){var o,i;if(e){if(!r&&e[t])return e[t];if(e!==this.rootNode){if(o=e[n])return o;for(i=e.parentNode;i&&i!==this.rootNode;i=i.parentNode)if(o=i[n])return o}}},oa.prototype.findPreviousNode=function(e,t,n,r){var o,i,a;if(e){if(o=e[n],this.rootNode&&o===this.rootNode)return;if(o){if(!r)for(a=o[t];a;a=a[t])if(!a[t])return a;return o}if((i=e.parentNode)&&i!==this.rootNode)return i}},oa);function oa(e,t){this.node=e,this.rootNode=t,this.current=this.current.bind(this),this.next=this.next.bind(this),this.prev=this.prev.bind(this),this.prev2=this.prev2.bind(this)}var ia,aa=hr.each,ua=hr.grep,sa=rr.ie,ca=/^([a-z0-9],?)+$/i,la=/^[ \t\r\n]*$/,fa=function(n,r,o){var i=r.keep_values,e={set:function(e,t,n){r.url_converter&&(t=r.url_converter.call(r.url_converter_scope||o(),t,n,e[0])),e.attr("data-mce-"+n,t).attr(n,t)},get:function(e,t){return e.attr("data-mce-"+t)||e.attr(t)}},t={style:{set:function(e,t){null===t||"object"!=typeof t?(i&&e.attr("data-mce-style",t),null!==t&&"string"==typeof t?(e.removeAttr("style"),e.css(n.parse(t))):e.attr("style",t)):e.css(t)},get:function(e){var t=e.attr("data-mce-style")||e.attr("style");return t=n.serialize(n.parse(t),e[0].nodeName)}}};return i&&(t.href=t.src=e),t},da=function(e,t){var n=t.attr("style"),r=e.serialize(e.parse(n),t[0].nodeName);r=r||null,t.attr("data-mce-style",r)},ma=function(e,t){var n,r,o=0;if(e)for(n=e.nodeType,e=e.previousSibling;e;e=e.previousSibling)r=e.nodeType,(!t||3!==r||r!==n&&e.nodeValue.length)&&(o++,n=r);return o};function pa(a,u){var s,c=this;void 0===u&&(u={});var r={},l=V.window,o={},t=0,e=vr(a,{contentCssCors:u.contentCssCors,referrerPolicy:u.referrerPolicy}),f=[],d=u.schema?u.schema:no({}),i=ao({url_converter:u.url_converter,url_converter_scope:u.url_converter_scope},u.schema),m=u.ownEvents?new ho:ho.Event,n=d.getBlockElements(),p=na.overrideDefaults(function(){return{context:a,element:H.getRoot()}}),g=function(e){if(e&&a&&"string"==typeof e){var t=a.getElementById(e);return t&&t.id!==e?a.getElementsByName(e)[1]:t}return e},h=function(e){return p("string"==typeof e?g(e):e)},v=function(e,t,n){var r,o,i=h(e);return i.length&&(o=(r=s[t])&&r.get?r.get(i,t):i.attr(t)),void 0===o&&(o=n||""),o},y=function(e){var t=g(e);return t?t.attributes:[]},b=function(e,t,n){var r,o;""===n&&(n=null);var i=h(e);r=i.attr(t),i.length&&((o=s[t])&&o.set?o.set(i,n,t):i.attr(t,n),r!==n&&u.onSetAttrib&&u.onSetAttrib({attrElm:i,attrName:t,attrValue:n}))},C=function(){return u.root_element||a.body},w=function(e,t){return bn(a.body,g(e),t)},x=function(e,t,n){var r=h(e);return n?r.css(t):("float"===(t=t.replace(/-(\D)/g,function(e,t){return t.toUpperCase()}))&&(t=rr.browser.isIE()?"styleFloat":"cssFloat"),r[0]&&r[0].style?r[0].style[t]:undefined)},S=function(e){var t,n;return e=g(e),t=x(e,"width"),n=x(e,"height"),-1===t.indexOf("px")&&(t=0),-1===n.indexOf("px")&&(n=0),{w:parseInt(t,10)||e.offsetWidth||e.clientWidth,h:parseInt(n,10)||e.offsetHeight||e.clientHeight}},N=function(e,t){var n;if(!e)return!1;if(!Array.isArray(e)){if("*"===t)return 1===e.nodeType;if(ca.test(t)){var r=t.toLowerCase().split(/,/),o=e.nodeName.toLowerCase();for(n=r.length-1;0<=n;n--)if(r[n]===o)return!0;return!1}if(e.nodeType&&1!==e.nodeType)return!1}var i=Array.isArray(e)?e:[e];return 0<hi(t,i[0].ownerDocument||i[0],null,i).length},E=function(e,t,n,r){var o,i=[],a=g(e);for(r=r===undefined,n=n||("BODY"!==C().nodeName?C().parentNode:null),hr.is(t,"string")&&(t="*"===(o=t)?function(e){return 1===e.nodeType}:function(e){return N(e,o)});a&&a!==n&&a.nodeType&&9!==a.nodeType;){if(!t||"function"==typeof t&&t(a)){if(!r)return[a];i.push(a)}a=a.parentNode}return r?i:null},k=function(e,t,n){var r=t;if(e)for("string"==typeof t&&(r=function(e){return N(e,t)}),e=e[n];e;e=e[n])if("function"==typeof r&&r(e))return e;return null},_=function(e,n,r){var o,t="string"==typeof e?g(e):e;if(!t)return!1;if(hr.isArray(t)&&(t.length||0===t.length))return o=[],aa(t,function(e,t){e&&("string"==typeof e&&(e=g(e)),o.push(n.call(r,e,t)))}),o;var i=r||c;return n.call(i,t)},R=function(e,t){h(e).each(function(e,n){aa(t,function(e,t){b(n,t,e)})})},T=function(e,r){var t=h(e);sa?t.each(function(e,t){if(!1!==t.canHaveHTML){for(;t.firstChild;)t.removeChild(t.firstChild);try{t.innerHTML="<br>"+r,t.removeChild(t.firstChild)}catch(n){na("<div></div>").html("<br>"+r).contents().slice(1).appendTo(t)}return r}}):t.html(r)},A=function(e,n,r,o,i){return _(e,function(e){var t="string"==typeof n?a.createElement(n):n;return R(t,r),o&&("string"!=typeof o&&o.nodeType?t.appendChild(o):"string"==typeof o&&T(t,o)),i?t:e.appendChild(t)})},D=function(e,t,n){return A(a.createElement(e),e,t,n,!0)},O=$r.decode,B=$r.encodeAllRaw,P=function(e,t){var n=h(e);return t?n.each(function(){for(var e;e=this.firstChild;)3===e.nodeType&&0===e.data.length?this.removeChild(e):this.parentNode.insertBefore(e,this)}).remove():n.remove(),1<n.length?n.toArray():n[0]},L=function(e,t,n){h(e).toggleClass(t,n).each(function(){""===this.className&&na(this).attr("class",null)})},I=function(t,e,n){return _(e,function(e){return hr.is(e,"array")&&(t=t.cloneNode(!0)),n&&aa(ua(e.childNodes),function(e){t.appendChild(e)}),e.parentNode.replaceChild(t,e)})},M=function(e){if($t(e)){var t="a"===e.nodeName.toLowerCase()&&!v(e,"href")&&v(e,"id");if(v(e,"name")||v(e,"data-mce-bookmark")||t)return!0}return!1},F=function(){return a.createRange()},U=function(e,t,n,r){if(hr.isArray(e)){for(var o=e.length,i=[];o--;)i[o]=U(e[o],t,n,r);return i}return!u.collect||e!==a&&e!==l||f.push([e,t,n,r]),m.bind(e,t,n,r||H)},z=function(e,t,n){var r;if(hr.isArray(e)){r=e.length;for(var o=[];r--;)o[r]=z(e[r],t,n);return o}if(0<f.length&&(e===a||e===l))for(r=f.length;r--;){var i=f[r];e!==i[0]||t&&t!==i[1]||n&&n!==i[2]||m.unbind(i[0],i[1],i[2])}return m.unbind(e,t,n)},j=function(e){if(e&&$t(e)){var t=e.getAttribute("data-mce-contenteditable");return t&&"inherit"!==t?t:"inherit"!==e.contentEditable?e.contentEditable:null}return null},H={doc:a,settings:u,win:l,files:o,stdMode:!0,boxModel:!0,styleSheetLoader:e,boundEvents:f,styles:i,schema:d,events:m,isBlock:function(e){if("string"==typeof e)return!!n[e];if(e){var t=e.nodeType;if(t)return!(1!==t||!n[e.nodeName])}return!1},$:p,$$:h,root:null,clone:function(t,e){if(!sa||1!==t.nodeType||e)return t.cloneNode(e);var n=a.createElement(t.nodeName);return aa(y(t),function(e){b(n,e.nodeName,v(t,e.nodeName))}),n},getRoot:C,getViewPort:function(e){var t=Ht(e);return{x:t.x,y:t.y,w:t.width,h:t.height}},getRect:function(e){var t,n;return e=g(e),t=w(e),n=S(e),{x:t.x,y:t.y,w:n.w,h:n.h}},getSize:S,getParent:function(e,t,n){var r=E(e,t,n,!1);return r&&0<r.length?r[0]:null},getParents:E,get:g,getNext:function(e,t){return k(e,t,"nextSibling")},getPrev:function(e,t){return k(e,t,"previousSibling")},select:function(e,t){return hi(e,g(t)||u.root_element||a,[])},is:N,add:A,create:D,createHTML:function(e,t,n){var r,o="";for(r in o+="<"+e,t)t.hasOwnProperty(r)&&null!==t[r]&&"undefined"!=typeof t[r]&&(o+=" "+r+'="'+B(t[r])+'"');return void 0!==n?o+">"+n+"</"+e+">":o+" />"},createFragment:function(e){var t,n=a.createElement("div"),r=a.createDocumentFragment();for(r.appendChild(n),e&&(n.innerHTML=e);t=n.firstChild;)r.appendChild(t);return r.removeChild(n),r},remove:P,setStyle:function(e,t,n){var r=q(t)?h(e).css(t,n):h(e).css(t);u.update_styles&&da(i,r)},getStyle:x,setStyles:function(e,t){var n=h(e).css(t);u.update_styles&&da(i,n)},removeAllAttribs:function(e){return _(e,function(e){var t,n=e.attributes;for(t=n.length-1;0<=t;t--)e.removeAttributeNode(n.item(t))})},setAttrib:b,setAttribs:R,getAttrib:v,getPos:w,parseStyle:function(e){return i.parse(e)},serializeStyle:function(e,t){return i.serialize(e,t)},addStyle:function(e){var t,n;if(H!==pa.DOM&&a===V.document){if(r[e])return;r[e]=!0}(n=a.getElementById("mceDefaultStyles"))||((n=a.createElement("style")).id="mceDefaultStyles",n.type="text/css",(t=a.getElementsByTagName("head")[0]).firstChild?t.insertBefore(n,t.firstChild):t.appendChild(n)),n.styleSheet?n.styleSheet.cssText+=e:n.appendChild(a.createTextNode(e))},loadCSS:function(e){var n;H===pa.DOM||a!==V.document?(e=e||"",n=a.getElementsByTagName("head")[0],aa(e.split(","),function(e){var t;e=hr._addCacheSuffix(e),o[e]||(o[e]=!0,t=D("link",pe(pe({rel:"stylesheet",type:"text/css",href:e},u.contentCssCors?{crossOrigin:"anonymous"}:{}),u.referrerPolicy?{referrerPolicy:u.referrerPolicy}:{})),n.appendChild(t))})):pa.DOM.loadCSS(e)},addClass:function(e,t){h(e).addClass(t)},removeClass:function(e,t){L(e,t,!1)},hasClass:function(e,t){return h(e).hasClass(t)},toggleClass:L,show:function(e){h(e).show()},hide:function(e){h(e).hide()},isHidden:function(e){return"none"===h(e).css("display")},uniqueId:function(e){return(e||"mce_")+t++},setHTML:T,getOuterHTML:function(e){var t="string"==typeof e?g(e):e;return $t(t)?t.outerHTML:na("<div></div>").append(na(t).clone()).html()},setOuterHTML:function(e,t){h(e).each(function(){try{if("outerHTML"in this)return void(this.outerHTML=t)}catch(e){}P(na(this).html(t),!0)})},decode:O,encode:B,insertAfter:function(e,t){var r=g(t);return _(e,function(e){var t,n;return t=r.parentNode,(n=r.nextSibling)?t.insertBefore(e,n):t.appendChild(e),e})},replace:I,rename:function(t,e){var n;return t.nodeName!==e.toUpperCase()&&(n=D(e),aa(y(t),function(e){b(n,e.nodeName,v(t,e.nodeName))}),I(n,t,!0)),n||t},findCommonAncestor:function(e,t){for(var n,r=e;r;){for(n=t;n&&r!==n;)n=n.parentNode;if(r===n)break;r=r.parentNode}return!r&&e.ownerDocument?e.ownerDocument.documentElement:r},toHex:function(e){return i.toHex(hr.trim(e))},run:_,getAttribs:y,isEmpty:function(e,t){var n,r,o=0;if(M(e))return!1;if(e=e.firstChild){var i=new ra(e,e.parentNode),a=d?d.getWhiteSpaceElements():{};t=t||(d?d.getNonEmptyElements():null);do{if(n=e.nodeType,$t(e)){var u=e.getAttribute("data-mce-bogus");if(u){e=i.next("all"===u);continue}if(r=e.nodeName.toLowerCase(),t&&t[r]){if("br"!==r)return!1;o++,e=i.next();continue}if(M(e))return!1}if(8===n)return!1;if(3===n&&!la.test(e.nodeValue))return!1;if(3===n&&e.parentNode&&a[e.parentNode.nodeName]&&la.test(e.nodeValue))return!1;e=i.next()}while(e)}return o<=1},createRng:F,nodeIndex:ma,split:function(e,t,n){var r,o,i,a=F();if(e&&t)return a.setStart(e.parentNode,ma(e)),a.setEnd(t.parentNode,ma(t)),r=a.extractContents(),(a=F()).setStart(t.parentNode,ma(t)+1),a.setEnd(e.parentNode,ma(e)+1),o=a.extractContents(),(i=e.parentNode).insertBefore(Pr(H,r),e),n?i.insertBefore(n,e):i.insertBefore(t,e),i.insertBefore(Pr(H,o),e),P(e),n||t},bind:U,unbind:z,fire:function(e,t,n){return m.fire(e,t,n)},getContentEditable:j,getContentEditableParent:function(e){for(var t=C(),n=null;e&&e!==t&&null===(n=j(e));e=e.parentNode);return n},destroy:function(){if(0<f.length)for(var e=f.length;e--;){var t=f[e];m.unbind(t[0],t[1],t[2])}hi.setDocument&&hi.setDocument()},isChildOf:function(e,t){for(;e;){if(t===e)return!0;e=e.parentNode}return!1},dumpRng:function(e){return"startContainer: "+e.startContainer.nodeName+", startOffset: "+e.startOffset+", endContainer: "+e.endContainer.nodeName+", endOffset: "+e.endOffset}};return s=fa(i,u,function(){return H}),H}(ia=pa=pa||{}).DOM=ia(V.document),ia.nodeIndex=ma;var ga=pa,ha=ga.DOM,va=hr.each,ya=hr.grep,ba=(Ca.prototype._setReferrerPolicy=function(e){this.settings.referrerPolicy=e},Ca.prototype.loadScript=function(e,t,n){var r,o,i=ha;o=i.uniqueId(),(r=V.document.createElement("script")).id=o,r.type="text/javascript",r.src=hr._addCacheSuffix(e),this.settings.referrerPolicy&&i.setAttrib(r,"referrerpolicy",this.settings.referrerPolicy),r.onload=function(){i.remove(o),r&&(r.onreadystatechange=r.onload=r=null),t()},r.onerror=function(){D(n)?n():"undefined"!=typeof V.console&&V.console.log&&V.console.log("Failed to load script: "+e)},(V.document.getElementsByTagName("head")[0]||V.document.body).appendChild(r)},Ca.prototype.isDone=function(e){return 2===this.states[e]},Ca.prototype.markDone=function(e){this.states[e]=2},Ca.prototype.add=function(e,t,n,r){this.states[e]===undefined&&(this.queue.push(e),this.states[e]=0),t&&(this.scriptLoadedCallbacks[e]||(this.scriptLoadedCallbacks[e]=[]),this.scriptLoadedCallbacks[e].push({success:t,failure:r,scope:n||this}))},Ca.prototype.load=function(e,t,n,r){return this.add(e,t,n,r)},Ca.prototype.remove=function(e){delete this.states[e],delete this.scriptLoadedCallbacks[e]},Ca.prototype.loadQueue=function(e,t,n){this.loadScripts(this.queue,e,t,n)},Ca.prototype.loadScripts=function(n,e,t,r){var o,i=this,a=[],u=function(t,e){va(i.scriptLoadedCallbacks[e],function(e){D(e[t])&&e[t].call(e.scope)}),i.scriptLoadedCallbacks[e]=undefined};i.queueLoadedCallbacks.push({success:e,failure:r,scope:t||this}),(o=function(){var e=ya(n);if(n.length=0,va(e,function(e){2!==i.states[e]?3!==i.states[e]?1!==i.states[e]&&(i.states[e]=1,i.loading++,i.loadScript(e,function(){i.states[e]=2,i.loading--,u("success",e),o()},function(){i.states[e]=3,i.loading--,a.push(e),u("failure",e),o()})):u("failure",e):u("success",e)}),!i.loading){var t=i.queueLoadedCallbacks.slice(0);i.queueLoadedCallbacks.length=0,va(t,function(e){0===a.length?D(e.success)&&e.success.call(e.scope):D(e.failure)&&e.failure.call(e.scope,a)})}})()},Ca.ScriptLoader=new Ca,Ca);function Ca(e){void 0===e&&(e={}),this.states={},this.queue=[],this.scriptLoadedCallbacks={},this.queueLoadedCallbacks=[],this.loading=0,this.settings=e}var wa,xa=function(e){var t=e;return{get:function(){return t},set:function(e){t=e}}},Sa={},Na=xa("en"),Ea=function(){return de(Sa,Na.get())},ka={getData:function(){return ie(Sa,function(e){return pe({},e)})},setCode:function(e){e&&Na.set(e)},getCode:function(){return Na.get()},add:function(e,t){var n=Sa[e];n||(Sa[e]=n={}),oe(t,function(e,t){n[t.toLowerCase()]=e})},translate:function(e){var t,n,r=Ea().getOr({}),o=function(e){return D(e)?Object.prototype.toString.call(e):i(e)?"":""+e},i=function(e){return""===e||null===e||e===undefined},a=function(e){var t=o(e);return de(r,t.toLowerCase()).map(o).getOr(t)},u=function(e){return e.replace(/{context:\w+}$/,"")};if(i(e))return"";if(E(t=e)&&me(t,"raw"))return o(e.raw);if(k(n=e)&&1<n.length){var s=e.slice(1);return u(a(e[0]).replace(/\{([0-9]+)\}/g,function(e,t){return me(s,t)?o(s[t]):e}))}return u(a(e))},isRtl:function(){return Ea().bind(function(e){return de(e,"_dir")}).exists(function(e){return"rtl"===e})},hasCode:function(e){return me(Sa,e)}};function _a(){var r=this,o=[],s={},c={},i=[],l=function(t,n){var e=H(i,function(e){return e.name===t&&e.state===n});z(e,function(e){return e.callback()})},f=function(e){var t;return c[e]&&(t=c[e].dependencies),t||[]},d=function(e,t){return"object"==typeof t?t:"string"==typeof e?{prefix:"",resource:t,suffix:""}:{prefix:e.prefix,resource:t,suffix:e.suffix}},m=function(o,i,a,u,e){if(!s[o]){var t="string"==typeof i?i:i.prefix+i.resource+i.suffix;0!==t.indexOf("/")&&-1===t.indexOf("://")&&(t=_a.baseURL+"/"+t),s[o]=t.substring(0,t.lastIndexOf("/"));var n=function(){var n,e,t,r;l(o,"loaded"),n=i,e=a,t=u,r=f(o),z(r,function(e){var t=d(n,e);m(t.resource,t,undefined,undefined)}),e&&(t?e.call(t):e.call(ba))};c[o]?n():ba.ScriptLoader.add(t,n,u,e)}},e=function(e,t,n){void 0===n&&(n="added"),me(c,e)&&"added"===n||me(s,e)&&"loaded"===n?t():i.push({name:e,state:n,callback:t})};return{items:o,urls:s,lookup:c,_listeners:i,get:function(e){return c[e]?c[e].instance:undefined},dependencies:f,requireLangPack:function(t,n){!1!==_a.languageLoad&&e(t,function(){var e=ka.getCode();!e||n&&-1===(","+(n||"")+",").indexOf(","+e+",")||ba.ScriptLoader.add(s[t]+"/langs/"+e+".js")},"loaded")},add:function(e,t,n){var r=t;return o.push(r),c[e]={instance:r,dependencies:n},l(e,"added"),r},remove:function(e){delete s[e],delete c[e]},createUrl:d,addComponents:function(e,t){var n=r.urls[e];z(t,function(e){ba.ScriptLoader.add(n+"/"+e)})},load:m,waitFor:e}}(wa=_a=_a||{}).PluginManager=wa(),wa.ThemeManager=wa();var Ra=_a,Ta=function(n,r){var o=null;return{cancel:function(){null!==o&&(V.clearTimeout(o),o=null)},throttle:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];null===o&&(o=V.setTimeout(function(){n.apply(null,e),o=null},r))}}},Aa=function(n,r){var o=null;return{cancel:function(){null!==o&&(V.clearTimeout(o),o=null)},throttle:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];null!==o&&V.clearTimeout(o),o=V.setTimeout(function(){n.apply(null,e),o=null},r)}}},Da=function(e,t){var n=fn(e,t);return n===undefined||""===n?[]:n.split(" ")},Oa=function(e){return e.dom().classList!==undefined},Ba=function(e,t){return o=t,i=Da(n=e,r="class").concat([o]),cn(n,r,i.join(" ")),!0;var n,r,o,i},Pa=function(e,t){return o=t,0<(i=H(Da(n=e,r="class"),function(e){return e!==o})).length?cn(n,r,i.join(" ")):dn(n,r),!1;var n,r,o,i},La=function(e,t){Oa(e)?e.dom().classList.add(t):Ba(e,t)},Ia=function(e){0===(Oa(e)?e.dom().classList:Da(e,"class")).length&&dn(e,"class")},Ma=function(e,t){return Oa(e)&&e.dom().classList.contains(t)},Fa=function(e,t){var n=[];return z(ht(e),function(e){t(e)&&(n=n.concat([e])),n=n.concat(Fa(e,t))}),n},Ua=function(e,t){return n=t,o=(r=e)===undefined?V.document:r.dom(),it(o)?[]:U(o.querySelectorAll(n),Ne.fromDom);var n,r,o};function za(e,t,n,r,o){return e(n,r)?R.some(n):D(o)&&o(n)?R.none():t(n,r,o)}var ja,Ha=function(e,t,n){for(var r=e.dom(),o=D(n)?n:x(!1);r.parentNode;){r=r.parentNode;var i=Ne.fromDom(r);if(t(i))return R.some(i);if(o(i))break}return R.none()},Va=function(e,t,n){return za(function(e,t){return t(e)},Ha,e,t,n)},qa=function(e,t,n){return Ha(e,function(e){return ot(e,t)},n)},$a=function(e,t){return n=t,o=(r=e)===undefined?V.document:r.dom(),it(o)?R.none():R.from(o.querySelector(n)).map(Ne.fromDom);var n,r,o},Wa=function(e,t,n){return za(function(e,t){return ot(e,t)},qa,e,t,n)},Ka=x("mce-annotation"),Xa=x("data-mce-annotation"),Ya=x("data-mce-annotation-uid"),Ga=function(r,e){var t=r.selection.getRng(),n=Ne.fromDom(t.startContainer),o=Ne.fromDom(r.getBody()),i=e.fold(function(){return"."+Ka()},function(e){return"["+Xa()+'="'+e+'"]'}),a=vt(n,t.startOffset).getOr(n),u=Wa(a,i,function(e){return at(e,o)}),s=function(e,t){return n=t,(r=e.dom())&&r.hasAttribute&&r.hasAttribute(n)?R.some(fn(e,t)):R.none();var n,r};return u.bind(function(e){return s(e,""+Ya()).bind(function(n){return s(e,""+Xa()).map(function(e){var t=Ja(r,n);return{uid:n,name:e,elements:t}})})})},Ja=function(e,t){var n=Ne.fromDom(e.getBody());return Ua(n,"["+Ya()+'="'+t+'"]')},Qa=function(i,e){var a=xa({}),c=function(e,t){u(e,function(e){return t(e),e})},u=function(e,t){var n=a.get(),r=t(n.hasOwnProperty(e)?n[e]:{listeners:[],previous:xa(R.none())});n[e]=r,a.set(n)},t=Aa(function(){var e,t,n,r=a.get(),o=(e=ne(r),(n=B.call(e,0)).sort(t),n);z(o,function(e){u(e,function(u){var s=u.previous.get();return Ga(i,R.some(e)).fold(function(){var t;s.isSome()&&(c(t=e,function(e){z(e.listeners,function(e){return e(!1,t)})}),u.previous.set(R.none()))},function(e){var t,n,r,o=e.uid,i=e.name,a=e.elements;s.is(o)||(n=o,r=a,c(t=i,function(e){z(e.listeners,function(e){return e(!0,t,{uid:n,nodes:U(r,function(e){return e.dom()})})})}),u.previous.set(R.some(o)))}),{previous:u.previous,listeners:u.listeners}})})},30);i.on("remove",function(){t.cancel()}),i.on("NodeChange",function(){t.throttle()});return{addListener:function(e,t){u(e,function(e){return{previous:e.previous,listeners:e.listeners.concat([t])}})}}},Za=function(e,n){e.on("init",function(){e.serializer.addNodeFilter("span",function(e){z(e,function(t){var e;e=t,R.from(e.attr(Xa())).bind(n.lookup).each(function(e){!1===e.persistent&&t.unwrap()})})})})},eu=0,tu=function(e){var t=(new Date).getTime();return e+"_"+Math.floor(1e9*Math.random())+ ++eu+String(t)},nu=function(e,t){var n,r,o=ct(e).dom(),i=Ne.fromDom(o.createDocumentFragment()),a=(n=t,(r=(o||V.document).createElement("div")).innerHTML=n,ht(Ne.fromDom(r)));Nt(i,a),Et(e),St(e,i)},ru=function(e,t){return Ne.fromDom(e.dom().cloneNode(t))},ou=function(e){return ru(e,!1)},iu=function(e){return ru(e,!0)},au=function(e,t,n){void 0===n&&(n=g);var r=new ra(e,t),o=function(e){for(var t;(t=r[e]())&&!Zt(t)&&!n(t););return R.from(t).filter(Zt)};return{current:function(){return R.from(r.current()).filter(Zt)},next:function(){return o("next")},prev:function(){return o("prev")},prev2:function(){return o("prev2")}}},uu=function(t,e){var i=e||function(e){return t.isBlock(e)||rn(e)||an(e)},a=function(e,t,n,r){if(Zt(e)){var o=r(e,t,e.data);if(-1!==o)return R.some({container:e,offset:o})}return n().bind(function(e){return a(e.container,e.offset,n,r)})};return{backwards:function(e,t,n,r){var o=au(e,r,i);return a(e,t,function(){return o.prev().map(function(e){return{container:e,offset:e.length}})},n).getOrNull()},forwards:function(e,t,n,r){var o=au(e,r,i);return a(e,t,function(){return o.next().map(function(e){return{container:e,offset:0}})},n).getOrNull()}}},su=ro,cu=function(e){return e===ro},lu=function(e){return e.replace(/\uFEFF/g,"")},fu=$t,du=Zt,mu=function(e){return du(e)&&(e=e.parentNode),fu(e)&&e.hasAttribute("data-mce-caret")},pu=function(e){return du(e)&&cu(e.data)},gu=function(e){return mu(e)||pu(e)},hu=function(e){return e.firstChild!==e.lastChild||!rn(e.firstChild)},vu=function(e){var t=e.container();return!(!e||!Zt(t))&&(t.data.charAt(e.offset())===su||e.isAtStart()&&pu(t.previousSibling))},yu=function(e){var t=e.container();return!(!e||!Zt(t))&&(t.data.charAt(e.offset()-1)===su||e.isAtEnd()&&pu(t.nextSibling))},bu=function(e,t,n){var r,o,i;return(r=t.ownerDocument.createElement(e)).setAttribute("data-mce-caret",n?"before":"after"),r.setAttribute("data-mce-bogus","all"),r.appendChild(((i=V.document.createElement("br")).setAttribute("data-mce-bogus","1"),i)),o=t.parentNode,n?o.insertBefore(r,t):t.nextSibling?o.insertBefore(r,t.nextSibling):o.appendChild(r),r},Cu=function(e){return du(e)&&e.data[0]===su},wu=function(e){return du(e)&&e.data[e.data.length-1]===su},xu=function(e){return e&&e.hasAttribute("data-mce-caret")?(t=e.getElementsByTagName("br"),n=t[t.length-1],Yt(n)&&n.parentNode.removeChild(n),e.removeAttribute("data-mce-caret"),e.removeAttribute("data-mce-bogus"),e.removeAttribute("style"),e.removeAttribute("_moz_abspos"),e):null;var t,n},Su=on,Nu=an,Eu=rn,ku=Zt,_u=Wt(["script","style","textarea"]),Ru=Wt(["img","input","textarea","hr","iframe","video","audio","object"]),Tu=Wt(["table"]),Au=gu,Du=function(e){return!Au(e)&&(ku(e)?!_u(e.parentNode):Ru(e)||Eu(e)||Tu(e)||Ou(e))},Ou=function(e){return!1===($t(t=e)&&"true"===t.getAttribute("unselectable"))&&Nu(e);var t},Bu=function(e,t){return Du(e)&&function(e,t){for(e=e.parentNode;e&&e!==t;e=e.parentNode){if(Ou(e))return!1;if(Su(e))return!0}return!0}(e,t)},Pu=Math.round,Lu=function(e){return e?{left:Pu(e.left),top:Pu(e.top),bottom:Pu(e.bottom),right:Pu(e.right),width:Pu(e.width),height:Pu(e.height)}:{left:0,top:0,bottom:0,right:0,width:0,height:0}},Iu=function(e,t){return e=Lu(e),t||(e.left=e.left+e.width),e.right=e.left,e.width=0,e},Mu=function(e,t,n){return 0<=e&&e<=Math.min(t.height,n.height)/2},Fu=function(e,t){return e.bottom-e.height/2<t.top||!(e.top>t.bottom)&&Mu(t.top-e.bottom,e,t)},Uu=function(e,t){return e.top>t.bottom||!(e.bottom<t.top)&&Mu(t.bottom-e.top,e,t)},zu=function(e,t,n){return t>=e.left&&t<=e.right&&n>=e.top&&n<=e.bottom},ju=function(e){var t=e.startContainer,n=e.startOffset;return t.hasChildNodes()&&e.endOffset===n+1?t.childNodes[n]:null},Hu=function(e,t){return 1===e.nodeType&&e.hasChildNodes()&&(t>=e.childNodes.length&&(t=e.childNodes.length-1),e=e.childNodes[t]),e},Vu=new RegExp("[\u0300-\u036f\u0483-\u0487\u0488-\u0489\u0591-\u05bd\u05bf\u05c1-\u05c2\u05c4-\u05c5\u05c7\u0610-\u061a\u064b-\u065f\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7-\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e3-\u0902\u093a\u093c\u0941-\u0948\u094d\u0951-\u0957\u0962-\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2-\u09e3\u0a01-\u0a02\u0a3c\u0a41-\u0a42\u0a47-\u0a48\u0a4b-\u0a4d\u0a51\u0a70-\u0a71\u0a75\u0a81-\u0a82\u0abc\u0ac1-\u0ac5\u0ac7-\u0ac8\u0acd\u0ae2-\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62-\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c00\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55-\u0c56\u0c62-\u0c63\u0c81\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc-\u0ccd\u0cd5-\u0cd6\u0ce2-\u0ce3\u0d01\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62-\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb-\u0ebc\u0ec8-\u0ecd\u0f18-\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86-\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039-\u103a\u103d-\u103e\u1058-\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085-\u1086\u108d\u109d\u135d-\u135f\u1712-\u1714\u1732-\u1734\u1752-\u1753\u1772-\u1773\u17b4-\u17b5\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927-\u1928\u1932\u1939-\u193b\u1a17-\u1a18\u1a1b\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1ab0-\u1abd\u1abe\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80-\u1b81\u1ba2-\u1ba5\u1ba8-\u1ba9\u1bab-\u1bad\u1be6\u1be8-\u1be9\u1bed\u1bef-\u1bf1\u1c2c-\u1c33\u1c36-\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1cf4\u1cf8-\u1cf9\u1dc0-\u1df5\u1dfc-\u1dff\u200c-\u200d\u20d0-\u20dc\u20dd-\u20e0\u20e1\u20e2-\u20e4\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302d\u302e-\u302f\u3099-\u309a\ua66f\ua670-\ua672\ua674-\ua67d\ua69e-\ua69f\ua6f0-\ua6f1\ua802\ua806\ua80b\ua825-\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\ua9e5\uaa29-\uaa2e\uaa31-\uaa32\uaa35-\uaa36\uaa43\uaa4c\uaa7c\uaab0\uaab2-\uaab4\uaab7-\uaab8\uaabe-\uaabf\uaac1\uaaec-\uaaed\uaaf6\uabe5\uabe8\uabed\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\uff9e-\uff9f]"),qu=function(e){return"string"==typeof e&&768<=e.charCodeAt(0)&&Vu.test(e)},$u=function(e,t,n){return e.isSome()&&t.isSome()?R.some(n(e.getOrDie(),t.getOrDie())):R.none()},Wu=$t,Ku=Du,Xu=Kt("display","block table"),Yu=Kt("float","left right"),Gu=function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return function(e){for(var t=0;t<n.length;t++)if(!n[t](e))return!1;return!0}}(Wu,Ku,m(Yu)),Ju=m(Kt("white-space","pre pre-line pre-wrap")),Qu=Zt,Zu=rn,es=ga.nodeIndex,ts=Hu,ns=function(e){return"createRange"in e?e.createRange():ga.DOM.createRng()},rs=function(e){return e&&/[\r\n\t ]/.test(e)},os=function(e){return!!e.setStart&&!!e.setEnd},is=function(e){var t,n=e.startContainer,r=e.startOffset;return!!(rs(e.toString())&&Ju(n.parentNode)&&Zt(n)&&(t=n.data,rs(t[r-1])||rs(t[r+1])))},as=function(e){return 0===e.left&&0===e.right&&0===e.top&&0===e.bottom},us=function(e){var t,n,r,o,i,a,u,s;return t=0<(n=e.getClientRects()).length?Lu(n[0]):Lu(e.getBoundingClientRect()),!os(e)&&Zu(e)&&as(t)?(i=(r=e).ownerDocument,a=ns(i),u=i.createTextNode(oo),(s=r.parentNode).insertBefore(u,r),a.setStart(u,0),a.setEnd(u,1),o=Lu(a.getBoundingClientRect()),s.removeChild(u),o):as(t)&&os(e)?function(e){var t=e.startContainer,n=e.endContainer,r=e.startOffset,o=e.endOffset;if(t===n&&Zt(n)&&0===r&&1===o){var i=e.cloneRange();return i.setEndAfter(n),us(i)}return null}(e):t},ss=function(e,t){var n=Iu(e,t);return n.width=1,n.right=n.left+1,n},cs=function(e){var t,n,r=[],o=function(e){var t,n;0!==e.height&&(0<r.length&&(t=e,n=r[r.length-1],t.left===n.left&&t.top===n.top&&t.bottom===n.bottom&&t.right===n.right)||r.push(e))},i=function(e,t){var n=ns(e.ownerDocument);if(t<e.data.length){if(qu(e.data[t]))return r;if(qu(e.data[t-1])&&(n.setStart(e,t),n.setEnd(e,t+1),!is(n)))return o(ss(us(n),!1)),r}0<t&&(n.setStart(e,t-1),n.setEnd(e,t),is(n)||o(ss(us(n),!1))),t<e.data.length&&(n.setStart(e,t),n.setEnd(e,t+1),is(n)||o(ss(us(n),!0)))};if(Qu(e.container()))return i(e.container(),e.offset()),r;if(Wu(e.container()))if(e.isAtEnd())n=ts(e.container(),e.offset()),Qu(n)&&i(n,n.data.length),Gu(n)&&!Zu(n)&&o(ss(us(n),!1));else{if(n=ts(e.container(),e.offset()),Qu(n)&&i(n,0),Gu(n)&&e.isAtEnd())return o(ss(us(n),!1)),r;t=ts(e.container(),e.offset()-1),Gu(t)&&!Zu(t)&&(!Xu(t)&&!Xu(n)&&Gu(n)||o(ss(us(t),!1))),Gu(n)&&o(ss(us(n),!0))}return r};function ls(t,n,e){var r=function(){return e=e||cs(ls(t,n))};return{container:x(t),offset:x(n),toRange:function(){var e;return(e=ns(t.ownerDocument)).setStart(t,n),e.setEnd(t,n),e},getClientRects:r,isVisible:function(){return 0<r().length},isAtStart:function(){return Qu(t),0===n},isAtEnd:function(){return Qu(t)?n>=t.data.length:n>=t.childNodes.length},isEqual:function(e){return e&&t===e.container()&&n===e.offset()},getNode:function(e){return ts(t,e?n-1:n)}}}(ja=ls=ls||{}).fromRangeStart=function(e){return ja(e.startContainer,e.startOffset)},ja.fromRangeEnd=function(e){return ja(e.endContainer,e.endOffset)},ja.after=function(e){return ja(e.parentNode,es(e)+1)},ja.before=function(e){return ja(e.parentNode,es(e))},ja.isAbove=function(e,t){return $u(Z(t.getClientRects()),ee(e.getClientRects()),Fu).getOr(!1)},ja.isBelow=function(e,t){return $u(ee(t.getClientRects()),Z(e.getClientRects()),Uu).getOr(!1)},ja.isAtStart=function(e){return!!e&&e.isAtStart()},ja.isAtEnd=function(e){return!!e&&e.isAtEnd()},ja.isTextPosition=function(e){return!!e&&Zt(e.container())},ja.isElementPosition=function(e){return!1===ja.isTextPosition(e)};var fs,ds,ms=ls,ps=Zt,gs=Yt,hs=ga.nodeIndex,vs=function(e){var t=e.parentNode;return gs(t)?vs(t):t},ys=function(e){return e?cr(e.childNodes,function(e,t){return gs(t)&&"BR"!==t.nodeName?e=e.concat(ys(t)):e.push(t),e},[]):[]},bs=function(t){return function(e){return t===e}},Cs=function(e){var t,r,n,o;return(ps(e)?"text()":e.nodeName.toLowerCase())+"["+(r=ys(vs(t=e)),n=lr(r,bs(t),t),r=r.slice(0,n+1),o=cr(r,function(e,t,n){return ps(t)&&ps(r[n-1])&&e++,e},0),r=ur(r,Wt([t.nodeName])),(n=lr(r,bs(t),t))-o)+"]"},ws=function(e,t){var n,r,o,i,a,u=[];return n=t.container(),r=t.offset(),ps(n)?o=function(e,t){for(;(e=e.previousSibling)&&ps(e);)t+=e.data.length;return t}(n,r):(r>=(i=n.childNodes).length?(o="after",r=i.length-1):o="before",n=i[r]),u.push(Cs(n)),a=function(e,t,n){var r=[];for(t=t.parentNode;t!==e&&(!n||!n(t));t=t.parentNode)r.push(t);return r}(e,n),a=ur(a,m(Yt)),(u=u.concat(ar(a,function(e){return Cs(e)}))).reverse().join("/")+","+o},xs=function(e,t){var n,r,o;return t?(t=(n=t.split(","))[0].split("/"),o=1<n.length?n[1]:"before",(r=cr(t,function(e,t){return(t=/([\w\-\(\)]+)\[([0-9]+)\]/.exec(t))?("text()"===t[1]&&(t[1]="#text"),n=e,r=t[1],o=parseInt(t[2],10),i=ys(n),i=ur(i,function(e,t){return!ps(e)||!ps(i[t-1])}),(i=ur(i,Wt([r])))[o]):null;var n,r,o,i},e))?ps(r)?function(e,t){for(var n,r=e,o=0;ps(r);){if(n=r.data.length,o<=t&&t<=o+n){e=r,t-=o;break}if(!ps(r.nextSibling)){e=r,t=n;break}o+=n,r=r.nextSibling}return ps(e)&&t>e.data.length&&(t=e.data.length),ms(e,t)}(r,parseInt(o,10)):(o="after"===o?hs(r)+1:hs(r),ms(r.parentNode,o)):null):null},Ss=function(e,t){Zt(t)&&0===t.data.length&&e.remove(t)},Ns=function(e,t,n){var r,o,i,a,u,s,c;nn(n)?(i=e,a=t,u=n,s=R.from(u.firstChild),c=R.from(u.lastChild),a.insertNode(u),s.each(function(e){return Ss(i,e.previousSibling)}),c.each(function(e){return Ss(i,e.nextSibling)})):(r=e,o=n,t.insertNode(o),Ss(r,o.previousSibling),Ss(r,o.nextSibling))},Es=an,ks=function(e,t,n,r,o){var i,a=r[o?"startContainer":"endContainer"],u=r[o?"startOffset":"endOffset"],s=[],c=0,l=e.getRoot();for(Zt(a)?s.push(n?function(e,t,n){var r,o;for(o=e(t.data.slice(0,n)).length,r=t.previousSibling;r&&Zt(r);r=r.previousSibling)o+=e(r.data).length;return o}(t,a,u):u):(u>=(i=a.childNodes).length&&i.length&&(c=1,u=Math.max(0,i.length-1)),s.push(e.nodeIndex(i[u],n)+c));a&&a!==l;a=a.parentNode)s.push(e.nodeIndex(a,n));return s},_s=function(e,t,n){var r=0;return hr.each(e.select(t),function(e){if("all"!==e.getAttribute("data-mce-bogus"))return e!==n&&void r++}),r},Rs=function(e,t){var n,r,o,i=t?"start":"end";n=e[i+"Container"],r=e[i+"Offset"],$t(n)&&"TR"===n.nodeName&&(n=(o=n.childNodes)[Math.min(t?r:r-1,o.length-1)])&&(r=t?0:n.childNodes.length,e["set"+(t?"Start":"End")](n,r))},Ts=function(e){return Rs(e,!0),Rs(e,!1),e},As=function(e,t){var n;if($t(e)&&(e=Hu(e,t),Es(e)))return e;if(gu(e)){if(Zt(e)&&mu(e)&&(e=e.parentNode),n=e.previousSibling,Es(n))return n;if(n=e.nextSibling,Es(n))return n}},Ds=function(e,t,n){var r=n.getNode(),o=r?r.nodeName:null,i=n.getRng();if(Es(r)||"IMG"===o)return{name:o,index:_s(n.dom,o,r)};var a,u,s,c,l,f,d,m=As((a=i).startContainer,a.startOffset)||As(a.endContainer,a.endOffset);return m?{name:o=m.tagName,index:_s(n.dom,o,m)}:(u=e,c=t,l=i,f=(s=n).dom,(d={}).start=ks(f,u,c,l,!0),s.isCollapsed()||(d.end=ks(f,u,c,l,!1)),d)},Os=function(e,t,n){var r={"data-mce-type":"bookmark",id:t,style:"overflow:hidden;line-height:0px"};return n?e.create("span",r,""):e.create("span",r)},Bs=function(e,t){var n=e.dom,r=e.getRng(),o=n.uniqueId(),i=e.isCollapsed(),a=e.getNode(),u=a.nodeName;if("IMG"===u)return{name:u,index:_s(n,u,a)};var s=Ts(r.cloneRange());if(!i){s.collapse(!1);var c=Os(n,o+"_end",t);Ns(n,s,c)}(r=Ts(r)).collapse(!0);var l=Os(n,o+"_start",t);return Ns(n,r,l),e.moveToBookmark({id:o,keep:!0}),{id:o}},Ps=function(e,t,n){return 2===t?Ds(lu,n,e):3===t?(o=(r=e).getRng(),{start:ws(r.dom.getRoot(),ms.fromRangeStart(o)),end:ws(r.dom.getRoot(),ms.fromRangeEnd(o))}):t?{rng:e.getRng()}:Bs(e,!1);var r,o},Ls=N(Ds,d,!0),Is="_mce_caret",Ms=function(e){return $t(e)&&e.id===Is},Fs=function(e,t){for(;t&&t!==e;){if(t.id===Is)return t;t=t.parentNode}return null},Us=ga.DOM,zs=function(e,t,n){var r=e.getParam(t,n);if(-1===r.indexOf("="))return r;var o=e.getParam(t,"","hash");return o.hasOwnProperty(e.id)?o[e.id]:n},js=function(e){return e.getParam("content_security_policy","")},Hs=function(e){if(e.getParam("force_p_newlines",!1))return"p";var t=e.getParam("forced_root_block","p");return!1===t?"":!0===t?"p":t},Vs=function(e){return e.getParam("forced_root_block_attrs",{})},qs=function(e){return e.getParam("automatic_uploads",!0,"boolean")},$s=function(e){return e.getParam("icons","","string")},Ws=function(e){return e.getParam("language","en","string")},Ks=function(e){return e.getParam("indent_use_margin",!1)},Xs=$t,Ys=Zt,Gs=function(e){var t=e.parentNode;t&&t.removeChild(e)},Js=function(e,t){0===t.length?Gs(e):e.nodeValue=t},Qs=function(e){var t=lu(e);return{count:e.length-t.length,text:t}},Zs=function(e,t){return rc(e),t},ec=function(e,t){var n,r,o=t.container(),i=(n=te(o.childNodes),(-1===(r=I(n,e))?R.none():R.some(r)).map(function(e){return e<t.offset()?ms(o,t.offset()-1):t}).getOr(t));return rc(e),i},tc=function(e,t){return Ys(e)&&t.container()===e?(r=t,o=Qs((n=e).data.substr(0,r.offset())),i=Qs(n.data.substr(r.offset())),0<(a=o.text+i.text).length?(Js(n,a),ms(n,r.offset()-o.count)):r):Zs(e,t);var n,r,o,i,a},nc=function(e,t){return ms.isTextPosition(t)?tc(e,t):(n=e,((r=t).container()===n.parentNode?ec:Zs)(n,r));var n,r},rc=function(e){if(Xs(e)&&gu(e)&&(hu(e)?e.removeAttribute("data-mce-caret"):Gs(e)),Ys(e)){var t=lu(function(e){try{return e.nodeValue}catch(t){return""}}(e));Js(e,t)}},oc=nt().browser,ic=an,ac=function(e,t,n){var r,o,i,a,u,s=Iu(t.getBoundingClientRect(),n);return i="BODY"===e.tagName?(r=e.ownerDocument.documentElement,o=e.scrollLeft||r.scrollLeft,e.scrollTop||r.scrollTop):(u=e.getBoundingClientRect(),o=e.scrollLeft-u.left,e.scrollTop-u.top),s.left+=o,s.right+=o,s.top+=i,s.bottom+=i,s.width=1,0<(a=t.offsetWidth-t.clientWidth)&&(n&&(a*=-1),s.left+=a,s.right+=a),s},uc=function(e,a,u,t){var n,s,c=xa(R.none()),r=Hs(e),l=0<r.length?r:"p",f=function(){!function(e){var t,n,r,o,i;for(t=Ua(Ne.fromDom(e),"*[contentEditable=false]"),o=0;o<t.length;o++)r=(n=t[o].dom()).previousSibling,wu(r)&&(1===(i=r.data).length?r.parentNode.removeChild(r):r.deleteData(i.length-1,1)),r=n.nextSibling,Cu(r)&&(1===(i=r.data).length?r.parentNode.removeChild(r):r.deleteData(0,1))}(a),s&&(rc(s),s=null),c.get().each(function(e){na(e.caret).remove(),c.set(R.none())}),n&&(Xn.clearInterval(n),n=null)},d=function(){n=Xn.setInterval(function(){t()?na("div.mce-visual-caret",a).toggleClass("mce-visual-caret-hidden"):na("div.mce-visual-caret",a).addClass("mce-visual-caret-hidden")},500)};return{show:function(t,e){var n,r,o;if(f(),$t(o=e)&&/^(TD|TH)$/i.test(o.tagName))return null;if(!u(e))return s=function(e,t){var n,r,o;if(r=e.ownerDocument.createTextNode(su),o=e.parentNode,t){if(n=e.previousSibling,du(n)){if(gu(n))return n;if(wu(n))return n.splitText(n.data.length-1)}o.insertBefore(r,e)}else{if(n=e.nextSibling,du(n)){if(gu(n))return n;if(Cu(n))return n.splitText(1),n}e.nextSibling?o.insertBefore(r,e.nextSibling):o.appendChild(r)}return r}(e,t),r=e.ownerDocument.createRange(),ic(s.nextSibling)?(r.setStart(s,0),r.setEnd(s,0)):(r.setStart(s,1),r.setEnd(s,1)),r;s=bu(l,e,t),n=ac(a,e,t),na(s).css("top",n.top);var i=na('<div class="mce-visual-caret" data-mce-bogus="all"></div>').css(n).appendTo(a)[0];return c.set(R.some({caret:i,element:e,before:t})),c.get().each(function(e){t&&na(e.caret).addClass("mce-visual-caret-before")}),d(),(r=e.ownerDocument.createRange()).setStart(s,0),r.setEnd(s,0),r},hide:f,getCss:function(){return".mce-visual-caret {position: absolute;background-color: black;background-color: currentcolor;}.mce-visual-caret-hidden {display: none;}*[data-mce-caret] {position: absolute;left: -1000px;right: auto;top: 0;margin: 0;padding: 0;}"},reposition:function(){c.get().each(function(e){var t=ac(a,e.element,e.before);na(e.caret).css(pe({},t))})},destroy:function(){return Xn.clearInterval(n)}}},sc=function(){return oc.isIE()||oc.isEdge()||oc.isFirefox()},cc=function(e){return ic(e)||Gt(e)&&sc()},lc=an,fc=Kt("display","block table table-cell table-caption list-item"),dc=gu,mc=mu,pc=$t,gc=Du,hc=function(e,t){for(var n;n=e(t);)if(!mc(n))return n;return null},vc=function(e,t,n,r,o){var i=new ra(e,r);if(t<0){if((lc(e)||mc(e))&&n(e=hc(i.prev,!0)))return e;for(;e=hc(i.prev,o);)if(n(e))return e}if(0<t){if((lc(e)||mc(e))&&n(e=hc(i.next,!0)))return e;for(;e=hc(i.next,o);)if(n(e))return e}return null},yc=function(e,t){for(;e&&e!==t;){if(fc(e))return e;e=e.parentNode}return null},bc=function(e,t,n){return yc(e.container(),n)===yc(t.container(),n)},Cc=function(e,t){var n,r;return t?(n=t.container(),r=t.offset(),pc(n)?n.childNodes[r+e]:null):null},wc=function(e,t){var n=t.ownerDocument.createRange();return e?(n.setStartBefore(t),n.setEndBefore(t)):(n.setStartAfter(t),n.setEndAfter(t)),n},xc=function(e,t,n){var r,o,i,a;for(o=e?"previousSibling":"nextSibling";n&&n!==t;){if(r=n[o],dc(r)&&(r=r[o]),lc(r)){if(a=n,yc(r,i=t)===yc(a,i))return r;break}if(gc(r))break;n=n.parentNode}return null},Sc=N(wc,!0),Nc=N(wc,!1),Ec=function(e,t,n){var r,o,i,a,u=N(xc,!0,t),s=N(xc,!1,t);if(o=n.startContainer,i=n.startOffset,mu(o)){if(pc(o)||(o=o.parentNode),"before"===(a=o.getAttribute("data-mce-caret"))&&(r=o.nextSibling,cc(r)))return Sc(r);if("after"===a&&(r=o.previousSibling,cc(r)))return Nc(r)}if(!n.collapsed)return n;if(Zt(o)){if(dc(o)){if(1===e){if(r=s(o))return Sc(r);if(r=u(o))return Nc(r)}if(-1===e){if(r=u(o))return Nc(r);if(r=s(o))return Sc(r)}return n}if(wu(o)&&i>=o.data.length-1)return 1===e&&(r=s(o))?Sc(r):n;if(Cu(o)&&i<=1)return-1===e&&(r=u(o))?Nc(r):n;if(i===o.data.length)return(r=s(o))?Sc(r):n;if(0===i)return(r=u(o))?Nc(r):n}return n},kc=function(e,t){return R.from(Cc(e?0:-1,t)).filter(lc)},_c=function(e,t,n){var r=Ec(e,t,n);return-1===e?ls.fromRangeStart(r):ls.fromRangeEnd(r)},Rc=function(e){return R.from(e.getNode()).map(Ne.fromDom)},Tc=function(e,t){for(;t=e(t);)if(t.isVisible())return t;return t},Ac=function(e,t){var n=bc(e,t);return!(n||!rn(e.getNode()))||n};(ds=fs=fs||{})[ds.Backwards=-1]="Backwards",ds[ds.Forwards=1]="Forwards";var Dc,Oc=an,Bc=Zt,Pc=$t,Lc=rn,Ic=Du,Mc=function(e){return Ru(e)||!!Ou(t=e)&&!0!==W(te(t.getElementsByTagName("*")),function(e,t){return e||Su(t)},!1);var t},Fc=Bu,Uc=function(e,t){return e.hasChildNodes()&&t<e.childNodes.length?e.childNodes[t]:null},zc=function(e,t){if(0<e){if(Ic(t.previousSibling)&&!Bc(t.previousSibling))return ms.before(t);if(Bc(t))return ms(t,0)}if(e<0){if(Ic(t.nextSibling)&&!Bc(t.nextSibling))return ms.after(t);if(Bc(t))return ms(t,t.data.length)}return!(e<0)||Lc(t)?ms.before(t):ms.after(t)},jc=function(e,t,n){var r,o,i,a,u;if(!Pc(n)||!t)return null;if(t.isEqual(ms.after(n))&&n.lastChild){if(u=ms.after(n.lastChild),e<0&&Ic(n.lastChild)&&Pc(n.lastChild))return Lc(n.lastChild)?ms.before(n.lastChild):u}else u=t;var s,c,l,f=u.container(),d=u.offset();if(Bc(f)){if(e<0&&0<d)return ms(f,--d);if(0<e&&d<f.length)return ms(f,++d);r=f}else{if(e<0&&0<d&&(o=Uc(f,d-1),Ic(o)))return!Mc(o)&&(i=vc(o,e,Fc,o))?Bc(i)?ms(i,i.data.length):ms.after(i):Bc(o)?ms(o,o.data.length):ms.before(o);if(0<e&&d<f.childNodes.length&&(o=Uc(f,d),Ic(o)))return Lc(o)?(s=n,(l=(c=o).nextSibling)&&Ic(l)?Bc(l)?ms(l,0):ms.before(l):jc(fs.Forwards,ms.after(c),s)):!Mc(o)&&(i=vc(o,e,Fc,o))?Bc(i)?ms(i,0):ms.before(i):Bc(o)?ms(o,0):ms.after(o);r=o||u.getNode()}return(0<e&&u.isAtEnd()||e<0&&u.isAtStart())&&(r=vc(r,e,x(!0),n,!0),Fc(r,n))?zc(e,r):(o=vc(r,e,Fc,n),!(a=fr(H(function(e,t){for(var n=[];e&&e!==t;)n.push(e),e=e.parentNode;return n}(f,n),Oc)))||o&&a.contains(o)?o?zc(e,o):null:u=0<e?ms.after(a):ms.before(a))},Hc=function(t){return{next:function(e){return jc(fs.Forwards,e,t)},prev:function(e){return jc(fs.Backwards,e,t)}}},Vc=function(e){return ms.isTextPosition(e)?0===e.offset():Du(e.getNode())},qc=function(e){if(ms.isTextPosition(e)){var t=e.container();return e.offset()===t.data.length}return Du(e.getNode(!0))},$c=function(e,t){return!ms.isTextPosition(e)&&!ms.isTextPosition(t)&&e.getNode()===t.getNode(!0)},Wc=function(e,t,n){return e?!$c(t,n)&&(r=t,!(!ms.isTextPosition(r)&&rn(r.getNode())))&&qc(t)&&Vc(n):!$c(n,t)&&Vc(t)&&qc(n);var r},Kc=function(e,t,n){var r=Hc(t);return R.from(e?r.next(n):r.prev(n))},Xc=function(t,n,r){return Kc(t,n,r).bind(function(e){return bc(r,e,n)&&Wc(t,r,e)?Kc(t,n,e):R.some(e)})},Yc=function(t,n,e,r){return Xc(t,n,e).bind(function(e){return r(e)?Yc(t,n,e,r):R.some(e)})},Gc=function(e,t){var n,r,o,i,a,u=e?t.firstChild:t.lastChild;return Zt(u)?R.some(ms(u,e?0:u.data.length)):u?Du(u)?R.some(e?ms.before(u):rn(a=u)?ms.before(a):ms.after(a)):(r=t,o=u,i=(n=e)?ms.before(o):ms.after(o),Kc(n,r,i)):R.none()},Jc=N(Kc,!0),Qc=N(Kc,!1),Zc=N(Gc,!0),el=N(Gc,!1),tl=function(e,t){return $t(t)&&e.isBlock(t)&&!t.innerHTML&&!rr.ie&&(t.innerHTML='<br data-mce-bogus="1" />'),t},nl=function(e,t){return el(e).fold(function(){return!1},function(e){return t.setStart(e.container(),e.offset()),t.setEnd(e.container(),e.offset()),!0})},rl=function(e,t,n){return!(!1!==t.hasChildNodes()||!Fs(e,t))&&(o=n,i=(r=t).ownerDocument.createTextNode(su),r.appendChild(i),o.setStart(i,0),o.setEnd(i,0),!0);var r,o,i},ol=function(e,t,n,r){var o,i,a,u,s=n[t?"start":"end"],c=e.getRoot();if(s){for(a=s[0],i=c,o=s.length-1;1<=o;o--){if(u=i.childNodes,rl(c,i,r))return!0;if(s[o]>u.length-1)return!!rl(c,i,r)||nl(i,r);i=u[s[o]]}3===i.nodeType&&(a=Math.min(s[0],i.nodeValue.length)),1===i.nodeType&&(a=Math.min(s[0],i.childNodes.length)),t?r.setStart(i,a):r.setEnd(i,a)}return!0},il=function(e){return Zt(e)&&0<e.data.length},al=function(e,t,n){var r,o,i,a,u,s,c=e.get(n.id+"_"+t),l=n.keep;if(c){if(r=c.parentNode,s=(u=(o="start"===t?l?c.hasChildNodes()?(r=c.firstChild,1):il(c.nextSibling)?(r=c.nextSibling,0):il(c.previousSibling)?(r=c.previousSibling,c.previousSibling.data.length):(r=c.parentNode,e.nodeIndex(c)+1):e.nodeIndex(c):l?c.hasChildNodes()?(r=c.firstChild,1):il(c.previousSibling)?(r=c.previousSibling,c.previousSibling.data.length):(r=c.parentNode,e.nodeIndex(c)):e.nodeIndex(c),r),o),!l){for(a=c.previousSibling,i=c.nextSibling,hr.each(hr.grep(c.childNodes),function(e){Zt(e)&&(e.nodeValue=e.nodeValue.replace(/\uFEFF/g,""))});c=e.get(n.id+"_"+t);)e.remove(c,!0);a&&i&&a.nodeType===i.nodeType&&Zt(a)&&!rr.opera&&(o=a.nodeValue.length,a.appendData(i.nodeValue),e.remove(i),s=(u=a,o))}return R.some(ms(u,s))}return R.none()},ul=function(e,t){var n,r,o,i,a,u,s,c,l,f,d,m,p,g,h=e.dom;if(t){if(g=t,hr.isArray(g.start))return m=t,p=(d=h).createRng(),ol(d,!0,m,p)&&ol(d,!1,m,p)?R.some(p):R.none();if("string"==typeof t.start)return R.some((c=t,l=(s=h).createRng(),f=xs(s.getRoot(),c.start),l.setStart(f.container(),f.offset()),f=xs(s.getRoot(),c.end),l.setEnd(f.container(),f.offset()),l));if(t.hasOwnProperty("id"))return a=al(o=h,"start",i=t),u=al(o,"end",i),$u(a,u.or(a),function(e,t){var n=o.createRng();return n.setStart(tl(o,e.container()),e.offset()),n.setEnd(tl(o,t.container()),t.offset()),n});if(t.hasOwnProperty("name"))return n=h,r=t,R.from(n.select(r.name)[r.index]).map(function(e){var t=n.createRng();return t.selectNode(e),t});if(t.hasOwnProperty("rng"))return R.some(t.rng)}return R.none()},sl=function(e,t,n){return Ps(e,t,n)},cl=function(t,e){ul(t,e).each(function(e){t.setRng(e)})},ll=function(e){return $t(e)&&"SPAN"===e.tagName&&"bookmark"===e.getAttribute("data-mce-type")},fl=(Dc=oo,function(e){return Dc===e}),dl=function(e){return""!==e&&-1!==" \f\n\r\t\x0B".indexOf(e)},ml=function(e){return!dl(e)&&!fl(e)},pl=function(e){return!!e.nodeType},gl=function(e,t,n){var r,o,i,a,u=n.startOffset,s=n.startContainer;if((n.startContainer!==n.endContainer||!(a=n.startContainer.childNodes[n.startOffset])||!/^(IMG)$/.test(a.nodeName))&&1===s.nodeType)for(u<(i=s.childNodes).length?(s=i[u],r=new ra(s,e.getParent(s,e.isBlock))):(s=i[i.length-1],(r=new ra(s,e.getParent(s,e.isBlock))).next(!0)),o=r.current();o;o=r.next())if(3===o.nodeType&&!bl(o))return n.setStart(o,0),void t.setRng(n)},hl=function(e,t,n){if(e){var r=t?"nextSibling":"previousSibling";for(e=n?e:e[r];e;e=e[r])if(1===e.nodeType||!bl(e))return e}},vl=function(e,t){return pl(t)&&(t=t.nodeName),!!e.schema.getTextBlockElements()[t.toLowerCase()]},yl=function(e,t,n){return e.schema.isValidChild(t,n)},bl=function(e){return e&&Zt(e)&&/^([\t \r\n]+|)$/.test(e.nodeValue)},Cl=function(e,n){return"string"!=typeof e?e=e(n):n&&(e=e.replace(/%(\w+)/g,function(e,t){return n[t]||e})),e},wl=function(e,t){return e=""+((e=e||"").nodeName||e),t=""+((t=t||"").nodeName||t),e.toLowerCase()===t.toLowerCase()},xl=function(e,t,n){return"color"!==n&&"backgroundColor"!==n||(t=e.toHex(t)),"fontWeight"===n&&700===t&&(t="bold"),"fontFamily"===n&&(t=t.replace(/[\'\"]/g,"").replace(/,\s+/g,",")),""+t},Sl=function(e,t,n){return xl(e,e.getStyle(t,n),n)},Nl=function(t,e){var n;return t.getParent(e,function(e){return(n=t.getStyle(e,"text-decoration"))&&"none"!==n}),n},El=function(e,t,n){return e.getParents(t,n,e.getRoot())},kl=function(t,e,n){var r=["inline","block","selector","attributes","styles","classes"],a=function(e){return le(e,function(e,t){return F(r,function(e){return e===t})})};return F(t.formatter.get(e),function(e){var i=a(e);return F(t.formatter.get(n),function(e){var t,n,r,o=a(e);return t=i,n=o,void 0===r&&(r=l),u(r).eq(t,n)})})},_l=ll,Rl=El,Tl=bl,Al=vl,Dl=function(e,t){for(var n=t;n;){if($t(n)&&e.getContentEditable(n))return"false"===e.getContentEditable(n)?n:t;n=n.parentNode}return t},Ol=function(e,t,n,r){for(var o=t.data,i=n;e?0<=i:i<o.length;e?i--:i++)if(r(o.charAt(i)))return e?i+1:i;return-1},Bl=function(e,t,n){return Ol(e,t,n,function(e){return fl(e)||dl(e)})},Pl=function(e,t,n){return Ol(e,t,n,ml)},Ll=function(i,e,t,n,a,r){var u,s=i.getParent(t,i.isBlock)||e,o=function(e,t,n){var r=uu(i),o=a?r.backwards:r.forwards;return R.from(o(e,t,function(e,t){return _l(e.parentNode)?-1:n(a,u=e,t)},s))};return o(t,n,Bl).bind(function(e){return r?o(e.container,e.offset+(a?-1:0),Pl):R.some(e)}).orThunk(function(){return u?R.some({container:u,offset:a?0:u.length}):R.none()})},Il=function(e,t,n,r,o){Zt(r)&&0===r.nodeValue.length&&r[o]&&(r=r[o]);for(var i=Rl(e,r),a=0;a<i.length;a++)for(var u=0;u<t.length;u++){var s=t[u];if(!("collapsed"in s&&s.collapsed!==n.collapsed)&&e.is(i[a],s.selector))return i[a]}return r},Ml=function(t,e,n,r){var o,i=t.dom,a=i.getRoot();if(e[0].wrapper||(o=i.getParent(n,e[0].block,a)),!o){var u=i.getParent(n,"LI,TD,TH");o=i.getParent(Zt(n)?n.parentNode:n,function(e){return e!==a&&Al(t,e)},u)}if(o&&e[0].wrapper&&(o=Rl(i,o,"ul,ol").reverse()[0]||o),!o)for(o=n;o[r]&&!i.isBlock(o[r])&&(o=o[r],!wl(o,"br")););return o||n},Fl=function(e,t,n,r,o,i,a){var u,s,c,l,f,d;if(u=s=a?n:o,l=a?"previousSibling":"nextSibling",f=e.getRoot(),Zt(u)&&!Tl(u)&&(a?0<r:i<u.nodeValue.length))return u;for(;;){if(!t[0].block_expand&&e.isBlock(s))return s;for(c=s[l];c;c=c[l])if(!_l(c)&&!Tl(c)&&("BR"!==(d=c).nodeName||!d.getAttribute("data-mce-bogus")||d.nextSibling))return s;if(s===f||s.parentNode===f){u=s;break}s=s.parentNode}return u},Ul=function(e,t,n,r){void 0===r&&(r=!1);var o=t.startContainer,i=t.startOffset,a=t.endContainer,u=t.endOffset,s=e.dom;$t(o)&&o.hasChildNodes()&&(o=Hu(o,i),Zt(o)&&(i=0)),$t(a)&&a.hasChildNodes()&&(a=Hu(a,t.collapsed?u:u-1),Zt(a)&&(u=a.nodeValue.length)),o=Dl(s,o),a=Dl(s,a),(_l(o.parentNode)||_l(o))&&(o=_l(o)?o:o.parentNode,o=t.collapsed?o.previousSibling||o:o.nextSibling||o,Zt(o)&&(i=t.collapsed?o.length:0)),(_l(a.parentNode)||_l(a))&&(a=_l(a)?a:a.parentNode,a=t.collapsed?a.nextSibling||a:a.previousSibling||a,Zt(a)&&(u=t.collapsed?0:a.length)),t.collapsed&&(Ll(s,e.getBody(),o,i,!0,r).each(function(e){var t=e.container,n=e.offset;o=t,i=n}),Ll(s,e.getBody(),a,u,!1,r).each(function(e){var t=e.container,n=e.offset;a=t,u=n}));return(n[0].inline||n[0].block_expand)&&(n[0].inline&&Zt(o)&&0!==i||(o=Fl(s,n,o,i,a,u,!0)),n[0].inline&&Zt(a)&&u!==a.nodeValue.length||(a=Fl(s,n,o,i,a,u,!1))),n[0].selector&&!1!==n[0].expand&&!n[0].inline&&(o=Il(s,n,t,o,"previousSibling"),a=Il(s,n,t,a,"nextSibling")),(n[0].block||n[0].selector)&&(o=Ml(e,n,o,"previousSibling"),a=Ml(e,n,a,"nextSibling"),n[0].block&&(s.isBlock(o)||(o=Fl(s,n,o,i,a,u,!0)),s.isBlock(a)||(a=Fl(s,n,o,i,a,u,!1)))),$t(o)&&(i=s.nodeIndex(o),o=o.parentNode),$t(a)&&(u=s.nodeIndex(a)+1,a=a.parentNode),{startContainer:o,startOffset:i,endContainer:a,endOffset:u}},zl=function(e,t){var n=e.childNodes;return t>=n.length?t=n.length-1:t<0&&(t=0),n[t]||e},jl=function(e,t,u){var n=t.startContainer,r=t.startOffset,o=t.endContainer,i=t.endOffset,s=function(e){var t;return 3===(t=e[0]).nodeType&&t===n&&r>=t.nodeValue.length&&e.splice(0,1),t=e[e.length-1],0===i&&0<e.length&&t===o&&3===t.nodeType&&e.splice(e.length-1,1),e},c=function(e,t,n){for(var r=[];e&&e!==n;e=e[t])r.push(e);return r},a=function(e,t){do{if(e.parentNode===t)return e;e=e.parentNode}while(e)},l=function(e,t,n){for(var r=n?"nextSibling":"previousSibling",o=e,i=o.parentNode;o&&o!==t;o=i){i=o.parentNode;var a=c(o===e?o:o[r],r);a.length&&(n||a.reverse(),u(s(a)))}};if(1===n.nodeType&&n.hasChildNodes()&&(n=zl(n,r)),1===o.nodeType&&o.hasChildNodes()&&(o=zl(o,i-1)),n===o)return u(s([n]));for(var f=e.findCommonAncestor(n,o),d=n;d;d=d.parentNode){if(d===o)return l(n,f,!0);if(d===f)break}for(d=o;d;d=d.parentNode){if(d===n)return l(o,f);if(d===f)break}var m=a(n,f)||n,p=a(o,f)||o;l(n,m,!0);var g=c(m===n?m:m.nextSibling,"nextSibling",p===o?p.nextSibling:p);g.length&&u(s(g)),l(o,p)},Hl=function(e){var t=[];if(e)for(var n=0;n<e.rangeCount;n++)t.push(e.getRangeAt(n));return t},Vl=function(e){return H(Y(e,function(e){var t=ju(e);return t?[Ne.fromDom(t)]:[]}),Dr)},ql=function(e,t){var n=Ua(t,"td[data-mce-selected],th[data-mce-selected]");return 0<n.length?n:Vl(e)},$l=function(e){return ql(Hl(e.selection.getSel()),Ne.fromDom(e.getBody()))},Wl=function(t){return yt(t).fold(x([t]),function(e){return[t].concat(Wl(e))})},Kl=function(t){return bt(t).fold(x([t]),function(e){return"br"===Rt(e)?dt(e).map(function(e){return[t].concat(Kl(e))}).getOr([]):[t].concat(Kl(e))})},Xl=function(o,e){return $u((a=(i=e).startContainer,u=i.startOffset,Zt(a)?0===u?R.some(Ne.fromDom(a)):R.none():R.from(a.childNodes[u]).map(Ne.fromDom)),(n=(t=e).endContainer,r=t.endOffset,Zt(n)?r===n.data.length?R.some(Ne.fromDom(n)):R.none():R.from(n.childNodes[r-1]).map(Ne.fromDom)),function(e,t){var n=K(Wl(o),N(at,e)),r=K(Kl(o),N(at,t));return n.isSome()&&r.isSome()}).getOr(!1);var t,n,r,i,a,u},Yl=function(e,t,n,r){var o=n,i=new ra(n,o),a=e.schema.getNonEmptyElements();do{if(3===n.nodeType&&0!==hr.trim(n.nodeValue).length)return void(r?t.setStart(n,0):t.setEnd(n,n.nodeValue.length));if(a[n.nodeName]&&!/^(TD|TH)$/.test(n.nodeName))return void(r?t.setStartBefore(n):"BR"===n.nodeName?t.setEndBefore(n):t.setEndAfter(n))}while(n=r?i.next():i.prev());"BODY"===o.nodeName&&(r?t.setStart(o,0):t.setEnd(o,o.childNodes.length))},Gl=function(e){var t=e.selection.getSel();return t&&0<t.rangeCount},Jl=function(r,o){var e=$l(r);0<e.length?z(e,function(e){var t=e.dom(),n=r.dom.createRng();n.setStartBefore(t),n.setEndAfter(t),o(n,!0)}):o(r.selection.getRng(),!1)},Ql=function(e,t,n){var r=Bs(e,t);n(r),e.moveToBookmark(r)};var Zl=function gE(n,r){var t=function(e){return n(e)?R.from(e.dom().nodeValue):R.none()};return{get:function(e){if(!n(e))throw new Error("Can only get "+r+" value of a "+r+" node");return t(e).getOr("")},getOption:t,set:function(e,t){if(!n(e))throw new Error("Can only set raw "+r+" value of a "+r+" node");e.dom().nodeValue=t}}}(Ot,"text"),ef=function(e){return Zl.get(e)},tf=function(r,o,i,a){return ft(o).fold(function(){return"skipping"},function(e){return"br"===a||Ot(n=o)&&ef(n)===ro?"valid":Dt(t=o)&&Ma(t,Ka())?"existing":Ms(o)?"caret":yl(r,i,a)&&yl(r,Rt(e),i)?"valid":"invalid-child";var t,n})},nf=function(e,t,n,r){var o=t.uid,i=void 0===o?tu("mce-annotation"):o,a=function p(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(e);o<r.length;o++)t.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(e,r[o])&&(n[r[o]]=e[r[o]])}return n}(t,["uid"]),u=Ne.fromTag("span",e);La(u,Ka()),cn(u,""+Ya(),i),cn(u,""+Xa(),n);var s,c=r(i,a),l=c.attributes,f=void 0===l?{}:l,d=c.classes,m=void 0===d?[]:d;return ln(u,f),s=u,z(m,function(e){La(s,e)}),u},rf=function(i,e,t,n,r){var a=[],u=nf(i.getDoc(),r,t,n),s=xa(R.none()),c=function(){s.set(R.none())},l=function(e){z(e,o)},o=function(e){var t,n;switch(tf(i,e,"span",Rt(e))){case"invalid-child":c();var r=ht(e);l(r),c();break;case"valid":var o=s.get().getOrThunk(function(){var e=ou(u);return a.push(e),s.set(R.some(e)),e});Ct(t=e,n=o),St(n,t)}};return jl(i.dom,e,function(e){var t;c(),t=U(e,Ne.fromDom),l(t)}),a},of=function(u,s,c,l){u.undoManager.transact(function(){var e,t,n,r=u.selection,o=r.getRng(),i=0<$l(u).length;if(o.collapsed&&!i&&(n=Ul(e=u,t=o,[{inline:!0}]),t.setStart(n.startContainer,n.startOffset),t.setEnd(n.endContainer,n.endOffset),e.selection.setRng(t)),r.getRng().collapsed&&!i){var a=nf(u.getDoc(),l,s,c.decorate);nu(a,oo),r.getRng().insertNode(a.dom()),r.select(a.dom())}else Ql(r,!1,function(){Jl(u,function(e){rf(u,e,s,c.decorate,l)})})})},af=function(u){var n,r=(n={},{register:function(e,t){n[e]={name:e,settings:t}},lookup:function(e){return n.hasOwnProperty(e)?R.from(n[e]).map(function(e){return e.settings}):R.none()}});Za(u,r);var o=Qa(u);return{register:function(e,t){r.register(e,t)},annotate:function(t,n){r.lookup(t).each(function(e){of(u,t,e,n)})},annotationChanged:function(e,t){o.addListener(e,t)},remove:function(e){Ga(u,R.some(e)).each(function(e){var t=e.elements;z(t,_t)})},getAll:function(e){var t,n,r,o,i,a=(t=u,n=e,r=Ne.fromDom(t.getBody()),o=Ua(r,"["+Xa()+'="'+n+'"]'),i={},z(o,function(e){var t=fn(e,Ya()),n=i.hasOwnProperty(t)?i[t]:[];i[t]=n.concat([e])}),i);return ie(a,function(e){return U(e,function(e){return e.dom()})})}}},uf=/^[ \t\r\n]*$/,sf={"#text":3,"#comment":8,"#cdata":4,"#pi":7,"#doctype":10,"#document-fragment":11},cf=function(e,t,n){var r=n?"lastChild":"firstChild",o=n?"prev":"next";if(e[r])return e[r];if(e!==t){var i=e[o];if(i)return i;for(var a=e.parent;a&&a!==t;a=a.parent)if(i=a[o])return i}},lf=function(e){if(!uf.test(e.value))return!1;var t=e.parent;return!t||"span"===t.name&&!t.attr("style")||!/^[ ]+$/.test(e.value)},ff=function(e){var t="a"===e.name&&!e.attr("href")&&e.attr("id");return e.attr("name")||e.attr("id")&&!e.firstChild||e.attr("data-mce-bookmark")||t},df=(mf.create=function(e,t){var n=new mf(e,sf[e]||1);return t&&oe(t,function(e,t){n.attr(t,e)}),n},mf.prototype.replace=function(e){return e.parent&&e.remove(),this.insert(e,this),this.remove(),this},mf.prototype.attr=function(e,t){var n,r=this;if("string"!=typeof e)return e!==undefined&&null!==e&&oe(e,function(e,t){r.attr(t,e)}),r;if(n=r.attributes){if(t===undefined)return n.map[e];if(null===t){if(e in n.map){delete n.map[e];for(var o=n.length;o--;)if(n[o].name===e)return n.splice(o,1),r}return r}if(e in n.map){for(o=n.length;o--;)if(n[o].name===e){n[o].value=t;break}}else n.push({name:e,value:t});return n.map[e]=t,r}},mf.prototype.clone=function(){var e,t=new mf(this.name,this.type);if(e=this.attributes){var n=[];n.map={};for(var r=0,o=e.length;r<o;r++){var i=e[r];"id"!==i.name&&(n[n.length]={name:i.name,value:i.value},n.map[i.name]=i.value)}t.attributes=n}return t.value=this.value,t.shortEnded=this.shortEnded,t},mf.prototype.wrap=function(e){return this.parent.insert(e,this),e.append(this),this},mf.prototype.unwrap=function(){for(var e=this.firstChild;e;){var t=e.next;this.insert(e,this,!0),e=t}this.remove()},mf.prototype.remove=function(){var e=this.parent,t=this.next,n=this.prev;return e&&(e.firstChild===this?(e.firstChild=t)&&(t.prev=null):n.next=t,e.lastChild===this?(e.lastChild=n)&&(n.next=null):t.prev=n,this.parent=this.next=this.prev=null),this},mf.prototype.append=function(e){e.parent&&e.remove();var t=this.lastChild;return t?((t.next=e).prev=t,this.lastChild=e):this.lastChild=this.firstChild=e,e.parent=this,e},mf.prototype.insert=function(e,t,n){e.parent&&e.remove();var r=t.parent||this;return n?(t===r.firstChild?r.firstChild=e:t.prev.next=e,e.prev=t.prev,(e.next=t).prev=e):(t===r.lastChild?r.lastChild=e:t.next.prev=e,e.next=t.next,(e.prev=t).next=e),e.parent=r,e},mf.prototype.getAll=function(e){for(var t=[],n=this.firstChild;n;n=cf(n,this))n.name===e&&t.push(n);return t},mf.prototype.empty=function(){if(this.firstChild){for(var e=[],t=this.firstChild;t;t=cf(t,this))e.push(t);for(var n=e.length;n--;)(t=e[n]).parent=t.firstChild=t.lastChild=t.next=t.prev=null}return this.firstChild=this.lastChild=null,this},mf.prototype.isEmpty=function(e,t,n){void 0===t&&(t={});var r=this.firstChild;if(ff(this))return!1;if(r)do{if(1===r.type){if(r.attr("data-mce-bogus"))continue;if(e[r.name])return!1;if(ff(r))return!1}if(8===r.type)return!1;if(3===r.type&&!lf(r))return!1;if(3===r.type&&r.parent&&t[r.parent.name]&&uf.test(r.value))return!1;if(n&&n(r))return!1}while(r=cf(r,this));return!0},mf.prototype.walk=function(e){return cf(this,null,e)},mf);function mf(e,t){this.name=e,1===(this.type=t)&&(this.attributes=[],this.attributes.map={})}var pf=hr.makeMap,gf=function(e){var u,s,c,l,f,d=[];return u=(e=e||{}).indent,s=pf(e.indent_before||""),c=pf(e.indent_after||""),l=$r.getEncodeFunc(e.entity_encoding||"raw",e.entities),f="html"===e.element_format,{start:function(e,t,n){var r,o,i,a;if(u&&s[e]&&0<d.length&&0<(a=d[d.length-1]).length&&"\n"!==a&&d.push("\n"),d.push("<",e),t)for(r=0,o=t.length;r<o;r++)i=t[r],d.push(" ",i.name,'="',l(i.value,!0),'"');d[d.length]=!n||f?">":" />",n&&u&&c[e]&&0<d.length&&0<(a=d[d.length-1]).length&&"\n"!==a&&d.push("\n")},end:function(e){var t;d.push("</",e,">"),u&&c[e]&&0<d.length&&0<(t=d[d.length-1]).length&&"\n"!==t&&d.push("\n")},text:function(e,t){0<e.length&&(d[d.length]=t?e:l(e))},cdata:function(e){d.push("<![CDATA[",e,"]]>")},comment:function(e){d.push("\x3c!--",e,"--\x3e")},pi:function(e,t){t?d.push("<?",e," ",l(t),"?>"):d.push("<?",e,"?>"),u&&d.push("\n")},doctype:function(e){d.push("<!DOCTYPE",e,">",u?"\n":"")},reset:function(){d.length=0},getContent:function(){return d.join("").replace(/\n$/,"")}}},hf=function(t,p){void 0===p&&(p=no());var g=gf(t);(t=t||{}).validate=!("validate"in t)||t.validate;return{serialize:function(e){var f,d;d=t.validate,f={3:function(e){g.text(e.value,e.raw)},8:function(e){g.comment(e.value)},7:function(e){g.pi(e.name,e.value)},10:function(e){g.doctype(e.value)},4:function(e){g.cdata(e.value)},11:function(e){if(e=e.firstChild)for(;m(e),e=e.next;);}},g.reset();var m=function(e){var t,n,r,o,i,a,u,s,c,l=f[e.type];if(l)l(e);else{if(t=e.name,n=e.shortEnded,r=e.attributes,d&&r&&1<r.length&&((a=[]).map={},c=p.getElementRule(e.name))){for(u=0,s=c.attributesOrder.length;u<s;u++)(o=c.attributesOrder[u])in r.map&&(i=r.map[o],a.map[o]=i,a.push({name:o,value:i}));for(u=0,s=r.length;u<s;u++)(o=r[u].name)in a.map||(i=r.map[o],a.map[o]=i,a.push({name:o,value:i}));r=a}if(g.start(e.name,r,n),!n){if(e=e.firstChild)for(;m(e),e=e.next;);g.end(t)}}};return 1!==e.type||t.inner?f[11](e):m(e),g.getContent()}}},vf=function(e,t){return e.replace(new RegExp(t.prefix+"_[0-9]+","g"),function(e){return de(t.uris,e).getOr(e)})},yf=function(e,t,n){var r,o,i,a,u=1;for(a=e.getShortEndedElements(),(i=/<([!?\/])?([A-Za-z0-9\-_\:\.]+)((?:\s+[^"\'>]+(?:(?:"[^"]*")|(?:\'[^\']*\')|[^>]*))*|\/|\s+)>/g).lastIndex=r=n;o=i.exec(t);){if(r=i.lastIndex,"/"===o[1])u--;else if(!o[1]){if(o[2]in a)continue;u++}if(0===u)break}return r},bf=function(e,t){var n=e.exec(t);if(n){var r=n[1],o=n[2];return"string"==typeof r&&"data-mce-bogus"===r.toLowerCase()?o:null}return null};function Cf(W,K){void 0===K&&(K=no());var e=function(){};!1!==(W=W||{}).fix_self_closing&&(W.fix_self_closing=!0);var X=W.comment?W.comment:e,Y=W.cdata?W.cdata:e,G=W.text?W.text:e,J=W.start?W.start:e,Q=W.end?W.end:e,Z=W.pi?W.pi:e,ee=W.doctype?W.doctype:e,n=function(m,e){void 0===e&&(e="html");var t,n,r,p,o,i,a,g,u,s,h,c,v,l,f,d,y,b,C,w,x,S,N,E,k,_,R,T,A,D=m.html,O=0,B=[],P=0,L=$r.decode,I=hr.makeMap("src,href,data,background,formaction,poster,xlink:href"),M=/((java|vb)script|mhtml):/i,F="html"===e?0:1,U=function(e){var t,n;for(t=B.length;t--&&B[t].name!==e;);if(0<=t){for(n=B.length-1;t<=n;n--)(e=B[n]).valid&&Q(e.name);B.length=t}},z=function(e,t){return G(vf(e,m),t)},j=function(e){""!==e&&(">"===e.charAt(0)&&(e=" "+e),W.allow_conditional_comments||"[if"!==e.substr(0,3).toLowerCase()||(e=" "+e),X(vf(e,m)))},H=function(e,t){var n=e||"",r=!Ve(n,"--"),o=function(e,t,n){void 0===n&&(n=0);var r=e.toLowerCase();if(-1!==r.indexOf("[if ",n)&&(u=n,/^\s*\[if [\w\W]+\]>.*<!\[endif\](--!?)?>/.test(r.substr(u)))){var o=r.indexOf("[endif]",n);return r.indexOf(">",o)}if(t){var i=r.indexOf(">",n);return-1!==i?i:r.length}var a=/--!?>/;a.lastIndex=n;var u,s=a.exec(e);return s?s.index+s[0].length:r.length}(D,r,t);return e=D.substr(t,o-t),j(r?n+e:e),o+1},V=function(e,t,n,r,o){var i,a,u,s,c,l;if(t=t.toLowerCase(),u=t in h?t:L(n||r||o||""),n=de(m.uris,u).getOr(u),v&&!g&&!1==(0===(s=t).indexOf("data-")||0===s.indexOf("aria-"))){if(!(i=b[t])&&C){for(a=C.length;a--&&!(i=C[a]).pattern.test(t););-1===a&&(i=null)}if(!i)return;if(i.validValues&&!(n in i.validValues))return}if(I[t]&&!W.allow_script_urls){var f=n.replace(/[\s\u0000-\u001F]+/g,"");try{f=decodeURIComponent(f)}catch(d){f=unescape(f)}if(M.test(f))return;if(l=f,!(c=W).allow_html_data_urls&&(/^data:image\//i.test(l)?!1===c.allow_svg_data_urls&&/^data:image\/svg\+xml/i.test(l):/^data:/i.test(l)))return}g&&(t in I||0===t.indexOf("on"))||(p.map[t]=n,p.push({name:t,value:n}))};for(k=new RegExp("<(?:(?:!--([\\w\\W]*?)--!?>)|(?:!\\[CDATA\\[([\\w\\W]*?)\\]\\]>)|(?:![Dd][Oo][Cc][Tt][Yy][Pp][Ee]([\\w\\W]*?)>)|(?:!(--)?)|(?:\\?([^\\s\\/<>]+) ?([\\w\\W]*?)[?/]>)|(?:\\/([A-Za-z][A-Za-z0-9\\-_\\:\\.]*)>)|(?:([A-Za-z][A-Za-z0-9\\-_\\:\\.]*)((?:\\s+[^\"'>]+(?:(?:\"[^\"]*\")|(?:'[^']*')|[^>]*))*|\\/|\\s+)>))","g"),_=/([\w:\-]+)(?:\s*=\s*(?:(?:\"((?:[^\"])*)\")|(?:\'((?:[^\'])*)\')|([^>\s]+)))?/g,s=K.getShortEndedElements(),E=W.self_closing_elements||K.getSelfClosingElements(),h=K.getBoolAttrs(),v=W.validate,u=W.remove_internals,A=W.fix_self_closing,R=K.getSpecialElements(),N=D+">";t=k.exec(N);){var q=t[0];if(O<t.index&&z(L(D.substr(O,t.index-O))),n=t[7])":"===(n=n.toLowerCase()).charAt(0)&&(n=n.substr(1)),U(n);else if(n=t[8]){if(t.index+q.length>D.length){z(L(D.substr(t.index))),O=t.index+q.length;continue}":"===(n=n.toLowerCase()).charAt(0)&&(n=n.substr(1)),c=n in s,A&&E[n]&&0<B.length&&B[B.length-1].name===n&&U(n);var $=bf(_,t[9]);if(null!==$){if("all"===$){O=yf(K,D,k.lastIndex),k.lastIndex=O;continue}f=!1}if(!v||(l=K.getElementRule(n))){if(f=!0,v&&(b=l.attributes,C=l.attributePatterns),(y=t[9])?((g=-1!==y.indexOf("data-mce-type"))&&u&&(f=!1),(p=[]).map={},y.replace(_,V)):(p=[]).map={},v&&!g){if(w=l.attributesRequired,x=l.attributesDefault,S=l.attributesForced,l.removeEmptyAttrs&&!p.length&&(f=!1),S)for(o=S.length;o--;)a=(d=S[o]).name,"{$uid}"===(T=d.value)&&(T="mce_"+P++),p.map[a]=T,p.push({name:a,value:T});if(x)for(o=x.length;o--;)(a=(d=x[o]).name)in p.map||("{$uid}"===(T=d.value)&&(T="mce_"+P++),p.map[a]=T,p.push({name:a,value:T}));if(w){for(o=w.length;o--&&!(w[o]in p.map););-1===o&&(f=!1)}if(d=p.map["data-mce-bogus"]){if("all"===d){O=yf(K,D,k.lastIndex),k.lastIndex=O;continue}f=!1}}f&&J(n,p,c)}else f=!1;if(r=R[n]){r.lastIndex=O=t.index+q.length,O=(t=r.exec(D))?(f&&(i=D.substr(O,t.index-O)),t.index+t[0].length):(i=D.substr(O),D.length),f&&(0<i.length&&z(i,!0),Q(n)),k.lastIndex=O;continue}c||(y&&y.indexOf("/")===y.length-1?f&&Q(n):B.push({name:n,valid:f}))}else if(n=t[1])j(n);else if(n=t[2]){if(!(1==F||W.preserve_cdata||0<B.length&&K.isValidChild(B[B.length-1].name,"#cdata"))){O=H("",t.index+2),k.lastIndex=O;continue}Y(n)}else if(n=t[3])ee(n);else{if((n=t[4])||"<!"===q){O=H(n,t.index+q.length),k.lastIndex=O;continue}if(n=t[5]){if(1!=F){O=H("?",t.index+2),k.lastIndex=O;continue}Z(n,t[6])}}O=t.index+q.length}for(O<D.length&&z(L(D.substr(O))),o=B.length-1;0<=o;o--)(n=B[o]).valid&&Q(n.name)};return{parse:function(e,t){void 0===t&&(t="html"),n(function(e){for(var t,n=/data:[^;]+;base64,([a-z0-9\+\/=]+)/gi,r=[],o={},i=tu("img"),a=0,u=0;t=n.exec(e);){var s=t[0],c=i+"_"+u++;o[c]=s,a<t.index&&r.push(e.substr(a,t.index-a)),r.push(c),a=t.index+s.length}return 0===a?{prefix:i,uris:o,html:e}:(a<e.length&&r.push(e.substr(a)),{prefix:i,uris:o,html:r.join("")})}(e),t)}}}(Cf=Cf||{}).findEndTag=yf;var wf,xf,Sf,Nf,Ef,kf=Cf,_f=function(e,t){var n,r,o,i,a,u,s,c,l=t,f=/<(\w+) [^>]*data-mce-bogus="all"[^>]*>/g,d=e.schema;for(u=e.getTempAttrs(),s=l,c=new RegExp(["\\s?("+u.join("|")+')="[^"]+"'].join("|"),"gi"),l=s.replace(c,""),a=d.getShortEndedElements();i=f.exec(l);)r=f.lastIndex,o=i[0].length,n=a[i[1]]?r:kf.findEndTag(d,l,r),l=l.substring(0,r-o)+l.substring(n),f.lastIndex=r-o;return lu(l)},Rf=_f,Tf=function(e,t,n,r){var o,i,a,u,s;if(t.format=n,t.get=!0,t.getInner=!0,t.no_events||e.fire("BeforeGetContent",t),"raw"===t.format)o=hr.trim(Rf(e.serializer,r.innerHTML));else if("text"===t.format)o=lu(r.innerText||r.textContent);else{if("tree"===t.format)return e.serializer.serialize(r,t);a=(i=e).serializer.serialize(r,t),u=Hs(i),s=new RegExp("^(<"+u+"[^>]*>( | |\\s|\xa0|<br \\/>|)<\\/"+u+">[\r\n]*|<br \\/>[\r\n]*)$"),o=a.replace(s,"")}return"text"===t.format||Or(Ne.fromDom(r))?t.content=o:t.content=hr.trim(o),t.no_events||e.fire("GetContent",t),t.content},Af=hr.each,Df=function(o){this.compare=function(e,t){if(e.nodeName!==t.nodeName)return!1;var n=function(n){var r={};return Af(o.getAttribs(n),function(e){var t=e.nodeName.toLowerCase();0!==t.indexOf("_")&&"style"!==t&&0!==t.indexOf("data-")&&(r[t]=o.getAttrib(n,t))}),r},r=function(e,t){var n,r;for(r in e)if(e.hasOwnProperty(r)){if(void 0===(n=t[r]))return!1;if(e[r]!==n)return!1;delete t[r]}for(r in t)if(t.hasOwnProperty(r))return!1;return!0};return!!r(n(e),n(t))&&(!!r(o.parseStyle(o.getAttrib(e,"style")),o.parseStyle(o.getAttrib(t,"style")))&&(!ll(e)&&!ll(t)))}},Of=function(n,r,o){return R.from(o.container()).filter(Zt).exists(function(e){var t=n?0:-1;return r(e.data.charAt(o.offset()+t))})},Bf=N(Of,!0,dl),Pf=N(Of,!1,dl),Lf=function(e){var t=e.container();return Zt(t)&&0===t.data.length},If=function(t,n){return function(e){return R.from(Cc(t?0:-1,e)).filter(n).isSome()}},Mf=function(e){return"IMG"===e.nodeName&&"block"===mn(Ne.fromDom(e),"display")},Ff=function(e){return an(e)&&!($t(t=e)&&"all"===t.getAttribute("data-mce-bogus"));var t},Uf=If(!0,Mf),zf=If(!1,Mf),jf=If(!0,Gt),Hf=If(!1,Gt),Vf=If(!0,Ff),qf=If(!1,Ff),$f=function(e,t){var n,r,o,i=Ne.fromDom(e),a=Ne.fromDom(t);return n=a,r="pre,code",o=N(at,i),qa(n,r,o).isSome()},Wf=function(e,t){return Du(t)&&!1===(r=e,Zt(o=t)&&/^[ \t\r\n]*$/.test(o.data)&&!1===$f(r,o))||$t(n=t)&&"A"===n.nodeName&&n.hasAttribute("name")||Kf(t);var n,r,o},Kf=Xt("data-mce-bookmark"),Xf=Xt("data-mce-bogus"),Yf=(wf="data-mce-bogus",xf="all",function(e){return $t(e)&&e.getAttribute(wf)===xf}),Gf=function(e,t){return void 0===t&&(t=!0),function(e,t){var n,r=0;if(Wf(e,e))return!1;if(!(n=e.firstChild))return!0;var o=new ra(n,e);do{if(t){if(Yf(n)){n=o.next(!0);continue}if(Xf(n)){n=o.next();continue}}if(rn(n))r++,n=o.next();else{if(Wf(e,n))return!1;n=o.next()}}while(n);return r<=1}(e.dom(),t)},Jf=function(e){var t=Ua(e,"br"),n=H(function(e){for(var t=[],n=e.dom();n;)t.push(Ne.fromDom(n)),n=n.lastChild;return t}(e).slice(-1),Er);t.length===n.length&&z(n,kt)},Qf=function(e){Et(e),St(e,Ne.fromHtml('<br data-mce-bogus="1">'))},Zf=function(n){bt(n).each(function(t){dt(t).each(function(e){Sr(n)&&Er(t)&&Sr(e)&&kt(t)})})},ed=function(e,t,n){return st(t,e)?function(e,t){for(var n=D(t)?t:g,r=e.dom(),o=[];null!==r.parentNode&&r.parentNode!==undefined;){var i=r.parentNode,a=Ne.fromDom(i);if(o.push(a),!0===n(a))break;r=i}return o}(e,function(e){return n(e)||at(e,t)}).slice(0,-1):[]},td=function(e,t){return ed(e,t,x(!1))},nd=function(e,t){return[e].concat(td(e,t))},rd=function(e,t,n){if(0!==n){var r,o,i,a=e.data.slice(t,t+n),u=t+n>=e.data.length,s=0===t;e.replaceData(t,n,(o=s,i=u,W(r=a,function(e,t){return dl(t)||fl(t)?e.previousCharIsSpace||""===e.str&&o||e.str.length===r.length-1&&i?{previousCharIsSpace:!1,str:e.str+oo}:{previousCharIsSpace:!0,str:e.str+" "}:{previousCharIsSpace:!1,str:e.str+t}},{previousCharIsSpace:!1,str:""}).str))}},od=function(e,t){var n=e.data.slice(t),r=n.length-We(n).length;return rd(e,t,r)},id=function(e,t){return r=e,o=(n=t).container(),i=n.offset(),!1===ms.isTextPosition(n)&&o===r.parentNode&&i>ms.before(r).offset()?ms(t.container(),t.offset()-1):t;var n,r,o,i},ad=function(e){return Du(e.previousSibling)?R.some((t=e.previousSibling,Zt(t)?ms(t,t.data.length):ms.after(t))):e.previousSibling?el(e.previousSibling):R.none();var t},ud=function(e){return Du(e.nextSibling)?R.some((t=e.nextSibling,Zt(t)?ms(t,0):ms.before(t))):e.nextSibling?Zc(e.nextSibling):R.none();var t},sd=function(r,o){return ad(o).orThunk(function(){return ud(o)}).orThunk(function(){return e=r,t=o,n=ms.before(t.previousSibling?t.previousSibling:t.parentNode),Qc(e,n).fold(function(){return Jc(e,ms.after(t))},R.some);var e,t,n})},cd=function(n,r){return ud(r).orThunk(function(){return ad(r)}).orThunk(function(){return t=r,Jc(e=n,ms.after(t)).fold(function(){return Qc(e,ms.before(t))},R.some);var e,t})},ld=function(e,t,n){return(e?cd:sd)(t,n).map(N(id,n))},fd=function(t,n,e){e.fold(function(){t.focus()},function(e){t.selection.setRng(e.toRange(),n)})},dd=function(e,t){return t&&e.schema.getBlockElements().hasOwnProperty(Rt(t))},md=function(e){if(Gf(e)){var t=Ne.fromHtml('<br data-mce-bogus="1">');return Et(e),St(e,t),R.some(ms.before(t.dom()))}return R.none()},pd=function(e,t,l){var n,r,o,i,a=dt(e).filter(Ot),u=mt(e).filter(Ot);return kt(e),r=u,o=t,i=function(e,t,n){var r,o,i,a,u=e.dom(),s=t.dom(),c=u.data.length;return o=s,i=l,a=Ke((r=u).data).length,r.appendData(o.data),kt(Ne.fromDom(o)),i&&od(r,a),n.container()===s?ms(u,c):n},((n=a).isSome()&&r.isSome()&&o.isSome()?R.some(i(n.getOrDie(),r.getOrDie(),o.getOrDie())):R.none()).orThunk(function(){return l&&(a.each(function(e){return t=e.dom(),n=e.dom().length,r=t.data.slice(0,n),o=r.length-Ke(r).length,rd(t,n-o,o);var t,n,r,o}),u.each(function(e){return od(e.dom(),0)})),t})},gd=function(t,n,e,r){void 0===r&&(r=!0);var o,i,a=ld(n,t.getBody(),e.dom()),u=Ha(e,N(dd,t),(o=t.getBody(),function(e){return e.dom()===o})),s=pd(e,a,(i=e,me(t.schema.getTextInlineElements(),Rt(i))));t.dom.isEmpty(t.getBody())?(t.setContent(""),t.selection.setCursorLocation()):u.bind(md).fold(function(){r&&fd(t,n,s)},function(e){r&&fd(t,n,R.some(e))})},hd=function(a){if(!k(a))throw new Error("cases must be an array");if(0===a.length)throw new Error("there must be at least one case");var u=[],n={};return z(a,function(e,r){var t=ne(e);if(1!==t.length)throw new Error("one and only one name per case");var o=t[0],i=e[o];if(n[o]!==undefined)throw new Error("duplicate key detected:"+o);if("cata"===o)throw new Error("cannot have a case named cata (sorry)");if(!k(i))throw new Error("case arguments must be an array");u.push(o),n[o]=function(){var e=arguments.length;if(e!==i.length)throw new Error("Wrong number of arguments to case "+o+". Expected "+i.length+" ("+i+"), got "+e);for(var n=new Array(e),t=0;t<n.length;t++)n[t]=arguments[t];return{fold:function(){if(arguments.length!==a.length)throw new Error("Wrong number of arguments to fold. Expected "+a.length+", got "+arguments.length);return arguments[r].apply(null,n)},match:function(e){var t=ne(e);if(u.length!==t.length)throw new Error("Wrong number of arguments to match. Expected: "+u.join(",")+"\nActual: "+t.join(","));if(!G(u,function(e){return M(t,e)}))throw new Error("Not all branches were specified when using match. Specified: "+t.join(", ")+"\nRequired: "+u.join(", "));return e[o].apply(null,n)},log:function(e){V.console.log(e,{constructors:u,constructor:o,params:n})}}}}),n},vd=function(e,t){return{start:e,end:t}},yd=hd([{removeTable:["element"]},{emptyCells:["cells"]},{deleteCellSelection:["rng","cell"]}]),bd=function(e,t){return Wa(Ne.fromDom(e),"td,th",t)},Cd=function(e,t){return qa(e,"table",t)},wd=function(e){return!at(e.start,e.end)},xd=function(e,t){return Cd(e.start,t).bind(function(r){return Cd(e.end,t).bind(function(e){return t=at(r,e),n=r,t?R.some(n):R.none();var t,n})})},Sd=function(e){return Ua(e,"td,th")},Nd=function(r,e){var t=bd(e.startContainer,r),n=bd(e.endContainer,r);return e.collapsed?R.none():$u(t,n,vd).fold(function(){return t.fold(function(){return n.bind(function(t){return Cd(t,r).bind(function(e){return Z(Sd(e)).map(function(e){return vd(e,t)})})})},function(t){return Cd(t,r).bind(function(e){return ee(Sd(e)).map(function(e){return vd(t,e)})})})},function(e){return Ed(r,e)?R.none():(n=r,Cd((t=e).start,n).bind(function(e){return ee(Sd(e)).map(function(e){return vd(t.start,e)})}));var t,n})},Ed=function(e,t){return xd(t,e).isSome()},kd=function(e,t,n){return e.filter(function(e){return wd(e)&&Ed(n,e)}).orThunk(function(){return Nd(n,t)}).bind(function(e){return xd(t=e,n).map(function(e){return{rng:t,table:e,cells:Sd(e)}});var t})},_d=function(e,t){return X(e,function(e){return at(e,t)})},Rd=function(e,r,o){return e.filter(function(e){return n=o,!wd(t=e)&&xd(t,n).exists(function(e){var t=e.dom().rows;return 1===t.length&&1===t[0].cells.length})&&Xl(e.start,r);var t,n}).map(function(e){return e.start})},Td=function(n){return $u(_d((r=n).cells,r.rng.start),_d(r.cells,r.rng.end),function(e,t){return r.cells.slice(e,t+1)}).map(function(e){var t=n.cells;return e.length===t.length?yd.removeTable(n.table):yd.emptyCells(e)});var r},Ad=function(e,t){var n,r,o,i,a,u=(n=e,function(e){return at(n,e)}),s=(o=u,i=bd((r=t).startContainer,o),a=bd(r.endContainer,o),$u(i,a,vd));return Rd(s,t,u).map(function(e){return yd.deleteCellSelection(t,e)}).orThunk(function(){return kd(s,t,u).bind(Td)})},Dd=function(e){var t;return(8===Tt(t=e)||"#comment"===Rt(t)?dt:bt)(e).bind(Dd).orThunk(function(){return R.some(e)})},Od=function(e,t){return z(t,Qf),e.selection.setCursorLocation(t[0].dom(),0),!0},Bd=function(e,t,n){t.deleteContents();var r,o=Dd(n).getOr(n),i=Ne.fromDom(e.dom.getParent(o.dom(),e.dom.isBlock));if(Gf(i)&&(Qf(i),e.selection.setCursorLocation(i.dom(),0)),!at(n,i)){var a=ft(i).is(n)?[]:ft(r=i).map(ht).map(function(e){return H(e,function(e){return!at(r,e)})}).getOr([]);z(a.concat(ht(n)),function(e){at(e,i)||st(e,i)||kt(e)})}return!0},Pd=function(e,t){return gd(e,!1,t),!0},Ld=function(n,e,r,t){return Md(e,t).fold(function(){return t=n,Ad(e,r).map(function(e){return e.fold(N(Pd,t),N(Od,t),N(Bd,t))});var t},function(e){return Fd(n,e)}).getOr(!1)},Id=function(e,t){return K(nd(t,e),Dr)},Md=function(e,t){return K(nd(t,e),function(e){return"caption"===Rt(e)})},Fd=function(e,t){return Qf(t),e.selection.setCursorLocation(t.dom(),0),R.some(!0)},Ud=function(u,s,c,l,f){return Xc(c,u.getBody(),f).bind(function(e){return o=c,i=f,a=e,Zc((r=l).dom()).bind(function(t){return el(r.dom()).map(function(e){return o?i.isEqual(t)&&a.isEqual(e):i.isEqual(e)&&a.isEqual(t)})}).getOr(!0)?Fd(u,l):(t=l,n=e,Md(s,Ne.fromDom(n.getNode())).map(function(e){return!1===at(e,t)}));var t,n,r,o,i,a}).or(R.some(!0))},zd=function(o,i,a,e){var u=ms.fromRangeStart(o.selection.getRng());return Id(a,e).bind(function(e){return Gf(e)?Fd(o,e):(t=a,n=e,r=u,Xc(i,o.getBody(),r).bind(function(e){return Id(t,Ne.fromDom(e.getNode())).map(function(e){return!1===at(e,n)})}));var t,n,r}).getOr(!1)},jd=function(e,t){return(e?jf:Hf)(t)},Hd=function(a,u,r){var s=Ne.fromDom(a.getBody());return Md(s,r).fold(function(){return zd(a,u,s,r)||(e=a,t=u,n=ms.fromRangeStart(e.selection.getRng()),jd(t,n)||Kc(t,e.getBody(),n).map(function(e){return jd(t,e)}).getOr(!1));var e,t,n},function(e){return t=a,n=u,r=s,o=e,i=ms.fromRangeStart(t.selection.getRng()),(Gf(o)?Fd(t,o):Ud(t,r,n,o,i)).getOr(!1);var t,n,r,o,i})},Vd=function(e,t){var n,r,o,i,a,u=Ne.fromDom(e.selection.getStart(!0)),s=$l(e);return e.selection.isCollapsed()&&0===s.length?Hd(e,t,u):(n=e,r=u,o=Ne.fromDom(n.getBody()),i=n.selection.getRng(),0!==(a=$l(n)).length?Od(n,a):Ld(n,o,i,r))},qd=function(a){var u=ms.fromRangeStart(a),s=ms.fromRangeEnd(a),c=a.commonAncestorContainer;return Kc(!1,c,s).map(function(e){return!bc(u,s,c)&&bc(u,e,c)?(t=u.container(),n=u.offset(),r=e.container(),o=e.offset(),(i=V.document.createRange()).setStart(t,n),i.setEnd(r,o),i):a;var t,n,r,o,i}).getOr(a)},$d=function(e){return e.collapsed?e:qd(e)},Wd=function(e,t){var n,r;return e.getBlockElements()[t.name]&&((r=t).firstChild&&r.firstChild===r.lastChild)&&("br"===(n=t.firstChild).name||n.value===oo)},Kd=function(e,t){var n,r,o,i=t.firstChild,a=t.lastChild;return i&&"meta"===i.name&&(i=i.next),a&&"mce_marker"===a.attr("id")&&(a=a.prev),r=a,o=(n=e).getNonEmptyElements(),r&&(r.isEmpty(o)||Wd(n,r))&&(a=a.prev),!(!i||i!==a)&&("ul"===i.name||"ol"===i.name)},Xd=function(e){return e&&e.firstChild&&e.firstChild===e.lastChild&&((t=e.firstChild).data===oo||rn(t));var t},Yd=function(e){return 0<e.length&&(!(t=e[e.length-1]).firstChild||Xd(t))?e.slice(0,-1):e;var t},Gd=function(e,t){var n=e.getParent(t,e.isBlock);return n&&"LI"===n.nodeName?n:null},Jd=function(e,t){var n=ms.after(e),r=Hc(t).prev(n);return r?r.toRange():null},Qd=function(t,e,n){var r,o,i,a,u=t.parentNode;return hr.each(e,function(e){u.insertBefore(e,t)}),r=t,o=n,i=ms.before(r),(a=Hc(o).next(i))?a.toRange():null},Zd=function(e,o,i,t){var n,r,a,u,s,c,l,f,d,m,p,g,h,v,y,b,C,w,x,S,N=(n=o,r=t,c=e.serialize(r),l=n.createFragment(c),u=(a=l).firstChild,s=a.lastChild,u&&"META"===u.nodeName&&u.parentNode.removeChild(u),s&&"mce_marker"===s.id&&s.parentNode.removeChild(s),a),E=Gd(o,i.startContainer),k=Yd((f=N.firstChild,hr.grep(f.childNodes,function(e){return"LI"===e.nodeName}))),_=o.getRoot(),R=function(e){var t=ms.fromRangeStart(i),n=Hc(o.getRoot()),r=1===e?n.prev(t):n.next(t);return!r||Gd(o,r.getNode())!==E};return R(1)?Qd(E,k,_):R(2)?(d=E,m=k,p=_,o.insertAfter(m.reverse(),d),Jd(m[0],p)):(h=k,v=_,y=g=E,C=(b=i).cloneRange(),w=b.cloneRange(),C.setStartBefore(y),w.setEndAfter(y),x=[C.cloneContents(),w.cloneContents()],(S=g.parentNode).insertBefore(x[0],g),hr.each(h,function(e){S.insertBefore(e,g)}),S.insertBefore(x[1],g),S.removeChild(g),Jd(h[h.length-1],v))},em=Wt(["td","th"]),tm=function(e,t){var n,r,o=e.selection.getRng(),i=o.startContainer,a=o.startOffset;o.collapsed&&(r=a,Zt(n=i)&&n.nodeValue[r-1]===oo)&&Zt(i)&&(i.insertData(a-1," "),i.deleteData(a,1),o.setStart(i,a),o.setEnd(i,a),e.selection.setRng(o)),e.selection.setContent(t)},nm=function(e){var t=e.dom,n=$d(e.selection.getRng());e.selection.setRng(n);var r,o,i,a=t.getParent(n.startContainer,em);r=t,o=n,null!==(i=a)&&i===r.getParent(o.endContainer,em)&&Xl(Ne.fromDom(i),o)?Bd(e,n,Ne.fromDom(a)):e.getDoc().execCommand("Delete",!1,null)},rm=function(e,t,n){var r,o,i,a,u,s,c,l,f,d,m,p=e.selection,g=e.dom;if(/^ | $/.test(t)&&(t=function(e,t){var n,r;n=e.startContainer,r=e.startOffset;var o=function(e){return n[e]&&3===n[e].nodeType};return 3===n.nodeType&&(0<r?t=t.replace(/^ /," "):o("previousSibling")||(t=t.replace(/^ /," ")),r<n.length?t=t.replace(/ (<br>|)$/," "):o("nextSibling")||(t=t.replace(/( | )(<br>|)$/," "))),t}(p.getRng(),t)),r=e.parser,m=n.merge,o=hf({validate:e.settings.validate},e.schema),d='<span id="mce_marker" data-mce-type="bookmark">​</span>',s={content:t,format:"html",selection:!0,paste:n.paste},(s=e.fire("BeforeSetContent",s)).isDefaultPrevented())e.fire("SetContent",{content:s.content,format:"html",selection:!0,paste:n.paste});else{-1===(t=s.content).indexOf("{$caret}")&&(t+="{$caret}"),t=t.replace(/\{\$caret\}/,d);var h,v,y,b,C,w,x=(l=p.getRng()).startContainer||(l.parentElement?l.parentElement():null),S=e.getBody();x===S&&p.isCollapsed()&&g.isBlock(S.firstChild)&&(h=e,(v=S.firstChild)&&!h.schema.getShortEndedElements()[v.nodeName])&&g.isEmpty(S.firstChild)&&((l=g.createRng()).setStart(S.firstChild,0),l.setEnd(S.firstChild,0),p.setRng(l)),p.isCollapsed()||(nm(e),y=e.selection.getRng(),b=t,C=y.startContainer,w=y.startOffset,3===C.nodeType&&y.collapsed&&(C.data[w]===oo?(C.deleteData(w,1),/[\u00a0| ]$/.test(b)||(b+=" ")):C.data[w-1]===oo&&(C.deleteData(w-1,1),/[\u00a0| ]$/.test(b)||(b=" "+b))),t=b);var N,E,k,_={context:(i=p.getNode()).nodeName.toLowerCase(),data:n.data,insert:!0};if(u=r.parse(t,_),!0===n.paste&&Kd(e.schema,u)&&Gd(g,i))return l=Zd(o,g,e.selection.getRng(),u),e.selection.setRng(l),void e.fire("SetContent",s);if(!function(e){for(var t=e;t=t.walk();)1===t.type&&t.attr("data-mce-fragment","1")}(u),"mce_marker"===(f=u.lastChild).attr("id"))for(f=(c=f).prev;f;f=f.walk(!0))if(3===f.type||!g.isBlock(f.name)){e.schema.isValidChild(f.parent.name,"span")&&f.parent.insert(c,f,"br"===f.name);break}if(e._selectionOverrides.showBlockCaretContainer(i),_.invalid){for(tm(e,d),i=p.getNode(),a=e.getBody(),9===i.nodeType?i=f=a:f=i;f!==a;)f=(i=f).parentNode;t=i===a?a.innerHTML:g.getOuterHTML(i),t=o.serialize(r.parse(t.replace(/<span (id="mce_marker"|id=mce_marker).+?<\/span>/i,function(){return o.serialize(u)}))),i===a?g.setHTML(a,t):g.setOuterHTML(i,t)}else!function(e,t,n){if("all"===n.getAttribute("data-mce-bogus"))n.parentNode.insertBefore(e.dom.createFragment(t),n);else{var r=n.firstChild,o=n.lastChild;!r||r===o&&"BR"===r.nodeName?e.dom.setHTML(n,t):tm(e,t)}}(e,t=o.serialize(u),i);!function(e,t){var n=e.schema.getTextInlineElements(),r=e.dom;if(t){var o=e.getBody(),i=new Df(r);hr.each(r.select("*[data-mce-fragment]"),function(e){for(var t=e.parentNode;t&&t!==o;t=t.parentNode)n[e.nodeName.toLowerCase()]&&i.compare(t,e)&&r.remove(e,!0)})}}(e,m),function(n,e){var t,r,o,i,a,u=n.dom,s=n.selection;if(e){if(n.selection.scrollIntoView(e),t=function(e){for(var t=n.getBody();e&&e!==t;e=e.parentNode)if("false"===n.dom.getContentEditable(e))return e;return null}(e))return u.remove(e),s.select(t);var c=u.createRng();(i=e.previousSibling)&&3===i.nodeType?(c.setStart(i,i.nodeValue.length),rr.ie||(a=e.nextSibling)&&3===a.nodeType&&(i.appendData(a.data),a.parentNode.removeChild(a))):(c.setStartBefore(e),c.setEndBefore(e));r=u.getParent(e,u.isBlock),u.remove(e),r&&u.isEmpty(r)&&(n.$(r).empty(),c.setStart(r,0),c.setEnd(r,0),em(r)||r.getAttribute("data-mce-fragment")||!(o=function(e){var t=ms.fromRangeStart(e);if(t=Hc(n.getBody()).next(t))return t.toRange()}(c))?u.add(r,u.create("br",{"data-mce-bogus":"1"})):(c=o,u.remove(r))),s.setRng(c)}}(e,g.get("mce_marker")),N=e.getBody(),hr.each(N.getElementsByTagName("*"),function(e){e.removeAttribute("data-mce-fragment")}),E=e.dom,k=e.selection.getStart(),R.from(E.getParent(k,"td,th")).map(Ne.fromDom).each(Zf),e.fire("SetContent",s),e.addVisual()}},om=function(e){var t=ct(e).dom();return e.dom()===t.activeElement},im=function(e){var t=e!==undefined?e.dom():V.document;return R.from(t.activeElement).map(Ne.fromDom)},am=function(e,t,n,r){return{start:x(e),soffset:x(t),finish:x(n),foffset:x(r)}},um=hd([{before:["element"]},{on:["element","offset"]},{after:["element"]}]),sm=(um.before,um.on,um.after,function(e){return e.fold(d,d,d)}),cm=hd([{domRange:["rng"]},{relative:["startSitu","finishSitu"]},{exact:["start","soffset","finish","foffset"]}]),lm={domRange:cm.domRange,relative:cm.relative,exact:cm.exact,exactFromRange:function(e){return cm.exact(e.start(),e.soffset(),e.finish(),e.foffset())},getWin:function(e){var t=e.match({domRange:function(e){return Ne.fromDom(e.startContainer)},relative:function(e,t){return sm(e)},exact:function(e,t,n,r){return e}});return lt(t)},range:am},fm=nt().browser,dm=function(e,t){var n=Ot(t)?ef(t).length:ht(t).length+1;return n<e?n:e<0?0:e},mm=function(e){return lm.range(e.start(),dm(e.soffset(),e.start()),e.finish(),dm(e.foffset(),e.finish()))},pm=function(e,t){return!qt(t.dom())&&(st(e,t)||at(e,t))},gm=function(t){return function(e){return pm(t,e.start())&&pm(t,e.finish())}},hm=function(e){return!0===e.inline||fm.isIE()},vm=function(e){return lm.range(Ne.fromDom(e.startContainer),e.startOffset,Ne.fromDom(e.endContainer),e.endOffset)},ym=function(e){var t,n,r=lt(e);return t=r.dom(),((n=t.getSelection())&&0!==n.rangeCount?R.from(n.getRangeAt(0)):R.none()).map(vm).filter(gm(e))},bm=function(e){var t=V.document.createRange();try{return t.setStart(e.start().dom(),e.soffset()),t.setEnd(e.finish().dom(),e.foffset()),R.some(t)}catch(n){return R.none()}},Cm=function(e){var t=hm(e)?ym(Ne.fromDom(e.getBody())):R.none();e.bookmark=t.isSome()?t:e.bookmark},wm=function(r){return(r.bookmark?r.bookmark:R.none()).bind(function(e){return t=Ne.fromDom(r.getBody()),n=e,R.from(n).filter(gm(t)).map(mm);var t,n}).bind(bm)},xm={isEditorUIElement:function(e){var t=e.className.toString();return-1!==t.indexOf("tox-")||-1!==t.indexOf("mce-")}},Sm=function(n,e){var t,r;nt().browser.isIE()?(r=n).on("focusout",function(){Cm(r)}):(t=e,n.on("mouseup touchend",function(e){t.throttle()})),n.on("keyup NodeChange",function(e){var t;"nodechange"===(t=e).type&&t.selectionChange||Cm(n)})},Nm=function(r){var o=Ta(function(){Cm(r)},0);r.on("init",function(){var e,t,n;r.inline&&(e=r,t=o,n=function(){t.throttle()},ga.DOM.bind(V.document,"mouseup",n),e.on("remove",function(){ga.DOM.unbind(V.document,"mouseup",n)})),Sm(r,o)}),r.on("remove",function(){o.cancel()})},Em=ga.DOM,km=function(t,e){var n=t?t.settings.custom_ui_selector:"";return null!==Em.getParent(e,function(e){return xm.isEditorUIElement(e)||!!n&&t.dom.is(e,n)})},_m=function(r,e){var t=e.editor;Nm(t),t.on("focusin",function(){var e=r.focusedEditor;e!==this&&(e&&e.fire("blur",{focusedEditor:this}),r.setActive(this),(r.focusedEditor=this).fire("focus",{blurredEditor:e}),this.focus(!0))}),t.on("focusout",function(){var t=this;Xn.setEditorTimeout(t,function(){var e=r.focusedEditor;km(t,function(){try{return V.document.activeElement}catch(e){return V.document.body}}())||e!==t||(t.fire("blur",{focusedEditor:null}),r.focusedEditor=null)})}),Sf||(Sf=function(e){var t,n=r.activeEditor;t=e.target,n&&t.ownerDocument===V.document&&(t===V.document.body||km(n,t)||r.focusedEditor!==n||(n.fire("blur",{focusedEditor:null}),r.focusedEditor=null))},Em.bind(V.document,"focusin",Sf))},Rm=function(e,t){e.focusedEditor===t.editor&&(e.focusedEditor=null),e.activeEditor||(Em.unbind(V.document,"focusin",Sf),Sf=null)},Tm=function(t,e){return((n=e).collapsed?R.from(Hu(n.startContainer,n.startOffset)).map(Ne.fromDom):R.none()).bind(function(e){return Ar(e)?R.some(e):!1===st(t,e)?R.some(t):R.none()});var n},Am=function(t,e){Tm(Ne.fromDom(t.getBody()),e).bind(function(e){return Zc(e.dom())}).fold(function(){t.selection.normalize()},function(e){return t.selection.setRng(e.toRange())})},Dm=function(e){if(e.setActive)try{e.setActive()}catch(t){e.focus()}else e.focus()},Om=function(e){return om(e)||im(ct(t=e)).filter(function(e){return t.dom().contains(e.dom())}).isSome();var t},Bm=function(r){return im().filter(function(e){return t=e.dom(),!((n=t.classList)!==undefined&&(n.contains("tox-edit-area")||n.contains("tox-edit-area__iframe")||n.contains("mce-content-body")))&&km(r,e.dom());var t,n}).isSome()},Pm=function(e){return e.inline?(n=e.getBody())&&Om(Ne.fromDom(n)):(t=e).iframeElement&&om(Ne.fromDom(t.iframeElement));var t,n},Lm=function(t){var e=t.selection,n=t.getBody(),r=e.getRng();t.quirks.refreshContentEditable(),t.bookmark!==undefined&&!1===Pm(t)&&wm(t).each(function(e){t.selection.setRng(e),r=e});var o,i,a=(o=t,i=e.getNode(),o.dom.getParent(i,function(e){return"true"===o.dom.getContentEditable(e)}));if(t.$.contains(n,a))return Dm(a),Am(t,r),void Im(t);t.inline||(rr.opera||Dm(n),t.getWin().focus()),(rr.gecko||t.inline)&&(Dm(n),Am(t,r)),Im(t)},Im=function(e){return e.editorManager.setActive(e)},Mm=function(e,t){t(e),e.firstChild&&Mm(e.firstChild,t),e.next&&Mm(e.next,t)},Fm=function(e,t,n){var r=function(e,n,t){var r={},o={},i=[];for(var a in t.firstChild&&Mm(t.firstChild,function(t){z(e,function(e){e.name===t.name&&(r[e.name]?r[e.name].nodes.push(t):r[e.name]={filter:e,nodes:[t]})}),z(n,function(e){"string"==typeof t.attr(e.name)&&(o[e.name]?o[e.name].nodes.push(t):o[e.name]={filter:e,nodes:[t]})})}),r)r.hasOwnProperty(a)&&i.push(r[a]);for(var u in o)o.hasOwnProperty(u)&&i.push(o[u]);return i}(e,t,n);z(r,function(t){z(t.filter.callbacks,function(e){e(t.nodes,t.filter.name,{})})})},Um=function(e){return e instanceof df},zm=function(e,t){var r;e.dom.setHTML(e.getBody(),t),Pm(r=e)&&Zc(r.getBody()).each(function(e){var t=e.getNode(),n=Gt(t)?Zc(t).getOr(e):e;r.selection.setRng(n.toRange())})},jm=function(u,s,c){return c.format=c.format?c.format:"html",c.set=!0,c.content=Um(s)?"":s,Um(s)||c.no_events||(u.fire("BeforeSetContent",c),s=c.content),R.from(u.getBody()).fold(x(s),function(e){return Um(s)?function(e,t,n,r){Fm(e.parser.getNodeFilters(),e.parser.getAttributeFilters(),n);var o=hf({validate:e.validate},e.schema).serialize(n);return r.content=Or(Ne.fromDom(t))?o:hr.trim(o),zm(e,r.content),r.no_events||e.fire("SetContent",r),n}(u,e,s,c):(t=u,n=e,o=c,0===(r=s).length||/^\s+$/.test(r)?(a='<br data-mce-bogus="1">',"TABLE"===n.nodeName?r="<tr><td>"+a+"</td></tr>":/^(UL|OL)$/.test(n.nodeName)&&(r="<li>"+a+"</li>"),r=(i=Hs(t))&&t.schema.isValidChild(n.nodeName.toLowerCase(),i.toLowerCase())?(r=a,t.dom.createHTML(i,t.settings.forced_root_block_attrs,r)):r||'<br data-mce-bogus="1">',zm(t,r),t.fire("SetContent",o)):("raw"!==o.format&&(r=hf({validate:t.validate},t.schema).serialize(t.parser.parse(r,{isRootContent:!0,insert:!0}))),o.content=Or(Ne.fromDom(n))?r:hr.trim(r),zm(t,o.content),o.no_events||t.fire("SetContent",o)),o.content);var t,n,r,o,i,a})},Hm=function(e,t){return e.splitText(t)},Vm=function(e){var t=e.startContainer,n=e.startOffset,r=e.endContainer,o=e.endOffset;return t===r&&Zt(t)?0<n&&n<t.nodeValue.length&&(t=(r=Hm(t,n)).previousSibling,n<o?(t=r=Hm(r,o-=n).previousSibling,o=r.nodeValue.length,n=0):o=0):(Zt(t)&&0<n&&n<t.nodeValue.length&&(t=Hm(t,n),n=0),Zt(r)&&0<o&&o<r.nodeValue.length&&(o=(r=Hm(r,o).previousSibling).nodeValue.length)),{startContainer:t,startOffset:n,endContainer:r,endOffset:o}},qm=wl,$m=function(e,t,n){var r=e.formatter.get(n);if(r)for(var o=0;o<r.length;o++)if(!1===r[o].inherit&&e.dom.is(t,r[o].selector))return!0;return!1},Wm=function(t,e,n,r){var o=t.dom.getRoot();return e!==o&&(e=t.dom.getParent(e,function(e){return!!$m(t,e,n)||(e.parentNode===o||!!Ym(t,e,n,r,!0))}),Ym(t,e,n,r))},Km=function(e,t,n){return!!qm(t,n.inline)||(!!qm(t,n.block)||(n.selector?1===t.nodeType&&e.is(t,n.selector):void 0))},Xm=function(e,t,n,r,o,i){var a,u,s,c=n[r];if(n.onmatch)return n.onmatch(t,n,r);if(c)if("undefined"==typeof c.length){for(a in c)if(c.hasOwnProperty(a)){if(u="attributes"===r?e.getAttrib(t,a):Sl(e,t,a),o&&!u&&!n.exact)return;if((!o||n.exact)&&!qm(u,xl(e,Cl(c[a],i),a)))return}}else for(s=0;s<c.length;s++)if("attributes"===r?e.getAttrib(t,c[s]):Sl(e,t,c[s]))return n;return n},Ym=function(e,t,n,r,o){var i,a,u,s,c=e.formatter.get(n),l=e.dom;if(c&&t)for(a=0;a<c.length;a++)if(i=c[a],Km(e.dom,t,i)&&Xm(l,t,i,"attributes",o,r)&&Xm(l,t,i,"styles",o,r)){if(s=i.classes)for(u=0;u<s.length;u++)if(!e.dom.hasClass(t,s[u]))return;return i}},Gm=function(e,t,n,r){var o;return r?Wm(e,r,t,n):(r=e.selection.getNode(),!!Wm(e,r,t,n)||!((o=e.selection.getStart())===r||!Wm(e,o,t,n)))},Jm=function(r,o,i){var a=[],u={},e=r.selection.getStart();return r.dom.getParent(e,function(e){for(var t=0;t<o.length;t++){var n=o[t];!u[n]&&Ym(r,e,n,i)&&(u[n]=!0,a.push(n))}},r.dom.getRoot()),a},Qm=function(e,t){var n,r,o,i,a,u=e.formatter.get(t),s=e.dom;if(u)for(n=e.selection.getStart(),r=El(s,n),i=u.length-1;0<=i;i--){if(!(a=u[i].selector)||u[i].defaultBlock)return!0;for(o=r.length-1;0<=o;o--)if(s.is(r[o],a))return!0}return!1},Zm=function(o,i,e){return W(e,function(e,t){var n,r=(n=t,F(o.formatter.get(n),function(t){var n=function(e){return 1<e.length&&"%"===e.charAt(0)};return F(["styles","attributes"],function(e){return de(t,e).exists(function(e){var t=k(e)?e:fe(e);return F(t,n)})})}));return o.formatter.matchNode(i,t,{},r)?e.concat([t]):e},[])},ep=su,tp="_mce_caret",np=function(e){return 0<function(e){for(var t=[];e;){if(3===e.nodeType&&e.nodeValue!==ep||1<e.childNodes.length)return[];1===e.nodeType&&t.push(e),e=e.firstChild}return t}(e).length},rp=function(e){if(e){var t=new ra(e,e);for(e=t.current();e;e=t.next())if(Zt(e))return e}return null},op=function(e){var t=Ne.fromTag("span");return ln(t,{id:tp,"data-mce-bogus":"1","data-mce-type":"format-caret"}),e&&St(t,Ne.fromText(ep)),t},ip=function(e,t,n){void 0===n&&(n=!0);var r,o=e.dom,i=e.selection;if(np(t))gd(e,!1,Ne.fromDom(t),n);else{var a=i.getRng(),u=o.getParent(t,o.isBlock),s=a.startContainer,c=a.startOffset,l=a.endContainer,f=a.endOffset,d=((r=rp(t))&&r.nodeValue.charAt(0)===ep&&r.deleteData(0,1),r);o.remove(t,!0),s===d&&0<c&&a.setStart(d,c-1),l===d&&0<f&&a.setEnd(d,f-1),u&&o.isEmpty(u)&&Qf(Ne.fromDom(u)),i.setRng(a)}},ap=function(e,t,n){void 0===n&&(n=!0);var r=e.dom,o=e.selection;if(t)ip(e,t,n);else if(!(t=Fs(e.getBody(),o.getStart())))for(;t=r.get(tp);)ip(e,t,!1)},up=function(e,t){return e.appendChild(t),t},sp=function(e,t){var n=$(e,function(e,t){return up(e,t.cloneNode(!1))},t);return up(n,n.ownerDocument.createTextNode(ep))},cp=function(e,t,n,r){var o,i,a,u,s,c,l,f,d=e.dom,m=e.selection,p=[],g=m.getRng(),h=g.startContainer,v=g.startOffset;for(3===(i=h).nodeType&&(v!==h.nodeValue.length&&(o=!0),i=i.parentNode);i;){if(Ym(e,i,t,n,r)){a=i;break}i.nextSibling&&(o=!0),p.push(i),i=i.parentNode}if(a)if(o){var y=m.getBookmark();g.collapse(!0);var b=Ul(e,g,e.formatter.get(t),!0);b=Vm(b),e.formatter.remove(t,n,b,r),m.moveToBookmark(y)}else{var C=Fs(e.getBody(),a),w=op(!1).dom();s=w,c=null!==C?C:a,l=(u=e).dom,(f=l.getParent(c,N(vl,u)))&&l.isEmpty(f)?c.parentNode.replaceChild(s,c):(Jf(Ne.fromDom(c)),l.isEmpty(c)?c.parentNode.replaceChild(s,c):l.insertAfter(s,c));var x=function(t,e,n,r,o,i){var a=t.formatter,u=t.dom,s=H(ne(a.get()),function(e){return"removeformat"!==e&&e!==r}),c=Zm(t,n,s);if(0<H(c,function(e){return!kl(t,e,r)}).length){var l=n.cloneNode(!1);return u.add(e,l),a.remove(r,o,l,i),u.remove(l),R.some(l)}return R.none()}(e,w,a,t,n,r),S=sp(p.concat(x.toArray()),w);ip(e,C,!1),m.setCursorLocation(S,1),d.isEmpty(a)&&d.remove(a)}},lp=function(i){i.on("mouseup keydown",function(e){var t,n,r,o;t=i,n=e.keyCode,r=t.selection,o=t.getBody(),ap(t,null,!1),8!==n&&46!==n||!r.isCollapsed()||r.getStart().innerHTML!==ep||ap(t,Fs(o,r.getStart())),37!==n&&39!==n||ap(t,Fs(o,r.getStart()))})},fp=function(e,t){return e.schema.getTextInlineElements().hasOwnProperty(Rt(t))&&!Ms(t.dom())&&!Yt(t.dom())},dp={},mp=ur,pp=ir;Ef=function(e){var t,n,r=e.selection.getRng();t=Wt(["pre"]),r.collapsed||(n=e.selection.getSelectedBlocks(),pp(mp(mp(n,t),function(e){return t(e.previousSibling)&&-1!==sr(n,e.previousSibling)}),function(e){var t,n;t=e.previousSibling,na(n=e).remove(),na(t).append("<br><br>").append(n.childNodes)}))},dp[Nf="pre"]||(dp[Nf]=[]),dp[Nf].push(Ef);var gp,hp,vp=/^(src|href|style)$/,yp=hr.each,bp=wl,Cp=function(e,t,n){return e.isChildOf(t,n)&&t!==n&&!e.isBlock(n)},wp=function(e,t,n){var r,o;if(r=t[n?"startContainer":"endContainer"],o=t[n?"startOffset":"endOffset"],$t(r)){var i=r.childNodes.length-1;!n&&o&&o--,r=r.childNodes[i<o?i:o]}return Zt(r)&&n&&o>=r.nodeValue.length&&(r=new ra(r,e.getBody()).next()||r),Zt(r)&&!n&&0===o&&(r=new ra(r,e.getBody()).prev()||r),r},xp=function(e,t,n,r){var o=e.create(n,r);return t.parentNode.insertBefore(o,t),o.appendChild(t),o},Sp=function(e,t,n,r,o){var i=Ne.fromDom(t),a=Ne.fromDom(e.create(r,o)),u=(n?gt:pt)(i);return Nt(a,u),n?(Ct(i,a),xt(a,i)):(wt(i,a),St(a,i)),a.dom()},Np=function(e,t,n,r){return!(t=hl(t,n,r))||"BR"===t.nodeName||e.isBlock(t)},Ep=function(e,r,o,t,i){var n,a,u,s,c,l=e.dom;if(u=l,!(bp(s=t,(c=r).inline)||bp(s,c.block)||c.selector&&($t(s)&&u.is(s,c.selector))||(a=t,r.links&&"A"===a.nodeName)))return!1;var f,d,m,p,g,h,v,y=t;if(r.inline&&"all"===r.remove&&k(r.preserve_attributes)){var b=H(l.getAttribs(y),function(e){return M(r.preserve_attributes,e.name.toLowerCase())});if(l.removeAllAttribs(y),z(b,function(e){return l.setAttrib(y,e.name,e.value)}),0<b.length)return e.dom.rename(t,"span"),!0}if("all"!==r.remove){yp(r.styles,function(e,t){e=xl(l,Cl(e,o),t),"number"==typeof t&&(t=e,i=null),!r.remove_similar&&i&&!bp(Sl(l,i,t),e)||l.setStyle(y,t,""),n=!0}),n&&""===l.getAttrib(y,"style")&&(y.removeAttribute("style"),y.removeAttribute("data-mce-style")),yp(r.attributes,function(e,t){var n;if(e=Cl(e,o),"number"==typeof t&&(t=e,i=null),r.remove_similar||!i||bp(l.getAttrib(i,t),e)){if("class"===t&&(e=l.getAttrib(y,t))&&(n="",z(e.split(/\s+/),function(e){/mce\-\w+/.test(e)&&(n+=(n?" ":"")+e)}),n))return void l.setAttrib(y,t,n);"class"===t&&y.removeAttribute("className"),vp.test(t)&&y.removeAttribute("data-mce-"+t),y.removeAttribute(t)}}),yp(r.classes,function(e){e=Cl(e,o),i&&!l.hasClass(i,e)||l.removeClass(y,e)});for(var C=l.getAttribs(y),w=0;w<C.length;w++){var x=C[w].nodeName;if(0!==x.indexOf("_")&&0!==x.indexOf("data-"))return!1}}return"none"!==r.remove?(f=e,m=r,g=(d=y).parentNode,h=f.dom,v=Hs(f),m.block&&(v?g===h.getRoot()&&(m.list_block&&bp(d,m.list_block)||z(te(d.childNodes),function(e){yl(f,v,e.nodeName.toLowerCase())?p?p.appendChild(e):(p=xp(h,e,v),h.setAttribs(p,f.settings.forced_root_block_attrs)):p=0})):h.isBlock(d)&&!h.isBlock(g)&&(Np(h,d,!1)||Np(h,d.firstChild,!0,!0)||d.insertBefore(h.create("br"),d.firstChild),Np(h,d,!0)||Np(h,d.lastChild,!1,!0)||d.appendChild(h.create("br")))),m.selector&&m.inline&&!bp(m.inline,d)||h.remove(d,!0),!0):void 0},kp=function(s,c,l,e,f){var d=s.formatter.get(c),m=d[0],i=!0,u=s.dom,t=s.selection,p=function(e){var n,t,r,o,i,a,u=(t=e,r=c,o=l,i=f,z(El((n=s).dom,t.parentNode).reverse(),function(e){if(!a&&"_start"!==e.id&&"_end"!==e.id){var t=Ym(n,e,r,o,i);t&&!1!==t.split&&(a=e)}}),a);return function(e,t,n,r,o,i,a,u){var s,c,l,f=e.dom;if(n){for(var d=n.parentNode,m=r.parentNode;m&&m!==d;m=m.parentNode){s=f.clone(m,!1);for(var p=0;p<t.length;p++)if(Ep(e,t[p],u,s,s)){s=0;break}s&&(c&&s.appendChild(c),l=l||s,c=s)}!i||a.mixed&&f.isBlock(n)||(r=f.split(n,r)),c&&(o.parentNode.insertBefore(c,o),l.appendChild(o))}return r}(s,d,u,e,e,!0,m,l)},g=function(e){var t,n,r;if($t(e)&&u.getContentEditable(e)&&(n=i,i="true"===u.getContentEditable(e),r=!0),t=te(e.childNodes),i&&!r)for(var o=0;o<d.length&&!Ep(s,d[o],l,e,e);o++);if(m.deep&&t.length){for(o=0;o<t.length;o++)g(t[o]);r&&(i=n)}},h=function(e){var t,n=u.get(e?"_start":"_end"),r=n[e?"firstChild":"lastChild"];return ll(t=r)&&$t(t)&&("_start"===t.id||"_end"===t.id)&&(r=r[e?"firstChild":"lastChild"]),Zt(r)&&0===r.data.length&&(r=e?n.previousSibling||n.nextSibling:n.nextSibling||n.previousSibling),u.remove(n,!0),r},n=function(e){var t,n,r=e.commonAncestorContainer,o=Ul(s,e,d,!0);if(m.split){if(o=Vm(o),(t=wp(s,o,!0))!==(n=wp(s,o))){if(/^(TR|TH|TD)$/.test(t.nodeName)&&t.firstChild&&(t="TR"===t.nodeName?t.firstChild.firstChild||t:t.firstChild||t),r&&/^T(HEAD|BODY|FOOT|R)$/.test(r.nodeName)&&/^(TH|TD)$/.test(n.nodeName)&&n.firstChild&&(n=n.firstChild||n),Cp(u,t,n)){var i=R.from(t.firstChild).getOr(t);return p(Sp(u,i,!0,"span",{id:"_start","data-mce-type":"bookmark"})),void h(!0)}if(Cp(u,n,t)){i=R.from(n.lastChild).getOr(n);return p(Sp(u,i,!1,"span",{id:"_end","data-mce-type":"bookmark"})),void h(!1)}t=xp(u,t,"span",{id:"_start","data-mce-type":"bookmark"}),n=xp(u,n,"span",{id:"_end","data-mce-type":"bookmark"});var a=u.createRng();a.setStartAfter(t),a.setEndBefore(n),jl(u,a,function(e){z(e,function(e){ll(e)||ll(e.parentNode)||p(e)})}),p(t),p(n),t=h(!0),n=h()}else t=n=p(t);o.startContainer=t.parentNode?t.parentNode:t,o.startOffset=u.nodeIndex(t),o.endContainer=n.parentNode?n.parentNode:n,o.endOffset=u.nodeIndex(n)+1}jl(u,o,function(e){z(e,function(t){g(t);z(["underline","line-through","overline"],function(e){$t(t)&&s.dom.getStyle(t,"text-decoration")===e&&t.parentNode&&Nl(u,t.parentNode)===e&&Ep(s,{deep:!1,exact:!0,inline:"span",styles:{textDecoration:e}},null,t)})})})};if(e)if(pl(e)){var r=u.createRng();r.setStartBefore(e),r.setEndAfter(e),n(r)}else n(e);else if("false"!==u.getContentEditable(t.getNode()))t.isCollapsed()&&m.inline&&!$l(s).length?cp(s,c,l,f):(Ql(t,!0,function(){Jl(s,n)}),m.inline&&Gm(s,c,l,t.getStart())&&gl(u,t,t.getRng()),s.nodeChanged());else{e=t.getNode();for(var o=0;o<d.length&&(!d[o].ceFalseOverride||!Ep(s,d[o],l,e,e));o++);}},_p=hr.each,Rp=function(e){return $t(e)&&!ll(e)&&!Ms(e)&&!Yt(e)},Tp=function(e,t){var n;for(n=e;n;n=n[t]){if(Zt(n)&&0!==n.nodeValue.length)return e;if($t(n)&&!ll(n))return n}return e},Ap=function(e,t,n){var r,o,i=new Df(e);if(t&&n&&(t=Tp(t,"previousSibling"),n=Tp(n,"nextSibling"),i.compare(t,n))){for(r=t.nextSibling;r&&r!==n;)r=(o=r).nextSibling,t.appendChild(o);return e.remove(n),hr.each(hr.grep(n.childNodes),function(e){t.appendChild(e)}),t}return n},Dp=function(e,t,n){_p(e.childNodes,function(e){Rp(e)&&(t(e)&&n(e),e.hasChildNodes()&&Dp(e,t,n))})},Op=function(t,n){return function(e){return!(!e||!Sl(t,e,n))}},Bp=function(t,n,r){return function(e){t.setStyle(e,n,r),""===e.getAttribute("style")&&e.removeAttribute("style"),Pp(t,e)}},Pp=function(e,t){"SPAN"===t.nodeName&&0===e.getAttribs(t).length&&e.remove(t,!0)},Lp=function(n,e,r,o){_p(e,function(t){_p(n.dom.select(t.inline,o),function(e){Rp(e)&&Ep(n,t,r,e,t.exact?e:null)}),function(r,e,t){if(e.clear_child_styles){var n=e.links?"*:not(a)":"*";_p(r.select(n,t),function(n){Rp(n)&&_p(e.styles,function(e,t){r.setStyle(n,t,"")})})}}(n.dom,t,o)})},Ip=hr.each,Mp=function(R,T,A,r){var e,D=R.formatter.get(T),O=D[0],o=!r&&R.selection.isCollapsed(),i=R.dom,t=R.selection,B=function(n,e){if(e=e||O,n){if(e.onformat&&e.onformat(n,e,A,r),Ip(e.styles,function(e,t){i.setStyle(n,t,Cl(e,A))}),e.styles){var t=i.getAttrib(n,"style");t&&i.setAttrib(n,"data-mce-style",t)}Ip(e.attributes,function(e,t){i.setAttrib(n,t,Cl(e,A))}),Ip(e.classes,function(e){e=Cl(e,A),i.hasClass(n,e)||i.addClass(n,e)})}},d=function(e,t){var n=!1;return!!O.selector&&(Ip(e,function(e){if(!("collapsed"in e&&e.collapsed!==o))return i.is(t,e.selector)&&!Ms(t)?(B(t,e),!(n=!0)):void 0}),n)},a=function(k,e,t,s){var c,l,_=[],f=!0;c=O.inline||O.block,l=k.create(c),B(l),jl(k,e,function(e){var a,u=function(e){var t=!1,n=f,r=e.nodeName.toLowerCase(),o=e.parentNode.nodeName.toLowerCase();if($t(e)&&k.getContentEditable(e)&&(n=f,f="true"===k.getContentEditable(e),t=!0),wl(r,"br"))return a=0,void(O.block&&k.remove(e));if(O.wrapper&&Ym(R,e,T,A))a=0;else{if(f&&!t&&O.block&&!O.wrapper&&vl(R,r)&&yl(R,o,c))return e=k.rename(e,c),B(e),_.push(e),void(a=0);if(O.selector){var i=d(D,e);if(!O.inline||i)return void(a=0)}!f||t||!yl(R,c,r)||!yl(R,o,c)||!s&&3===e.nodeType&&1===e.nodeValue.length&&65279===e.nodeValue.charCodeAt(0)||Ms(e)||O.inline&&k.isBlock(e)?(a=0,Ip(hr.grep(e.childNodes),u),t&&(f=n),a=0):(a||(a=k.clone(l,!1),e.parentNode.insertBefore(a,e),_.push(a)),a.appendChild(e))}};Ip(e,u)}),!0===O.links&&Ip(_,function(e){var t=function(e){"A"===e.nodeName&&B(e,O),Ip(hr.grep(e.childNodes),t)};t(e)}),Ip(_,function(e){var t,n,r,o,i,a,u,s,c,l,f,d,m,p,g,h,v,y,b,C,w,x,S,N,E=function(e){var n=!1;return Ip(e.childNodes,function(e){if((t=e)&&1===t.nodeType&&!ll(t)&&!Ms(t)&&!Yt(t))return n=e,!1;var t}),n};(n=0,Ip(e.childNodes,function(e){var t;(t=e)&&Zt(t)&&0===t.length||ll(e)||n++}),t=n,!(1<_.length)&&k.isBlock(e)||0!==t)?(O.inline||O.wrapper)&&(O.exact||1!==t||((S=E(x=e))&&!ll(S)&&Km(k,S,O)&&(N=k.clone(S,!1),B(N),k.replace(N,x,!0),k.remove(S,!0)),e=N||x),Lp(R,D,A,e),y=O,b=T,C=A,Ym(v=R,(w=e).parentNode,b,C)&&Ep(v,y,C,w)||y.merge_with_parents&&v.dom.getParent(w.parentNode,function(e){if(Ym(v,e,b,C))return Ep(v,y,C,w),!0}),m=k,g=A,h=e,(p=O).styles&&p.styles.backgroundColor&&Dp(h,Op(m,"fontSize"),Bp(m,"backgroundColor",Cl(p.styles.backgroundColor,g))),c=k,f=e,d=function(e){if(1===e.nodeType&&e.parentNode&&1===e.parentNode.nodeType){var t=Nl(c,e.parentNode);c.getStyle(e,"color")&&t?c.setStyle(e,"text-decoration",t):c.getStyle(e,"text-decoration")===t&&c.setStyle(e,"text-decoration",null)}},(l=O).styles&&(l.styles.color||l.styles.textDecoration)&&(hr.walk(f,d,"childNodes"),d(f)),a=k,s=e,"sub"!==(u=O).inline&&"sup"!==u.inline||(Dp(s,Op(a,"fontSize"),Bp(a,"fontSize","")),a.remove(a.select("sup"===u.inline?"sub":"sup",s),!0)),r=k,o=O,(i=e)&&!1!==o.merge_siblings&&(i=Ap(r,hl(i),i),i=Ap(r,i,hl(i,!0)))):k.remove(e,!0)})};if("false"!==i.getContentEditable(t.getNode())){if(O){if(r)pl(r)?d(D,r)||((e=i.createRng()).setStartBefore(r),e.setEndAfter(r),a(i,Ul(R,e,D),0,!0)):a(i,r,0,!0);else if(o&&O.inline&&!$l(R).length)!function(e,t,n){var r,o,i=e.selection,a=i.getRng(),u=a.startOffset,s=a.startContainer.nodeValue;(r=Fs(e.getBody(),i.getStart()))&&(o=rp(r));var c,l,f=/[^\s\u00a0\u00ad\u200b\ufeff]/;if(s&&0<u&&u<s.length&&f.test(s.charAt(u))&&f.test(s.charAt(u-1))){var d=i.getBookmark();a.collapse(!0);var m=Ul(e,a,e.formatter.get(t));m=Vm(m),e.formatter.apply(t,n,m),i.moveToBookmark(d)}else r&&o.nodeValue===ep||(c=e.getDoc(),l=op(!0).dom(),o=(r=c.importNode(l,!0)).firstChild,a.insertNode(r),u=1),e.formatter.apply(t,n,r),i.setCursorLocation(o,u)}(R,T,A);else{var n=t.getNode();R.settings.forced_root_block||!D[0].defaultBlock||i.getParent(n,i.isBlock)||Mp(R,D[0].defaultBlock),t.setRng($d(t.getRng())),Ql(t,!0,function(e){Jl(R,function(e,t){var n=t?e:Ul(R,e,D);a(i,n)})}),gl(i,t,t.getRng()),R.nodeChanged()}u=R,pp(dp[T],function(e){e(u)})}var u}else{r=t.getNode();for(var s=0,c=D.length;s<c;s++)if(D[s].ceFalseOverride&&i.is(r,D[s].selector))return void B(r,D[s])}},Fp=function(n,e){return U(e,function(e){var t=n.fire("GetSelectionRange",{range:e});return t.range!==e?t.range:e})},Up=function(e,t){var n=(t||V.document).createDocumentFragment();return z(e,function(e){n.appendChild(e.dom())}),Ne.fromDom(n)},zp=function(e,t,n){return{element:x(e),width:x(t),rows:x(n)}},jp=function(e,t){return{element:x(e),cells:x(t)}},Hp=function(e,t){var n=parseInt(fn(e,t),10);return isNaN(n)?1:n},Vp=function(e){return W(e,function(e,t){return t.cells().length>e?t.cells().length:e},0)},qp=function(e,t){for(var n,r=e.rows(),o=0;o<r.length;o++)for(var i=r[o].cells(),a=0;a<i.length;a++)if(at(i[a],t))return R.some((n=o,{x:x(a),y:x(n)}));return R.none()},$p=function(e,t,n,r,o){for(var i=[],a=e.rows(),u=n;u<=o;u++){var s=a[u].cells(),c=t<r?s.slice(t,r+1):s.slice(r,t+1);i.push(jp(a[u].element(),c))}return i},Wp=function(e){var o=zp(ou(e),0,[]);return z(Ua(e,"tr"),function(n,r){z(Ua(n,"td,th"),function(e,t){!function(e,t,n,r,o){for(var i=Hp(o,"rowspan"),a=Hp(o,"colspan"),u=e.rows(),s=n;s<n+i;s++){u[s]||(u[s]=jp(iu(r),[]));for(var c=t;c<t+a;c++){u[s].cells()[c]=s===n&&c===t?o:ou(o)}}}(o,function(e,t,n){for(;r=t,o=n,i=void 0,((i=e.rows())[o]?i[o].cells():[])[r];)t++;var r,o,i;return t}(o,t,r),r,n,e)})}),zp(o.element(),Vp(o.rows()),o.rows())},Kp=function(e){return n=U((t=e).rows(),function(e){var t=U(e.cells(),function(e){var t=iu(e);return dn(t,"colspan"),dn(t,"rowspan"),t}),n=ou(e.element());return Nt(n,t),n}),r=ou(t.element()),o=Ne.fromTag("tbody"),Nt(o,n),St(r,o),r;var t,n,r,o},Xp=function(l,e,t){return qp(l,e).bind(function(c){return qp(l,t).map(function(e){return t=l,r=e,o=(n=c).x(),i=n.y(),a=r.x(),u=r.y(),s=i<u?$p(t,o,i,a,u):$p(t,o,u,a,i),zp(t.element(),Vp(s),s);var t,n,r,o,i,a,u,s})})},Yp=function(t,n){return K(t,function(e){return"li"===Rt(e)&&Xl(e,n)}).fold(x([]),function(e){return K(t,function(e){return"ul"===Rt(e)||"ol"===Rt(e)}).map(function(e){return[Ne.fromTag("li"),Ne.fromTag(Rt(e))]}).getOr([])})},Gp=function(e,t){var n,r=Ne.fromDom(t.commonAncestorContainer),o=nd(r,e),i=H(o,function(e){return Nr(e)||xr(e)}),a=Yp(o,t),u=i.concat(a.length?a:Rr(n=r)?ft(n).filter(_r).fold(x([]),function(e){return[n,e]}):_r(n)?[n]:[]);return U(u,ou)},Jp=function(){return Up([])},Qp=function(e,t){return n=Ne.fromDom(t.cloneContents()),r=Gp(e,t),o=W(r,function(e,t){return St(t,e),t},n),0<r.length?Up([o]):o;var n,r,o},Zp=function(e,o){return t=e,n=o[0],qa(n,"table",N(at,t)).bind(function(e){var t=o[0],n=o[o.length-1],r=Wp(e);return Xp(r,t,n).map(function(e){return Up([Kp(e)])})}).getOrThunk(Jp);var t,n},eg=function(e,t){var n,r,o=ql(t,e);return 0<o.length?Zp(e,o):(n=e,0<(r=t).length&&r[0].collapsed?Jp():Qp(n,r[0]))},tg=function(e,t,n){if(void 0===n&&(n={}),n.get=!0,n.format=t,n.selection=!0,(n=e.fire("BeforeGetContent",n)).isDefaultPrevented())return e.fire("GetContent",n),n.content;if("text"===n.format)return l=e,R.from(l.selection.getRng()).map(function(e){var t=l.dom.add(l.getBody(),"div",{"data-mce-bogus":"all",style:"overflow: hidden; opacity: 0;"},e.cloneContents()),n=lu(t.innerText);return l.dom.remove(t),n}).getOr("");n.getInner=!0;var r,o,i,a,u,s,c,l,f=(o=n,i=(r=e).selection.getRng(),a=r.dom.create("body"),u=r.selection.getSel(),s=Fp(r,Hl(u)),(c=o.contextual?eg(Ne.fromDom(r.getBody()),s).dom():i.cloneContents())&&a.appendChild(c),r.selection.serializer.serialize(a,o));return"tree"===n.format?f:(n.content=e.selection.isCollapsed()?"":f,e.fire("GetContent",n),n.content)},ng=function(e){return $t(e)?e.outerHTML:Zt(e)?$r.encodeRaw(e.data,!1):en(e)?"\x3c!--"+e.data+"--\x3e":""},rg=function(e,t,n){var r=function(e){var t,n,r;for(r=V.document.createElement("div"),t=V.document.createDocumentFragment(),e&&(r.innerHTML=e);n=r.firstChild;)t.appendChild(n);return t}(t);if(e.hasChildNodes()&&n<e.childNodes.length){var o=e.childNodes[n];o.parentNode.insertBefore(r,o)}else e.appendChild(r)},og=function(e,t){var n,r,p,g,o,h,v,c,y,l,i,a=U(te(t.childNodes),ng);return g=e,o=(p=a).length+g.length+2,h=new Array(o),v=new Array(o),c=function(e,t,n,r,o){var i=l(e,t,n,r);if(null===i||i.start===t&&i.diag===t-r||i.end===e&&i.diag===e-n)for(var a=e,u=n;a<t||u<r;)a<t&&u<r&&p[a]===g[u]?(o.push([0,p[a]]),++a,++u):r-n<t-e?(o.push([2,p[a]]),++a):(o.push([1,g[u]]),++u);else{c(e,i.start,n,i.start-i.diag,o);for(var s=i.start;s<i.end;++s)o.push([0,p[s]]);c(i.end,t,i.end-i.diag,r,o)}},y=function(e,t,n,r){for(var o=e;o-t<r&&o<n&&p[o]===g[o-t];)++o;return{start:e,end:o,diag:t}},l=function(e,t,n,r){var o=t-e,i=r-n;if(0==o||0==i)return null;var a,u,s,c,l,f=o-i,d=i+o,m=(d%2==0?d:1+d)/2;for(h[1+m]=e,v[1+m]=t+1,a=0;a<=m;++a){for(u=-a;u<=a;u+=2){for(s=u+m,u===-a||u!==a&&h[s-1]<h[s+1]?h[s]=h[s+1]:h[s]=h[s-1]+1,l=(c=h[s])-e+n-u;c<t&&l<r&&p[c]===g[l];)h[s]=++c,++l;if(f%2!=0&&f-a<=u&&u<=f+a&&v[s-f]<=h[s])return y(v[s-f],u+e-n,t,r)}for(u=f-a;u<=f+a;u+=2){for(s=u+m-f,u===f-a||u!==f+a&&v[s+1]<=v[s-1]?v[s]=v[s+1]-1:v[s]=v[s-1],l=(c=v[s]-1)-e+n-u;e<=c&&n<=l&&p[c]===g[l];)v[s]=c--,l--;if(f%2==0&&-a<=u&&u<=a&&v[s]<=h[s+f])return y(v[s],u+e-n,t,r)}}},i=[],c(0,p.length,0,g.length,i),n=t,r=0,z(i,function(e){0===e[0]?r++:1===e[0]?(rg(n,e[1],r),r++):2===e[0]&&function(e,t){if(e.hasChildNodes()&&t<e.childNodes.length){var n=e.childNodes[t];n.parentNode.removeChild(n)}}(n,r)}),t},ig=xa(R.none()),ag=function(n){var e,t,r,o;return o=n.getBody(),e=H(U(te(o.childNodes),ng),function(e){return 0<e.length}),t=(r=Y(e,function(e){var t=_f(n.serializer,e);return 0<t.length?[t]:[]})).join(""),-1!==t.indexOf("</iframe>")?{type:"fragmented",fragments:r,content:"",bookmark:null,beforeBookmark:null}:{type:"complete",fragments:null,content:t,bookmark:null,beforeBookmark:null}},ug=function(e,t,n){"fragmented"===t.type?og(t.fragments,e.getBody()):e.setContent(t.content,{format:"raw"}),e.selection.moveToBookmark(n?t.beforeBookmark:t.bookmark)},sg=function(e){return"fragmented"===e.type?e.fragments.join(""):e.content},cg=function(e){var t=Ne.fromTag("body",ig.get().getOrThunk(function(){var e=V.document.implementation.createHTMLDocument("undo");return ig.set(R.some(e)),e}));return nu(t,sg(e)),z(Ua(t,"*[data-mce-bogus]"),_t),t.dom().innerHTML},lg=function(e,t){return!(!e||!t)&&(r=t,sg(e)===sg(r)||(n=t,cg(e)===cg(n)));var n,r},fg=function(e){return 0===e.get()},dg=function(e,t,n){fg(n)&&(e.typing=t)},mg=function(e,t){e.typing&&(dg(e,!1,t),e.add())},pg=function(e){return e instanceof df},gg=function(e,t){Fm(e.serializer.getNodeFilters(),e.serializer.getAttributeFilters(),t)},hg=function(){return{type:"complete",fragments:[],content:"",bookmark:null,beforeBookmark:null}},vg=function(s){return{undoManager:{beforeChange:function(e,t){return n=s,r=t,void(fg(e)&&r.set(R.some(Ls(n.selection))));var n,r},addUndoLevel:function(e,t,n,r,o,i){return function(e,t,n,r,o,i,a){var u=e.settings,s=ag(e);if(i=i||{},i=hr.extend(i,s),!1===fg(r)||e.removed)return null;var c=t.data[n.get()];if(e.fire("BeforeAddUndo",{level:i,lastLevel:c,originalEvent:a}).isDefaultPrevented())return null;if(c&&lg(c,i))return null;if(t.data[n.get()]&&o.get().each(function(e){t.data[n.get()].beforeBookmark=e}),u.custom_undo_redo_levels&&t.data.length>u.custom_undo_redo_levels){for(var l=0;l<t.data.length-1;l++)t.data[l]=t.data[l+1];t.data.length--,n.set(t.data.length)}i.bookmark=Ls(e.selection),n.get()<t.data.length-1&&(t.data.length=n.get()+1),t.data.push(i),n.set(t.data.length-1);var f={level:i,lastLevel:c,originalEvent:a};return e.fire("AddUndo",f),0<n.get()&&(e.setDirty(!0),e.fire("change",f)),i}(s,e,t,n,r,o,i)},undo:function(e,t,n){return r=s,i=t,a=n,(o=e).typing&&(o.add(),o.typing=!1,dg(o,!1,i)),0<a.get()&&(a.set(a.get()-1),u=o.data[a.get()],ug(r,u,!0),r.setDirty(!0),r.fire("Undo",{level:u})),u;var r,o,i,a,u},redo:function(e,t){return n=s,o=t,(r=e).get()<o.length-1&&(r.set(r.get()+1),i=o[r.get()],ug(n,i,!1),n.setDirty(!0),n.fire("Redo",{level:i})),i;var n,r,o,i},clear:function(e,t){return n=s,o=t,(r=e).data=[],o.set(0),r.typing=!1,void n.fire("ClearUndos");var n,r,o},reset:function(e){return(t=e).clear(),void t.add();var t},hasUndo:function(e,t){return n=s,r=e,0<t.get()||r.typing&&r.data[0]&&!lg(ag(n),r.data[0]);var n,r},hasRedo:function(e,t){return n=e,t.get()<n.data.length-1&&!n.typing;var n},transact:function(e,t,n){return o=n,mg(r=e,t),r.beforeChange(),r.ignore(o),r.add();var r,o},ignore:function(e,t){return function(e,t){try{e.set(e.get()+1),t()}finally{e.set(e.get()-1)}}(e,t)},extra:function(e,t,n,r){return function(e,t,n,r,o){if(t.transact(r)){var i=t.data[n.get()].bookmark,a=t.data[n.get()-1];ug(e,a,!0),t.transact(o)&&(t.data[n.get()-1].beforeBookmark=i)}}(s,e,t,n,r)}},formatter:{apply:function(e,t,n){return Mp(s,e,t,n)},remove:function(e,t,n,r){return kp(s,e,t,n,r)},toggle:function(e,t,n){return o=e,i=t,a=n,u=(r=s).formatter.get(o),void(!Gm(r,o,i,a)||"toggle"in u[0]&&!u[0].toggle?Mp:kp)(r,o,i,a);var r,o,i,a,u}},editor:{getContent:function(e,t){return n=s,r=e,o=t,R.from(n.getBody()).fold(x("tree"===r.format?new df("body",11):""),function(e){return Tf(n,r,o,e)});var n,r,o},setContent:function(e,t){return jm(s,e,t)},insertContent:function(e,t){return rm(s,e,t)}},selection:{getContent:function(e,t){return tg(s,e,t)}},raw:{getModel:function(){return R.none()}}}},yg=function(e){return me(e.plugins,"rtc")},bg=function(n){var r=n;return de(n.plugins,"rtc").fold(function(){return r.rtcInstance=vg(n),R.none()},function(e){return R.some(e.setup().then(function(e){var o,i,a,t;return r.rtcInstance=(o=n,i=e,a=function(e){return E(e)?e:{}},t=p("Unimplemented feature for rtc"),{undoManager:{beforeChange:f,addUndoLevel:t,undo:function(){return i.undo(),hg()},redo:function(){return i.redo(),hg()},clear:t,reset:t,hasUndo:function(){return i.hasUndo()},hasRedo:function(){return i.hasRedo()},transact:function(e,t,n){return i.transact(n),hg()},ignore:t,extra:t},formatter:{apply:function(e,t,n){return i.applyFormat(e,a(t))},remove:function(e,t,n,r){return i.removeFormat(e,a(t))},toggle:function(e,t,n){return i.toggleFormat(e,a(t))}},editor:{getContent:function(e,t){if("html"!==t&&"tree"!==t)return vg(o).editor.getContent(e,t);var n=i.getContent(),r=hf({inner:!0});return gg(o,n),"tree"===t?n:r.serialize(n)},setContent:function(e,t){var n=pg(e)?e:o.parser.parse(e,{isRootContent:!0,insert:!0});return i.setContent(n),e},insertContent:function(e,t){var n=pg(e)?e:o.parser.parse(e,{insert:!0});i.insertContent(n)}},selection:{getContent:function(e,t){if("html"!==e&&"tree"!==e)return vg(o).selection.getContent(e,t);var n=i.getSelectedContent(),r=hf({});return gg(o,n),"tree"===e?n:r.serialize(n)}},raw:{getModel:function(){return R.some(i.getRawModel())}}}),e.isRemote}))})},Cg=function(e){return e.rtcInstance?e.rtcInstance:vg(e)},wg=function(e){var t=e.rtcInstance;if(t)return t;throw new Error("Failed to get RTC instance not yet initialized.")},xg=function(e,t){void 0===t&&(t={});var n,r,o=t.format?t.format:"html";return n=t,r=o,Cg(e).editor.getContent(n,r)},Sg=function(e,t,n){return void 0===n&&(n={}),r=t,o=n,Cg(e).editor.setContent(r,o);var r,o},Ng=ga.DOM,Eg=function(e){return R.from(e).each(function(e){return e.destroy()})},kg=function(e){if(!e.removed){var t=e._selectionOverrides,n=e.editorUpload,r=e.getBody(),o=e.getElement();r&&e.save({is_removing:!0}),e.removed=!0,e.unbindAllNativeEvents(),e.hasHiddenInput&&o&&Ng.remove(o.nextSibling),e.fire("remove"),e.editorManager.remove(e),!e.inline&&r&&(i=e,Ng.setStyle(i.id,"display",i.orgDisplay)),e.fire("detach"),Ng.remove(e.getContainer()),Eg(t),Eg(n),e.destroy()}var i},_g=function(e,t){var n,r,o,i=e.selection,a=e.dom;e.destroyed||(t||e.removed?(t||(e.editorManager.off("beforeunload",e._beforeUnload),e.theme&&e.theme.destroy&&e.theme.destroy(),Eg(i),Eg(a)),(r=(n=e).formElement)&&(r._mceOldSubmit&&(r.submit=r._mceOldSubmit,r._mceOldSubmit=null),Ng.unbind(r,"submit reset",n.formEventDelegate)),(o=e).contentAreaContainer=o.formElement=o.container=o.editorContainer=null,o.bodyElement=o.contentDocument=o.contentWindow=null,o.iframeElement=o.targetElm=null,o.selection&&(o.selection=o.selection.win=o.selection.dom=o.selection.dom.doc=null),e.destroyed=!0):e.remove())},Rg=Object.prototype.hasOwnProperty,Tg=(gp=function(e,t){return E(e)&&E(t)?Tg(e,t):t},function(){for(var e=new Array(arguments.length),t=0;t<e.length;t++)e[t]=arguments[t];if(0===e.length)throw new Error("Can't merge zero objects");for(var n={},r=0;r<e.length;r++){var o=e[r];for(var i in o)Rg.call(o,i)&&(n[i]=gp(n[i],o[i]))}return n}),Ag=nt().deviceType,Dg=Ag.isTouch(),Og=Ag.isPhone(),Bg=Ag.isTablet(),Pg=["lists","autolink","autosave"],Lg={table_grid:!1,object_resizing:!1,resize:!1},Ig=function(e){var t=k(e)?e.join(" "):e,n=U(q(t)?t.split(" "):[],$e);return H(n,function(e){return 0<e.length})},Mg=function(n,e){var t,r,o=ce(e,function(e,t){return M(n,t)});return t=o.t,r=o.f,{sections:x(t),settings:x(r)}},Fg=function(e,t){return e.sections().hasOwnProperty(t)},Ug=function(e,t){return de(e,"toolbar_mode").orThunk(function(){return de(e,"toolbar_drawer").map(function(e){return!1===e?"wrap":e})}).getOr(t)},zg=function(e,t,n,r){var o,i,a,u,s,c,l,f=Ig(n.forced_plugins),d=Ig(r.plugins),m=Fg(o=t,i="mobile")?o.sections()[i]:{},p=m.plugins?Ig(m.plugins):d,g=e&&(s=u="mobile",c=(a=t).sections(),Fg(a,u)&&c[u].theme===s)?H(p,N(M,Pg)):e&&Fg(t,"mobile")?p:d,h=(l=g,[].concat(Ig(f)).concat(Ig(l)));return hr.extend(r,{plugins:h.join(" ")})},jg=function(e,t,n,r,o){var i,a,u,s,c,l,f,d=e?{mobile:(i=o.mobile||{},a=t,u={resize:!1,toolbar_mode:Ug(i,"scrolling"),toolbar_sticky:!1},pe(pe(pe({},Lg),u),a?{menubar:!1}:{}))}:{},m=Mg(["mobile"],Tg(d,o)),p=hr.extend(n,r,m.settings(),(f=m,e&&Fg(f,"mobile")?function(e,t,n){void 0===n&&(n={});var r=e.sections(),o=r.hasOwnProperty(t)?r[t]:{};return hr.extend({},n,o)}(m,"mobile"):{}),{validate:!0,external_plugins:(s=r,c=m.settings(),l=c.external_plugins?c.external_plugins:{},s&&s.external_plugins?hr.extend({},s.external_plugins,l):l)});return zg(e,m,r,p)},Hg=function(e,t,n,r,o){var i,a,u,s,c=(i=n,a=Dg,u=e,s={id:t,theme:"silver",toolbar_mode:Ug(o,"floating"),plugins:"",document_base_url:i,add_form_submit_trigger:!0,submit_patch:!0,add_unload_trigger:!0,convert_urls:!0,relative_urls:!0,remove_script_host:!0,object_resizing:!0,doctype:"<!DOCTYPE html>",visual:!0,font_size_legacy_values:"xx-small,small,medium,large,x-large,xx-large,300%",forced_root_block:"p",hidden_input:!0,inline_styles:!0,convert_fonts_to_spans:!0,indent:!0,indent_before:"p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist",indent_after:"p,h1,h2,h3,h4,h5,h6,blockquote,div,title,style,pre,script,td,th,ul,ol,li,dl,dt,dd,area,table,thead,tfoot,tbody,tr,section,summary,article,hgroup,aside,figure,figcaption,option,optgroup,datalist",entity_encoding:"named",url_converter:u.convertURL,url_converter_scope:u},pe(pe({},s),a?Lg:{}));return jg(Og||Bg,Og,c,r,o)},Vg=function(e,t,n){return R.from(t.settings[n]).filter(e)},qg=function(e,t,n,r){var o,i,a,u=t in e.settings?e.settings[t]:n;return"hash"===r?(a={},"string"==typeof(i=u)?z(0<i.indexOf("=")?i.split(/[;,](?![^=;,]*(?:[;,]|$))/):i.split(","),function(e){var t=e.split("=");1<t.length?a[hr.trim(t[0])]=hr.trim(t[1]):a[hr.trim(t[0])]=hr.trim(t[0])}):a=i,a):"string"===r?Vg(q,e,t).getOr(n):"number"===r?Vg(O,e,t).getOr(n):"boolean"===r?Vg(T,e,t).getOr(n):"object"===r?Vg(E,e,t).getOr(n):"array"===r?Vg(k,e,t).getOr(n):"string[]"===r?Vg((o=q,function(e){return k(e)&&G(e,o)}),e,t).getOr(n):"function"===r?Vg(D,e,t).getOr(n):u},$g=(hp={},{add:function(e,t){hp[e]=t},get:function(e){return hp[e]?hp[e]:{icons:{}}},has:function(e){return me(hp,e)}}),Wg=function(e,t){return t.dom()[e]},Kg=function(e,t){return parseInt(mn(t,e),10)},Xg=N(Wg,"clientWidth"),Yg=N(Wg,"clientHeight"),Gg=N(Kg,"margin-top"),Jg=N(Kg,"margin-left"),Qg=function(e,t,n){var r,o,i,a,u,s,c,l,f,d,m,p=Ne.fromDom(e.getBody()),g=e.inline?p:(r=p,Ne.fromDom(r.dom().ownerDocument.documentElement)),h=(o=e.inline,a=t,u=n,s=(i=g).dom().getBoundingClientRect(),{x:a-(o?s.left+i.dom().clientLeft+Jg(i):0),y:u-(o?s.top+i.dom().clientTop+Gg(i):0)});return l=h.x,f=h.y,d=Xg(c=g),m=Yg(c),0<=l&&0<=f&&l<=d&&f<=m},Zg=function(e){var t,n=e.inline?e.getBody():e.getContentAreaContainer();return t=n,R.from(t).map(Ne.fromDom).map(function(e){return st(ct(e),e)}).getOr(!1)};function eh(n){var t,o=[],i=function(){var e=n.theme;return e&&e.getNotificationManagerImpl?e.getNotificationManagerImpl():function t(){var e=function(){throw new Error("Theme did not provide a NotificationManager implementation.")};return{open:e,close:e,reposition:e,getArgs:e}}()},a=function(){0<o.length&&i().reposition(o)},u=function(t){X(o,function(e){return e===t}).each(function(e){o.splice(e,1)})},r=function(r){if(!n.removed&&Zg(n))return K(o,function(e){return t=i().getArgs(e),n=r,!(t.type!==n.type||t.text!==n.text||t.progressBar||t.timeout||n.progressBar||n.timeout);var t,n}).getOrThunk(function(){n.editorManager.setActive(n);var e,t=i().open(r,function(){u(t),a()});return e=t,o.push(e),a(),t})};return(t=n).on("SkinLoaded",function(){var e=t.settings.service_message;e&&r({text:e,type:"warning",timeout:0})}),t.on("ResizeEditor ResizeWindow NodeChange",function(){Xn.requestAnimationFrame(a)}),t.on("remove",function(){z(o.slice(),function(e){i().close(e)})}),{open:r,close:function(){R.from(o[0]).each(function(e){i().close(e),u(e),a()})},getNotifications:function(){return o}}}var th=Ra.PluginManager,nh=Ra.ThemeManager;var rh=function(n){var r=[],o=function(){var e=n.theme;return e&&e.getWindowManagerImpl?e.getWindowManagerImpl():function t(){var e=function(){throw new Error("Theme did not provide a WindowManager implementation.")};return{open:e,openUrl:e,alert:e,confirm:e,close:e,getParams:e,setParams:e}}()},i=function(e,t){return function(){return t?t.apply(e,arguments):undefined}},a=function(e){var t;r.push(e),t=e,n.fire("OpenWindow",{dialog:t})},u=function(t){var e;e=t,n.fire("CloseWindow",{dialog:e}),0===(r=H(r,function(e){return e!==t})).length&&n.focus()},s=function(e){n.editorManager.setActive(n),Cm(n);var t=e();return a(t),t};return n.on("remove",function(){z(r,function(e){o().close(e)})}),{open:function(e,t){return s(function(){return o().open(e,t,u)})},openUrl:function(e){return s(function(){return o().openUrl(e,u)})},alert:function(e,t,n){o().alert(e,i(n||this,t))},confirm:function(e,t,n){o().confirm(e,i(n||this,t))},close:function(){R.from(r[r.length-1]).each(function(e){o().close(e),u(e)})}}},oh=function(e,t){e.notificationManager.open({type:"error",text:t})},ih=function(e,t){e._skinLoaded?oh(e,t):e.on("SkinLoaded",function(){oh(e,t)})},ah=function(e,t,n){var r,o;r=t,o={message:n},e.fire(r,o),V.console.error(n)},uh=function(e,t,n){return n?"Failed to load "+e+": "+n+" from url "+t:"Failed to load "+e+" url: "+t},sh=function(e,t,n){ah(e,"PluginLoadError",uh("plugin",t,n))},ch=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r=V.window.console;r&&(r.error?r.error.apply(r,ge([e],t)):r.log.apply(r,ge([e],t)))},lh=function(t){var e,n,r=(n=(e=t).settings.content_css,q(n)?U(n.split(","),$e):k(n)?n:!1===n||e.inline?[]:["default"]),o=t.editorManager.baseURL+"/skins/content",i="content"+t.editorManager.suffix+".css",a=!0===t.inline;return U(r,function(e){return/^[a-z0-9\-]+$/i.test(e)&&!a?o+"/"+e+"/"+i:t.documentBaseURI.toAbsolute(e)})};var fh=function hE(r,o){var e=function(e){var t=o(e);if(t<=0||null===t){var n=mn(e,r);return parseFloat(n)||0}return t},i=function(o,e){return W(e,function(e,t){var n=mn(o,t),r=n===undefined?0:parseInt(n,10);return isNaN(r)?e:e+r},0)};return{set:function(e,t){if(!O(t)&&!t.match(/^[0-9]+$/))throw new Error(r+".set accepts only positive integer values. Value was "+t);var n=e.dom();un(n)&&(n.style[r]=t+"px")},get:e,getOuter:e,aggregate:i,max:function(e,t,n){var r=i(e,n);return r<t?t-r:0}}}("height",function(e){var t=e.dom();return Bt(e)?t.getBoundingClientRect().height:t.offsetHeight}),dh=function(r,e){return r.view(e).fold(x([]),function(e){var t=r.owner(e),n=dh(r,t);return[e].concat(n)})},mh=/* */Object.freeze({__proto__:null,view:function(e){return(e.dom()===V.document?R.none():R.from(e.dom().defaultView.frameElement)).map(Ne.fromDom)},owner:function(e){return ct(e)}}),ph=function(e){var t,n,r,o=Ne.fromDom(V.document),i=Ft(o),a=(t=e,r=(n=mh).owner(t),dh(n,r)),u=Mt(e),s=$(a,function(e,t){var n=Mt(t);return{left:e.left+n.left(),top:e.top+n.top()}},{left:0,top:0});return Lt(s.left+u.left()+i.left(),s.top+u.top()+i.top())},gh=function(e){return"textarea"===Rt(e)},hh=function(e,t){var n,r=function(e){var t=e.dom().ownerDocument,n=t.body,r=t.defaultView,o=t.documentElement;if(n===e.dom())return Lt(n.offsetLeft,n.offsetTop);var i=It(r.pageYOffset,o.scrollTop),a=It(r.pageXOffset,o.scrollLeft),u=It(o.clientTop,n.clientTop),s=It(o.clientLeft,n.clientLeft);return Mt(e).translate(a-s,i-u)}(e),o=(n=e,fh.get(n));return{element:e,bottom:r.top()+o,height:o,pos:r,cleanup:t}},vh=function(e,t){var n=function(e,t){var n=ht(e);if(0===n.length||gh(e))return{element:e,offset:t};if(t<n.length&&!gh(n[t]))return{element:n[t],offset:0};var r=n[n.length-1];return gh(r)?{element:e,offset:t}:"img"===Rt(r)?{element:r,offset:1}:Ot(r)?{element:r,offset:ef(r).length}:{element:r,offset:ht(r).length}}(e,t),r=Ne.fromHtml('<span data-mce-bogus="all">\ufeff</span>');return Ct(n.element,r),hh(r,function(){return kt(r)})},yh=function(n,r,o,i){xh(n,function(e,t){return Ch(n,r,o,i)},o)},bh=function(e,t,n,r,o){var i,a,u={elm:r.element.dom(),alignToTop:o};i=u,e.fire("ScrollIntoView",i).isDefaultPrevented()||(n(t,Ft(t).top(),r,o),a=u,e.fire("AfterScrollIntoView",a))},Ch=function(e,t,n,r){var o=Ne.fromDom(e.getBody()),i=Ne.fromDom(e.getDoc());o.dom().offsetWidth;var a=vh(Ne.fromDom(n.startContainer),n.startOffset);bh(e,i,t,a,r),a.cleanup()},wh=function(e,t,n,r){var o,i=Ne.fromDom(e.getDoc());bh(e,i,n,(o=t,hh(Ne.fromDom(o),f)),r)},xh=function(e,t,n){var r=n.startContainer,o=n.startOffset,i=n.endContainer,a=n.endOffset;t(Ne.fromDom(r),Ne.fromDom(i));var u=e.dom.createRng();u.setStart(r,o),u.setEnd(i,a),e.selection.setRng(n)},Sh=function(e,t,n,r){var o=e.pos;if(n)Ut(o.left(),o.top(),r);else{var i=o.top()-t+e.height;Ut(o.left(),i,r)}},Nh=function(e,t,n,r,o){var i=n+t,a=r.pos.top(),u=r.bottom,s=n<=u-a;if(a<t)Sh(r,n,!1!==o,e);else if(i<a){Sh(r,n,s?!1!==o:!0===o,e)}else i<u&&!s&&Sh(r,n,!0===o,e)},Eh=function(e,t,n,r){var o=e.dom().defaultView.innerHeight;Nh(e,t,o,n,r)},kh=function(e,t,n,r){var o=e.dom().defaultView.innerHeight;Nh(e,t,o,n,r);var i=ph(n.element),a=Ht(V.window);i.top()<a.y?zt(n.element,!1!==r):i.top()>a.bottom&&zt(n.element,!0===r)},_h=function(e,t,n){return yh(e,Eh,t,n)},Rh=function(e,t,n){return wh(e,t,Eh,n)},Th=function(e,t,n){return yh(e,kh,t,n)},Ah=function(e,t,n){return wh(e,t,kh,n)},Dh=function(e,t,n){(e.inline?_h:Th)(e,t,n)},Oh=function(e){return on(e)||an(e)},Bh=function(e,t,n){var r,o,i,a,u,s=n;if(s.caretPositionFromPoint)(o=s.caretPositionFromPoint(e,t))&&((r=n.createRange()).setStart(o.offsetNode,o.offset),r.collapse(!0));else if(n.caretRangeFromPoint)r=n.caretRangeFromPoint(e,t);else if(s.body.createTextRange){r=s.body.createTextRange();try{r.moveToPoint(e,t),r.collapse(!0)}catch(c){r=function(e,n,t){var r,o,i;if(r=t.elementFromPoint(e,n),o=t.body.createTextRange(),r&&"HTML"!==r.tagName||(r=t.body),o.moveToElementText(r),0<(i=(i=hr.toArray(o.getClientRects())).sort(function(e,t){return(e=Math.abs(Math.max(e.top-n,e.bottom-n)))-(t=Math.abs(Math.max(t.top-n,t.bottom-n)))})).length){n=(i[0].bottom+i[0].top)/2;try{return o.moveToPoint(e,n),o.collapse(!0),o}catch(a){}}return null}(e,t,n)}return i=r,a=n.body,u=i&&i.parentElement?i.parentElement():null,an(function(e,t,n){for(;e&&e!==t;){if(n(e))return e;e=e.parentNode}return null}(u,a,Oh))?null:i}return r},Ph=function(e,t,n,r,o){var i=n?t.startContainer:t.endContainer,a=n?t.startOffset:t.endOffset;return R.from(i).map(Ne.fromDom).map(function(e){return r&&t.collapsed?e:vt(e,o(e,a)).getOr(e)}).bind(function(e){return Dt(e)?R.some(e):ft(e).filter(Dt)}).map(function(e){return e.dom()}).getOr(e)},Lh=function(e,t,n){return Ph(e,t,!0,n,function(e,t){return Math.min(e.dom().childNodes.length,t)})},Ih=function(e,t,n){return Ph(e,t,!1,n,function(e,t){return 0<t?t-1:t})},Mh=function(e,t){for(var n=e;e&&Zt(e)&&0===e.length;)e=t?e.nextSibling:e.previousSibling;return e||n},Fh=function(e,t){void 0===t&&(t={});var n,r,o=t.format?t.format:"html";return n=o,r=t,wg(e).selection.getContent(n,r)},Uh=function(e,t){return e&&t&&e.startContainer===t.startContainer&&e.startOffset===t.startOffset&&e.endContainer===t.endContainer&&e.endOffset===t.endOffset},zh=function(e,t,n){return null!==function(e,t,n){for(;e&&e!==t;){if(n(e))return e;e=e.parentNode}return null}(e,t,n)},jh=function(e,t,n){return zh(e,t,function(e){return e.nodeName===n})},Hh=function(e){return e&&"TABLE"===e.nodeName},Vh=function(e,t,n){for(var r=new ra(t,e.getParent(t.parentNode,e.isBlock)||e.getRoot());t=r[n?"prev":"next"]();)if(rn(t))return!0},qh=function(e,t,n,r,o){var i,a,u=e.getRoot(),s=e.schema.getNonEmptyElements(),c=e.getParent(o.parentNode,e.isBlock)||u;if(r&&rn(o)&&t&&e.isEmpty(c))return R.some(ls(o.parentNode,e.nodeIndex(o)));for(var l,f,d=new ra(o,c);a=d[r?"prev":"next"]();){if("false"===e.getContentEditableParent(a)||(f=u,gu(l=a)&&!1===zh(l,f,Ms)))return R.none();if(Zt(a)&&0<a.nodeValue.length)return!1===jh(a,u,"A")?R.some(ls(a,r?a.nodeValue.length:0)):R.none();if(e.isBlock(a)||s[a.nodeName.toLowerCase()])return R.none();i=a}return n&&i?R.some(ls(i,0)):R.none()},$h=function(e,t,n,r){var o,i,a,u,s,c,l,f,d,m=e.getRoot(),p=!1;if(o=r[(n?"start":"end")+"Container"],i=r[(n?"start":"end")+"Offset"],c=$t(o)&&i===o.childNodes.length,u=e.schema.getNonEmptyElements(),s=n,gu(o))return R.none();if($t(o)&&i>o.childNodes.length-1&&(s=!1),tn(o)&&(o=m,i=0),o===m){if(s&&(a=o.childNodes[0<i?i-1:0])){if(gu(a))return R.none();if(u[a.nodeName]||Hh(a))return R.none()}if(o.hasChildNodes()){if(i=Math.min(!s&&0<i?i-1:i,o.childNodes.length-1),o=o.childNodes[i],i=Zt(o)&&c?o.data.length:0,!t&&o===m.lastChild&&Hh(o))return R.none();if(function(e,t){for(;t&&t!==e;){if(an(t))return!0;t=t.parentNode}return!1}(m,o)||gu(o))return R.none();if(o.hasChildNodes()&&!1===Hh(o)){var g=new ra(a=o,m);do{if(an(a)||gu(a)){p=!1;break}if(Zt(a)&&0<a.nodeValue.length){i=s?0:a.nodeValue.length,o=a,p=!0;break}if(u[a.nodeName.toLowerCase()]&&(!(l=a)||!/^(TD|TH|CAPTION)$/.test(l.nodeName))){i=e.nodeIndex(a),o=a.parentNode,s||i++,p=!0;break}}while(a=s?g.next():g.prev())}}}return t&&(Zt(o)&&0===i&&qh(e,c,t,!0,o).each(function(e){o=e.container(),i=e.offset(),p=!0}),$t(o)&&(!(a=(a=o.childNodes[i])||o.childNodes[i-1])||!rn(a)||(d="A",(f=a).previousSibling&&f.previousSibling.nodeName===d)||Vh(e,a,!1)||Vh(e,a,!0)||qh(e,c,t,!0,a).each(function(e){o=e.container(),i=e.offset(),p=!0}))),s&&!t&&Zt(o)&&i===o.nodeValue.length&&qh(e,c,t,!1,o).each(function(e){o=e.container(),i=e.offset(),p=!0}),p?R.some(ls(o,i)):R.none()},Wh=function(e,t){var n=t.collapsed,r=t.cloneRange(),o=ls.fromRangeStart(t);return $h(e,n,!0,r).each(function(e){n&&ls.isAbove(o,e)||r.setStart(e.container(),e.offset())}),n||$h(e,n,!1,r).each(function(e){r.setEnd(e.container(),e.offset())}),n&&r.collapse(!0),Uh(t,r)?R.none():R.some(r)},Kh=function(e){return 0===e.dom().length?(kt(e),R.none()):R.some(e)},Xh=function(r,e){var t=R.from(e.firstChild).map(Ne.fromDom),n=R.from(e.lastChild).map(Ne.fromDom);r.deleteContents(),r.insertNode(e);var o=t.bind(dt).filter(Ot).bind(Kh),i=n.bind(mt).filter(Ot).bind(Kh);$u(o,t.filter(Ot),function(e,t){var n,r;n=t.dom(),r=e.dom().data,n.insertData(0,r),kt(e)}),$u(i,n.filter(Ot),function(e,t){var n=t.dom().length;t.dom().appendData(e.dom().data),r.setEnd(t.dom(),n),kt(e)}),r.collapse(!1)},Yh=function(e,t,n){void 0===n&&(n={});var r,o=(r=t,pe(pe({format:"html"},n),{set:!0,selection:!0,content:r}));if(o.no_events||!(o=e.fire("BeforeSetContent",o)).isDefaultPrevented()){n.content=function(e,t){if("raw"===t.format)return t.content;var n=e.parser.parse(t.content,pe({isRootContent:!0,forced_root_block:!1},t));return hf({validate:e.validate},e.schema).serialize(n)}(e,o);var i=e.selection.getRng();Xh(i,i.createContextualFragment(n.content)),e.selection.setRng(i),Dh(e,i),o.no_events||e.fire("SetContent",o)}else e.fire("SetContent",o)};function Gh(e){return{getBookmark:N(sl,e),moveToBookmark:N(cl,e)}}(Gh=Gh||{}).isBookmarkNode=ll;var Jh=Gh,Qh=function(t,n,e){if(e.collapsed)return!1;if(rr.browser.isIE()&&e.startOffset===e.endOffset-1&&e.startContainer===e.endContainer){var r=e.startContainer.childNodes[e.startOffset];if($t(r))return F(r.getClientRects(),function(e){return zu(e,t,n)})}return F(e.getClientRects(),function(e){return zu(e,t,n)})},Zh={BACKSPACE:8,DELETE:46,DOWN:40,ENTER:13,LEFT:37,RIGHT:39,SPACEBAR:32,TAB:9,UP:38,END:35,HOME:36,modifierPressed:function(e){return e.shiftKey||e.ctrlKey||e.altKey||this.metaKeyPressed(e)},metaKeyPressed:function(e){return rr.mac?e.metaKey:e.ctrlKey&&!e.altKey}},ev=an,tv=on,nv=function(r,s){var c,l,f,a,d,m,p,g,h,v,y,b,C,w,x,S,N,E=s.dom,u=hr.each,k=s.getDoc(),_=V.document,R=Math.abs,T=Math.round,A=s.getBody();a={nw:[0,0,-1,-1],ne:[1,0,1,-1],se:[1,1,1,1],sw:[0,1,-1,1]};var D=function(e){return e&&("IMG"===e.nodeName||s.dom.is(e,"figure.image"))},n=function(e){var t=e.target;!function(e,t){if("longpress"!==e.type&&0!==e.type.indexOf("touch"))return D(e.target)&&!Qh(e.clientX,e.clientY,t);var n=e.touches[0];return D(e.target)&&!Qh(n.clientX,n.clientY,t)}(e,s.selection.getRng())||e.isDefaultPrevented()||s.selection.select(t)},O=function(e){return s.dom.is(e,"figure.image")?e.querySelector("img"):e},B=function(e){var t=s.getParam("object_resizing");return!1!==t&&!rr.iOS&&("string"!=typeof t&&(t="table,img,figure.image,div"),"false"!==e.getAttribute("data-mce-resize")&&(e!==s.getBody()&&ot(Ne.fromDom(e),t)))},P=function(e,t,n){E.setStyles(O(e),{width:t,height:n})},L=function(e){var t,n,r,o,i,a,u;t=e.screenX-m,n=e.screenY-p,w=t*d[2]+v,x=n*d[3]+y,w=w<5?5:w,x=x<5?5:x,(D(c)&&!1!==s.getParam("resize_img_proportional",!0,"boolean")?!Zh.modifierPressed(e):Zh.modifierPressed(e))&&(R(t)>R(n)?(x=T(w*b),w=T(x/b)):(w=T(x/b),x=T(w*b))),P(l,w,x),r=0<(r=d.startPos.x+t)?r:0,o=0<(o=d.startPos.y+n)?o:0,E.setStyles(f,{left:r,top:o,display:"block"}),f.innerHTML=w+" × "+x,d[2]<0&&l.clientWidth<=w&&E.setStyle(l,"left",g+(v-w)),d[3]<0&&l.clientHeight<=x&&E.setStyle(l,"top",h+(y-x)),(t=A.scrollWidth-S)+(n=A.scrollHeight-N)!==0&&E.setStyles(f,{left:r-t,top:o-n}),C||(i=c,a=v,u=y,s.fire("ObjectResizeStart",{target:i,width:a,height:u}),C=!0)},I=function(){var e=C;C=!1;var t,n,r,o=function(e,t){t&&(c.style[e]||!s.schema.isValid(c.nodeName.toLowerCase(),e)?E.setStyle(O(c),e,t):E.setAttrib(O(c),e,""+t))};e&&(o("width",w),o("height",x)),E.unbind(k,"mousemove",L),E.unbind(k,"mouseup",I),_!==k&&(E.unbind(_,"mousemove",L),E.unbind(_,"mouseup",I)),E.remove(l),E.remove(f),i(c),e&&(t=c,n=w,r=x,s.fire("ObjectResized",{target:t,width:n,height:r}),E.setAttrib(c,"style",E.getAttrib(c,"style"))),s.nodeChanged()},i=function(e){var t,r,o,n,i;M(),U(),t=E.getPos(e,A),g=t.x,h=t.y,i=e.getBoundingClientRect(),r=i.width||i.right-i.left,o=i.height||i.bottom-i.top,c!==e&&(c=e,w=x=0),n=s.fire("ObjectSelected",{target:e}),B(e)&&!n.isDefaultPrevented()?u(a,function(n,e){var t;(t=E.get("mceResizeHandle"+e))&&E.remove(t),t=E.add(A,"div",{id:"mceResizeHandle"+e,"data-mce-bogus":"all","class":"mce-resizehandle",unselectable:!0,style:"cursor:"+e+"-resize; margin:0; padding:0"}),11===rr.ie&&(t.contentEditable=!1),E.bind(t,"mousedown",function(e){var t;e.stopImmediatePropagation(),e.preventDefault(),m=(t=e).screenX,p=t.screenY,v=O(c).clientWidth,y=O(c).clientHeight,b=y/v,(d=n).startPos={x:r*n[0]+g,y:o*n[1]+h},S=A.scrollWidth,N=A.scrollHeight,l=c.cloneNode(!0),E.addClass(l,"mce-clonedresizable"),E.setAttrib(l,"data-mce-bogus","all"),l.contentEditable=!1,l.unSelectabe=!0,E.setStyles(l,{left:g,top:h,margin:0}),P(l,r,o),l.removeAttribute("data-mce-selected"),A.appendChild(l),E.bind(k,"mousemove",L),E.bind(k,"mouseup",I),_!==k&&(E.bind(_,"mousemove",L),E.bind(_,"mouseup",I)),f=E.add(A,"div",{"class":"mce-resize-helper","data-mce-bogus":"all"},v+" × "+y)}),n.elm=t,E.setStyles(t,{left:r*n[0]+g-t.offsetWidth/2,top:o*n[1]+h-t.offsetHeight/2})}):M(),c.setAttribute("data-mce-selected","1")},M=function(){U(),c&&c.removeAttribute("data-mce-selected"),oe(a,function(e,t){var n=E.get("mceResizeHandle"+t);n&&(E.unbind(n),E.remove(n))})},o=function(e){var t,n=function(e,t){if(e)do{if(e===t)return!0}while(e=e.parentNode)};C||s.removed||(u(E.select("img[data-mce-selected],hr[data-mce-selected]"),function(e){e.removeAttribute("data-mce-selected")}),t="mousedown"===e.type?e.target:r.getNode(),n(t=E.$(t).closest("table,img,figure.image,hr")[0],A)&&(z(),n(r.getStart(!0),t)&&n(r.getEnd(!0),t))?i(t):M())},F=function(e){return ev(function(e,t){for(;t&&t!==e;){if(tv(t)||ev(t))return t;t=t.parentNode}return null}(s.getBody(),e))},U=function(){oe(a,function(e){e.elm&&(E.unbind(e.elm),delete e.elm)})},z=function(){try{s.getDoc().execCommand("enableObjectResizing",!1,!1)}catch(e){}};s.on("init",function(){if(z(),rr.browser.isIE()||rr.browser.isEdge()){s.on("mousedown click",function(e){var t=e.target,n=t.nodeName;C||!/^(TABLE|IMG|HR)$/.test(n)||F(t)||(2!==e.button&&s.selection.select(t,"TABLE"===n),"mousedown"===e.type&&s.nodeChanged())});var e=function(e){var t=function(e){Xn.setEditorTimeout(s,function(){return s.selection.select(e)})};if(F(e.target))return e.preventDefault(),void t(e.target);/^(TABLE|IMG|HR)$/.test(e.target.nodeName)&&(e.preventDefault(),"IMG"===e.target.tagName&&t(e.target))};E.bind(A,"mscontrolselect",e),s.on("remove",function(){return E.unbind(A,"mscontrolselect",e)})}var t=Xn.throttle(function(e){s.composing||o(e)});s.on("nodechange ResizeEditor ResizeWindow ResizeContent drop FullscreenStateChanged",t),s.on("keyup compositionend",function(e){c&&"TABLE"===c.nodeName&&t(e)}),s.on("hide blur",M),s.on("contextmenu longpress",n,!0)}),s.on("remove",U);return{isResizable:B,showResizeRect:i,hideResizeRect:M,updateResizeRect:o,destroy:function(){c=l=null}}},rv=function(e,t,n){if(e&&e.hasOwnProperty(t)){var r=H(e[t],function(e){return e!==n});0===r.length?delete e[t]:e[t]=r}};var ov=function(e){return!!e.select},iv=function(e){return!(!e||!e.ownerDocument)&&st(Ne.fromDom(e.ownerDocument),Ne.fromDom(e))},av=function(u,s,e,c){var n,t,l,f,r=function h(i,n){var a,u;return{selectorChangedWithUnbind:function(e,t){return a||(a={},u={},n.on("NodeChange",function(e){var n=e.element,r=i.getParents(n,null,i.getRoot()),o={};hr.each(a,function(e,n){hr.each(r,function(t){if(i.is(t,n))return u[n]||(hr.each(e,function(e){e(!0,{node:t,selector:n,parents:r})}),u[n]=e),o[n]=e,!1})}),hr.each(u,function(e,t){o[t]||(delete u[t],hr.each(e,function(e){e(!1,{node:n,selector:t,parents:r})}))})})),a[e]||(a[e]=[]),a[e].push(t),{unbind:function(){rv(a,e,t),rv(u,e,t)}}}}}(u,c).selectorChangedWithUnbind,o=function(e,t){return Yh(c,e,t)},i=function(e){var t=m();t.collapse(!!e),a(t)},d=function(){return s.getSelection?s.getSelection():s.document.selection},m=function(){var e,t,n,r,o=function(e,t,n){try{return t.compareBoundaryPoints(e,n)}catch(r){return-1}};if(!s)return null;if(null==(r=s.document))return null;if(c.bookmark!==undefined&&!1===Pm(c)){var i=wm(c);if(i.isSome())return i.map(function(e){return Fp(c,[e])[0]}).getOr(r.createRange())}try{(e=d())&&!qt(e.anchorNode)&&(t=0<e.rangeCount?e.getRangeAt(0):e.createRange?e.createRange():r.createRange())}catch(a){}return(t=(t=Fp(c,[t])[0])||(r.createRange?r.createRange():r.body.createTextRange())).setStart&&9===t.startContainer.nodeType&&t.collapsed&&(n=u.getRoot(),t.setStart(n,0),t.setEnd(n,0)),l&&f&&(0===o(t.START_TO_START,t,l)&&0===o(t.END_TO_END,t,l)?t=f:f=l=null),t},a=function(e,t){var n,r;if((o=e)&&(ov(o)||iv(o.startContainer)&&iv(o.endContainer))){var o,i=ov(e)?e:null;if(i){f=null;try{i.select()}catch(a){}}else{if(n=d(),e=c.fire("SetSelectionRange",{range:e,forward:t}).range,n){f=e;try{n.removeAllRanges(),n.addRange(e)}catch(a){}!1===t&&n.extend&&(n.collapse(e.endContainer,e.endOffset),n.extend(e.startContainer,e.startOffset)),l=0<n.rangeCount?n.getRangeAt(0):null}e.collapsed||e.startContainer!==e.endContainer||!n.setBaseAndExtent||rr.ie||e.endOffset-e.startOffset<2&&e.startContainer.hasChildNodes()&&(r=e.startContainer.childNodes[e.startOffset])&&"IMG"===r.tagName&&(n.setBaseAndExtent(e.startContainer,e.startOffset,e.endContainer,e.endOffset),n.anchorNode===e.startContainer&&n.focusNode===e.endContainer||n.setBaseAndExtent(r,0,r,1)),c.fire("AfterSetSelectionRange",{range:e,forward:t})}}},p=function(){var e,t,n=d();return!(n&&n.anchorNode&&n.focusNode)||((e=u.createRng()).setStart(n.anchorNode,n.anchorOffset),e.collapse(!0),(t=u.createRng()).setStart(n.focusNode,n.focusOffset),t.collapse(!0),e.compareBoundaryPoints(e.START_TO_START,t)<=0)},g={bookmarkManager:null,controlSelection:null,dom:u,win:s,serializer:e,editor:c,collapse:i,setCursorLocation:function(e,t){var n=u.createRng();e?(n.setStart(e,t),n.setEnd(e,t),a(n),i(!1)):(Yl(u,n,c.getBody(),!0),a(n))},getContent:function(e){return Fh(c,e)},setContent:o,getBookmark:function(e,t){return n.getBookmark(e,t)},moveToBookmark:function(e){return n.moveToBookmark(e)},select:function(e,t){var r,n,o;return r=u,n=e,o=t,R.from(n).map(function(e){var t=r.nodeIndex(e),n=r.createRng();return n.setStart(e.parentNode,t),n.setEnd(e.parentNode,t+1),o&&(Yl(r,n,e,!0),Yl(r,n,e,!1)),n}).each(a),e},isCollapsed:function(){var e=m(),t=d();return!(!e||e.item)&&(e.compareEndPoints?0===e.compareEndPoints("StartToEnd",e):!t||e.collapsed)},isForward:p,setNode:function(e){return o(u.getOuterHTML(e)),e},getNode:function(){return e=c.getBody(),(t=m())?(r=t.startContainer,o=t.endContainer,i=t.startOffset,a=t.endOffset,n=t.commonAncestorContainer,!t.collapsed&&(r===o&&a-i<2&&r.hasChildNodes()&&(n=r.childNodes[i]),3===r.nodeType&&3===o.nodeType&&(r=r.length===i?Mh(r.nextSibling,!0):r.parentNode,o=0===a?Mh(o.previousSibling,!1):o.parentNode,r&&r===o))?r:n&&3===n.nodeType?n.parentNode:n):e;var e,t,n,r,o,i,a},getSel:d,setRng:a,getRng:m,getStart:function(e){return Lh(c.getBody(),m(),e)},getEnd:function(e){return Ih(c.getBody(),m(),e)},getSelectedBlocks:function(e,t){return function(e,t,n,r){var o,i,a=[];if(i=e.getRoot(),n=e.getParent(n||Lh(i,t,t.collapsed),e.isBlock),r=e.getParent(r||Ih(i,t,t.collapsed),e.isBlock),n&&n!==i&&a.push(n),n&&r&&n!==r)for(var u=new ra(o=n,i);(o=u.next())&&o!==r;)e.isBlock(o)&&a.push(o);return r&&n!==r&&r!==i&&a.push(r),a}(u,m(),e,t)},normalize:function(){var e=m(),t=d();if(1<Hl(t).length||!Gl(c))return e;var n=Wh(u,e);return n.each(function(e){a(e,p())}),n.getOr(e)},selectorChanged:function(e,t){return r(e,t),g},selectorChangedWithUnbind:r,getScrollContainer:function(){for(var e,t=u.getRoot();t&&"BODY"!==t.nodeName;){if(t.scrollHeight>t.clientHeight){e=t;break}t=t.parentNode}return e},scrollIntoView:function(e,t){return r=e,o=t,void((n=c).inline?Rh:Ah)(n,r,o);var n,r,o},placeCaretAt:function(e,t){return a(Bh(e,t,c.getDoc()))},getBoundingClientRect:function(){var e=m();return e.collapsed?ms.fromRangeStart(e).getClientRects()[0]:e.getBoundingClientRect()},destroy:function(){s=l=f=null,t.destroy()}};return n=Jh(g),t=nv(g,c),g.bookmarkManager=n,g.controlSelection=t,g},uv=function(e,a,u){e.addNodeFilter("font",function(e){z(e,function(e){var t,n=a.parse(e.attr("style")),r=e.attr("color"),o=e.attr("face"),i=e.attr("size");r&&(n.color=r),o&&(n["font-family"]=o),i&&(n["font-size"]=u[parseInt(e.attr("size"),10)-1]),e.name="span",e.attr("style",a.serialize(n)),t=e,z(["color","face","size"],function(e){t.attr(e,null)})})})},sv=function(e,t){var n,r=ao();t.convert_fonts_to_spans&&uv(e,r,hr.explode(t.font_size_legacy_values)),n=r,e.addNodeFilter("strike",function(e){z(e,function(e){var t=n.parse(e.attr("style"));t["text-decoration"]="line-through",e.name="span",e.attr("style",n.serialize(t))})})},cv=function(e){var t,n,r=decodeURIComponent(e).split(",");return(n=/data:([^;]+)/.exec(r[0]))&&(t=n[1]),{type:t,data:r[1]}},lv=function(e,t){var n;try{n=V.atob(t)}catch(pE){return R.none()}for(var r=new Uint8Array(n.length),o=0;o<r.length;o++)r[o]=n.charCodeAt(o);return R.some(new V.Blob([r],{type:e}))},fv=function(e){return 0===e.indexOf("blob:")?(i=e,new Mn(function(e,t){var n=function(){t("Cannot convert "+i+" to Blob. Resource might not exist or is inaccessible.")};try{var r=new V.XMLHttpRequest;r.open("GET",i,!0),r.responseType="blob",r.onload=function(){200===this.status?e(this.response):n()},r.onerror=n,r.send()}catch(o){n()}})):0===e.indexOf("data:")?(o=e,new Mn(function(e){var t=cv(o),n=t.type,r=t.data;lv(n,r).fold(function(){return e(new V.Blob([]))},e)})):null;var i,o},dv=0,mv=function(e){return(e||"blobid")+dv++},pv=function(r,o,i,t){var a,u;if(0!==o.src.indexOf("blob:")){var e=cv(o.src),n=e.data,s=e.type;a=n,(u=r.getByData(a,s))?i({image:o,blobInfo:u}):fv(o.src).then(function(e){u=r.create(mv(),e,a),r.add(u),i({image:o,blobInfo:u})},function(e){t(e)})}else(u=r.getByUri(o.src))?i({image:o,blobInfo:u}):fv(o.src).then(function(t){var n;n=t,new Mn(function(e){var t=new V.FileReader;t.onloadend=function(){e(t.result)},t.readAsDataURL(n)}).then(function(e){a=cv(e).data,u=r.create(mv(),t,a),r.add(u),i({image:o,blobInfo:u})})},function(e){t(e)})};function gv(i,a){var u={};return{findAll:function(e,n){var t,r;n=n||x(!0),t=H((r=e)?te(r.getElementsByTagName("img")):[],function(e){var t=e.src;return!!rr.fileApi&&(!e.hasAttribute("data-mce-bogus")&&(!e.hasAttribute("data-mce-placeholder")&&(!(!t||t===rr.transparentSrc)&&(0===t.indexOf("blob:")?!i.isUploaded(t)&&n(e):0===t.indexOf("data:")&&n(e)))))});var o=U(t,function(n){if(u[n.src]!==undefined)return new Mn(function(t){u[n.src].then(function(e){if("string"==typeof e)return e;t({image:n,blobInfo:e.blobInfo})})});var e=new Mn(function(e,t){pv(a,n,e,t)}).then(function(e){return delete u[e.image.src],e})["catch"](function(e){return delete u[n.src],e});return u[n.src]=e});return Mn.all(o)}}}var hv=function(e,t,n,r){(e.padd_empty_with_br||t.insert)&&n[r.name]?r.empty().append(new df("br",1)).shortEnded=!0:r.empty().append(new df("#text",3)).value=oo},vv=function(e,t){return e&&e.firstChild&&e.firstChild===e.lastChild&&e.firstChild.name===t},yv=function(r,e,t,n){return n.isEmpty(e,t,function(e){return t=e,(n=r.getElementRule(t.name))&&n.paddEmpty;var t,n})},bv=function(e,t){var r=t.blob_cache,n=function(t){var e,n=t.attr("src");n!==rr.transparentSrc&&((e=/data:([^;]+);base64,([a-z0-9\+\/=]+)/i.exec(n))?R.some({type:e[1],data:decodeURIComponent(e[2])}):R.none()).bind(function(e){var t=e.type,n=e.data;return R.from(r.getByData(n,t)).orThunk(function(){return lv(t,n).map(function(e){var t=r.create(mv(),e,n);return r.add(t),t})})}).each(function(e){t.attr("src",e.blobUri())})};r&&e.addAttributeFilter("src",function(e){return z(e,n)})},Cv=function(e,g){var h=e.schema;g.remove_trailing_brs&&e.addNodeFilter("br",function(e,t,n){var r,o,i,a,u,s,c,l,f=e.length,d=hr.extend({},h.getBlockElements()),m=h.getNonEmptyElements(),p=h.getNonEmptyElements();for(d.body=1,r=0;r<f;r++)if(i=(o=e[r]).parent,d[o.parent.name]&&o===i.lastChild){for(u=o.prev;u;){if("span"!==(s=u.name)||"bookmark"!==u.attr("data-mce-type")){if("br"!==s)break;if("br"===s){o=null;break}}u=u.prev}o&&(o.remove(),yv(h,m,p,i)&&(c=h.getElementRule(i.name))&&(c.removeEmpty?i.remove():c.paddEmpty&&hv(g,n,d,i)))}else{for(a=o;i&&i.firstChild===a&&i.lastChild===a&&!d[(a=i).name];)i=i.parent;a===i&&!0!==g.padd_empty_with_br&&((l=new df("#text",3)).value=oo,o.replace(l))}}),e.addAttributeFilter("href",function(e){var t=e.length,n=function(e){var t=e?hr.trim(e):"";return/\b(noopener)\b/g.test(t)?t:t.split(" ").filter(function(e){return 0<e.length}).concat(["noopener"]).sort().join(" ")};if(!g.allow_unsafe_link_target)for(;t--;){var r=e[t];"a"===r.name&&"_blank"===r.attr("target")&&r.attr("rel",n(r.attr("rel")))}}),g.allow_html_in_named_anchor||e.addAttributeFilter("id,name",function(e){for(var t,n,r,o,i=e.length;i--;)if("a"===(o=e[i]).name&&o.firstChild&&!o.attr("href"))for(r=o.parent,t=o.lastChild;n=t.prev,r.insert(t,o),t=n;);}),g.fix_list_elements&&e.addNodeFilter("ul,ol",function(e){for(var t,n,r=e.length;r--;)if("ul"===(n=(t=e[r]).parent).name||"ol"===n.name)if(t.prev&&"li"===t.prev.name)t.prev.append(t);else{var o=new df("li",1);o.attr("style","list-style-type: none"),t.wrap(o)}}),g.validate&&h.getValidClasses()&&e.addAttributeFilter("class",function(e){for(var t,n,r,o,i,a,u,s=e.length,c=h.getValidClasses();s--;){for(n=(t=e[s]).attr("class").split(" "),i="",r=0;r<n.length;r++)o=n[r],u=!1,(a=c["*"])&&a[o]&&(u=!0),a=c[t.name],!u&&a&&a[o]&&(u=!0),u&&(i&&(i+=" "),i+=o);i.length||(i=null),t.attr("class",i)}}),bv(e,g)},wv=hr.makeMap,xv=hr.each,Sv=hr.explode,Nv=hr.extend,Ev=function(R,T){void 0===T&&(T=no());var A={},D=[],O={},B={};(R=R||{}).validate=!("validate"in R)||R.validate,R.root_name=R.root_name||"body";var e,t,P=function(e){var t,n,r;(n=e.name)in A&&((r=O[n])?r.push(e):O[n]=[e]),t=D.length;for(;t--;)(n=D[t].name)in e.attributes.map&&((r=B[n])?r.push(e):B[n]=[e]);return e},n={schema:T,addAttributeFilter:function(e,n){xv(Sv(e),function(e){var t;for(t=0;t<D.length;t++)if(D[t].name===e)return void D[t].callbacks.push(n);D.push({name:e,callbacks:[n]})})},getAttributeFilters:function(){return[].concat(D)},addNodeFilter:function(e,n){xv(Sv(e),function(e){var t=A[e];t||(A[e]=t=[]),t.push(n)})},getNodeFilters:function(){var e=[];for(var t in A)A.hasOwnProperty(t)&&e.push({name:t,callbacks:A[t]});return e},filterNode:P,parse:function(e,u){var t,n,r,o,i,a,s,c,l,f,d,m=[];u=u||{},O={},B={},l=Nv(wv("script,style,head,html,body,title,meta,param"),T.getBlockElements());var p,g=T.getNonEmptyElements(),h=T.children,v=R.validate,y="forced_root_block"in u?u.forced_root_block:R.forced_root_block,b=!1===(p=y)?"":!0===p?"p":p,C=T.getWhiteSpaceElements(),w=/^[ \t\r\n]+/,x=/[ \t\r\n]+$/,S=/[ \t\r\n]+/g,N=/^[ \t\r\n]+$/;f=C.hasOwnProperty(u.context)||C.hasOwnProperty(R.root_name);var E=function(e,t){var n,r=new df(e,t);return e in A&&((n=O[e])?n.push(r):O[e]=[r]),r},k=function(e){var t,n,r,o,i=T.getBlockElements();for(t=e.prev;t&&3===t.type;){if(0<(r=t.value.replace(x,"")).length)return void(t.value=r);if(n=t.next){if(3===n.type&&n.value.length){t=t.prev;continue}if(!i[n.name]&&"script"!==n.name&&"style"!==n.name){t=t.prev;continue}}o=t.prev,t.remove(),t=o}};t=kf({validate:v,allow_script_urls:R.allow_script_urls,allow_conditional_comments:R.allow_conditional_comments,preserve_cdata:R.preserve_cdata,self_closing_elements:function(e){var t,n={};for(t in e)"li"!==t&&"p"!==t&&(n[t]=e[t]);return n}(T.getSelfClosingElements()),cdata:function(e){d.append(E("#cdata",4)).value=e},text:function(e,t){var n,r,o;f||(e=e.replace(S," "),r=d.lastChild,o=l,r&&(o[r.name]||"br"===r.name)&&(e=e.replace(w,""))),0!==e.length&&((n=E("#text",3)).raw=!!t,d.append(n).value=e)},comment:function(e){d.append(E("#comment",8)).value=e},pi:function(e,t){d.append(E(e,7)).value=t,k(d)},doctype:function(e){d.append(E("#doctype",10)).value=e,k(d)},start:function(e,t,n){var r,o,i,a,u;if(i=v?T.getElementRule(e):{}){for((r=E(i.outputName||e,1)).attributes=t,r.shortEnded=n,d.append(r),(u=h[d.name])&&h[r.name]&&!u[r.name]&&m.push(r),o=D.length;o--;)(a=D[o].name)in t.map&&((s=B[a])?s.push(r):B[a]=[r]);l[e]&&k(r),n||(d=r),!f&&C[e]&&(f=!0)}},end:function(e){var t,n,r,o,i,a;if(n=v?T.getElementRule(e):{}){if(l[e]&&!f){if((t=d.firstChild)&&3===t.type)if(0<(r=t.value.replace(w,"")).length)t.value=r,t=t.next;else for(o=t.next,t.remove(),t=o;t&&3===t.type;)r=t.value,o=t.next,0!==r.length&&!N.test(r)||(t.remove(),t=o),t=o;if((t=d.lastChild)&&3===t.type)if(0<(r=t.value.replace(x,"")).length)t.value=r,t=t.prev;else for(o=t.prev,t.remove(),t=o;t&&3===t.type;)r=t.value,o=t.prev,0!==r.length&&!N.test(r)||(t.remove(),t=o),t=o}if(f&&C[e]&&(f=!1),n.removeEmpty&&yv(T,g,C,d))return i=d.parent,l[d.name]?d.empty().remove():d.unwrap(),void(d=i);n.paddEmpty&&(vv(a=d,"#text")&&a.firstChild.value===oo||yv(T,g,C,d))&&hv(R,u,l,d),d=d.parent}}},T);var _=d=new df(u.context||R.root_name,11);if(t.parse(e,u.format),v&&m.length&&(u.context?u.invalid=!0:function(e){var t,n,r,o,i,a,u,s,c,l,f,d,m,p,g,h;for(d=wv("tr,td,th,tbody,thead,tfoot,table"),l=T.getNonEmptyElements(),f=T.getWhiteSpaceElements(),m=T.getTextBlockElements(),p=T.getSpecialElements(),t=0;t<e.length;t++)if((n=e[t]).parent&&!n.fixed)if(m[n.name]&&"li"===n.parent.name){for(g=n.next;g&&m[g.name];)g.name="li",g.fixed=!0,n.parent.insert(g,n.parent),g=g.next;n.unwrap(n)}else{for(o=[n],r=n.parent;r&&!T.isValidChild(r.name,n.name)&&!d[r.name];r=r.parent)o.push(r);if(r&&1<o.length){for(o.reverse(),i=a=P(o[0].clone()),c=0;c<o.length-1;c++){for(T.isValidChild(a.name,o[c].name)?(u=P(o[c].clone()),a.append(u)):u=a,s=o[c].firstChild;s&&s!==o[c+1];)h=s.next,u.append(s),s=h;a=u}yv(T,l,f,i)?r.insert(n,o[0],!0):(r.insert(i,o[0],!0),r.insert(n,i)),r=o[0],(yv(T,l,f,r)||vv(r,"br"))&&r.empty().remove()}else if(n.parent){if("li"===n.name){if((g=n.prev)&&("ul"===g.name||"ul"===g.name)){g.append(n);continue}if((g=n.next)&&("ul"===g.name||"ul"===g.name)){g.insert(n,g.firstChild,!0);continue}n.wrap(P(new df("ul",1)));continue}T.isValidChild(n.parent.name,"div")&&T.isValidChild("div",n.name)?n.wrap(P(new df("div",1))):p[n.name]?n.empty().remove():n.unwrap()}}}(m)),b&&("body"===_.name||u.isRootContent)&&function(){var e,t,n=_.firstChild,r=function(e){e&&((n=e.firstChild)&&3===n.type&&(n.value=n.value.replace(w,"")),(n=e.lastChild)&&3===n.type&&(n.value=n.value.replace(x,"")))};if(T.isValidChild(_.name,b.toLowerCase())){for(;n;)e=n.next,3===n.type||1===n.type&&"p"!==n.name&&!l[n.name]&&!n.attr("data-mce-type")?(t||((t=E(b,1)).attr(R.forced_root_block_attrs),_.insert(t,n)),t.append(n)):(r(t),t=null),n=e;r(t)}}(),!u.invalid){for(c in O)if(O.hasOwnProperty(c)){for(s=A[c],i=(n=O[c]).length;i--;)n[i].parent||n.splice(i,1);for(r=0,o=s.length;r<o;r++)s[r](n,c,u)}for(r=0,o=D.length;r<o;r++)if((s=D[r]).name in B){for(i=(n=B[s.name]).length;i--;)n[i].parent||n.splice(i,1);for(i=0,a=s.callbacks.length;i<a;i++)s.callbacks[i](n,s.name,u)}}return _}};return Cv(n,R),e=n,(t=R).inline_styles&&sv(e,t),n},kv=function(e,t,n){return m=n,(d=e)&&d.hasEventListeners("PreProcess")&&!m.no_events?(o=t,i=n,f=(r=e).dom,o=o.cloneNode(!0),(a=V.document.implementation).createHTMLDocument&&(u=a.createHTMLDocument(""),hr.each("BODY"===o.nodeName?o.childNodes:[o],function(e){u.body.appendChild(u.importNode(e,!0))}),o="BODY"!==o.nodeName?u.body.firstChild:u.body,s=f.doc,f.doc=u),c=r,l=pe(pe({},i),{node:o}),c.fire("PreProcess",l),s&&(f.doc=s),o):t;var r,o,i,a,u,s,c,l,f,d,m},_v=function(e,t,n){-1===hr.inArray(t,n)&&(e.addAttributeFilter(n,function(e,t){for(var n=e.length;n--;)e[n].attr(t,null)}),t.push(n))},Rv=function(e,t,n,r,o){var i,a,u,s,c,l,f=(i=r,hf(t,n).serialize(i));return a=e,s=f,(u=o).no_events||!a?s:(c=a,l=pe(pe({},u),{content:s}),c.fire("PostProcess",l).content)},Tv=function(y,b){var e=["data-mce-selected"],C=b&&b.dom?b.dom:ga.DOM,w=b&&b.schema?b.schema:no(y);y.entity_encoding=y.entity_encoding||"named",y.remove_trailing_brs=!("remove_trailing_brs"in y)||y.remove_trailing_brs;var t,s,c,x=Ev(y,w);s=y,c=C,(t=x).addAttributeFilter("data-mce-tabindex",function(e,t){for(var n,r=e.length;r--;)(n=e[r]).attr("tabindex",n.attr("data-mce-tabindex")),n.attr(t,null)}),t.addAttributeFilter("src,href,style",function(e,t){for(var n,r,o=e.length,i="data-mce-"+t,a=s.url_converter,u=s.url_converter_scope;o--;)(r=(n=e[o]).attr(i))!==undefined?(n.attr(t,0<r.length?r:null),n.attr(i,null)):(r=n.attr(t),"style"===t?r=c.serializeStyle(c.parseStyle(r),n.name):a&&(r=a.call(u,r,t,n.name)),n.attr(t,0<r.length?r:null))}),t.addAttributeFilter("class",function(e){for(var t,n,r=e.length;r--;)(n=(t=e[r]).attr("class"))&&(n=t.attr("class").replace(/(?:^|\s)mce-item-\w+(?!\S)/g,""),t.attr("class",0<n.length?n:null))}),t.addAttributeFilter("data-mce-type",function(e,t,n){for(var r,o=e.length;o--;){if("bookmark"===(r=e[o]).attr("data-mce-type")&&!n.cleanup)R.from(r.firstChild).exists(function(e){return!cu(e.value)})?r.unwrap():r.remove()}}),t.addNodeFilter("noscript",function(e){for(var t,n=e.length;n--;)(t=e[n].firstChild)&&(t.value=$r.decode(t.value))}),t.addNodeFilter("script,style",function(e,t){for(var n,r,o,i=e.length,a=function(e){return e.replace(/(<!--\[CDATA\[|\]\]-->)/g,"\n").replace(/^[\r\n]*|[\r\n]*$/g,"").replace(/^\s*((<!--)?(\s*\/\/)?\s*<!\[CDATA\[|(<!--\s*)?\/\*\s*<!\[CDATA\[\s*\*\/|(\/\/)?\s*<!--|\/\*\s*<!--\s*\*\/)\s*[\r\n]*/gi,"").replace(/\s*(\/\*\s*\]\]>\s*\*\/(-->)?|\s*\/\/\s*\]\]>(-->)?|\/\/\s*(-->)?|\]\]>|\/\*\s*-->\s*\*\/|\s*-->\s*)\s*$/g,"")};i--;)r=(n=e[i]).firstChild?n.firstChild.value:"","script"===t?((o=n.attr("type"))&&n.attr("type","mce-no/type"===o?null:o.replace(/^mce\-/,"")),"xhtml"===s.element_format&&0<r.length&&(n.firstChild.value="// <![CDATA[\n"+a(r)+"\n// ]]>")):"xhtml"===s.element_format&&0<r.length&&(n.firstChild.value="\x3c!--\n"+a(r)+"\n--\x3e")}),t.addNodeFilter("#comment",function(e){for(var t,n=e.length;n--;)t=e[n],s.preserve_cdata&&0===t.value.indexOf("[CDATA[")?(t.name="#cdata",t.type=4,t.value=c.decode(t.value.replace(/^\[CDATA\[|\]\]$/g,""))):0===t.value.indexOf("mce:protected ")&&(t.name="#text",t.type=3,t.raw=!0,t.value=unescape(t.value).substr(14))}),t.addNodeFilter("xml:namespace,input",function(e,t){for(var n,r=e.length;r--;)7===(n=e[r]).type?n.remove():1===n.type&&("input"!==t||n.attr("type")||n.attr("type","text"))}),t.addAttributeFilter("data-mce-type",function(e){z(e,function(e){"format-caret"===e.attr("data-mce-type")&&(e.isEmpty(t.schema.getNonEmptyElements())?e.remove():e.unwrap())})}),t.addAttributeFilter("data-mce-src,data-mce-href,data-mce-style,data-mce-selected,data-mce-expando,data-mce-type,data-mce-resize,data-mce-placeholder",function(e,t){for(var n=e.length;n--;)e[n].attr(t,null)});return{schema:w,addNodeFilter:x.addNodeFilter,addAttributeFilter:x.addAttributeFilter,serialize:function(e,t){void 0===t&&(t={});var n,r,o,i,a,u,s,c,l,f,d,m,p=pe({format:"html"},t),g=kv(b,e,p),h=(n=C,r=g,i=lu((o=p).getInner?r.innerHTML:n.getOuterHTML(r)),o.selection||Or(Ne.fromDom(r))?i:hr.trim(i)),v=(a=x,u=h,d=(s=p).selection?pe({forced_root_block:!1},s):s,m=a.parse(u,d),(f=function(e){return e&&"br"===e.name})(c=m.lastChild)&&f(l=c.prev)&&(c.remove(),l.remove()),m);return"tree"===p.format?v:Rv(b,y,w,v,p)},addRules:function(e){w.addValidElements(e)},setRules:function(e){w.setValidElements(e)},addTempAttr:N(_v,x,e),getTempAttrs:function(){return e},getNodeFilters:x.getNodeFilters,getAttributeFilters:x.getAttributeFilters}},Av=function(e,t){var n=Tv(e,t);return{schema:n.schema,addNodeFilter:n.addNodeFilter,addAttributeFilter:n.addAttributeFilter,serialize:n.serialize,addRules:n.addRules,setRules:n.setRules,addTempAttr:n.addTempAttr,getTempAttrs:n.getTempAttrs,getNodeFilters:n.getNodeFilters,getAttributeFilters:n.getAttributeFilters}};function Dv(u,s){var r={},n=function(e,r,o,t){var i,n;(i=new V.XMLHttpRequest).open("POST",s.url),i.withCredentials=s.credentials,i.upload.onprogress=function(e){t(e.loaded/e.total*100)},i.onerror=function(){o("Image upload failed due to a XHR Transport error. Code: "+i.status)},i.onload=function(){var e,t,n;i.status<200||300<=i.status?o("HTTP Error: "+i.status):(e=JSON.parse(i.responseText))&&"string"==typeof e.location?r((t=s.basePath,n=e.location,t?t.replace(/\/$/,"")+"/"+n.replace(/^\//,""):n)):o("Invalid JSON: "+i.responseText)},(n=new V.FormData).append("file",e.blob(),e.filename()),i.send(n)},c=function(e,t){return{url:t,blobInfo:e,status:!0}},l=function(e,t){return{url:"",blobInfo:e,status:!1,error:t}},f=function(e,t){hr.each(r[e],function(e){e(t)}),delete r[e]},o=function(e,n){return e=hr.grep(e,function(e){return!u.isUploaded(e.blobUri())}),Mn.all(hr.map(e,function(e){return u.isPending(e.blobUri())?(t=e.blobUri(),new Mn(function(e){r[t]=r[t]||[],r[t].push(e)})):(o=e,i=s.handler,a=n,u.markPending(o.blobUri()),new Mn(function(t){var n;try{var r=function(){n&&n.close()};i(o,function(e){r(),u.markUploaded(o.blobUri(),e),f(o.blobUri(),c(o,e)),t(c(o,e))},function(e){r(),u.removeFailed(o.blobUri()),f(o.blobUri(),l(o,e)),t(l(o,e))},function(e){e<0||100<e||(n=n||a()).progressBar.value(e)})}catch(e){t(l(o,e.message))}}));var o,i,a,t}))};return!1===D(s.handler)&&(s.handler=n),{upload:function(e,t){return s.url||s.handler!==n?o(e,t):new Mn(function(e){e([])})}}}var Ov=0,Bv=function(e){return e+Ov+++(t=function(){return Math.round(4294967295*Math.random()).toString(36)},"s"+(new Date).getTime().toString(36)+t()+t()+t());var t},Pv=function(u){var n,o,e,t,r,i,s=(n=[],o=function(e){var t,n;if(!e.blob||!e.base64)throw new Error("blob and base64 representations of the image are required for BlobInfo to be created");return t=e.id||Bv("blobid"),n=e.name||t,{id:x(t),name:x(n),filename:x(n+"."+({"image/jpeg":"jpg","image/jpg":"jpg","image/gif":"gif","image/png":"png"}[e.blob.type.toLowerCase()]||"dat")),blob:x(e.blob),base64:x(e.base64),blobUri:x(e.blobUri||V.URL.createObjectURL(e.blob)),uri:x(e.uri)}},{create:function(e,t,n,r){if(q(e))return o({id:e,name:r,blob:t,base64:n});if(E(e))return o(e);throw new Error("Unknown input type")},add:function(e){t(e.id())||n.push(e)},get:t=function(t){return e(function(e){return e.id()===t})},getByUri:function(t){return e(function(e){return e.blobUri()===t})},getByData:function(t,n){return e(function(e){return e.base64()===t&&e.blob().type===n})},findFirst:e=function(e){return K(n,e).getOrUndefined()},removeByUri:function(t){n=H(n,function(e){return e.blobUri()!==t||(V.URL.revokeObjectURL(e.blobUri()),!1)})},destroy:function(){z(n,function(e){V.URL.revokeObjectURL(e.blobUri())}),n=[]}}),a=function w(){var n={},r=function(e,t){return{status:e,resultUri:t}},t=function(e){return e in n};return{hasBlobUri:t,getResultUri:function(e){var t=n[e];return t?t.resultUri:null},isPending:function(e){return!!t(e)&&1===n[e].status},isUploaded:function(e){return!!t(e)&&2===n[e].status},markPending:function(e){n[e]=r(1,null)},markUploaded:function(e,t){n[e]=r(2,t)},removeFailed:function(e){delete n[e]},destroy:function(){n={}}}}(),c=[],l=function(t){return function(e){return u.selection?t(e):[]}},f=function(e,t,n){for(var r=0;-1!==(r=e.indexOf(t,r))&&(e=e.substring(0,r)+n+e.substr(r+t.length),r+=n.length-t.length+1),-1!==r;);return e},d=function(e,t,n){return e=f(e,'src="'+t+'"','src="'+n+'"'),e=f(e,'data-mce-src="'+t+'"','data-mce-src="'+n+'"')},m=function(t,n){z(u.undoManager.data,function(e){"fragmented"===e.type?e.fragments=U(e.fragments,function(e){return d(e,t,n)}):e.content=d(e.content,t,n)})},p=function(){return u.notificationManager.open({text:u.translate("Image uploading..."),type:"info",timeout:-1,progressBar:!0})},g=function(e,t){var n,r=u.convertURL(t,"src");m(e.src,t),u.$(e).attr({src:u.getParam("images_reuse_filename",!1,"boolean")?(n=t)+(-1===n.indexOf("?")?"?":"&")+(new Date).getTime():t,"data-mce-src":r})},h=function(n){return r=r||Dv(a,{url:u.getParam("images_upload_url","","string"),basePath:u.getParam("images_upload_base_path","","string"),credentials:u.getParam("images_upload_credentials",!1,"boolean"),handler:u.getParam("images_upload_handler",null,"function")}),b().then(l(function(a){var e=U(a,function(e){return e.blobInfo});return r.upload(e,p).then(l(function(e){var t=U(e,function(e,t){var n,r,o=a[t].blobInfo,i=a[t].image;return e.status&&u.getParam("images_replace_blob_uris",!0,"boolean")?(s.removeByUri(i.src),g(i,e.url)):e.error&&(n=u,r=e.error,ih(n,ka.translate(["Failed to upload image: {0}",r]))),{element:i,status:e.status,uploadUri:e.url,blobInfo:o}});return n&&n(t),t}))}))},v=function(e){if(qs(u))return h(e)},y=function(t){return!1!==G(c,function(e){return e(t)})&&(0!==t.getAttribute("src").indexOf("data:")||u.getParam("images_dataimg_filter",x(!0),"function")(t))},b=function(){return(i=i||gv(a,s)).findAll(u.getBody(),y).then(l(function(e){return e=H(e,function(e){return"string"!=typeof e||(ih(u,e),!1)}),z(e,function(e){m(e.image.src,e.blobInfo.blobUri()),e.image.src=e.blobInfo.blobUri(),e.image.removeAttribute("data-mce-src")}),e}))},C=function(e){return e.replace(/src="(blob:[^"]+)"/g,function(e,n){var t=a.getResultUri(n);if(t)return'src="'+t+'"';var r=s.getByUri(n);return(r=r||W(u.editorManager.get(),function(e,t){return e||t.editorUpload&&t.editorUpload.blobCache.getByUri(n)},null))?'src="data:'+r.blob().type+";base64,"+r.base64()+'"':e})};return u.on("SetContent",function(){(qs(u)?v:b)()}),u.on("RawSaveContent",function(e){e.content=C(e.content)}),u.on("GetContent",function(e){e.source_view||"raw"===e.format||(e.content=C(e.content))}),u.on("PostRender",function(){u.parser.addNodeFilter("img",function(e){z(e,function(e){var t=e.attr("src");if(!s.getByUri(t)){var n=a.getResultUri(t);n&&e.attr("src",n)}})})}),{blobCache:s,addFilter:function(e){c.push(e)},uploadImages:h,uploadImagesAuto:v,scanForImages:b,destroy:function(){s.destroy(),a.destroy(),i=r=null}}},Lv=function(r,e,t,n){var o=ne(t.get()),i={},a={},u=H(El(r.dom,e),function(e){return 1===e.nodeType&&!e.getAttribute("data-mce-bogus")});oe(n,function(e,n){hr.each(u,function(t){return r.formatter.matchNode(t,n,{},e.similar)?(-1===o.indexOf(n)&&(z(e.callbacks,function(e){e(!0,{node:t,format:n,parents:u})}),i[n]=e.callbacks),a[n]=e.callbacks,!1):!$m(r,t,n)&&void 0})});var s=Iv(t.get(),a,e,u);t.set(pe(pe({},i),s))},Iv=function(e,n,r,o){return ce(e,function(e,t){return!!me(n,t)||(z(e,function(e){e(!1,{node:r,format:t,parents:o})}),!1)}).t},Mv=function(e,o,i,a,t){var n,r,u,s,c,l,f,d;return null===o.get()&&(r=e,u=xa({}),(n=o).set({}),r.on("NodeChange",function(e){Lv(r,e.element,u,n.get())})),c=i,l=a,f=t,d=(s=o).get(),z(c.split(","),function(e){d[e]||(d[e]={similar:f,callbacks:[]}),d[e].callbacks.push(l)}),s.set(d),{unbind:function(){return t=i,n=a,r=(e=o).get(),z(t.split(","),function(e){r[e].callbacks=H(r[e].callbacks,function(e){return e!==n}),0===r[e].callbacks.length&&delete r[e]}),void e.set(r);var e,t,n,r}}};function Fv(e){var r,t,n={},o=function(e,t){e&&("string"!=typeof e?hr.each(e,function(e,t){o(t,e)}):(k(t)||(t=[t]),hr.each(t,function(e){"undefined"==typeof e.deep&&(e.deep=!e.selector),"undefined"==typeof e.split&&(e.split=!e.selector||e.inline),"undefined"==typeof e.remove&&e.selector&&!e.inline&&(e.remove="none"),e.selector&&e.inline&&(e.mixed=!0,e.block_expand=!0),"string"==typeof e.classes&&(e.classes=e.classes.split(/\s+/))}),n[e]=t))};return o((r=e.dom,t={valigntop:[{selector:"td,th",styles:{verticalAlign:"top"}}],valignmiddle:[{selector:"td,th",styles:{verticalAlign:"middle"}}],valignbottom:[{selector:"td,th",styles:{verticalAlign:"bottom"}}],alignleft:[{selector:"figure.image",collapsed:!1,classes:"align-left",ceFalseOverride:!0,preview:"font-family font-size"},{selector:"figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li",styles:{textAlign:"left"},inherit:!1,preview:!1,defaultBlock:"div"},{selector:"img,table",collapsed:!1,styles:{"float":"left"},preview:"font-family font-size"}],aligncenter:[{selector:"figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li",styles:{textAlign:"center"},inherit:!1,preview:"font-family font-size",defaultBlock:"div"},{selector:"figure.image",collapsed:!1,classes:"align-center",ceFalseOverride:!0,preview:"font-family font-size"},{selector:"img",collapsed:!1,styles:{display:"block",marginLeft:"auto",marginRight:"auto"},preview:!1},{selector:"table",collapsed:!1,styles:{marginLeft:"auto",marginRight:"auto"},preview:"font-family font-size"}],alignright:[{selector:"figure.image",collapsed:!1,classes:"align-right",ceFalseOverride:!0,preview:"font-family font-size"},{selector:"figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li",styles:{textAlign:"right"},inherit:!1,preview:"font-family font-size",defaultBlock:"div"},{selector:"img,table",collapsed:!1,styles:{"float":"right"},preview:"font-family font-size"}],alignjustify:[{selector:"figure,p,h1,h2,h3,h4,h5,h6,td,th,tr,div,ul,ol,li",styles:{textAlign:"justify"},inherit:!1,defaultBlock:"div",preview:"font-family font-size"}],bold:[{inline:"strong",remove:"all",preserve_attributes:["class","style"]},{inline:"span",styles:{fontWeight:"bold"}},{inline:"b",remove:"all",preserve_attributes:["class","style"]}],italic:[{inline:"em",remove:"all",preserve_attributes:["class","style"]},{inline:"span",styles:{fontStyle:"italic"}},{inline:"i",remove:"all",preserve_attributes:["class","style"]}],underline:[{inline:"span",styles:{textDecoration:"underline"},exact:!0},{inline:"u",remove:"all",preserve_attributes:["class","style"]}],strikethrough:[{inline:"span",styles:{textDecoration:"line-through"},exact:!0},{inline:"strike",remove:"all",preserve_attributes:["class","style"]}],forecolor:{inline:"span",styles:{color:"%value"},links:!0,remove_similar:!0,clear_child_styles:!0},hilitecolor:{inline:"span",styles:{backgroundColor:"%value"},links:!0,remove_similar:!0,clear_child_styles:!0},fontname:{inline:"span",toggle:!1,styles:{fontFamily:"%value"},clear_child_styles:!0},fontsize:{inline:"span",toggle:!1,styles:{fontSize:"%value"},clear_child_styles:!0},fontsize_class:{inline:"span",attributes:{"class":"%value"}},blockquote:{block:"blockquote",wrapper:!0,remove:"all"},subscript:{inline:"sub"},superscript:{inline:"sup"},code:{inline:"code"},link:{inline:"a",selector:"a",remove:"all",split:!0,deep:!0,onmatch:function(){return!0},onformat:function(n,e,t){hr.each(t,function(e,t){r.setAttrib(n,t,e)})}},removeformat:[{selector:"b,strong,em,i,font,u,strike,sub,sup,dfn,code,samp,kbd,var,cite,mark,q,del,ins",remove:"all",split:!0,expand:!1,block_expand:!0,deep:!0},{selector:"span",attributes:["style","class"],remove:"empty",split:!0,expand:!1,deep:!0},{selector:"*",attributes:["style","class"],split:!1,expand:!1,deep:!0}]},hr.each("p h1 h2 h3 h4 h5 h6 div address pre div dt dd samp".split(/\s/),function(e){t[e]={block:e,remove:"all"}}),t)),o(e.settings.formats),{get:function(e){return e?n[e]:n},has:function(e){return me(n,e)},register:o,unregister:function(e){return e&&n[e]&&delete n[e],n}}}var Uv,zv,jv=hr.each,Hv=ga.DOM,Vv=function(e,t){var n,o,r,m=t&&t.schema||no({}),p=function(e){var t,n,r;return o="string"==typeof e?{name:e,classes:[],attrs:{}}:e,t=Hv.create(o.name),n=t,(r=o).classes.length&&Hv.addClass(n,r.classes.join(" ")),Hv.setAttribs(n,r.attrs),t},g=function(n,e,t){var r,o,i,a,u,s,c,l,f=0<e.length&&e[0],d=f&&f.name;if(u=d,s="string"!=typeof(a=n)?a.nodeName.toLowerCase():a,c=m.getElementRule(s),i=!(!(l=c&&c.parentsRequired)||!l.length)&&(u&&-1!==hr.inArray(l,u)?u:l[0]))d===i?(o=e[0],e=e.slice(1)):o=i;else if(f)o=e[0],e=e.slice(1);else if(!t)return n;return o&&(r=p(o)).appendChild(n),t&&(r||(r=Hv.create("div")).appendChild(n),hr.each(t,function(e){var t=p(e);r.insertBefore(t,n)})),g(r,e,o&&o.siblings)};return e&&e.length?(o=e[0],n=p(o),(r=Hv.create("div")).appendChild(g(n,e.slice(1),o.siblings)),r):""},qv=function(e){var t,a={classes:[],attrs:{}};return"*"!==(e=a.selector=hr.trim(e))&&(t=e.replace(/(?:([#\.]|::?)([\w\-]+)|(\[)([^\]]+)\]?)/g,function(e,t,n,r,o){switch(t){case"#":a.attrs.id=n;break;case".":a.classes.push(n);break;case":":-1!==hr.inArray("checked disabled enabled read-only required".split(" "),n)&&(a.attrs[n]=n)}if("["===r){var i=o.match(/([\w\-]+)(?:\=\"([^\"]+))?/);i&&(a.attrs[i[1]]=i[2])}return""})),a.name=t||"div",a},$v=function(n,e){var t,r,o,i,a,u,s="";if(!1===(u=n.settings.preview_styles))return"";"string"!=typeof u&&(u="font-family font-size font-weight font-style text-decoration text-transform color background-color border border-radius outline text-shadow");var c,l=function(e){return e.replace(/%(\w+)/g,"")};if("string"==typeof e){if(!(e=n.formatter.get(e)))return;e=e[0]}return"preview"in e&&!1===(u=e.preview)?"":(t=e.block||e.inline||"span",r=(i=(c=e.selector)&&"string"==typeof c?(c=(c=c.split(/\s*,\s*/)[0]).replace(/\s*(~\+|~|\+|>)\s*/g,"$1"),hr.map(c.split(/(?:>|\s+(?![^\[\]]+\]))/),function(e){var t=hr.map(e.split(/(?:~\+|~|\+)/),qv),n=t.pop();return t.length&&(n.siblings=t),n}).reverse()):[]).length?(i[0].name||(i[0].name=t),t=e.selector,Vv(i,n)):Vv([t],n),o=Hv.select(t,r)[0]||r.firstChild,jv(e.styles,function(e,t){(e=l(e))&&Hv.setStyle(o,t,e)}),jv(e.attributes,function(e,t){(e=l(e))&&Hv.setAttrib(o,t,e)}),jv(e.classes,function(e){e=l(e),Hv.hasClass(o,e)||Hv.addClass(o,e)}),n.fire("PreviewFormats"),Hv.setStyles(r,{position:"absolute",left:-65535}),n.getBody().appendChild(r),a=Hv.getStyle(n.getBody(),"fontSize",!0),a=/px$/.test(a)?parseInt(a,10):0,jv(u.split(" "),function(e){var t=Hv.getStyle(o,e,!0);if(!("background-color"===e&&/transparent|rgba\s*\([^)]+,\s*0\)/.test(t)&&(t=Hv.getStyle(n.getBody(),e,!0),"#ffffff"===Hv.toHex(t).toLowerCase())||"color"===e&&"#000000"===Hv.toHex(t).toLowerCase())){if("font-size"===e&&/em|%$/.test(t)){if(0===a)return;t=parseFloat(t)/(/%$/.test(t)?100:1)*a+"px"}"border"===e&&t&&(s+="padding:0 2px;"),s+=e+":"+t+";"}}),n.fire("AfterPreviewFormats"),Hv.remove(r),s)},Wv=function(s){var e=Fv(s),t=xa(null);return function(e){e.addShortcut("meta+b","","Bold"),e.addShortcut("meta+i","","Italic"),e.addShortcut("meta+u","","Underline");for(var t=1;t<=6;t++)e.addShortcut("access+"+t,"",["FormatBlock",!1,"h"+t]);e.addShortcut("access+7","",["FormatBlock",!1,"p"]),e.addShortcut("access+8","",["FormatBlock",!1,"div"]),e.addShortcut("access+9","",["FormatBlock",!1,"address"])}(s),lp(s),{get:e.get,has:e.has,register:e.register,unregister:e.unregister,apply:function(e,t,n){var r,o,i;r=e,o=t,i=n,wg(s).formatter.apply(r,o,i)},remove:function(e,t,n,r){var o,i,a,u;o=e,i=t,a=n,u=r,wg(s).formatter.remove(o,i,a,u)},toggle:function(e,t,n){var r,o,i;r=e,o=t,i=n,wg(s).formatter.toggle(r,o,i)},match:N(Gm,s),matchAll:N(Jm,s),matchNode:N(Ym,s),canApply:N(Qm,s),formatChanged:N(Mv,s,t),getCssText:N($v,s)}},Kv=function(n,r,o){var i=xa(!1),a=function(e){dg(r,!1,o),r.add({},e)};n.on("init",function(){r.add()}),n.on("BeforeExecCommand",function(e){var t=e.command;"Undo"!==t&&"Redo"!==t&&"mceRepaint"!==t&&(mg(r,o),r.beforeChange())}),n.on("ExecCommand",function(e){var t=e.command;"Undo"!==t&&"Redo"!==t&&"mceRepaint"!==t&&a(e)}),n.on("ObjectResizeStart cut",function(){r.beforeChange()}),n.on("SaveContent ObjectResized blur",a),n.on("dragend",a),n.on("keyup",function(e){var t=e.keyCode;e.isDefaultPrevented()||((33<=t&&t<=36||37<=t&&t<=40||45===t||e.ctrlKey)&&(a(),n.nodeChanged()),46!==t&&8!==t||n.nodeChanged(),i.get()&&r.typing&&!1===lg(ag(n),r.data[0])&&(!1===n.isDirty()&&(n.setDirty(!0),n.fire("change",{level:r.data[0],lastLevel:null})),n.fire("TypingUndo"),i.set(!1),n.nodeChanged()))}),n.on("keydown",function(e){var t=e.keyCode;if(!e.isDefaultPrevented())if(33<=t&&t<=36||37<=t&&t<=40||45===t)r.typing&&a(e);else{var n=e.ctrlKey&&!e.altKey||e.metaKey;!(t<16||20<t)||224===t||91===t||r.typing||n||(r.beforeChange(),dg(r,!0,o),r.add({},e),i.set(!0))}}),n.on("mousedown",function(e){r.typing&&a(e)});n.on("input",function(e){var t;e.inputType&&("insertReplacementText"===e.inputType||"insertText"===(t=e).inputType&&null===t.data)&&a(e)}),n.on("AddUndo Undo Redo ClearUndos",function(e){e.isDefaultPrevented()||n.nodeChanged()})},Xv=function(s){var e,c=xa(R.none()),l=xa(0),f=xa(0),d={data:[],typing:!1,beforeChange:function(){var e,t;e=l,t=c,wg(s).undoManager.beforeChange(e,t)},add:function(e,t){return n=d,r=f,o=l,i=c,a=e,u=t,wg(s).undoManager.addUndoLevel(n,r,o,i,a,u);var n,r,o,i,a,u},undo:function(){return e=d,t=l,n=f,wg(s).undoManager.undo(e,t,n);var e,t,n},redo:function(){return e=s,t=f,n=d.data,wg(e).undoManager.redo(t,n);var e,t,n},clear:function(){var e,t;e=d,t=f,wg(s).undoManager.clear(e,t)},reset:function(){var e;e=d,wg(s).undoManager.reset(e)},hasUndo:function(){return e=d,t=f,wg(s).undoManager.hasUndo(e,t);var e,t},hasRedo:function(){return e=d,t=f,wg(s).undoManager.hasRedo(e,t);var e,t},transact:function(e){return t=d,n=l,r=e,wg(s).undoManager.transact(t,n,r);var t,n,r},ignore:function(e){var t,n;t=l,n=e,wg(s).undoManager.ignore(t,n)},extra:function(e,t){var n,r,o,i;n=d,r=f,o=e,i=t,wg(s).undoManager.extra(n,r,o,i)}};return yg(s)||Kv(s,d,l),(e=s).addShortcut("meta+z","","Undo"),e.addShortcut("meta+y,meta+shift+z","","Redo"),d},Yv=[9,27,Zh.HOME,Zh.END,19,20,44,144,145,33,34,45,16,17,18,91,92,93,Zh.DOWN,Zh.UP,Zh.LEFT,Zh.RIGHT].concat(rr.browser.isFirefox()?[224]:[]),Gv="data-mce-placeholder",Jv=function(e){return"keydown"===e.type||"keyup"===e.type},Qv=function(e){var t=e.keyCode;return t===Zh.BACKSPACE||t===Zh.DELETE},Zv=function(a){var e,u=a.dom,s=Hs(a),c=(e=a).getParam("placeholder",Us.getAttrib(e.getElement(),"placeholder"),"string"),l=function(e,t){if(!function(e){if(Jv(e)){var t=e.keyCode;return!Qv(e)&&(Zh.metaKeyPressed(e)||e.altKey||112<=t&&t<=123||M(Yv,t))}return!1}(e)){var n,r,o=a.getBody(),i=!(Jv(n=e)&&!(Qv(n)||"keyup"===n.type&&229===n.keyCode))&&function(e,t,n){if(Gf(Ne.fromDom(t),!1)){var r=""===n,o=t.firstElementChild;return!o||!e.getStyle(t.firstElementChild,"padding-left")&&!e.getStyle(t.firstElementChild,"padding-right")&&(r?!e.isBlock(o):n===o.nodeName.toLowerCase())}return!1}(u,o,s);""!==u.getAttrib(o,Gv)===i&&!t||(u.setAttrib(o,Gv,i?c:null),u.setAttrib(o,"aria-placeholder",i?c:null),r=i,a.fire("PlaceholderToggle",{state:r}),a.on(i?"keydown":"keyup",l),a.off(i?"keyup":"keydown",l))}};c&&a.on("init",function(e){l(e,!0),a.on("change SetContent ExecCommand",l),a.on("paste",function(e){return Xn.setEditorTimeout(a,function(){return l(e)})}),a.on("remove",function(){var e=a.getBody();u.setAttrib(e,Gv,null),u.setAttrib(e,"aria-placeholder",null)})})},ey=function(e){return e.touches===undefined||1!==e.touches.length?R.none():R.some(e.touches[0])},ty=function(a){var u=xa(R.none()),s=xa(!1),r=Aa(function(e){a.fire("longpress",pe(pe({},e),{type:"longpress"})),s.set(!0)},400);a.on("touchstart",function(n){ey(n).each(function(e){r.cancel();var t={x:x(e.clientX),y:x(e.clientY),target:x(n.target)};r.throttle(n),s.set(!1),u.set(R.some(t))})},!0),a.on("touchmove",function(e){r.cancel(),ey(e).each(function(i){u.get().each(function(e){var t,n,r,o;t=i,n=e,r=Math.abs(t.clientX-n.x()),o=Math.abs(t.clientY-n.y()),(5<r||5<o)&&(u.set(R.none()),s.set(!1),a.fire("longpresscancel"))})})},!0),a.on("touchend touchcancel",function(t){r.cancel(),"touchcancel"!==t.type&&u.get().filter(function(e){return e.target().isEqualNode(t.target)}).each(function(){s.get()?t.preventDefault():a.fire("tap",pe(pe({},t),{type:"tap"}))})},!0)},ny=function(e,t){return e.hasOwnProperty(t.nodeName)},ry=function(e,t){if(Zt(t)){if(0===t.nodeValue.length)return!0;if(/^\s+$/.test(t.nodeValue)&&(!t.nextSibling||ny(e,t.nextSibling)))return!0}return!1},oy=function(e){var t,n,r,o,i,a,u,s,c,l,f=e.dom,d=e.selection,m=e.schema,p=m.getBlockElements(),g=d.getStart(),h=e.getBody(),v=Hs(e);if(g&&$t(g)&&v&&(l=h.nodeName.toLowerCase(),m.isValidChild(l,v.toLowerCase())&&(y=p,b=h,C=g,!F(td(Ne.fromDom(C),Ne.fromDom(b)),function(e){return ny(y,e.dom())})))){var y,b,C,w,x;for(n=(t=d.getRng()).startContainer,r=t.startOffset,o=t.endContainer,i=t.endOffset,c=Pm(e),g=h.firstChild;g;)if(w=p,Zt(x=g)||$t(x)&&!ny(w,x)&&!ll(x)){if(ry(p,g)){g=(u=g).nextSibling,f.remove(u);continue}a||(a=f.create(v,Vs(e)),g.parentNode.insertBefore(a,g),s=!0),g=(u=g).nextSibling,a.appendChild(u)}else a=null,g=g.nextSibling;s&&c&&(t.setStart(n,r),t.setEnd(o,i),d.setRng(t),e.nodeChanged())}},iy=function(e,t,n){var r=e?1:-1;return t.setRng(ms(n.container(),n.offset()+r).toRange()),t.getSel().modify("move",e?"forward":"backward","word"),!0},ay=function(e,t){var n=t.selection.getRng(),r=e?ms.fromRangeEnd(n):ms.fromRangeStart(n);return!!D(t.selection.getSel().modify)&&(e&&vu(r)?iy(!0,t.selection,r):!(e||!yu(r))&&iy(!1,t.selection,r))},uy=Zt,sy=function(e){return uy(e)&&e.data[0]===su},cy=function(e){return uy(e)&&e.data[e.data.length-1]===su},ly=function(e){return e.ownerDocument.createTextNode(su)},fy=function(e,t){return(e?function(e){if(uy(e.previousSibling))return cy(e.previousSibling)||e.previousSibling.appendData(su),e.previousSibling;if(uy(e))return sy(e)||e.insertData(0,su),e;var t=ly(e);return e.parentNode.insertBefore(t,e),t}:function(e){if(uy(e.nextSibling))return sy(e.nextSibling)||e.nextSibling.insertData(0,su),e.nextSibling;if(uy(e))return cy(e)||e.appendData(su),e;var t=ly(e);return e.nextSibling?e.parentNode.insertBefore(t,e.nextSibling):e.parentNode.appendChild(t),t})(t)},dy=N(fy,!0),my=N(fy,!1),py=function(e,t){return Zt(e.container())?fy(t,e.container()):fy(t,e.getNode())},gy=function(e,t){var n=t.get();return n&&e.container()===n&&pu(n)},hy=function(n,e){return e.fold(function(e){rc(n.get());var t=dy(e);return n.set(t),R.some(ms(t,t.length-1))},function(e){return Zc(e).map(function(e){if(gy(e,n))return ms(n.get(),1);rc(n.get());var t=py(e,!0);return n.set(t),ms(t,1)})},function(e){return el(e).map(function(e){if(gy(e,n))return ms(n.get(),n.get().length-1);rc(n.get());var t=py(e,!1);return n.set(t),ms(t,t.length-1)})},function(e){rc(n.get());var t=my(e);return n.set(t),R.some(ms(t,1))})},vy=/[\u0591-\u07FF\uFB1D-\uFDFF\uFE70-\uFEFC]/,yy=function(e,t){return ot(Ne.fromDom(t),e.getParam("inline_boundaries_selector","a[href],code,.mce-annotation","string"))},by=function(e){return"rtl"===ga.DOM.getStyle(e,"direction",!0)||(t=e.textContent,vy.test(t));var t},Cy=function(e,t,n){var r,o,i,a=(r=e,o=t,i=n,H(ga.DOM.getParents(i.container(),"*",o),r));return R.from(a[a.length-1])},wy=function(e,t){if(!t)return t;var n=t.container(),r=t.offset();return e?pu(n)?Zt(n.nextSibling)?ms(n.nextSibling,0):ms.after(n):vu(t)?ms(n,r+1):t:pu(n)?Zt(n.previousSibling)?ms(n.previousSibling,n.previousSibling.data.length):ms.before(n):yu(t)?ms(n,r-1):t},xy=N(wy,!0),Sy=N(wy,!1),Ny=function(e,t){for(var n=0;n<e.length;n++){var r=e[n].apply(null,t);if(r.isSome())return r}return R.none()},Ey=hd([{before:["element"]},{start:["element"]},{end:["element"]},{after:["element"]}]),ky=function(e,t){var n=yc(t,e);return n||e},_y=function(e,t,n){var r=xy(n),o=ky(t,r.container());return Cy(e,o,r).fold(function(){return Jc(o,r).bind(N(Cy,e,o)).map(function(e){return Ey.before(e)})},R.none)},Ry=function(e,t){return null===Fs(e,t)},Ty=function(e,t,n){return Cy(e,t,n).filter(N(Ry,t))},Ay=function(e,t,n){var r=Sy(n);return Ty(e,t,r).bind(function(e){return Qc(e,r).isNone()?R.some(Ey.start(e)):R.none()})},Dy=function(e,t,n){var r=xy(n);return Ty(e,t,r).bind(function(e){return Jc(e,r).isNone()?R.some(Ey.end(e)):R.none()})},Oy=function(e,t,n){var r=Sy(n),o=ky(t,r.container());return Cy(e,o,r).fold(function(){return Qc(o,r).bind(N(Cy,e,o)).map(function(e){return Ey.after(e)})},R.none)},By=function(e){return!1===by(Ly(e))},Py=function(e,t,n){return Ny([_y,Ay,Dy,Oy],[e,t,n]).filter(By)},Ly=function(e){return e.fold(d,d,d,d)},Iy=function(e){return e.fold(x("before"),x("start"),x("end"),x("after"))},My=function(e){return e.fold(Ey.before,Ey.before,Ey.after,Ey.after)},Fy=function(e){return e.fold(Ey.start,Ey.start,Ey.end,Ey.end)},Uy=function(a,e,u,t,n,s){return $u(Cy(e,u,t),Cy(e,u,n),function(e,t){return e!==t&&(r=t,o=yc(e,n=u),i=yc(r,n),o&&o===i)?Ey.after(a?e:t):s;var n,r,o,i}).getOr(s)},zy=function(e,r){return e.fold(x(!0),function(e){return n=r,!(Iy(t=e)===Iy(n)&&Ly(t)===Ly(n));var t,n})},jy=function(e,t){return e?t.fold(a(R.some,Ey.start),R.none,a(R.some,Ey.after),R.none):t.fold(R.none,a(R.some,Ey.before),R.none,a(R.some,Ey.end))},Hy=function(e,a,u,s){var t=wy(e,s),c=Py(a,u,t);return Py(a,u,t).bind(N(jy,e)).orThunk(function(){return n=a,r=u,o=c,i=wy(t=e,s),Kc(t,r,i).map(N(wy,t)).fold(function(){return o.map(My)},function(e){return Py(n,r,e).map(N(Uy,t,n,r,i,e)).filter(N(zy,o))}).filter(By);var t,n,r,o,i})},Vy=(N(Hy,!1),N(Hy,!0),function(e,t){var n=e.dom.createRng();n.setStart(t.container(),t.offset()),n.setEnd(t.container(),t.offset()),e.selection.setRng(n)}),qy=function(e){return!1!==e.settings.inline_boundaries},$y=function(e,t){e?t.setAttribute("data-mce-selected","inline-boundary"):t.removeAttribute("data-mce-selected")},Wy=function(t,e,n){return hy(e,n).map(function(e){return Vy(t,e),n})},Ky=function(e,t){if(e.selection.isCollapsed()&&!0!==e.composing&&t.get()){var n=ms.fromRangeStart(e.selection.getRng());ms.isTextPosition(n)&&!1===(vu(r=n)||yu(r))&&(Vy(e,nc(t.get(),n)),t.set(null))}var r},Xy=function(a,u,s){return function(){return!!qy(a)&&(n=u,e=s,r=(t=a).getBody(),o=ms.fromRangeStart(t.selection.getRng()),i=N(yy,t),Hy(e,i,r,o).bind(function(e){return Wy(t,n,e)}).isSome());var t,n,e,r,o,i}},Yy=function(e,t,n){return function(){return!!qy(t)&&ay(e,t)}},Gy=function(u){var s=xa(null),c=N(yy,u);return u.on("NodeChange",function(e){var t,n,r,o,i,a;!qy(u)||rr.browser.isIE()&&e.initial||(t=c,n=u.dom,r=e.parents,o=U(Ua(Ne.fromDom(n.getRoot()),'*[data-mce-selected="inline-boundary"]'),function(e){return e.dom()}),i=H(o,t),a=H(r,t),z(Q(i,a),N($y,!1)),z(Q(a,i),N($y,!0)),Ky(u,s),function(n,r,o,e){if(r.selection.isCollapsed()){var t=H(e,n);z(t,function(e){var t=ms.fromRangeStart(r.selection.getRng());Py(n,r.getBody(),t).bind(function(e){return Wy(r,o,e)})})}}(c,u,s,e.parents))}),s},Jy=N(Yy,!0),Qy=N(Yy,!1),Zy=function(e){return W(e,function(e,t){return e.concat(function(t){var e=function(e){return U(e,function(e){return(e=Lu(e)).node=t,e})};if($t(t))return e(t.getClientRects());if(Zt(t)){var n=t.ownerDocument.createRange();return n.setStart(t,0),n.setEnd(t,t.data.length),e(n.getClientRects())}}(t))},[])};(zv=Uv=Uv||{})[zv.Up=-1]="Up",zv[zv.Down=1]="Down";var eb,tb,nb=function(o,i,a,e,u,t){var n,s,c=0,l=[],r=function(e){var t,n,r;for(r=Zy([e]),-1===o&&(r=r.reverse()),t=0;t<r.length;t++)if(n=r[t],!a(n,s)){if(0<l.length&&i(n,fr(l))&&c++,n.line=c,u(n))return!0;l.push(n)}};return(s=fr(t.getClientRects()))&&(r(n=t.getNode()),function(e,t,n,r){for(;r=vc(r,e,Bu,t);)if(n(r))return}(o,e,r,n)),l},rb=N(nb,Uv.Up,Fu,Uu),ob=N(nb,Uv.Down,Uu,Fu),ib=function(n){return function(e){return t=n,e.line>t;var t}},ab=function(n){return function(e){return t=n,e.line===t;var t}},ub=an,sb=vc,cb=function(e,t){return Math.abs(e.left-t)},lb=function(e,t){return Math.abs(e.right-t)},fb=function(e,t){return e>=t.left&&e<=t.right},db=function(e,o){return cr(e,function(e,t){var n,r;return n=Math.min(cb(e,o),lb(e,o)),r=Math.min(cb(t,o),lb(t,o)),fb(o,t)||!fb(o,e)&&(r===n&&ub(t.node)||r<n)?t:e})},mb=function(e,t,n,r){for(;r=sb(r,e,Bu,t);)if(n(r))return},pb=function(e,t,n){var r,o,i,a,u,s,c,l=Zy(H(te(e.getElementsByTagName("*")),cc)),f=H(l,function(e){return n>=e.top&&n<=e.bottom});return(r=(r=db(f,t))&&db((a=e,c=function(t,e){var n;return n=H(Zy([e]),function(e){return!t(e,u)}),s=s.concat(n),0===n.length},(s=[]).push(u=r),mb(Uv.Up,a,N(c,Fu),u.node),mb(Uv.Down,a,N(c,Uu),u.node),s),t))&&cc(r.node)?(i=t,{node:(o=r).node,before:cb(o,i)<lb(o,i)}):null},gb=on,hb=an,vb=function(e,t,n,r,o){return t._selectionOverrides.showCaret(e,n,r,o)},yb=function(e,t){var n,r;return e.fire("BeforeObjectSelected",{target:t}).isDefaultPrevented()?null:((r=(n=t).ownerDocument.createRange()).selectNode(n),r)},bb=function(e,t,n){var r=Ec(1,e.getBody(),t),o=ms.fromRangeStart(r),i=o.getNode();if(hb(i))return vb(1,e,i,!o.isAtEnd(),!1);var a=o.getNode(!0);if(hb(a))return vb(1,e,a,!1,!1);var u=e.dom.getParent(o.getNode(),function(e){return hb(e)||gb(e)});return hb(u)?vb(1,e,u,!1,n):null},Cb=function(e,t,n){if(!t||!t.collapsed)return t;var r=bb(e,t,n);return r||t};(tb=eb=eb||{})[tb.Br=0]="Br",tb[tb.Block=1]="Block",tb[tb.Wrap=2]="Wrap",tb[tb.Eol=3]="Eol";var wb=function(e,t){return e===fs.Backwards?J(t):t},xb=function(e,t,n,r){for(var o,i,a,u,s,c,l=Hc(n),f=r,d=[];f&&(s=l,c=f,o=t===fs.Forwards?s.next(c):s.prev(c));){if(rn(o.getNode(!1)))return t===fs.Forwards?{positions:wb(t,d).concat([o]),breakType:eb.Br,breakAt:R.some(o)}:{positions:wb(t,d),breakType:eb.Br,breakAt:R.some(o)};if(o.isVisible()){if(e(f,o)){var m=(i=t,a=f,rn((u=o).getNode(i===fs.Forwards))?eb.Br:!1===bc(a,u)?eb.Block:eb.Wrap);return{positions:wb(t,d),breakType:m,breakAt:R.some(o)}}d.push(o),f=o}else f=o}return{positions:wb(t,d),breakType:eb.Eol,breakAt:R.none()}},Sb=function(n,r,o,e){return r(o,e).breakAt.map(function(e){var t=r(o,e).positions;return n===fs.Backwards?t.concat(e):[e].concat(t)}).getOr([])},Nb=function(e,i){return W(e,function(e,o){return e.fold(function(){return R.some(o)},function(r){return $u(Z(r.getClientRects()),Z(o.getClientRects()),function(e,t){var n=Math.abs(i-e.left);return Math.abs(i-t.left)<=n?o:r}).or(e)})},R.none())},Eb=function(t,e){return Z(e.getClientRects()).bind(function(e){return Nb(t,e.left)})},kb=N(xb,ls.isAbove,-1),_b=N(xb,ls.isBelow,1),Rb=N(Sb,-1,kb),Tb=N(Sb,1,_b),Ab=an,Db=ju,Ob=function(e,t,n,r){var o=e===fs.Forwards,i=o?Vf:qf;if(!r.collapsed){var a=Db(r);if(Ab(a))return vb(e,t,a,e===fs.Backwards,!0)}var u=mu(r.startContainer),s=_c(e,t.getBody(),r);if(i(s))return yb(t,s.getNode(!o));var c=wy(o,n(s));if(!c)return u?r:null;if(i(c))return vb(e,t,c.getNode(!o),o,!0);var l=n(c);return l&&i(l)&&Ac(c,l)?vb(e,t,l.getNode(!o),o,!0):u?Cb(t,c.toRange(),!0):null},Bb=function(e,t,n,r){var o,i,a,u,s,c,l,f,d;if(d=Db(r),o=_c(e,t.getBody(),r),i=n(t.getBody(),ib(1),o),a=H(i,ab(1)),s=fr(o.getClientRects()),(Vf(o)||jf(o))&&(d=o.getNode()),(qf(o)||Hf(o))&&(d=o.getNode(!0)),!s)return null;if(c=s.left,(u=db(a,c))&&Ab(u.node))return l=Math.abs(c-u.left),f=Math.abs(c-u.right),vb(e,t,u.node,l<f,!0);if(d){var m=function(e,t,n,r){var o,i,a,u,s,c,l=Hc(t),f=[],d=0,m=function(e){return fr(e.getClientRects())};c=m(u=1===e?(o=l.next,i=Uu,a=Fu,ms.after(r)):(o=l.prev,i=Fu,a=Uu,ms.before(r)));do{if(u.isVisible()&&!a(s=m(u),c)){if(0<f.length&&i(s,fr(f))&&d++,(s=Lu(s)).position=u,s.line=d,n(s))return f;f.push(s)}}while(u=o(u));return f}(e,t.getBody(),ib(1),d);if(u=db(H(m,ab(1)),c))return Cb(t,u.position.toRange(),!0);if(u=fr(H(m,ab(0))))return Cb(t,u.position.toRange(),!0)}},Pb=function(e,t,n){var r,o,i,a,u=Hc(e.getBody()),s=N(Tc,u.next),c=N(Tc,u.prev);if(n.collapsed&&e.settings.forced_root_block){if(!(r=e.dom.getParent(n.startContainer,"PRE")))return;(1===t?s:c)(ms.fromRangeStart(n))||(a=(i=e).dom.create(Hs(i)),(!rr.ie||11<=rr.ie)&&(a.innerHTML='<br data-mce-bogus="1">'),o=a,1===t?e.$(r).after(o):e.$(r).before(o),e.selection.select(o,!0),e.selection.collapse())}},Lb=function(l,f){return function(){var e,t,n,r,o,i,a,u,s,c=(t=f,r=Hc((e=l).getBody()),o=N(Tc,r.next),i=N(Tc,r.prev),a=t?fs.Forwards:fs.Backwards,u=t?o:i,s=e.selection.getRng(),(n=Ob(a,e,u,s))?n:(n=Pb(e,a,s))||null);return!!c&&(l.selection.setRng(c),!0)}},Ib=function(u,s){return function(){var e,t,n,r,o,i,a=(r=(t=s)?1:-1,o=t?ob:rb,i=(e=u).selection.getRng(),(n=Bb(r,e,o,i))?n:(n=Pb(e,r,i))||null);return!!a&&(u.selection.setRng(a),!0)}},Mb=function(r,o){return function(){var t,e=o?ms.fromRangeEnd(r.selection.getRng()):ms.fromRangeStart(r.selection.getRng()),n=(o?_b:kb)(r.getBody(),e);return(o?ee:Z)(n.positions).filter((t=o,function(e){return(t?qf:Vf)(e)})).fold(x(!1),function(e){return r.selection.setRng(e.toRange()),!0})}},Fb=function(o,e){return Y(e,function(e){var t,n,r=(t=Lu(e.getBoundingClientRect()),n=-1,{left:t.left-n,top:t.top-n,right:t.right+2*n,bottom:t.bottom+2*n,width:t.width+n,height:t.height+n});return[{x:r.left,y:o(r),cell:e},{x:r.right,y:o(r),cell:e}]})},Ub=function(e,t,n,r,o){var i,a,u=Ua(Ne.fromDom(n),"td,th,caption").map(function(e){return e.dom()}),s=H(Fb(e,u),function(e){return t(e,o)});return i=r,a=o,W(s,function(e,r){return e.fold(function(){return R.some(r)},function(e){var t=Math.sqrt(Math.abs(e.x-i)+Math.abs(e.y-a)),n=Math.sqrt(Math.abs(r.x-i)+Math.abs(r.y-a));return R.some(n<t?r:e)})},R.none()).map(function(e){return e.cell})},zb=N(Ub,function(e){return e.bottom},function(e,t){return e.y<t}),jb=N(Ub,function(e){return e.top},function(e,t){return e.y>t}),Hb=function(t,n){return Z(n.getClientRects()).bind(function(e){return zb(t,e.left,e.top)}).bind(function(e){return Eb(el(t=e).map(function(e){return kb(t,e).positions.concat(e)}).getOr([]),n);var t})},Vb=function(t,n){return ee(n.getClientRects()).bind(function(e){return jb(t,e.left,e.top)}).bind(function(e){return Eb(Zc(t=e).map(function(e){return[e].concat(_b(t,e).positions)}).getOr([]),n);var t})},qb=function(e,t){e.selection.setRng(t),Dh(e,t)},$b=function(e,t,n){var r,o,i,a,u=e(t,n);return(a=u).breakType===eb.Wrap&&0===a.positions.length||!rn(n.getNode())&&((i=u).breakType===eb.Br&&1===i.positions.length)?(r=e,o=t,!u.breakAt.map(function(e){return r(o,e).breakAt.isSome()}).getOr(!1)):u.breakAt.isNone()},Wb=N($b,kb),Kb=N($b,_b),Xb=function(e,t,n,r){var o,i,a,u,s=e.selection.getRng(),c=t?1:-1;if(sc()&&(o=t,i=s,a=n,u=ms.fromRangeStart(i),Gc(!o,a).map(function(e){return e.isEqual(u)}).getOr(!1))){var l=vb(c,e,n,!t,!0);return qb(e,l),!0}return!1},Yb=function(e,t){var n=t.getNode(e);return $t(n)&&"TABLE"===n.nodeName?R.some(n):R.none()},Gb=function(u,s,c){var e=Yb(!!s,c),t=!1===s;e.fold(function(){return qb(u,c.toRange())},function(a){return Gc(t,u.getBody()).filter(function(e){return e.isEqual(c)}).fold(function(){return qb(u,c.toRange())},function(e){return n=s,o=a,t=c,void((i=Hs(r=u))?r.undoManager.transact(function(){var e=Ne.fromTag(i);ln(e,Vs(r)),St(e,Ne.fromTag("br")),(n?wt:Ct)(Ne.fromDom(o),e);var t=r.dom.createRng();t.setStart(e.dom(),0),t.setEnd(e.dom(),0),qb(r,t)}):qb(r,t.toRange()));var n,r,o,t,i})})},Jb=function(e,t,n,r){var o,i,a,u,s,c,l=e.selection.getRng(),f=ms.fromRangeStart(l),d=e.getBody();if(!t&&Wb(r,f)){var m=(u=d,Hb(s=n,c=f).orThunk(function(){return Z(c.getClientRects()).bind(function(e){return Nb(Rb(u,ms.before(s)),e.left)})}).getOr(ms.before(s)));return Gb(e,t,m),!0}if(t&&Kb(r,f)){m=(o=d,Vb(i=n,a=f).orThunk(function(){return Z(a.getClientRects()).bind(function(e){return Nb(Tb(o,ms.after(i)),e.left)})}).getOr(ms.after(i)));return Gb(e,t,m),!0}return!1},Qb=function(t,n){return function(){return R.from(t.dom.getParent(t.selection.getNode(),"td,th")).bind(function(e){return R.from(t.dom.getParent(e,"table")).map(function(e){return Xb(t,n,e)})}).getOr(!1)}},Zb=function(n,r){return function(){return R.from(n.dom.getParent(n.selection.getNode(),"td,th")).bind(function(t){return R.from(n.dom.getParent(t,"table")).map(function(e){return Jb(n,r,e,t)})}).getOr(!1)}},eC=function(e){return M(["figcaption"],Rt(e))},tC=function(e){var t=V.document.createRange();return t.setStartBefore(e.dom()),t.setEndBefore(e.dom()),t},nC=function(e,t,n){(n?St:xt)(e,t)},rC=function(e,t,n,r){return""===t?(l=e,f=r,d=Ne.fromTag("br"),nC(l,d,f),tC(d)):(o=e,i=r,a=t,u=n,s=Ne.fromTag(a),c=Ne.fromTag("br"),ln(s,u),St(s,c),nC(o,s,i),tC(c));var o,i,a,u,s,c,l,f,d},oC=function(e,t,n){return t?(o=e.dom(),_b(o,n).breakAt.isNone()):(r=e.dom(),kb(r,n).breakAt.isNone());var r,o},iC=function(t,n){var e,r,o=Ne.fromDom(t.getBody()),i=ms.fromRangeStart(t.selection.getRng()),a=Hs(t),u=Vs(t);return e=i,r=N(at,o),Va(Ne.fromDom(e.container()),Sr,r).filter(eC).exists(function(){if(oC(o,n,i)){var e=rC(o,a,u,n);return t.selection.setRng(e),!0}return!1})},aC=function(e,t){return function(){return!!e.selection.isCollapsed()&&iC(e,t)}},uC=function(e,r){return Y(U(e,function(e){return pe({shiftKey:!1,altKey:!1,ctrlKey:!1,metaKey:!1,keyCode:0,action:f},e)}),function(e){return t=e,(n=r).keyCode===t.keyCode&&n.shiftKey===t.shiftKey&&n.altKey===t.altKey&&n.ctrlKey===t.ctrlKey&&n.metaKey===t.metaKey?[e]:[];var t,n})},sC=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];return function(){return e.apply(null,t)}},cC=function(e,t){return K(uC(e,t),function(e){return e.action()})},lC=function(i,a){i.on("keydown",function(e){var t,n,r,o;!1===e.isDefaultPrevented()&&(t=i,n=a,r=e,o=nt().os,cC([{keyCode:Zh.RIGHT,action:Lb(t,!0)},{keyCode:Zh.LEFT,action:Lb(t,!1)},{keyCode:Zh.UP,action:Ib(t,!1)},{keyCode:Zh.DOWN,action:Ib(t,!0)},{keyCode:Zh.RIGHT,action:Qb(t,!0)},{keyCode:Zh.LEFT,action:Qb(t,!1)},{keyCode:Zh.UP,action:Zb(t,!1)},{keyCode:Zh.DOWN,action:Zb(t,!0)},{keyCode:Zh.RIGHT,action:Xy(t,n,!0)},{keyCode:Zh.LEFT,action:Xy(t,n,!1)},{keyCode:Zh.RIGHT,ctrlKey:!o.isOSX(),altKey:o.isOSX(),action:Jy(t,n)},{keyCode:Zh.LEFT,ctrlKey:!o.isOSX(),altKey:o.isOSX(),action:Qy(t,n)},{keyCode:Zh.UP,action:aC(t,!1)},{keyCode:Zh.DOWN,action:aC(t,!0)}],r).each(function(e){r.preventDefault()}))})},fC=function(e,t){return st(e,t)?Va(t,function(e){return kr(e)||Rr(e)},(n=e,function(e){return at(n,Ne.fromDom(e.dom().parentNode))})):R.none();var n},dC=function(e){var t,n,r;e.dom.isEmpty(e.getBody())&&(e.setContent(""),n=(t=e).getBody(),r=n.firstChild&&t.dom.isBlock(n.firstChild)?n.firstChild:n,t.selection.setCursorLocation(r,0))},mC=function(e,t){return{from:e,to:t}},pC=function(e,t){var n=Ne.fromDom(e),r=Ne.fromDom(t.container());return fC(n,r).map(function(e){return{block:e,position:t}})},gC=function(o,i,e){var t=pC(o,ms.fromRangeStart(e)),n=t.bind(function(e){return Kc(i,o,e.position).bind(function(e){return pC(o,e).map(function(e){return t=o,n=i,rn((r=e).position.getNode())&&!1===Gf(r.block)?Gc(!1,r.block.dom()).bind(function(e){return e.isEqual(r.position)?Kc(n,t,e).bind(function(e){return pC(t,e)}):R.some(r)}).getOr(r):r;var t,n,r})})});return $u(t,n,mC).filter(function(e){return!1===at((r=e).from.block,r.to.block)&&ft((n=e).from.block).bind(function(t){return ft(n.to.block).filter(function(e){return at(t,e)})}).isSome()&&(!1===an((t=e).from.block.dom())&&!1===an(t.to.block.dom()));var t,n,r})},hC=function(e){var t,n=(t=ht(e),X(t,Sr).fold(function(){return t},function(e){return t.slice(0,e)}));return z(n,kt),n},vC=function(e,t){var n=nd(t,e);return K(n.reverse(),function(e){return Gf(e)}).each(kt)},yC=function(e,t,n,r){if(Gf(n))return Qf(n),Zc(n.dom());0===H(pt(r),function(e){return!Gf(e)}).length&&Gf(t)&&Ct(r,Ne.fromTag("br"));var o=Qc(n.dom(),ms.before(r.dom()));return z(hC(t),function(e){Ct(r,e)}),vC(e,t),o},bC=function(e,t,n){if(Gf(n))return kt(n),Gf(t)&&Qf(t),Zc(t.dom());var r=el(n.dom());return z(hC(t),function(e){St(n,e)}),vC(e,t),r},CC=function(e,t){return st(t,e)?(n=nd(e,t),R.from(n[n.length-1])):R.none();var n},wC=function(e,t){Gc(e,t.dom()).map(function(e){return e.getNode()}).map(Ne.fromDom).filter(Er).each(kt)},xC=function(e,t,n){return wC(!0,t),wC(!1,n),CC(t,n).fold(N(bC,e,t,n),N(yC,e,t,n))},SC=function(e,t,n,r){return t?xC(e,r,n):xC(e,n,r)},NC=function(t,n){var e,r,o,i=Ne.fromDom(t.getBody()),a=(e=i.dom(),r=n,((o=t.selection.getRng()).collapsed?gC(e,r,o):R.none()).bind(function(e){return SC(i,n,e.from.block,e.to.block)}));return a.each(function(e){t.selection.setRng(e.toRange())}),a.isSome()},EC=function(e,t){var n=Ne.fromDom(t),r=N(at,e);return Ha(n,Dr,r).isSome()},kC=function(e,t){var n,r,o=Qc(e.dom(),ms.fromRangeStart(t)).isNone(),i=Jc(e.dom(),ms.fromRangeEnd(t)).isNone();return!(EC(n=e,(r=t).startContainer)||EC(n,r.endContainer))&&o&&i},_C=function(e){var n,r,o,t,i=Ne.fromDom(e.getBody()),a=e.selection.getRng();return kC(i,a)?((t=e).setContent(""),t.selection.setCursorLocation(),!0):(n=i,r=e.selection,o=r.getRng(),$u(fC(n,Ne.fromDom(o.startContainer)),fC(n,Ne.fromDom(o.endContainer)),function(e,t){return!1===at(e,t)&&(o.deleteContents(),SC(n,!0,e,t).each(function(e){r.setRng(e.toRange())}),!0)}).getOr(!1))},RC=function(e,t){return!e.selection.isCollapsed()&&_C(e)},TC=function(e){return Rc(e).exists(Er)},AC=function(e,t,n){var r=H(nd(Ne.fromDom(n.container()),t),Sr),o=Z(r).getOr(t);return Kc(e,o.dom(),n).filter(TC)},DC=function(e,t){return Rc(t).exists(Er)||AC(!0,e,t).isSome()},OC=function(e,t){return n=t,R.from(n.getNode(!0)).map(Ne.fromDom).exists(Er)||AC(!1,e,t).isSome();var n},BC=N(AC,!1),PC=N(AC,!0),LC=hd([{remove:["element"]},{moveToElement:["element"]},{moveToPosition:["position"]}]),IC=function(e,t,n,r){var o=r.getNode(!1===t);return fC(Ne.fromDom(e),Ne.fromDom(n.getNode())).map(function(e){return Gf(e)?LC.remove(e.dom()):LC.moveToElement(o)}).orThunk(function(){return R.some(LC.moveToElement(o))})},MC=function(u,s,c){return Kc(s,u,c).bind(function(e){return a=e.getNode(),Dr(Ne.fromDom(a))||Rr(Ne.fromDom(a))?R.none():(t=u,o=e,i=function(e){return Nr(Ne.fromDom(e))&&!bc(r,o,t)},kc(!(n=s),r=c).fold(function(){return kc(n,o).fold(x(!1),i)},i)?R.none():s&&an(e.getNode())||!1===s&&an(e.getNode(!0))?IC(u,s,c,e):s&&qf(c)||!1===s&&Vf(c)?R.some(LC.moveToPosition(e)):R.none());var t,n,r,o,i,a})},FC=function(r,e,o){return i=e,a=o.getNode(!1===i),u=i?"after":"before",$t(a)&&a.getAttribute("data-mce-caret")===u?(t=e,n=o.getNode(!1===e),(t&&an(n.nextSibling)?R.some(LC.moveToElement(n.nextSibling)):!1===t&&an(n.previousSibling)?R.some(LC.moveToElement(n.previousSibling)):R.none()).fold(function(){return MC(r,e,o)},R.some)):MC(r,e,o).bind(function(e){return t=r,n=o,e.fold(function(e){return R.some(LC.remove(e))},function(e){return R.some(LC.moveToElement(e))},function(e){return bc(n,e,t)?R.none():R.some(LC.moveToPosition(e))});var t,n});var t,n,i,a,u},UC=function(e,t){return R.from(HC(e.getBody(),t))},zC=function(a,u){var e=a.selection.getNode();return UC(a,e).filter(an).fold(function(){var e,t,n,r,o,i;return(e=a.getBody(),t=u,n=a.selection.getRng(),r=Ec(t?1:-1,e,n),o=ms.fromRangeStart(r),i=Ne.fromDom(e),(!1===t&&qf(o)?R.some(LC.remove(o.getNode(!0))):t&&Vf(o)?R.some(LC.remove(o.getNode())):!1===t&&Vf(o)&&OC(i,o)?BC(i,o).map(function(e){return LC.remove(e.getNode())}):t&&qf(o)&&DC(i,o)?PC(i,o).map(function(e){return LC.remove(e.getNode())}):FC(e,t,o)).map(function(e){return e.fold(function(e){return o._selectionOverrides.hideFakeCaret(),gd(o,i,Ne.fromDom(e)),!0},(r=i=u,function(e){var t=r?ms.before(e):ms.after(e);return n.selection.setRng(t.toRange()),!0}),(t=n=o=a,function(e){return t.selection.setRng(e.toRange()),!0}));var t,n,r,o,i})).getOr(!1)},function(){return!0})},jC=function(t,n){var e=t.selection.getNode();return!!an(e)&&UC(t,e.parentNode).filter(an).fold(function(){var e;return e=Ne.fromDom(t.getBody()),z(Ua(e,".mce-offscreen-selection"),kt),gd(t,n,Ne.fromDom(t.selection.getNode())),dC(t),!0},function(){return!0})},HC=function(e,t){for(;t&&t!==e;){if(on(t)||an(t))return t;t=t.parentNode}return null},VC=function(e){var t,n=HC(e.getBody(),e.selection.getNode());return on(n)&&e.dom.isBlock(n)&&e.dom.isEmpty(n)&&(t=e.dom.create("br",{"data-mce-bogus":"1"}),e.dom.setHTML(n,""),n.appendChild(t),e.selection.setRng(ms.before(t).toRange())),!0},qC=function(e,t){return(e.selection.isCollapsed()?zC:jC)(e,t)},$C=function(e,t,n,r,o,i){var a,u,s=vb(r,e,i.getNode(!o),o,!0);if(t.collapsed){var c=t.cloneRange();o?c.setEnd(s.startContainer,s.startOffset):c.setStart(s.endContainer,s.endOffset),c.deleteContents()}else t.deleteContents();return e.selection.setRng(s),a=e.dom,Zt(u=n)&&0===u.data.length&&a.remove(u),!0},WC=function(e,t){return function(e,t){var n=e.selection.getRng();if(!Zt(n.commonAncestorContainer))return!1;var r=t?fs.Forwards:fs.Backwards,o=Hc(e.getBody()),i=N(Tc,o.next),a=N(Tc,o.prev),u=t?i:a,s=t?Vf:qf,c=_c(r,e.getBody(),n),l=wy(t,u(c));if(!l||!Ac(c,l))return!1;if(s(l))return $C(e,n,c.getNode(),r,t,l);var f=u(l);return!!(f&&s(f)&&Ac(l,f))&&$C(e,n,c.getNode(),r,t,f)}(e,t)},KC=function(t,n){return function(e){return hy(n,e).map(function(e){return Vy(t,e),!0}).getOr(!1)}},XC=function(r,o,i,a){var u=r.getBody(),s=N(yy,r);r.undoManager.ignore(function(){var e,t,n;r.selection.setRng((e=i,t=a,(n=V.document.createRange()).setStart(e.container(),e.offset()),n.setEnd(t.container(),t.offset()),n)),r.execCommand("Delete"),Py(s,u,ms.fromRangeStart(r.selection.getRng())).map(Fy).map(KC(r,o))}),r.nodeChanged()},YC=function(n,r,i,o){var e,t,a=(e=n.getBody(),t=o.container(),yc(t,e)||e),u=N(yy,n),s=Py(u,a,o);return s.bind(function(e){return i?e.fold(x(R.some(Fy(e))),R.none,x(R.some(My(e))),R.none):e.fold(R.none,x(R.some(My(e))),R.none,x(R.some(Fy(e))))}).map(KC(n,r)).getOrThunk(function(){var t=Xc(i,a,o),e=t.bind(function(e){return Py(u,a,e)});return s.isSome()&&e.isSome()?Cy(u,a,o).map(function(e){return!!$u(Zc(o=e),el(o),function(e,t){var n=wy(!0,e),r=wy(!1,t);return Jc(o,n).map(function(e){return e.isEqual(r)}).getOr(!0)}).getOr(!0)&&(gd(n,i,Ne.fromDom(e)),!0);var o}).getOr(!1):e.bind(function(e){return t.map(function(e){return i?XC(n,r,o,e):XC(n,r,e,o),!0})}).getOr(!1)})},GC=function(e,t,n){if(e.selection.isCollapsed()&&!1!==e.settings.inline_boundaries){var r=ms.fromRangeStart(e.selection.getRng());return YC(e,t,n,r)}return!1},JC=function(e){return 1===ht(e).length},QC=function(e,t,n,r){var o,i,a,u,s=N(fp,t),c=U(H(r,s),function(e){return e.dom()});if(0===c.length)gd(t,e,n);else{var l=(o=n.dom(),i=c,a=op(!1),u=sp(i,a.dom()),Ct(Ne.fromDom(o),a),kt(Ne.fromDom(o)),ms(u,0));t.selection.setRng(l.toRange())}},ZC=function(r,o){var t,e=Ne.fromDom(r.getBody()),n=Ne.fromDom(r.selection.getStart()),s=H((t=nd(n,e),X(t,Sr).fold(x(t),function(e){return t.slice(0,e)})),JC);return ee(s).map(function(e){var t,i,a,u,n=ms.fromRangeStart(r.selection.getRng());return i=o,a=n,u=e.dom(),!(!$u(Zc(u),el(u),function(e,t){var n=wy(!0,e),r=wy(!1,t),o=wy(!1,a);return i?Jc(u,o).map(function(e){return e.isEqual(r)&&a.isEqual(n)}).getOr(!1):Qc(u,o).map(function(e){return e.isEqual(n)&&a.isEqual(r)}).getOr(!1)}).getOr(!0)||Ms((t=e).dom())&&np(t.dom()))&&(QC(o,r,e,s),!0)}).getOr(!1)},ew=function(e,t){return!!e.selection.isCollapsed()&&ZC(e,t)},tw=function(e,t){return!!e.selection.isCollapsed()&&(n=e,r=t,o=ms.fromRangeStart(n.selection.getRng()),Kc(r,n.getBody(),o).filter(function(e){return(r?Uf:zf)(e)}).bind(function(e){return R.from(Cc(r?0:-1,e))}).map(function(e){return n.selection.select(e),!0}).getOr(!1));var n,r,o},nw=function(e){var t=parseInt(e,10);return isNaN(t)?0:t},rw=function(e,t){return(e||"table"===Rt(t)?"margin":"padding")+("rtl"===mn(t,"direction")?"-right":"-left")},ow=function(e){var r,t=aw(e);return!e.mode.isReadOnly()&&(1<t.length||(r=e,G(t,function(e){var t=rw(Ks(r),e),n=gn(e,t).map(nw).getOr(0);return"false"!==r.dom.getContentEditable(e.dom())&&0<n})))},iw=function(e){return _r(e)||Rr(e)},aw=function(e){return H(U(e.selection.getSelectedBlocks(),Ne.fromDom),function(e){return!iw(e)&&!ft(e).map(iw).getOr(!1)&&Va(e,function(e){return on(e.dom())||an(e.dom())}).exists(function(e){return on(e.dom())})})},uw=function(e,t){var n=e.dom,r=e.selection,o=e.formatter,i=e.getParam("indentation","40px","string"),a=/[a-z%]+$/i.exec(i)[0],u=parseInt(i,10),s=Ks(e),c=Hs(e);e.queryCommandState("InsertUnorderedList")||e.queryCommandState("InsertOrderedList")||""!==c||n.getParent(r.getNode(),n.isBlock)||o.apply("div"),z(aw(e),function(e){!function(e,t,n,r,o,i){var a=rw(n,Ne.fromDom(i));if("outdent"===t){var u=Math.max(0,nw(i.style[a])-r);e.setStyle(i,a,u?u+o:"")}else{u=nw(i.style[a])+r+o;e.setStyle(i,a,u)}}(n,t,s,u,a,e.dom())})},sw=function(e,t,n){return Yc(e,t,n,Lf)},cw=function(e,t){return K(nd(Ne.fromDom(t.container()),e),Sr)},lw=function(e,n,r){return sw(e,n.dom(),r).forall(function(t){return cw(n,r).fold(function(){return!1===bc(t,r,n.dom())},function(e){return!1===bc(t,r,n.dom())&&st(e,Ne.fromDom(t.container()))})})},fw=function(t,n,r){return cw(n,r).fold(function(){return sw(t,n.dom(),r).forall(function(e){return!1===bc(e,r,n.dom())})},function(e){return sw(t,e.dom(),r).isNone()})},dw=N(fw,!1),mw=N(fw,!0),pw=N(lw,!1),gw=N(lw,!0),hw=function(e,t,n){if(e.selection.isCollapsed()&&ow(e)){var r=e.dom,o=e.selection.getRng(),i=ms.fromRangeStart(o),a=r.getParent(o.startContainer,r.isBlock);if(null!==a&&dw(Ne.fromDom(a),i))return uw(e,"outdent"),!0}return!1},vw=function(o,i){o.on("keydown",function(e){var t,n,r;!1===e.isDefaultPrevented()&&(t=o,n=i,r=e,cC([{keyCode:Zh.BACKSPACE,action:sC(hw,t,!1)},{keyCode:Zh.BACKSPACE,action:sC(qC,t,!1)},{keyCode:Zh.DELETE,action:sC(qC,t,!0)},{keyCode:Zh.BACKSPACE,action:sC(WC,t,!1)},{keyCode:Zh.DELETE,action:sC(WC,t,!0)},{keyCode:Zh.BACKSPACE,action:sC(GC,t,n,!1)},{keyCode:Zh.DELETE,action:sC(GC,t,n,!0)},{keyCode:Zh.BACKSPACE,action:sC(Vd,t,!1)},{keyCode:Zh.DELETE,action:sC(Vd,t,!0)},{keyCode:Zh.BACKSPACE,action:sC(tw,t,!1)},{keyCode:Zh.DELETE,action:sC(tw,t,!0)},{keyCode:Zh.BACKSPACE,action:sC(RC,t,!1)},{keyCode:Zh.DELETE,action:sC(RC,t,!0)},{keyCode:Zh.BACKSPACE,action:sC(NC,t,!1)},{keyCode:Zh.DELETE,action:sC(NC,t,!0)},{keyCode:Zh.BACKSPACE,action:sC(ew,t,!1)},{keyCode:Zh.DELETE,action:sC(ew,t,!0)}],r).each(function(e){r.preventDefault()}))}),o.on("keyup",function(e){var t,n;!1===e.isDefaultPrevented()&&(t=o,n=e,cC([{keyCode:Zh.BACKSPACE,action:sC(VC,t)},{keyCode:Zh.DELETE,action:sC(VC,t)}],n))})},yw=function(e,t){var n,r,o=t,i=e.dom,a=e.schema.getMoveCaretBeforeOnEnterElements();if(t){if(/^(LI|DT|DD)$/.test(t.nodeName)){var u=function(e){for(;e;){if(1===e.nodeType||3===e.nodeType&&e.data&&/[\r\n\s]/.test(e.data))return e;e=e.nextSibling}}(t.firstChild);u&&/^(UL|OL|DL)$/.test(u.nodeName)&&t.insertBefore(i.doc.createTextNode(oo),t.firstChild)}if(r=i.createRng(),t.normalize(),t.hasChildNodes()){for(var s=new ra(t,t);n=s.current();){if(Zt(n)){r.setStart(n,0),r.setEnd(n,0);break}if(a[n.nodeName.toLowerCase()]){r.setStartBefore(n),r.setEndBefore(n);break}o=n,n=s.next()}n||(r.setStart(o,0),r.setEnd(o,0))}else rn(t)?t.nextSibling&&i.isBlock(t.nextSibling)?(r.setStartBefore(t),r.setEndBefore(t)):(r.setStartAfter(t),r.setEndAfter(t)):(r.setStart(t,0),r.setEnd(t,0));e.selection.setRng(r),Dh(e,r)}},bw=function(e){return R.from(e.dom.getParent(e.selection.getStart(!0),e.dom.isBlock))},Cw=function(e,t){return e&&e.parentNode&&e.parentNode.nodeName===t},ww=function(e){return e&&/^(OL|UL|LI)$/.test(e.nodeName)},xw=function(e){var t=e.parentNode;return/^(LI|DT|DD)$/.test(t.nodeName)?t:e},Sw=function(e,t,n){for(var r=e[n?"firstChild":"lastChild"];r&&!$t(r);)r=r[n?"nextSibling":"previousSibling"];return r===t},Nw=function(e,t,n,r,o){var i=e.dom,a=e.selection.getRng();if(n!==e.getBody()){var u;ww(u=n)&&ww(u.parentNode)&&(o="LI");var s,c,l=o?t(o):i.create("BR");if(Sw(n,r,!0)&&Sw(n,r,!1))Cw(n,"LI")?i.insertAfter(l,xw(n)):i.replace(l,n);else if(Sw(n,r,!0))Cw(n,"LI")?(i.insertAfter(l,xw(n)),l.appendChild(i.doc.createTextNode(" ")),l.appendChild(n)):n.parentNode.insertBefore(l,n);else if(Sw(n,r,!1))i.insertAfter(l,xw(n));else{n=xw(n);var f=a.cloneRange();f.setStartAfter(r),f.setEndAfter(n);var d=f.extractContents();"LI"===o&&(c="LI",(s=d).firstChild&&s.firstChild.nodeName===c)?(l=d.firstChild,i.insertAfter(d,n)):(i.insertAfter(d,n),i.insertAfter(l,n))}i.remove(r),yw(e,l)}},Ew=function(e){e.innerHTML='<br data-mce-bogus="1">'},kw=function(e,t){return e.nodeName===t||e.previousSibling&&e.previousSibling.nodeName===t},_w=function(e,t){return t&&e.isBlock(t)&&!/^(TD|TH|CAPTION|FORM)$/.test(t.nodeName)&&!/^(fixed|absolute)/i.test(t.style.position)&&"true"!==e.getContentEditable(t)},Rw=function(e,t,n){return!1===Zt(t)?n:e?1===n&&t.data.charAt(n-1)===su?0:n:n===t.data.length-1&&t.data.charAt(n)===su?t.data.length:n},Tw=function(e,t){var n,r,o=e.getRoot();for(n=t;n!==o&&"false"!==e.getContentEditable(n);)"true"===e.getContentEditable(n)&&(r=n),n=n.parentNode;return n!==o?r:o},Aw=function(o,i,e){R.from(e.style).map(o.dom.parseStyle).each(function(e){var t=function(e){var t={},n=e.dom();if(un(n))for(var r=0;r<n.style.length;r++){var o=n.style.item(r);t[o]=n.style[o]}return t}(Ne.fromDom(i)),n=pe(pe({},t),e);o.dom.setStyles(i,n)});var t=R.from(e["class"]).map(function(e){return e.split(/\s+/)}),n=R.from(i.className).map(function(e){return H(e.split(/\s+/),function(e){return""!==e})});$u(t,n,function(t,e){var n=H(e,function(e){return!M(t,e)}),r=ge(t,n);o.dom.setAttrib(i,"class",r.join(" "))});var r=["style","class"],a=le(e,function(e,t){return!M(r,t)});o.dom.setAttribs(i,a)},Dw=function(e,t){var n=Hs(e);if(n&&n.toLowerCase()===t.tagName.toLowerCase()){var r=Vs(e);Aw(e,t,r)}},Ow=function(a,e){var t,u,s,i,c,n,r,o,l,f,d,m,p,g=a.dom,h=a.schema,v=h.getNonEmptyElements(),y=a.selection.getRng(),b=function(e){var t,n,r,o=s,i=h.getTextInlineElements();if(r=t=e||"TABLE"===f||"HR"===f?g.create(e||m):c.cloneNode(!1),!1===a.getParam("keep_styles",!0))g.setAttrib(t,"style",null),g.setAttrib(t,"class",null);else do{if(i[o.nodeName]){if(Ms(o)||ll(o))continue;n=o.cloneNode(!1),g.setAttrib(n,"id",""),t.hasChildNodes()?n.appendChild(t.firstChild):r=n,t.appendChild(n)}}while((o=o.parentNode)&&o!==u);return Dw(a,t),Ew(r),t},C=function(e){var t,n,r=Rw(e,s,i);if(Zt(s)&&(e?0<r:r<s.nodeValue.length))return!1;if(s.parentNode===c&&p&&!e)return!0;if(e&&$t(s)&&s===c.firstChild)return!0;if(kw(s,"TABLE")||kw(s,"HR"))return p&&!e||!p&&e;var o=new ra(s,c);for(Zt(s)&&(e&&0===r?o.prev():e||r!==s.nodeValue.length||o.next());t=o.current();){if($t(t)){if(!t.getAttribute("data-mce-bogus")&&(n=t.nodeName.toLowerCase(),v[n]&&"br"!==n))return!1}else if(Zt(t)&&!/^[ \t\r\n]*$/.test(t.nodeValue))return!1;e?o.prev():o.next()}return!0},w=function(){r=/^(H[1-6]|PRE|FIGURE)$/.test(f)&&"HGROUP"!==d?b(m):b(),a.getParam("end_container_on_empty_block",!1)&&_w(g,l)&&g.isEmpty(c)?r=g.split(l,c):g.insertAfter(r,c),yw(a,r)};Wh(g,y).each(function(e){y.setStart(e.startContainer,e.startOffset),y.setEnd(e.endContainer,e.endOffset)}),s=y.startContainer,i=y.startOffset,m=Hs(a),n=!(!e||!e.shiftKey);var x,S,N,E,k,_,R=!(!e||!e.ctrlKey);$t(s)&&s.hasChildNodes()&&(p=i>s.childNodes.length-1,s=s.childNodes[Math.min(i,s.childNodes.length-1)]||s,i=p&&Zt(s)?s.nodeValue.length:0),(u=Tw(g,s))&&((m&&!n||!m&&n)&&(s=function(e,t,n,r,o){var i,a,u,s,c,l,f,d=t||"P",m=e.dom,p=Tw(m,r);if(!(a=m.getParent(r,m.isBlock))||!_w(m,a)){if(l=(a=a||p)===e.getBody()||(f=a)&&/^(TD|TH|CAPTION)$/.test(f.nodeName)?a.nodeName.toLowerCase():a.parentNode.nodeName.toLowerCase(),!a.hasChildNodes())return i=m.create(d),Dw(e,i),a.appendChild(i),n.setStart(i,0),n.setEnd(i,0),i;for(s=r;s.parentNode!==a;)s=s.parentNode;for(;s&&!m.isBlock(s);)s=(u=s).previousSibling;if(u&&e.schema.isValidChild(l,d.toLowerCase())){for(i=m.create(d),Dw(e,i),u.parentNode.insertBefore(i,u),s=u;s&&!m.isBlock(s);)c=s.nextSibling,i.appendChild(s),s=c;n.setStart(r,o),n.setEnd(r,o)}}return r}(a,m,y,s,i)),c=g.getParent(s,g.isBlock),l=c?g.getParent(c.parentNode,g.isBlock):null,f=c?c.nodeName.toUpperCase():"","LI"!==(d=l?l.nodeName.toUpperCase():"")||R||(l=(c=l).parentNode,f=d),/^(LI|DT|DD)$/.test(f)&&g.isEmpty(c)?Nw(a,b,l,c,m):m&&c===a.getBody()||(m=m||"P",mu(c)?(r=xu(c),g.isEmpty(c)&&Ew(c),Dw(a,r),yw(a,r)):C()?w():C(!0)?(r=c.parentNode.insertBefore(b(),c),yw(a,kw(c,"HR")?r:c)):((_=(k=y).cloneRange()).setStart(k.startContainer,Rw(!0,k.startContainer,k.startOffset)),_.setEnd(k.endContainer,Rw(!1,k.endContainer,k.endOffset)),(t=_.cloneRange()).setEndAfter(c),o=t.extractContents(),E=o,z(Fa(Ne.fromDom(E),Ot),function(e){var t=e.dom();t.nodeValue=lu(t.nodeValue)}),function(e){for(;Zt(e)&&(e.nodeValue=e.nodeValue.replace(/^[\r\n]+/,"")),e=e.firstChild;);}(o),r=o.firstChild,g.insertAfter(o,c),function(e,t,n){var r,o=n,i=[];if(o){for(;o=o.firstChild;){if(e.isBlock(o))return;$t(o)&&!t[o.nodeName.toLowerCase()]&&i.push(o)}for(r=i.length;r--;)!(o=i[r]).hasChildNodes()||o.firstChild===o.lastChild&&""===o.firstChild.nodeValue?e.remove(o):(a=e,(u=o)&&"A"===u.nodeName&&a.isEmpty(u)&&e.remove(o));var a,u}}(g,v,r),x=g,(S=c).normalize(),(N=S.lastChild)&&!/^(left|right)$/gi.test(x.getStyle(N,"float",!0))||x.add(S,"br"),g.isEmpty(c)&&Ew(c),r.normalize(),g.isEmpty(r)?(g.remove(r),w()):(Dw(a,r),yw(a,r))),g.setAttrib(r,"id",""),a.fire("NewBlock",{newBlock:r})))},Bw=function(e,t,n){var r=e.create("span",{}," ");n.parentNode.insertBefore(r,n),t.scrollIntoView(r),e.remove(r)},Pw=function(e,t,n,r){var o=e.createRng();r?(o.setStartBefore(n),o.setEndBefore(n)):(o.setStartAfter(n),o.setEndAfter(n)),t.setRng(o)},Lw=function(e,t){var n,r,o=e.selection,i=e.dom,a=o.getRng();Wh(i,a).each(function(e){a.setStart(e.startContainer,e.startOffset),a.setEnd(e.endContainer,e.endOffset)});var u=a.startOffset,s=a.startContainer;if(1===s.nodeType&&s.hasChildNodes()){var c=u>s.childNodes.length-1;s=s.childNodes[Math.min(u,s.childNodes.length-1)]||s,u=c&&3===s.nodeType?s.nodeValue.length:0}var l=i.getParent(s,i.isBlock),f=l?i.getParent(l.parentNode,i.isBlock):null,d=f?f.nodeName.toUpperCase():"",m=!(!t||!t.ctrlKey);"LI"!==d||m||(l=f),s&&3===s.nodeType&&u>=s.nodeValue.length&&!function(e,t,n){for(var r,o=new ra(t,n),i=e.getNonEmptyElements();r=o.next();)if(i[r.nodeName.toLowerCase()]||0<r.length)return!0}(e.schema,s,l)&&(n=i.create("br"),a.insertNode(n),a.setStartAfter(n),a.setEndAfter(n),r=!0),n=i.create("br"),Ns(i,a,n),Bw(i,o,n),Pw(i,o,n,r),e.undoManager.add()},Iw=function(e,t){var n=Ne.fromTag("br");Ct(Ne.fromDom(t),n),e.undoManager.add()},Mw=function(e,t){Fw(e.getBody(),t)||wt(Ne.fromDom(t),Ne.fromTag("br"));var n=Ne.fromTag("br");wt(Ne.fromDom(t),n),Bw(e.dom,e.selection,n.dom()),Pw(e.dom,e.selection,n.dom(),!1),e.undoManager.add()},Fw=function(e,t){return n=ms.after(t),!!rn(n.getNode())||Jc(e,ms.after(t)).map(function(e){return rn(e.getNode())}).getOr(!1);var n},Uw=function(e){return e&&"A"===e.nodeName&&"href"in e},zw=function(e){return e.fold(x(!1),Uw,Uw,x(!1))},jw=function(e,t){t.fold(f,N(Iw,e),N(Mw,e),f)},Hw=function(e,t){var n,r,o,i=(r=N(yy,n=e),o=ms.fromRangeStart(n.selection.getRng()),Py(r,n.getBody(),o).filter(zw));i.isSome()?i.each(N(jw,e)):Lw(e,t)},Vw=function(e,t){return bw(e).filter(function(e){return 0<t.length&&ot(Ne.fromDom(e),t)}).isSome()},qw=hd([{br:[]},{block:[]},{none:[]}]),$w=function(e,t){return Vw(n=e,n.getParam("no_newline_selector",""));var n},Ww=function(n){return function(e,t){return""===Hs(e)===n}},Kw=function(n){return function(e,t){return bw(e).filter(function(e){return Rr(Ne.fromDom(e))}).isSome()===n}},Xw=function(n,r){return function(e,t){return bw(e).fold(x(""),function(e){return e.nodeName.toUpperCase()})===n.toUpperCase()===r}},Yw=function(e){return Xw("pre",e)},Gw=function(n){return function(e,t){return e.getParam("br_in_pre",!0)===n}},Jw=function(e,t){return Vw(n=e,n.getParam("br_newline_selector",".mce-toc h2,figcaption,caption"));var n},Qw=function(e,t){return t},Zw=function(e){var t=Hs(e),n=function(e,t){var n,r,o=e.getRoot();for(n=t;n!==o&&"false"!==e.getContentEditable(n);)"true"===e.getContentEditable(n)&&(r=n),n=n.parentNode;return n!==o?r:o}(e.dom,e.selection.getStart());return n&&e.schema.isValidChild(n.nodeName,t||"P")},ex=function(e,t){return function(n,r){return W(e,function(e,t){return e&&t(n,r)},!0)?R.some(t):R.none()}},tx=function(e,t){return Ny([ex([$w],qw.none()),ex([Xw("summary",!0)],qw.br()),ex([Yw(!0),Gw(!1),Qw],qw.br()),ex([Yw(!0),Gw(!1)],qw.block()),ex([Yw(!0),Gw(!0),Qw],qw.block()),ex([Yw(!0),Gw(!0)],qw.br()),ex([Kw(!0),Qw],qw.br()),ex([Kw(!0)],qw.block()),ex([Ww(!0),Qw,Zw],qw.block()),ex([Ww(!0)],qw.br()),ex([Jw],qw.br()),ex([Ww(!1),Qw],qw.br()),ex([Zw],qw.block())],[e,!(!t||!t.shiftKey)]).getOr(qw.none())},nx=function(e,t){tx(e,t).fold(function(){Hw(e,t)},function(){Ow(e,t)},f)},rx=function(o){o.on("keydown",function(e){var t,n,r;e.keyCode===Zh.ENTER&&(t=o,(n=e).isDefaultPrevented()||(n.preventDefault(),(r=t.undoManager).typing&&(r.typing=!1,r.add()),t.undoManager.transact(function(){!1===t.selection.isCollapsed()&&t.execCommand("Delete"),nx(t,n)})))})},ox=function(n,r){var e=r.container(),t=r.offset();return Zt(e)?(e.insertData(t,n),R.some(ls(e,t+n.length))):Rc(r).map(function(e){var t=Ne.fromText(n);return(r.isAtEnd()?wt:Ct)(e,t),ls(t.dom(),n.length)})},ix=N(ox,oo),ax=N(ox," "),ux=function(e){return ls.isTextPosition(e)&&!e.isAtStart()&&!e.isAtEnd()},sx=function(e,t){var n=H(nd(Ne.fromDom(t.container()),e),Sr);return Z(n).getOr(e)},cx=function(e,t){return ux(t)?Pf(t):Pf(t)||Qc(sx(e,t).dom(),t).exists(Pf)},lx=function(e,t){return ux(t)?Bf(t):Bf(t)||Jc(sx(e,t).dom(),t).exists(Bf)},fx=function(e){return Rc(e).bind(function(e){return Va(e,Dt)}).exists(function(e){return t=mn(e,"white-space"),M(["pre","pre-wrap"],t);var t})},dx=function(e,t){return r=t,Qc(e.dom(),r).isNone()||(n=t,Jc(e.dom(),n).isNone())||dw(e,t)||mw(e,t)||OC(e,t)||DC(e,t);var n,r},mx=function(e,t){var n,r,o,i=(r=(n=t).container(),o=n.offset(),Zt(r)&&o<r.data.length?ls(r,o+1):n);return!fx(i)&&(mw(e,i)||gw(e,i)||DC(e,i)||lx(e,i))},px=function(e,t){return n=e,!fx(r=t)&&(dw(n,r)||pw(n,r)||OC(n,r)||cx(n,r))||mx(e,t);var n,r},gx=function(e,t){return fl(e.charAt(t))},hx=function(e){var t=e.container();return Zt(t)&&He(t.data,oo)},vx=function(e){var n,t=e.data,r=(n=t.split(""),U(n,function(e,t){return fl(e)&&0<t&&t<n.length-1&&ml(n[t-1])&&ml(n[t+1])?" ":e}).join(""));return r!==t&&(e.data=r,!0)},yx=function(l,e){return R.some(e).filter(hx).bind(function(e){var t,n,r,o,i,a,u,s,c=e.container();return(i=l,u=(a=c).data,s=ls(a,0),!(!gx(u,0)||px(i,s)||(a.data=" "+u.slice(1),0))||vx(c)||(t=l,r=(n=c).data,o=ls(n,r.length-1),!(!gx(r,r.length-1)||px(t,o)||(n.data=r.slice(0,-1)+" ",0))))?R.some(e):R.none()})},bx=function(t){var e=Ne.fromDom(t.getBody());t.selection.isCollapsed()&&yx(e,ls.fromRangeStart(t.selection.getRng())).each(function(e){t.selection.setRng(e.toRange())})},Cx=function(r,o){return function(e){return t=r,(!fx(n=e)&&(dx(t,n)||cx(t,n)||lx(t,n))?ix:ax)(o);var t,n}},wx=function(e){var t,n,r=ms.fromRangeStart(e.selection.getRng()),o=Ne.fromDom(e.getBody());if(e.selection.isCollapsed()){var i=N(yy,e),a=ms.fromRangeStart(e.selection.getRng());return Py(i,e.getBody(),a).bind((n=o,function(e){return e.fold(function(e){return Qc(n.dom(),ms.before(e))},function(e){return Zc(e)},function(e){return el(e)},function(e){return Jc(n.dom(),ms.after(e))})})).bind(Cx(o,r)).exists((t=e,function(e){return t.selection.setRng(e.toRange()),t.nodeChanged(),!0}))}return!1},xx=function(r){r.on("keydown",function(e){var t,n;!1===e.isDefaultPrevented()&&(t=r,n=e,cC([{keyCode:Zh.SPACEBAR,action:sC(wx,t)}],n).each(function(e){n.preventDefault()}))})},Sx=function(e,t){var n;t.hasAttribute("data-mce-caret")&&(xu(t),(n=e).selection.setRng(n.selection.getRng()),e.selection.scrollIntoView(t))},Nx=function(e,t){var n,r=(n=e,$a(Ne.fromDom(n.getBody()),"*[data-mce-caret]").fold(x(null),function(e){return e.dom()}));if(r)return"compositionstart"===t.type?(t.preventDefault(),t.stopPropagation(),void Sx(e,r)):void(hu(r)&&(Sx(e,r),e.undoManager.add()))},Ex=nt().browser,kx=function(t){var e,n;e=t,n=Ta(function(){e.composing||bx(e)},0),Ex.isIE()&&(e.on("keypress",function(e){n.throttle()}),e.on("remove",function(e){n.cancel()})),t.on("input",function(e){!1===e.isComposing&&bx(t)})},_x=function(r){r.on("keydown",function(e){var t,n;!1===e.isDefaultPrevented()&&(t=r,n=e,cC([{keyCode:Zh.END,action:Mb(t,!0)},{keyCode:Zh.HOME,action:Mb(t,!1)}],n).each(function(e){n.preventDefault()}))})},Rx=function(e){var t,n=Gy(e);(t=e).on("keyup compositionstart",N(Nx,t)),lC(e,n),vw(e,n),rx(e),xx(e),kx(e),_x(e)},Tx=(Ax.prototype.nodeChanged=function(e){var t,n,r,o=this.editor.selection;this.editor.initialized&&o&&!this.editor.settings.disable_nodechange&&!this.editor.mode.isReadOnly()&&(r=this.editor.getBody(),(t=o.getStart(!0)||r).ownerDocument===this.editor.getDoc()&&this.editor.dom.isChildOf(t,r)||(t=r),n=[],this.editor.dom.getParent(t,function(e){if(e===r)return!0;n.push(e)}),(e=e||{}).element=t,e.parents=n,this.editor.fire("NodeChange",e))},Ax.prototype.isSameElementPath=function(e){var t,n;if((n=this.editor.$(e).parentsUntil(this.editor.getBody()).add(e)).length===this.lastPath.length){for(t=n.length;0<=t&&n[t]===this.lastPath[t];t--);if(-1===t)return this.lastPath=n,!0}return this.lastPath=n,!1},Ax);function Ax(r){var o;this.lastPath=[],this.editor=r;var t=this;"onselectionchange"in r.getDoc()||r.on("NodeChange click mouseup keyup focus",function(e){var t,n;n={startContainer:(t=r.selection.getRng()).startContainer,startOffset:t.startOffset,endContainer:t.endContainer,endOffset:t.endOffset},"nodechange"!==e.type&&Uh(n,o)||r.fire("SelectionChange"),o=n}),r.on("contextmenu",function(){r.fire("SelectionChange")}),r.on("SelectionChange",function(){var e=r.selection.getStart(!0);!e||!rr.range&&r.selection.isCollapsed()||Gl(r)&&!t.isSameElementPath(e)&&r.dom.isChildOf(e,r.getBody())&&r.nodeChanged({selectionChange:!0})}),r.on("mouseup",function(e){!e.isDefaultPrevented()&&Gl(r)&&("IMG"===r.selection.getNode().nodeName?Xn.setEditorTimeout(r,function(){r.nodeChanged()}):r.nodeChanged())})}var Dx=function(e){var t,n;(t=e).on("click",function(e){t.dom.getParent(e.target,"details")&&e.preventDefault()}),(n=e).parser.addNodeFilter("details",function(e){z(e,function(e){e.attr("data-mce-open",e.attr("open")),e.attr("open","open")})}),n.serializer.addNodeFilter("details",function(e){z(e,function(e){var t=e.attr("data-mce-open");e.attr("open",q(t)?t:null),e.attr("data-mce-open",null)})})},Ox=function(e){return $t(e)&&kr(Ne.fromDom(e))},Bx=function(t){t.on("click",function(e){3<=e.detail&&function(e){var t=e.selection.getRng(),n=ls.fromRangeStart(t),r=ls.fromRangeEnd(t);if(ls.isElementPosition(n)){var o=n.container();Ox(o)&&Zc(o).each(function(e){return t.setStart(e.container(),e.offset())})}if(ls.isElementPosition(r)){o=n.container();Ox(o)&&el(o).each(function(e){return t.setEnd(e.container(),e.offset())})}e.selection.setRng($d(t))}(t)})},Px=function(e){var t,n,r,o;return o=e.getBoundingClientRect(),n=(t=e.ownerDocument).documentElement,r=t.defaultView,{top:o.top+r.pageYOffset-n.clientTop,left:o.left+r.pageXOffset-n.clientLeft}},Lx=function(e,t){return n=(u=e).inline?Px(u.getBody()):{left:0,top:0},a=(i=e).getBody(),r=i.inline?{left:a.scrollLeft,top:a.scrollTop}:{left:0,top:0},{pageX:(o=function(e,t){if(t.target.ownerDocument===e.getDoc())return{left:t.pageX,top:t.pageY};var n,r,o,i,a,u=Px(e.getContentAreaContainer()),s=(r=(n=e).getBody(),o=n.getDoc().documentElement,i={left:r.scrollLeft,top:r.scrollTop},a={left:r.scrollLeft||o.scrollLeft,top:r.scrollTop||o.scrollTop},n.inline?i:a);return{left:t.pageX-u.left+s.left,top:t.pageY-u.top+s.top}}(e,t)).left-n.left+r.left,pageY:o.top-n.top+r.top};var n,r,o,i,a,u},Ix=an,Mx=on,Fx=function(e){e&&e.parentNode&&e.parentNode.removeChild(e)},Ux=function(u,s){return function(e){if(0===e.button){var t=K(s.dom.getParents(e.target),function(){for(var n=[],e=0;e<arguments.length;e++)n[e]=arguments[e];return function(e){for(var t=0;t<n.length;t++)if(n[t](e))return!0;return!1}}(Ix,Mx)).getOr(null);if(i=s.getBody(),Ix(a=t)&&a!==i){var n=s.dom.getPos(t),r=s.getBody(),o=s.getDoc().documentElement;u.element=t,u.screenX=e.screenX,u.screenY=e.screenY,u.maxX=(s.inline?r.scrollWidth:o.offsetWidth)-2,u.maxY=(s.inline?r.scrollHeight:o.offsetHeight)-2,u.relX=e.pageX-n.x,u.relY=e.pageY-n.y,u.width=t.offsetWidth,u.height=t.offsetHeight,u.ghost=function(e,t,n,r){var o=t.cloneNode(!0);e.dom.setStyles(o,{width:n,height:r}),e.dom.setAttrib(o,"data-mce-selected",null);var i=e.dom.create("div",{"class":"mce-drag-container","data-mce-bogus":"all",unselectable:"on",contenteditable:"false"});return e.dom.setStyles(i,{position:"absolute",opacity:.5,overflow:"hidden",border:0,padding:0,margin:0,width:n,height:r}),e.dom.setStyles(o,{margin:0,boxSizing:"border-box"}),i.appendChild(o),i}(s,t,u.width,u.height)}}var i,a}},zx=function(g,h){var v=Xn.throttle(function(e,t){h._selectionOverrides.hideFakeCaret(),h.selection.placeCaretAt(e,t)},0);return function(e){var t,n,r,o,i,a,u,s,c,l,f,d,m=Math.max(Math.abs(e.screenX-g.screenX),Math.abs(e.screenY-g.screenY));if(g.element&&!g.dragging&&10<m){if(h.fire("dragstart",{target:g.element}).isDefaultPrevented())return;g.dragging=!0,h.focus()}if(g.dragging){var p=(f=g,{pageX:(d=Lx(h,e)).pageX-f.relX,pageY:d.pageY+5});c=g.ghost,l=h.getBody(),c.parentNode!==l&&l.appendChild(c),t=g.ghost,n=p,r=g.width,o=g.height,i=g.maxX,a=g.maxY,s=u=0,t.style.left=n.pageX+"px",t.style.top=n.pageY+"px",n.pageX+r>i&&(u=n.pageX+r-i),n.pageY+o>a&&(s=n.pageY+o-a),t.style.width=r-u+"px",t.style.height=o-s+"px",v(e.clientX,e.clientY)}}},jx=function(l,f){return function(e){if(l.dragging&&(s=(i=f).selection,c=s.getSel().getRangeAt(0).startContainer,a=3===c.nodeType?c.parentNode:c,u=l.element,a!==u&&!i.dom.isChildOf(a,u)&&!Ix(a))){var t=(r=l.element,(o=r.cloneNode(!0)).removeAttribute("data-mce-selected"),o),n=f.fire("drop",{targetClone:t,clientX:e.clientX,clientY:e.clientY});n.isDefaultPrevented()||(t=n.targetClone,f.undoManager.transact(function(){Fx(l.element),f.insertContent(f.dom.getOuterHTML(t)),f._selectionOverrides.hideFakeCaret()}))}var r,o,i,a,u,s,c;Hx(l)}},Hx=function(e){e.dragging=!1,e.element=null,Fx(e.ghost)},Vx=function(e){var t,n,r,o,i,a,u,s,c={};t=ga.DOM,a=V.document,n=Ux(c,e),r=zx(c,e),o=jx(c,e),u=c,i=function(){u.dragging&&s.fire("dragend"),Hx(u)},(s=e).on("mousedown",n),e.on("mousemove",r),e.on("mouseup",o),t.bind(a,"mousemove",r),t.bind(a,"mouseup",i),e.on("remove",function(){t.unbind(a,"mousemove",r),t.unbind(a,"mouseup",i)})},qx=function(e){var n;Vx(e),(n=e).on("drop",function(e){var t="undefined"!=typeof e.clientX?n.getDoc().elementFromPoint(e.clientX,e.clientY):null;(Ix(t)||Ix(n.dom.getContentEditableParent(t)))&&e.preventDefault()})},$x=on,Wx=an,Kx=function(e,t){for(var n=e.getBody();t&&t!==n;){if($x(t)||Wx(t))return t;t=t.parentNode}return null},Xx=function(g){var h,v=g.getBody(),o=uc(g,v,function(e){return g.dom.isBlock(e)},function(){return Pm(g)}),y="sel-"+g.dom.uniqueId(),a=function(e){e&&g.selection.setRng(e)},r=function(){return g.selection.getRng()},b=function(e,t,n,r){return void 0===r&&(r=!0),g.fire("ShowCaret",{target:t,direction:e,before:n}).isDefaultPrevented()?null:(r&&g.selection.scrollIntoView(t,-1===e),o.show(n,t))},t=function(e){return gu(e)||Cu(e)||wu(e)},C=function(e){return t(e.startContainer)||t(e.endContainer)},u=function(e){var t=g.schema.getShortEndedElements(),n=g.dom.createRng(),r=e.startContainer,o=e.startOffset,i=e.endContainer,a=e.endOffset;return me(t,r.nodeName.toLowerCase())?0===o?n.setStartBefore(r):n.setStartAfter(r):n.setStart(r,o),me(t,i.nodeName.toLowerCase())?0===a?n.setEndBefore(i):n.setEndAfter(i):n.setEnd(i,a),n},s=function(e,t){var n,r,o,i,a,u,s,c,l,f,d=g.$,m=g.dom;if(!e)return null;if(e.collapsed){if(!C(e))if(!1===t){if(c=_c(-1,v,e),cc(c.getNode(!0)))return b(-1,c.getNode(!0),!1,!1);if(cc(c.getNode()))return b(-1,c.getNode(),!c.isAtEnd(),!1)}else{if(c=_c(1,v,e),cc(c.getNode()))return b(1,c.getNode(),!c.isAtEnd(),!1);if(cc(c.getNode(!0)))return b(1,c.getNode(!0),!1,!1)}return null}if(i=e.startContainer,a=e.startOffset,u=e.endOffset,3===i.nodeType&&0===a&&Wx(i.parentNode)&&(i=i.parentNode,a=m.nodeIndex(i),i=i.parentNode),1!==i.nodeType)return null;if(u===a+1&&i===e.endContainer&&(n=i.childNodes[a]),!Wx(n))return null;if(l=f=n.cloneNode(!0),(s=g.fire("ObjectSelected",{target:n,targetClone:l})).isDefaultPrevented())return null;r=$a(Ne.fromDom(g.getBody()),"#"+y).fold(function(){return d([])},function(e){return d([e.dom()])}),l=s.targetClone,0===r.length&&(r=d('<div data-mce-bogus="all" class="mce-offscreen-selection"></div>').attr("id",y)).appendTo(g.getBody()),e=g.dom.createRng(),l===f&&rr.ie?(r.empty().append('<p style="font-size: 0" data-mce-bogus="all">\xa0</p>').append(l),e.setStartAfter(r[0].firstChild.firstChild),e.setEndAfter(l)):(r.empty().append(oo).append(l).append(oo),e.setStart(r[0].firstChild,1),e.setEnd(r[0].lastChild,0)),r.css({top:m.getPos(n,g.getBody()).y}),r[0].focus(),(o=g.selection.getSel()).removeAllRanges(),o.addRange(e);var p=Ne.fromDom(n);return z(Ua(Ne.fromDom(g.getBody()),"*[data-mce-selected]"),function(e){at(p,e)||dn(e,"data-mce-selected")}),g.dom.getAttrib(n,"data-mce-selected")||n.setAttribute("data-mce-selected","1"),h=n,w(),e},c=function(){h&&(h.removeAttribute("data-mce-selected"),$a(Ne.fromDom(g.getBody()),"#"+y).each(kt),h=null),$a(Ne.fromDom(g.getBody()),"#"+y).each(kt),h=null},w=function(){o.hide()};return rr.ceFalse&&function(){g.on("mouseup",function(e){var t=r();t.collapsed&&Qg(g,e.clientX,e.clientY)&&a(bb(g,t,!1))}),g.on("click",function(e){var t;(t=Kx(g,e.target))&&(Wx(t)&&(e.preventDefault(),g.focus()),$x(t)&&g.dom.isChildOf(t,g.selection.getNode())&&c())}),g.on("blur NewBlock",function(){c()}),g.on("ResizeWindow FullscreenStateChanged",function(){return o.reposition()});var n,i=function(e,t){var n,r,o=g.dom.getParent(e,g.dom.isBlock),i=g.dom.getParent(t,g.dom.isBlock);return!(!o||!g.dom.isChildOf(o,i)||!1!==Wx(Kx(g,o)))||o&&(n=o,r=i,!(g.dom.getParent(n,g.dom.isBlock)===g.dom.getParent(r,g.dom.isBlock)))&&function(e){var t=Hc(e);if(!e.firstChild)return!1;var n=ms.before(e.firstChild),r=t.next(n);return r&&!Vf(r)&&!qf(r)}(o)};(n=g).on("tap",function(e){var t=Kx(n,e.target);Wx(t)&&(e.preventDefault(),s(yb(n,t)))},!0),g.on("mousedown",function(e){var t,n=e.target;if((n===v||"HTML"===n.nodeName||g.dom.isChildOf(n,v))&&!1!==Qg(g,e.clientX,e.clientY))if(t=Kx(g,n))Wx(t)?(e.preventDefault(),s(yb(g,t))):(c(),$x(t)&&e.shiftKey||Qh(e.clientX,e.clientY,g.selection.getRng())||(w(),g.selection.placeCaretAt(e.clientX,e.clientY)));else if(!1===cc(n)){c(),w();var r=pb(v,e.clientX,e.clientY);if(r&&!i(e.target,r.node)){e.preventDefault();var o=b(1,r.node,r.before,!1);g.getBody().focus(),a(o)}}}),g.on("keypress",function(e){Zh.modifierPressed(e)||(e.keyCode,Wx(g.selection.getNode())&&e.preventDefault())}),g.on("GetSelectionRange",function(e){var t=e.range;if(h){if(!h.parentNode)return void(h=null);(t=t.cloneRange()).selectNode(h),e.range=t}}),g.on("SetSelectionRange",function(e){e.range=u(e.range);var t=s(e.range,e.forward);t&&(e.range=t)});var t,e;g.on("AfterSetSelectionRange",function(e){var t,n=e.range;C(n)||"mcepastebin"===n.startContainer.parentNode.id||w(),t=n.startContainer.parentNode,g.dom.hasClass(t,"mce-offscreen-selection")||c()}),g.on("copy",function(e){var t,n=e.clipboardData;if(!e.isDefaultPrevented()&&e.clipboardData&&!rr.ie){var r=(t=g.dom.get(y))?t.getElementsByTagName("*")[0]:t;r&&(e.preventDefault(),n.clearData(),n.setData("text/html",r.outerHTML),n.setData("text/plain",r.outerText))}}),qx(g),e=Ta(function(){if(!t.removed&&t.getBody().contains(V.document.activeElement)&&t.selection.getRng().collapsed){var e=Cb(t,t.selection.getRng(),!1);t.selection.setRng(e)}},0),(t=g).on("focus",function(){e.throttle()}),t.on("blur",function(){e.cancel()})}(),{showCaret:b,showBlockCaretContainer:function(e){e.hasAttribute("data-mce-caret")&&(xu(e),a(r()),g.selection.scrollIntoView(e))},hideFakeCaret:w,destroy:function(){o.destroy(),h=null}}},Yx=function(u){var s,n,r,o=hr.each,c=Zh.BACKSPACE,l=Zh.DELETE,f=u.dom,d=u.selection,e=u.settings,t=u.parser,i=rr.gecko,a=rr.ie,m=rr.webkit,p="data:text/mce-internal,",g=a?"Text":"URL",h=function(e,t){try{u.getDoc().execCommand(e,!1,t)}catch(n){}},v=function(e){return e.isDefaultPrevented()},y=function(){u.shortcuts.add("meta+a",null,"SelectAll")},b=function(){u.on("keydown",function(e){if(!v(e)&&e.keyCode===c&&d.isCollapsed()&&0===d.getRng().startOffset){var t=d.getNode().previousSibling;if(t&&t.nodeName&&"table"===t.nodeName.toLowerCase())return e.preventDefault(),!1}})},C=function(){u.inline||(u.contentStyles.push("body {min-height: 150px}"),u.on("click",function(e){var t;if("HTML"===e.target.nodeName){if(11<rr.ie)return void u.getBody().focus();t=u.selection.getRng(),u.getBody().focus(),u.selection.setRng(t),u.selection.normalize(),u.nodeChanged()}}))};return u.on("keydown",function(e){var t,n,r,o,i;if(!v(e)&&e.keyCode===Zh.BACKSPACE&&(n=(t=d.getRng()).startContainer,r=t.startOffset,o=f.getRoot(),i=n,t.collapsed&&0===r)){for(;i&&i.parentNode&&i.parentNode.firstChild===i&&i.parentNode!==o;)i=i.parentNode;"BLOCKQUOTE"===i.tagName&&(u.formatter.toggle("blockquote",null,i),(t=f.createRng()).setStart(n,0),t.setEnd(n,0),d.setRng(t))}}),s=function(e){var t=f.create("body"),n=e.cloneContents();return t.appendChild(n),d.serializer.serialize(t,{format:"html"})},u.on("keydown",function(e){var t,n,r,o,i,a=e.keyCode;if(!v(e)&&(a===l||a===c)){if(t=u.selection.isCollapsed(),n=u.getBody(),t&&!f.isEmpty(n))return;if(!t&&(r=u.selection.getRng(),o=s(r),(i=f.createRng()).selectNode(u.getBody()),o!==s(i)))return;e.preventDefault(),u.setContent(""),n.firstChild&&f.isBlock(n.firstChild)?u.selection.setCursorLocation(n.firstChild,0):u.selection.setCursorLocation(n,0),u.nodeChanged()}}),rr.windowsPhone||u.on("keyup focusin mouseup",function(e){Zh.modifierPressed(e)||d.normalize()},!0),m&&(u.inline||f.bind(u.getDoc(),"mousedown mouseup",function(e){var t;if(e.target===u.getDoc().documentElement)if(t=d.getRng(),u.getBody().focus(),"mousedown"===e.type){if(gu(t.startContainer))return;d.placeCaretAt(e.clientX,e.clientY)}else d.setRng(t)}),u.on("click",function(e){var t=e.target;/^(IMG|HR)$/.test(t.nodeName)&&"false"!==f.getContentEditableParent(t)&&(e.preventDefault(),u.selection.select(t),u.nodeChanged()),"A"===t.nodeName&&f.hasClass(t,"mce-item-anchor")&&(e.preventDefault(),d.select(t))}),e.forced_root_block&&u.on("init",function(){h("DefaultParagraphSeparator",Hs(u))}),u.on("init",function(){u.dom.bind(u.getBody(),"submit",function(e){e.preventDefault()})}),b(),t.addNodeFilter("br",function(e){for(var t=e.length;t--;)"Apple-interchange-newline"===e[t].attr("class")&&e[t].remove()}),rr.iOS?(u.inline||u.on("keydown",function(){V.document.activeElement===V.document.body&&u.getWin().focus()}),C(),u.on("click",function(e){var t=e.target;do{if("A"===t.tagName)return void e.preventDefault()}while(t=t.parentNode)}),u.contentStyles.push(".mce-content-body {-webkit-touch-callout: none}")):y()),11<=rr.ie&&(C(),b()),rr.ie&&(y(),h("AutoUrlDetect",!1),u.on("dragstart",function(e){var t,n,r;(t=e).dataTransfer&&(u.selection.isCollapsed()&&"IMG"===t.target.tagName&&d.select(t.target),0<(n=u.selection.getContent()).length&&(r=p+escape(u.id)+","+escape(n),t.dataTransfer.setData(g,r)))}),u.on("drop",function(e){if(!v(e)){var t=(i=e).dataTransfer&&(a=i.dataTransfer.getData(g))&&0<=a.indexOf(p)?(a=a.substr(p.length).split(","),{id:unescape(a[0]),html:unescape(a[1])}):null;if(t&&t.id!==u.id){e.preventDefault();var n=Bh(e.x,e.y,u.getDoc());d.setRng(n),r=t.html,o=!0,u.queryCommandSupported("mceInsertClipboardContent")?u.execCommand("mceInsertClipboardContent",!1,{content:r,internal:o}):u.execCommand("mceInsertContent",!1,r)}}var r,o,i,a})),i&&(u.on("keydown",function(e){if(!v(e)&&e.keyCode===c){if(!u.getBody().getElementsByTagName("hr").length)return;if(d.isCollapsed()&&0===d.getRng().startOffset){var t=d.getNode(),n=t.previousSibling;if("HR"===t.nodeName)return f.remove(t),void e.preventDefault();n&&n.nodeName&&"hr"===n.nodeName.toLowerCase()&&(f.remove(n),e.preventDefault())}}}),V.Range.prototype.getClientRects||u.on("mousedown",function(e){if(!v(e)&&"HTML"===e.target.nodeName){var t=u.getBody();t.blur(),Xn.setEditorTimeout(u,function(){t.focus()})}}),n=function(){var e=f.getAttribs(d.getStart().cloneNode(!1));return function(){var t=d.getStart();t!==u.getBody()&&(f.setAttrib(t,"style",null),o(e,function(e){t.setAttributeNode(e.cloneNode(!0))}))}},r=function(){return!d.isCollapsed()&&f.getParent(d.getStart(),f.isBlock)!==f.getParent(d.getEnd(),f.isBlock)},u.on("keypress",function(e){var t;if(!v(e)&&(8===e.keyCode||46===e.keyCode)&&r())return t=n(),u.getDoc().execCommand("delete",!1,null),t(),e.preventDefault(),!1}),f.bind(u.getDoc(),"cut",function(e){var t;!v(e)&&r()&&(t=n(),Xn.setEditorTimeout(u,function(){t()}))}),e.readonly||u.on("BeforeExecCommand mousedown",function(){h("StyleWithCSS",!1),h("enableInlineTableEditing",!1),e.object_resizing||h("enableObjectResizing",!1)}),u.on("SetContent ExecCommand",function(e){"setcontent"!==e.type&&"mceInsertLink"!==e.command||o(f.select("a"),function(e){var t=e.parentNode,n=f.getRoot();if(t.lastChild===e){for(;t&&!f.isBlock(t);){if(t.parentNode.lastChild!==t||t===n)return;t=t.parentNode}f.add(t,"br",{"data-mce-bogus":1})}})}),u.contentStyles.push("img:-moz-broken {-moz-force-broken-image-icon:1;min-width:24px;min-height:24px}"),rr.mac&&u.on("keydown",function(e){!Zh.metaKeyPressed(e)||e.shiftKey||37!==e.keyCode&&39!==e.keyCode||(e.preventDefault(),u.selection.getSel().modify("move",37===e.keyCode?"backward":"forward","lineboundary"))}),b()),{refreshContentEditable:function(){},isHidden:function(){var e;return!(!i||u.removed)&&(!(e=u.selection.getSel())||!e.rangeCount||0===e.rangeCount)}}},Gx=ga.DOM,Jx=function(e){return le(e,function(e){return!1===A(e)})},Qx=function(e){var t,n=e.settings,r=e.editorUpload.blobCache;return Jx({allow_conditional_comments:n.allow_conditional_comments,allow_html_in_named_anchor:n.allow_html_in_named_anchor,allow_script_urls:n.allow_script_urls,allow_unsafe_link_target:n.allow_unsafe_link_target,convert_fonts_to_spans:n.convert_fonts_to_spans,fix_list_elements:n.fix_list_elements,font_size_legacy_values:n.font_size_legacy_values,forced_root_block:n.forced_root_block,forced_root_block_attrs:n.forced_root_block_attrs,padd_empty_with_br:n.padd_empty_with_br,preserve_cdata:n.preserve_cdata,remove_trailing_brs:n.remove_trailing_brs,inline_styles:n.inline_styles,root_name:(t=e).inline?t.getElement().nodeName.toLowerCase():undefined,validate:!0,blob_cache:r})},Zx=function(u){var e=u.dom.getRoot();u.inline||Gl(u)&&u.selection.getStart(!0)!==e||Zc(e).each(function(e){var t,n,r,o,i=e.getNode(),a=Gt(i)?Zc(i).getOr(e):e;rr.browser.isIE()?(t=u,n=a.toRange(),r=Ne.fromDom(t.getBody()),o=(hm(t)?R.from(n):R.none()).map(vm).filter(gm(r)),t.bookmark=o.isSome()?o:t.bookmark):u.selection.setRng(a.toRange())})},eS=function(e){var t;e.bindPendingEventDelegates(),e.initialized=!0,e.fire("Init"),e.focus(!0),Zx(e),e.nodeChanged({initial:!0}),e.execCallback("init_instance_callback",e),(t=e).settings.auto_focus&&Xn.setEditorTimeout(t,function(){var e;(e=!0===t.settings.auto_focus?t:t.editorManager.get(t.settings.auto_focus)).destroyed||e.focus()},100)},tS=function(t,e){var n=t.settings,r=t.getDoc(),o=t.getBody();n.browser_spellcheck||n.gecko_spellcheck||(r.body.spellcheck=!1,Gx.setAttrib(o,"spellcheck","false")),t.quirks=Yx(t),t.fire("PostRender");var i,a,u,s,c,l=t.getParam("directionality",ka.isRtl()?"rtl":undefined);if(l!==undefined&&(o.dir=l),n.protect&&t.on("BeforeSetContent",function(t){hr.each(n.protect,function(e){t.content=t.content.replace(e,function(e){return"\x3c!--mce:protected "+escape(e)+"--\x3e"})})}),t.on("SetContent",function(){t.addVisual(t.getBody())}),!1===e&&t.load({initial:!0,format:"html"}),t.startContent=t.getContent({format:"raw"}),t.on("compositionstart compositionend",function(e){t.composing="compositionstart"===e.type}),0<t.contentStyles.length){var f="";hr.each(t.contentStyles,function(e){f+=e+"\r\n"}),t.dom.addStyle(f)}((i=t).inline?Gx.styleSheetLoader:i.dom.styleSheetLoader).loadAll(t.contentCSS,function(e){eS(t)},function(e){eS(t)}),n.content_style&&(a=t,u=n.content_style,s=Ne.fromDom(a.getDoc().head),c=Ne.fromTag("style"),cn(c,"type","text/css"),St(c,Ne.fromText(u)),St(s,c))},nS=function(t,e){var n,u,r,o,i,a,s,c=t.settings,l=t.getElement(),f=t.getDoc();c.inline||(t.getElement().style.visibility=t.orgVisibility),e||t.inline||(f.open(),f.write(t.iframeHTML),f.close()),t.inline&&(t.on("remove",function(){var e=this.getBody();Gx.removeClass(e,"mce-content-body"),Gx.removeClass(e,"mce-edit-focus"),Gx.setAttrib(e,"contentEditable",null)}),Gx.addClass(l,"mce-content-body"),t.contentDocument=f=V.document,t.contentWindow=V.window,t.bodyElement=l,t.contentAreaContainer=l),(n=t.getBody()).disabled=!0,t.readonly=!!c.readonly,t.readonly||(t.inline&&"static"===Gx.getStyle(n,"position",!0)&&(n.style.position="relative"),n.contentEditable=t.getParam("content_editable_state",!0)),n.disabled=!1,t.editorUpload=Pv(t),t.schema=no(c),t.dom=ga(f,{keep_values:!0,url_converter:t.convertURL,url_converter_scope:t,hex_colors:c.force_hex_style_colors,update_styles:!0,root_element:t.inline?t.getBody():null,collect:function(){return t.inline},schema:t.schema,contentCssCors:t.getParam("content_css_cors",!1,"boolean"),referrerPolicy:t.getParam("referrer_policy","","string"),onSetAttrib:function(e){t.fire("SetAttrib",e)}}),t.parser=((r=Ev(Qx(u=t),u.schema)).addAttributeFilter("src,href,style,tabindex",function(e,t){for(var n,r,o=e.length,i=u.dom,a="data-mce-"+t;o--;)if((r=(n=e[o]).attr(t))&&!n.attr(a)){if(0===r.indexOf("data:")||0===r.indexOf("blob:"))continue;"style"===t?((r=i.serializeStyle(i.parseStyle(r),n.name)).length||(r=null),n.attr(a,r),n.attr(t,r)):"tabindex"===t?(n.attr(a,r),n.attr(t,null)):n.attr(a,u.convertURL(r,t,n.name))}}),r.addNodeFilter("script",function(e){for(var t,n,r=e.length;r--;)0!==(n=(t=e[r]).attr("type")||"no/type").indexOf("mce-")&&t.attr("type","mce-"+n)}),u.settings.preserve_cdata&&r.addNodeFilter("#cdata",function(e){for(var t,n=e.length;n--;)(t=e[n]).type=8,t.name="#comment",t.value="[CDATA["+u.dom.encode(t.value)+"]]"}),r.addNodeFilter("p,h1,h2,h3,h4,h5,h6,div",function(e){for(var t,n=e.length,r=u.schema.getNonEmptyElements();n--;)(t=e[n]).isEmpty(r)&&0===t.getAll("br").length&&(t.append(new df("br",1)).shortEnded=!0)}),r),t.serializer=Av((i=(o=t).settings,pe(pe({},Qx(o)),Jx({url_converter:i.url_converter,url_converter_scope:i.url_converter_scope,element_format:i.element_format,entities:i.entities,entity_encoding:i.entity_encoding,indent:i.indent,indent_after:i.indent_after,indent_before:i.indent_before,block_elements:i.block_elements,boolean_attributes:i.boolean_attributes,custom_elements:i.custom_elements,extended_valid_elements:i.extended_valid_elements,invalid_elements:i.invalid_elements,invalid_styles:i.invalid_styles,move_caret_before_on_enter_elements:i.move_caret_before_on_enter_elements,non_empty_elements:i.non_empty_elements,schema:i.schema,self_closing_elements:i.self_closing_elements,short_ended_elements:i.short_ended_elements,special:i.special,text_block_elements:i.text_block_elements,text_inline_elements:i.text_inline_elements,valid_children:i.valid_children,valid_classes:i.valid_classes,valid_elements:i.valid_elements,valid_styles:i.valid_styles,verify_html:i.verify_html,whitespace_elements:i.whitespace_elements}))),t),t.selection=av(t.dom,t.getWin(),t.serializer,t),t.annotator=af(t),t.formatter=Wv(t),t.undoManager=Xv(t),t._nodeChangeDispatcher=new Tx(t),t._selectionOverrides=Xx(t),ty(t),Dx(t),yg(t)||Bx(t),yg(a=t)||Rx(a),Hs(s=t)&&s.on("NodeChange",N(oy,s)),Zv(t),t.fire("PreInit"),bg(t).fold(function(){tS(t,!1)},function(e){t.setProgressState(!0),e.then(function(e){t.setProgressState(!1),tS(t,e)})})},rS=ga.DOM,oS=function(e){var t,n,r;return r=e.getParam("doctype","<!DOCTYPE html>")+"<html><head>",e.getParam("document_base_url","")!==e.documentBaseUrl&&(r+='<base href="'+e.documentBaseURI.getURI()+'" />'),r+='<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />',t=zs(e,"body_id","tinymce"),n=zs(e,"body_class",""),js(e)&&(r+='<meta http-equiv="Content-Security-Policy" content="'+js(e)+'" />'),r+='</head><body id="'+t+'" class="mce-content-body '+n+'" data-id="'+e.id+'"><br></body></html>'},iS=function(e,t){var n,r,o,i,a=e.editorManager.translate("Rich Text Area. Press ALT-0 for help."),u=(n=e.id,r=a,t.height,o=e.getParam("iframe_attrs",{}),i=Ne.fromTag("iframe"),ln(i,o),ln(i,{id:n+"_ifr",frameBorder:"0",allowTransparency:"true",title:r}),La(i,"tox-edit-area__iframe"),i.dom());u.onload=function(){u.onload=null,e.fire("load")};var s=function(e,t){if(V.document.domain!==V.window.location.hostname&&rr.browser.isIE()){var n=Bv("mce");e[n]=function(){nS(e)};var r='javascript:(function(){document.open();document.domain="'+V.document.domain+'";var ed = window.parent.tinymce.get("'+e.id+'");document.write(ed.iframeHTML);document.close();ed.'+n+"(true);})()";return rS.setAttrib(t,"src",r),!0}return!1}(e,u);return e.contentAreaContainer=t.iframeContainer,e.iframeElement=u,e.iframeHTML=oS(e),rS.add(t.iframeContainer,u),s},aS=ga.DOM,uS=function(t,n,e){var r=th.get(e),o=th.urls[e]||t.documentBaseUrl.replace(/\/$/,"");if(e=hr.trim(e),r&&-1===hr.inArray(n,e)){if(hr.each(th.dependencies(e),function(e){uS(t,n,e)}),t.plugins[e])return;try{var i=new r(t,o,t.$);(t.plugins[e]=i).init&&(i.init(t,o),n.push(e))}catch(pE){!function(e,t,n){var r=ka.translate(["Failed to initialize plugin: {0}",t]);ch(r,n),ih(e,r)}(t,e,pE)}}},sS=function(e){return e.replace(/^\-/,"")},cS=function(e){return{editorContainer:e,iframeContainer:e}},lS=function(e){var t,n,r=e.getElement();return e.inline?cS(null):(t=r,n=aS.create("div"),aS.insertAfter(n,t),cS(n))},fS=function(e){var n,t,r,o,i,a;e.fire("ScriptsLoaded"),n=e,t=hr.trim($s(n)),r=n.ui.registry.getAll().icons,o=pe(pe({},$g.get("default").icons),$g.get(t).icons),oe(o,function(e,t){me(r,t)||n.ui.registry.addIcon(t,e)}),function(e){var t=e.settings.theme;if(q(t)){e.settings.theme=sS(t);var n=nh.get(t);e.theme=new n(e,nh.urls[t]),e.theme.init&&e.theme.init(e,nh.urls[t]||e.documentBaseUrl.replace(/\/$/,""),e.$)}else e.theme={}}(e),i=e,a=[],hr.each(i.settings.plugins.split(/[ ,]/),function(e){uS(i,a,sS(e))});var u,s,c,l,f,d,m,p,g,h=(f=(u=e).getElement(),u.orgDisplay=f.style.display,q(u.settings.theme)?u.theme.renderUI():D(u.settings.theme)?(c=(s=u).getElement(),(l=(0,s.settings.theme)(s,c)).editorContainer.nodeType&&(l.editorContainer.id=l.editorContainer.id||s.id+"_parent"),l.iframeContainer&&l.iframeContainer.nodeType&&(l.iframeContainer.id=l.iframeContainer.id||s.id+"_iframecontainer"),l.height=l.iframeHeight?l.iframeHeight:c.offsetHeight,l):lS(u));return e.editorContainer=h.editorContainer?h.editorContainer:null,(d=e).contentCSS=d.contentCSS.concat(lh(d)),e.inline?nS(e):(g=iS(m=e,p=h),p.editorContainer&&(rS.get(p.editorContainer).style.display=m.orgDisplay,m.hidden=rS.isHidden(p.editorContainer)),m.getElement().style.display="none",rS.setAttrib(m.id,"aria-hidden","true"),void(g||nS(m)))},dS=ga.DOM,mS=function(e){return"-"===e.charAt(0)},pS=function(e,t){var n=Ws(t),r=t.getParam("language_url","","string");if(!1===ka.hasCode(n)&&"en"!==n){var o=""!==r?r:t.editorManager.baseURL+"/langs/"+n+".js";e.add(o,f,undefined,function(){ah(t,"LanguageLoadError",uh("language",o,n))})}},gS=function(t,e,n){return R.from(e).filter(function(e){return 0<e.length&&!$g.has(e)}).map(function(e){return{url:t.editorManager.baseURL+"/icons/"+e+"/icons"+n+".js",name:R.some(e)}})},hS=function(e,o,t){var n,r=gS(o,"default",t),i=(n=o,R.from(n.getParam("icons_url","","string")).filter(function(e){return 0<e.length}).map(function(e){return{url:e,name:R.none()}}).orThunk(function(){return gS(o,$s(o),"")}));z(function(e){for(var t=[],n=function(e){t.push(e)},r=0;r<e.length;r++)e[r].each(n);return t}([r,i]),function(r){e.add(r.url,f,undefined,function(){var e,t,n;e=o,t=r.url,n=r.name.getOrUndefined(),ah(e,"IconsLoadError",uh("icons",t,n))})})},vS=function(e,t){var i=ba.ScriptLoader;!function(e,t,n,r){var o=t.settings,i=o.theme;if(q(i)){if(!mS(i)&&!nh.urls.hasOwnProperty(i)){var a=o.theme_url;a?nh.load(i,t.documentBaseURI.toAbsolute(a)):nh.load(i,"themes/"+i+"/theme"+n+".js")}e.loadQueue(function(){nh.waitFor(i,r)})}else r()}(i,e,t,function(){var r,n,o;pS(i,e),hS(i,e,t),n=(r=e).settings,o=t,k(n.plugins)&&(n.plugins=n.plugins.join(" ")),hr.each(n.external_plugins,function(e,t){th.load(t,e,f,undefined,function(){sh(r,e,t)}),n.plugins+=" "+t}),hr.each(n.plugins.split(/[ ,]/),function(e){if((e=hr.trim(e))&&!th.urls[e])if(mS(e)){e=e.substr(1,e.length);var t=th.dependencies(e);hr.each(t,function(e){var t={prefix:"plugins/",resource:e,suffix:"/plugin"+o+".js"},n=th.createUrl(t,e);th.load(n.resource,n,f,undefined,function(){sh(r,n.prefix+n.resource+n.suffix,n.resource)})})}else{var n={prefix:"plugins/",resource:e,suffix:"/plugin"+o+".js"};th.load(e,n,f,undefined,function(){sh(r,n.prefix+n.resource+n.suffix,e)})}}),i.loadQueue(function(){e.removed||fS(e)},e,function(){e.removed||fS(e)})})},yS=function(e,t){var n,r,o,i,a="string"!=typeof(n=t)?(r=hr.extend({paste:n.paste,data:{paste:n.paste}},n),{content:n.content,details:r}):{content:n,details:{}};o=a.content,i=a.details,Cg(e).editor.insertContent(o,i)},bS=function(e,t){e.getDoc().execCommand(t,!1,null)},CS=function(e){return D(e)?e:x(!1)},wS=function(e,t,n){var r=t(e),o=CS(n);return r.orThunk(function(){return o(e)?R.none():function(e,t,n){for(var r=e.dom(),o=CS(n);r.parentNode;){r=r.parentNode;var i=Ne.fromDom(r),a=t(i);if(a.isSome())return a;if(o(i))break}return R.none()}(e,t,o)})},xS={"font-size":"size","font-family":"face"},SS=function(e,t,n){var r=function(r){return gn(r,e).orThunk(function(){return"font"===Rt(r)?de(xS,e).bind(function(e){return t=r,n=e,R.from(fn(t,n));var t,n}):R.none()})};return wS(Ne.fromDom(n),function(e){return r(e)},function(e){return at(Ne.fromDom(t),e)})},NS=function(o){return function(r,e){return R.from(e).map(Ne.fromDom).filter(Dt).bind(function(e){return SS(o,r,e.dom()).or((t=o,n=e.dom(),R.from(ga.DOM.getStyle(n,t,!0))));var t,n}).getOr("")}},ES=NS("font-size"),kS=a(function(e){return e.replace(/[\'\"\\]/g,"").replace(/,\s+/g,",")},NS("font-family")),_S=function(e){return Zc(e.getBody()).map(function(e){var t=e.container();return Zt(t)?t.parentNode:t})},RS=function(o){return R.from(o.selection.getRng()).bind(function(e){var t,n,r=o.getBody();return n=r,(t=e).startContainer===n&&0===t.startOffset?R.none():R.from(o.selection.getStart(!0))})},TS=function(e,t){if(/^[0-9\.]+$/.test(t)){var n=parseInt(t,10);if(1<=n&&n<=7){var r=(a=e,hr.explode(a.getParam("font_size_style_values","xx-small,x-small,small,medium,large,x-large,xx-large"))),o=(i=e,hr.explode(i.getParam("font_size_classes","")));return o?o[n-1]||t:r[n-1]||t}return t}return t;var i,a},AS=function(e,t){var n,r=TS(e,t);e.formatter.toggle("fontname",{value:(n=r.split(/\s*,\s*/),U(n,function(e){return-1===e.indexOf(" ")||Ve(e,'"')||Ve(e,"'")?e:"'"+e+"'"}).join(","))}),e.nodeChanged()},DS=hr.each,OS=hr.map,BS=hr.inArray,PS=(LS.prototype.execCommand=function(t,n,r,e){var o,i,a=!1,u=this;if(!u.editor.removed){var s;if(/^(mceAddUndoLevel|mceEndUndoLevel|mceBeginUndoLevel|mceRepaint)$/.test(t)||e&&e.skip_focus?(s=u.editor,wm(s).each(function(e){s.selection.setRng(e)})):u.editor.focus(),(e=u.editor.fire("BeforeExecCommand",{command:t,ui:n,value:r})).isDefaultPrevented())return!1;if(i=t.toLowerCase(),o=u.commands.exec[i])return o(i,n,r),u.editor.fire("ExecCommand",{command:t,ui:n,value:r}),!0;if(DS(this.editor.plugins,function(e){if(e.execCommand&&e.execCommand(t,n,r))return u.editor.fire("ExecCommand",{command:t,ui:n,value:r}),!(a=!0)}),a)return a;if(u.editor.theme&&u.editor.theme.execCommand&&u.editor.theme.execCommand(t,n,r))return u.editor.fire("ExecCommand",{command:t,ui:n,value:r}),!0;try{a=u.editor.getDoc().execCommand(t,n,r)}catch(c){}return!!a&&(u.editor.fire("ExecCommand",{command:t,ui:n,value:r}),!0)}},LS.prototype.queryCommandState=function(e){var t;if(!this.editor.quirks.isHidden()&&!this.editor.removed){if(e=e.toLowerCase(),t=this.commands.state[e])return t(e);try{return this.editor.getDoc().queryCommandState(e)}catch(n){}return!1}},LS.prototype.queryCommandValue=function(e){var t;if(!this.editor.quirks.isHidden()&&!this.editor.removed){if(e=e.toLowerCase(),t=this.commands.value[e])return t(e);try{return this.editor.getDoc().queryCommandValue(e)}catch(n){}}},LS.prototype.addCommands=function(e,n){var r=this;n=n||"exec",DS(e,function(t,e){DS(e.toLowerCase().split(","),function(e){r.commands[n][e]=t})})},LS.prototype.addCommand=function(e,o,i){var a=this;e=e.toLowerCase(),this.commands.exec[e]=function(e,t,n,r){return o.call(i||a.editor,t,n,r)}},LS.prototype.queryCommandSupported=function(e){if(e=e.toLowerCase(),this.commands.exec[e])return!0;try{return this.editor.getDoc().queryCommandSupported(e)}catch(t){}return!1},LS.prototype.addQueryStateHandler=function(e,t,n){var r=this;e=e.toLowerCase(),this.commands.state[e]=function(){return t.call(n||r.editor)}},LS.prototype.addQueryValueHandler=function(e,t,n){var r=this;e=e.toLowerCase(),this.commands.value[e]=function(){return t.call(n||r.editor)}},LS.prototype.hasCustomCommand=function(e){return e=e.toLowerCase(),!!this.commands.exec[e]},LS.prototype.execNativeCommand=function(e,t,n){return t===undefined&&(t=!1),n===undefined&&(n=null),this.editor.getDoc().execCommand(e,t,n)},LS.prototype.isFormatMatch=function(e){return this.editor.formatter.match(e)},LS.prototype.toggleFormat=function(e,t){this.editor.formatter.toggle(e,t?{value:t}:undefined),this.editor.nodeChanged()},LS.prototype.storeSelection=function(e){this.selectionBookmark=this.editor.selection.getBookmark(e)},LS.prototype.restoreSelection=function(){this.editor.selection.moveToBookmark(this.selectionBookmark)},LS.prototype.setupCommands=function(i){var a=this;this.addCommands({"mceResetDesignMode,mceBeginUndoLevel":function(){},"mceEndUndoLevel,mceAddUndoLevel":function(){i.undoManager.add()},"Cut,Copy,Paste":function(e){var t,n=i.getDoc();try{a.execNativeCommand(e)}catch(o){t=!0}if("paste"!==e||n.queryCommandEnabled(e)||(t=!0),t||!n.queryCommandSupported(e)){var r=i.translate("Your browser doesn't support direct access to the clipboard. Please use the Ctrl+X/C/V keyboard shortcuts instead.");rr.mac&&(r=r.replace(/Ctrl\+/g,"\u2318+")),i.notificationManager.open({text:r,type:"error"})}},unlink:function(){if(i.selection.isCollapsed()){var e=i.dom.getParent(i.selection.getStart(),"a");e&&i.dom.remove(e,!0)}else i.formatter.remove("link")},"JustifyLeft,JustifyCenter,JustifyRight,JustifyFull,JustifyNone":function(e){var t=e.substring(7);"full"===t&&(t="justify"),DS("left,center,right,justify".split(","),function(e){t!==e&&i.formatter.remove("align"+e)}),"none"!==t&&a.toggleFormat("align"+t)},"InsertUnorderedList,InsertOrderedList":function(e){var t,n;a.execNativeCommand(e),(t=i.dom.getParent(i.selection.getNode(),"ol,ul"))&&(n=t.parentNode,/^(H[1-6]|P|ADDRESS|PRE)$/.test(n.nodeName)&&(a.storeSelection(),i.dom.split(n,t),a.restoreSelection()))},"Bold,Italic,Underline,Strikethrough,Superscript,Subscript":function(e){a.toggleFormat(e)},"ForeColor,HiliteColor":function(e,t,n){a.toggleFormat(e,n)},FontName:function(e,t,n){AS(i,n)},FontSize:function(e,t,n){var r,o;o=n,(r=i).formatter.toggle("fontsize",{value:TS(r,o)}),r.nodeChanged()},RemoveFormat:function(e){i.formatter.remove(e)},mceBlockQuote:function(){a.toggleFormat("blockquote")},FormatBlock:function(e,t,n){return a.toggleFormat(n||"p")},mceCleanup:function(){var e=i.selection.getBookmark();i.setContent(i.getContent()),i.selection.moveToBookmark(e)},mceRemoveNode:function(e,t,n){var r=n||i.selection.getNode();r!==i.getBody()&&(a.storeSelection(),i.dom.remove(r,!0),a.restoreSelection())},mceSelectNodeDepth:function(e,t,n){var r=0;i.dom.getParent(i.selection.getNode(),function(e){if(1===e.nodeType&&r++===n)return i.selection.select(e),!1},i.getBody())},mceSelectNode:function(e,t,n){i.selection.select(n)},mceInsertContent:function(e,t,n){yS(i,n)},mceInsertRawHTML:function(e,t,n){i.selection.setContent("tiny_mce_marker");var r=i.getContent();i.setContent(r.replace(/tiny_mce_marker/g,function(){return n}))},mceInsertNewLine:function(e,t,n){nx(i,n)},mceToggleFormat:function(e,t,n){a.toggleFormat(n)},mceSetContent:function(e,t,n){i.setContent(n)},"Indent,Outdent":function(e){uw(i,e)},mceRepaint:function(){},InsertHorizontalRule:function(){i.execCommand("mceInsertContent",!1,"<hr />")},mceToggleVisualAid:function(){i.hasVisual=!i.hasVisual,i.addVisual()},mceReplaceContent:function(e,t,n){i.execCommand("mceInsertContent",!1,n.replace(/\{\$selection\}/g,i.selection.getContent({format:"text"})))},mceInsertLink:function(e,t,n){var r;"string"==typeof n&&(n={href:n}),r=i.dom.getParent(i.selection.getNode(),"a"),n.href=n.href.replace(/ /g,"%20"),r&&n.href||i.formatter.remove("link"),n.href&&i.formatter.apply("link",n,r)},selectAll:function(){var e=i.dom.getParent(i.selection.getStart(),on);if(e){var t=i.dom.createRng();t.selectNodeContents(e),i.selection.setRng(t)}},"delete":function(){var e;hw(e=i)||qC(e,!1)||WC(e,!1)||GC(e,!1)||NC(e,!1)||Vd(e)||RC(e)||ew(e,!1)||(bS(e,"Delete"),dC(e))},forwardDelete:function(){var e;qC(e=i,!0)||WC(e,!0)||GC(e,!0)||NC(e,!0)||Vd(e)||RC(e)||ew(e,!0)||bS(e,"ForwardDelete")},mceNewDocument:function(){i.setContent("")},InsertLineBreak:function(e,t,n){return Hw(i,n),!0}});var e=function(n){return function(){var e=i.selection.isCollapsed()?[i.dom.getParent(i.selection.getNode(),i.dom.isBlock)]:i.selection.getSelectedBlocks(),t=OS(e,function(e){return!!i.formatter.matchNode(e,n)});return-1!==BS(t,!0)}};a.addCommands({JustifyLeft:e("alignleft"),JustifyCenter:e("aligncenter"),JustifyRight:e("alignright"),JustifyFull:e("alignjustify"),"Bold,Italic,Underline,Strikethrough,Superscript,Subscript":function(e){return a.isFormatMatch(e)},mceBlockQuote:function(){return a.isFormatMatch("blockquote")},Outdent:function(){return ow(i)},"InsertUnorderedList,InsertOrderedList":function(e){var t=i.dom.getParent(i.selection.getNode(),"ul,ol");return t&&("insertunorderedlist"===e&&"UL"===t.tagName||"insertorderedlist"===e&&"OL"===t.tagName)}},"state"),a.addCommands({Undo:function(){i.undoManager.undo()},Redo:function(){i.undoManager.redo()}}),a.addQueryValueHandler("FontName",function(){return RS(t=i).fold(function(){return _S(t).map(function(e){return kS(t.getBody(),e)}).getOr("")},function(e){return kS(t.getBody(),e)});var t},this),a.addQueryValueHandler("FontSize",function(){return RS(t=i).fold(function(){return _S(t).map(function(e){return ES(t.getBody(),e)}).getOr("")},function(e){return ES(t.getBody(),e)});var t},this)},LS);function LS(e){this.commands={state:{},exec:{},value:{}},this.editor=e,this.setupCommands(e)}var IS=hr.makeMap("focus blur focusin focusout click dblclick mousedown mouseup mousemove mouseover beforepaste paste cut copy selectionchange mouseout mouseenter mouseleave wheel keydown keypress keyup input beforeinput contextmenu dragstart dragend dragover draggesture dragdrop drop drag submit compositionstart compositionend compositionupdate touchstart touchmove touchend touchcancel"," "),MS=(FS.isNative=function(e){return!!IS[e.toLowerCase()]},FS.prototype.fire=function(e,t){var n,r,o,i;if(e=e.toLowerCase(),(t=t||{}).type=e,t.target||(t.target=this.scope),t.preventDefault||(t.preventDefault=function(){t.isDefaultPrevented=h},t.stopPropagation=function(){t.isPropagationStopped=h},t.stopImmediatePropagation=function(){t.isImmediatePropagationStopped=h},t.isDefaultPrevented=g,t.isPropagationStopped=g,t.isImmediatePropagationStopped=g),this.settings.beforeFire&&this.settings.beforeFire(t),n=this.bindings[e])for(r=0,o=n.length;r<o;r++){if((i=n[r]).once&&this.off(e,i.func),t.isImmediatePropagationStopped())return t.stopPropagation(),t;if(!1===i.func.call(this.scope,t))return t.preventDefault(),t}return t},FS.prototype.on=function(e,t,n,r){var o,i,a;if(!1===t&&(t=g),t){var u={func:t};for(r&&hr.extend(u,r),a=(i=e.toLowerCase().split(" ")).length;a--;)e=i[a],(o=this.bindings[e])||(o=this.bindings[e]=[],this.toggleEvent(e,!0)),n?o.unshift(u):o.push(u)}return this},FS.prototype.off=function(e,t){var n,r,o,i,a=this;if(e)for(n=(o=e.toLowerCase().split(" ")).length;n--;){if(e=o[n],r=this.bindings[e],!e)return oe(this.bindings,function(e,t){a.toggleEvent(t,!1),delete a.bindings[t]}),this;if(r){if(t)for(i=r.length;i--;)r[i].func===t&&(r=r.slice(0,i).concat(r.slice(i+1)),this.bindings[e]=r);else r.length=0;r.length||(this.toggleEvent(e,!1),delete this.bindings[e])}}else oe(this.bindings,function(e,t){a.toggleEvent(t,!1)}),this.bindings={};return this},FS.prototype.once=function(e,t,n){return this.on(e,t,n,{once:!0})},FS.prototype.has=function(e){return e=e.toLowerCase(),!(!this.bindings[e]||0===this.bindings[e].length)},FS);function FS(e){this.bindings={},this.settings=e||{},this.scope=this.settings.scope||this,this.toggleEvent=this.settings.toggleEvent||g}var US,zS=function(n){return n._eventDispatcher||(n._eventDispatcher=new MS({scope:n,toggleEvent:function(e,t){MS.isNative(e)&&n.toggleNativeEvent&&n.toggleNativeEvent(e,t)}})),n._eventDispatcher},jS={fire:function(e,t,n){if(this.removed&&"remove"!==e&&"detach"!==e)return t;var r=zS(this).fire(e,t);if(!1!==n&&this.parent)for(var o=this.parent();o&&!r.isPropagationStopped();)o.fire(e,r,!1),o=o.parent();return r},on:function(e,t,n){return zS(this).on(e,t,n)},off:function(e,t){return zS(this).off(e,t)},once:function(e,t){return zS(this).once(e,t)},hasEventListeners:function(e){return zS(this).has(e)}},HS="data-mce-contenteditable",VS=function(e,t,n){Ma(e,t)&&!1===n?function(e,t){Oa(e)?e.dom().classList.remove(t):Pa(e,t);Ia(e)}(e,t):n&&La(e,t)},qS=function(e,t,n){try{e.getDoc().execCommand(t,!1,n)}catch(r){}},$S=function(e,t){e.dom().contentEditable=t?"true":"false"},WS=function(e,t){var n,r,o,i=Ne.fromDom(e.getBody());VS(i,"mce-content-readonly",t),t?(e.selection.controlSelection.hideResizeRect(),e._selectionOverrides.hideFakeCaret(),o=e,R.from(o.selection.getNode()).each(function(e){e.removeAttribute("data-mce-selected")}),e.readonly=!0,$S(i,!1),z(Ua(i,'*[contenteditable="true"]'),function(e){cn(e,HS,"true"),$S(e,!1)})):(e.readonly=!1,$S(i,!0),z(Ua(i,"*["+HS+'="true"]'),function(e){dn(e,HS),$S(e,!0)}),qS(e,"StyleWithCSS",!1),qS(e,"enableInlineTableEditing",!1),qS(e,"enableObjectResizing",!1),(Pm(r=e)||Bm(r))&&e.focus(),(n=e).selection.setRng(n.selection.getRng()),e.nodeChanged())},KS=function(e){return e.readonly},XS=function(t){t.parser.addAttributeFilter("contenteditable",function(e){KS(t)&&z(e,function(e){e.attr(HS,e.attr("contenteditable")),e.attr("contenteditable","false")})}),t.serializer.addAttributeFilter(HS,function(e){KS(t)&&z(e,function(e){e.attr("contenteditable",e.attr(HS))})}),t.serializer.addTempAttr(HS)},YS=ga.DOM,GS=function(e,t){return"selectionchange"===t?e.getDoc():!e.inline&&/^mouse|touch|click|contextmenu|drop|dragover|dragend/.test(t)?e.getDoc().documentElement:e.settings.event_root?(e.eventRoot||(e.eventRoot=YS.select(e.settings.event_root)[0]),e.eventRoot):e.getBody()},JS=function(e,t,n){var r,o,i,a,u;(u=e).hidden||KS(u)?KS(e)&&(r=e,a=(o=n).target,"click"!==o.type||Zh.metaKeyPressed(o)||(i=a,null===r.dom.getParent(i,"a"))||o.preventDefault()):e.fire(t,n)},QS=function(i,a){var e,t;if(i.delegates||(i.delegates={}),!i.delegates[a]&&!i.removed)if(e=GS(i,a),i.settings.event_root){if(US||(US={},i.editorManager.on("removeEditor",function(){i.editorManager.activeEditor||US&&(oe(US,function(e,t){i.dom.unbind(GS(i,t))}),US=null)})),US[a])return;t=function(e){for(var t=e.target,n=i.editorManager.get(),r=n.length;r--;){var o=n[r].getBody();o!==t&&!YS.isChildOf(t,o)||JS(n[r],a,e)}},US[a]=t,YS.bind(e,a,t)}else t=function(e){JS(i,a,e)},YS.bind(e,a,t),i.delegates[a]=t},ZS=pe(pe({},jS),{bindPendingEventDelegates:function(){var t=this;hr.each(t._pendingNativeEvents,function(e){QS(t,e)})},toggleNativeEvent:function(e,t){var n=this;"focus"!==e&&"blur"!==e&&(t?n.initialized?QS(n,e):n._pendingNativeEvents?n._pendingNativeEvents.push(e):n._pendingNativeEvents=[e]:n.initialized&&(n.dom.unbind(GS(n,e),e,n.delegates[e]),delete n.delegates[e]))},unbindAllNativeEvents:function(){var n=this,e=n.getBody(),t=n.dom;n.delegates&&(oe(n.delegates,function(e,t){n.dom.unbind(GS(n,t),t,e)}),delete n.delegates),!n.inline&&e&&t&&(e.onload=null,t.unbind(n.getWin()),t.unbind(n.getDoc())),t&&(t.unbind(e),t.unbind(n.getContainer()))}}),eN=["design","readonly"],tN=function(e,t,n,r){var o,i=n[t.get()],a=n[r];try{a.activate()}catch(pE){return void V.console.error("problem while activating editor mode "+r+":",pE)}i.deactivate(),i.editorReadOnly!==a.editorReadOnly&&WS(e,a.editorReadOnly),t.set(r),o=r,e.fire("SwitchMode",{mode:o})},nN=function(t){var e,n,r=xa("design"),o=xa({design:{activate:f,deactivate:f,editorReadOnly:!1},readonly:{activate:f,deactivate:f,editorReadOnly:!0}});return(e=t).serializer?XS(e):e.on("PreInit",function(){XS(e)}),(n=t).on("ShowCaret",function(e){KS(n)&&e.preventDefault()}),n.on("ObjectSelected",function(e){KS(n)&&e.preventDefault()}),{isReadOnly:function(){return KS(t)},set:function(e){return function(e,t,n,r){if(r!==n.get()){if(!me(t,r))throw new Error("Editor mode '"+r+"' is invalid");e.initialized?tN(e,n,t,r):e.on("init",function(){return tN(e,n,t,r)})}}(t,o.get(),r,e)},get:function(){return r.get()},register:function(e,t){o.set(function(e,t,n){var r;if(M(eN,t))throw new Error("Cannot override default mode "+t);return pe(pe({},e),((r={})[t]=pe(pe({},n),{deactivate:function(){try{n.deactivate()}catch(pE){V.console.error("problem while deactivating editor mode "+t+":",pE)}}}),r))}(o.get(),e,t))}}},rN=hr.each,oN=hr.explode,iN={f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123},aN=hr.makeMap("alt,ctrl,shift,meta,access"),uN=(sN.prototype.add=function(e,n,r,o){var t,i=this;return"string"==typeof(t=r)?r=function(){i.editor.execCommand(t,!1,null)}:hr.isArray(t)&&(r=function(){i.editor.execCommand(t[0],t[1],t[2])}),rN(oN(hr.trim(e)),function(e){var t=i.createShortcut(e,n,r,o);i.shortcuts[t.id]=t}),!0},sN.prototype.remove=function(e){var t=this.createShortcut(e);return!!this.shortcuts[t.id]&&(delete this.shortcuts[t.id],!0)},sN.prototype.parseShortcut=function(e){var t,n,r={};for(n in rN(oN(e.toLowerCase(),"+"),function(e){e in aN?r[e]=!0:/^[0-9]{2,}$/.test(e)?r.keyCode=parseInt(e,10):(r.charCode=e.charCodeAt(0),r.keyCode=iN[e]||e.toUpperCase().charCodeAt(0))}),t=[r.keyCode],aN)r[n]?t.push(n):r[n]=!1;return r.id=t.join(","),r.access&&(r.alt=!0,rr.mac?r.ctrl=!0:r.shift=!0),r.meta&&(rr.mac?r.meta=!0:(r.ctrl=!0,r.meta=!1)),r},sN.prototype.createShortcut=function(e,t,n,r){var o;return(o=hr.map(oN(e,">"),this.parseShortcut))[o.length-1]=hr.extend(o[o.length-1],{func:n,scope:r||this.editor}),hr.extend(o[0],{desc:this.editor.translate(t),subpatterns:o.slice(1)})},sN.prototype.hasModifier=function(e){return e.altKey||e.ctrlKey||e.metaKey},sN.prototype.isFunctionKey=function(e){return"keydown"===e.type&&112<=e.keyCode&&e.keyCode<=123},sN.prototype.matchShortcut=function(e,t){return!!t&&t.ctrl===e.ctrlKey&&t.meta===e.metaKey&&t.alt===e.altKey&&t.shift===e.shiftKey&&!!(e.keyCode===t.keyCode||e.charCode&&e.charCode===t.charCode)&&(e.preventDefault(),!0)},sN.prototype.executeShortcutAction=function(e){return e.func?e.func.call(e.scope):null},sN);function sN(e){this.shortcuts={},this.pendingPatterns=[],this.editor=e;var n=this;e.on("keyup keypress keydown",function(t){!n.hasModifier(t)&&!n.isFunctionKey(t)||t.isDefaultPrevented()||(rN(n.shortcuts,function(e){if(n.matchShortcut(t,e))return n.pendingPatterns=e.subpatterns.slice(0),"keydown"===t.type&&n.executeShortcutAction(e),!0}),n.matchShortcut(t,n.pendingPatterns[0])&&(1===n.pendingPatterns.length&&"keydown"===t.type&&n.executeShortcutAction(n.pendingPatterns[0]),n.pendingPatterns.shift()))})}var cN=function(){var e,t,n,r,o,i,a,u,s=(t={},n={},r={},o={},i={},a={},{addButton:(u=function(n,r){return function(e,t){return n[e.toLowerCase()]=pe(pe({},t),{type:r})}})(e={},"button"),addGroupToolbarButton:u(e,"grouptoolbarbutton"),addToggleButton:u(e,"togglebutton"),addMenuButton:u(e,"menubutton"),addSplitButton:u(e,"splitbutton"),addMenuItem:u(t,"menuitem"),addNestedMenuItem:u(t,"nestedmenuitem"),addToggleMenuItem:u(t,"togglemenuitem"),addAutocompleter:u(n,"autocompleter"),addContextMenu:u(o,"contextmenu"),addContextToolbar:u(i,"contexttoolbar"),addContextForm:u(i,"contextform"),addSidebar:u(a,"sidebar"),addIcon:function(e,t){return r[e.toLowerCase()]=t},getAll:function(){return{buttons:e,menuItems:t,icons:r,popups:n,contextMenus:o,contextToolbars:i,sidebars:a}}});return{addAutocompleter:s.addAutocompleter,addButton:s.addButton,addContextForm:s.addContextForm,addContextMenu:s.addContextMenu,addContextToolbar:s.addContextToolbar,addIcon:s.addIcon,addMenuButton:s.addMenuButton,addMenuItem:s.addMenuItem,addNestedMenuItem:s.addNestedMenuItem,addSidebar:s.addSidebar,addSplitButton:s.addSplitButton,addToggleButton:s.addToggleButton,addGroupToolbarButton:s.addGroupToolbarButton,addToggleMenuItem:s.addToggleMenuItem,getAll:s.getAll}},lN=hr.each,fN=hr.trim,dN="source protocol authority userInfo user password host port relative path directory file query anchor".split(" "),mN={ftp:21,http:80,https:443,mailto:25},pN=(gN.parseDataUri=function(e){var t,n=decodeURIComponent(e).split(","),r=/data:([^;]+)/.exec(n[0]);return r&&(t=r[1]),{type:t,data:n[1]}},gN.getDocumentBaseUrl=function(e){var t;return t=0!==e.protocol.indexOf("http")&&"file:"!==e.protocol?e.href:e.protocol+"//"+e.host+e.pathname,/^[^:]+:\/\/\/?[^\/]+\//.test(t)&&(t=t.replace(/[\?#].*$/,"").replace(/[\/\\][^\/]+$/,""),/[\/\\]$/.test(t)||(t+="/")),t},gN.prototype.setPath=function(e){var t=/^(.*?)\/?(\w+)?$/.exec(e);this.path=t[0],this.directory=t[1],this.file=t[2],this.source="",this.getURI()},gN.prototype.toRelative=function(e){var t;if("./"===e)return e;var n=new gN(e,{base_uri:this});if("mce_host"!==n.host&&this.host!==n.host&&n.host||this.port!==n.port||this.protocol!==n.protocol&&""!==n.protocol)return n.getURI();var r=this.getURI(),o=n.getURI();return r===o||"/"===r.charAt(r.length-1)&&r.substr(0,r.length-1)===o?r:(t=this.toRelPath(this.path,n.path),n.query&&(t+="?"+n.query),n.anchor&&(t+="#"+n.anchor),t)},gN.prototype.toAbsolute=function(e,t){var n=new gN(e,{base_uri:this});return n.getURI(t&&this.isSameOrigin(n))},gN.prototype.isSameOrigin=function(e){if(this.host==e.host&&this.protocol==e.protocol){if(this.port==e.port)return!0;var t=mN[this.protocol];if(t&&(this.port||t)==(e.port||t))return!0}return!1},gN.prototype.toRelPath=function(e,t){var n,r,o,i=0,a="",u=e.substring(0,e.lastIndexOf("/")).split("/");if(n=t.split("/"),u.length>=n.length)for(r=0,o=u.length;r<o;r++)if(r>=n.length||u[r]!==n[r]){i=r+1;break}if(u.length<n.length)for(r=0,o=n.length;r<o;r++)if(r>=u.length||u[r]!==n[r]){i=r+1;break}if(1===i)return t;for(r=0,o=u.length-(i-1);r<o;r++)a+="../";for(r=i-1,o=n.length;r<o;r++)a+=r!==i-1?"/"+n[r]:n[r];return a},gN.prototype.toAbsPath=function(e,t){var n,r,o,i=0,a=[];r=/\/$/.test(t)?"/":"";var u=e.split("/"),s=t.split("/");for(lN(u,function(e){e&&a.push(e)}),u=a,n=s.length-1,a=[];0<=n;n--)0!==s[n].length&&"."!==s[n]&&(".."!==s[n]?0<i?i--:a.push(s[n]):i++);return 0!==(o=(n=u.length-i)<=0?J(a).join("/"):u.slice(0,n).join("/")+"/"+J(a).join("/")).indexOf("/")&&(o="/"+o),r&&o.lastIndexOf("/")!==o.length-1&&(o+=r),o},gN.prototype.getURI=function(e){var t;return void 0===e&&(e=!1),this.source&&!e||(t="",e||(this.protocol?t+=this.protocol+"://":t+="//",this.userInfo&&(t+=this.userInfo+"@"),this.host&&(t+=this.host),this.port&&(t+=":"+this.port)),this.path&&(t+=this.path),this.query&&(t+="?"+this.query),this.anchor&&(t+="#"+this.anchor),this.source=t),this.source},gN);function gN(e,t){e=fN(e),this.settings=t||{};var n=this.settings.base_uri,r=this;if(/^([\w\-]+):([^\/]{2})/i.test(e)||/^\s*#/.test(e))r.source=e;else{var o=0===e.indexOf("//");if(0!==e.indexOf("/")||o||(e=(n&&n.protocol||"http")+"://mce_host"+e),!/^[\w\-]*:?\/\//.test(e)){var i=this.settings.base_uri?this.settings.base_uri.path:new gN(V.document.location.href).directory;if(this.settings.base_uri&&""==this.settings.base_uri.protocol)e="//mce_host"+r.toAbsPath(i,e);else{var a=/([^#?]*)([#?]?.*)/.exec(e);e=(n&&n.protocol||"http")+"://mce_host"+r.toAbsPath(i,a[1])+a[2]}}e=e.replace(/@@/g,"(mce_at)");var u=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@\/]*):?([^:@\/]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/.exec(e);lN(dN,function(e,t){var n=u[t];n=n&&n.replace(/\(mce_at\)/g,"@@"),r[e]=n}),n&&(r.protocol||(r.protocol=n.protocol),r.userInfo||(r.userInfo=n.userInfo),r.port||"mce_host"!==r.host||(r.port=n.port),r.host&&"mce_host"!==r.host||(r.host=n.host),r.source=""),o&&(r.protocol="")}}var hN=ga.DOM,vN=hr.extend,yN=hr.each,bN=hr.resolve,CN=rr.ie,wN=(xN.prototype.render=function(){!function(t){var e=t.settings,n=t.id;ka.setCode(Ws(t));var r=function(){dS.unbind(V.window,"ready",r),t.render()};if(ho.Event.domLoaded){if(t.getElement()&&rr.contentEditable){e.inline?t.inline=!0:(t.orgVisibility=t.getElement().style.visibility,t.getElement().style.visibility="hidden");var o=t.getElement().form||dS.getParent(n,"form");o&&(t.formElement=o,e.hidden_input&&!Qt(t.getElement())&&(dS.insertAfter(dS.create("input",{type:"hidden",name:n}),n),t.hasHiddenInput=!0),t.formEventDelegate=function(e){t.fire(e.type,e)},dS.bind(o,"submit reset",t.formEventDelegate),t.on("reset",function(){t.resetContent()}),!e.submit_patch||o.submit.nodeType||o.submit.length||o._mceOldSubmit||(o._mceOldSubmit=o.submit,o.submit=function(){return t.editorManager.triggerSave(),t.setDirty(!1),o._mceOldSubmit(o)})),t.windowManager=rh(t),t.notificationManager=eh(t),"xml"===e.encoding&&t.on("GetContent",function(e){e.save&&(e.content=dS.encode(e.content))}),e.add_form_submit_trigger&&t.on("submit",function(){t.initialized&&t.save()}),e.add_unload_trigger&&(t._beforeUnload=function(){!t.initialized||t.destroyed||t.isHidden()||t.save({format:"raw",no_events:!0,set_dirty:!1})},t.editorManager.on("BeforeUnload",t._beforeUnload)),t.editorManager.add(t),vS(t,t.suffix)}}else dS.bind(V.window,"ready",r)}(this)},xN.prototype.focus=function(e){var t,n;n=e,(t=this).removed||(n?Im:Lm)(t)},xN.prototype.hasFocus=function(){return Pm(this)},xN.prototype.execCallback=function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n];var r,o=this.settings[e];if(o)return this.callbackLookup&&(r=this.callbackLookup[e])&&(o=r.func,r=r.scope),"string"==typeof o&&(r=(r=o.replace(/\.\w+$/,""))?bN(r):0,o=bN(o),this.callbackLookup=this.callbackLookup||{},this.callbackLookup[e]={func:o,scope:r}),o.apply(r||this,t)},xN.prototype.translate=function(e){return ka.translate(e)},xN.prototype.getParam=function(e,t,n){return qg(this,e,t,n)},xN.prototype.nodeChanged=function(e){this._nodeChangeDispatcher.nodeChanged(e)},xN.prototype.addCommand=function(e,t,n){this.editorCommands.addCommand(e,t,n)},xN.prototype.addQueryStateHandler=function(e,t,n){this.editorCommands.addQueryStateHandler(e,t,n)},xN.prototype.addQueryValueHandler=function(e,t,n){this.editorCommands.addQueryValueHandler(e,t,n)},xN.prototype.addShortcut=function(e,t,n,r){this.shortcuts.add(e,t,n,r)},xN.prototype.execCommand=function(e,t,n,r){return this.editorCommands.execCommand(e,t,n,r)},xN.prototype.queryCommandState=function(e){return this.editorCommands.queryCommandState(e)},xN.prototype.queryCommandValue=function(e){return this.editorCommands.queryCommandValue(e)},xN.prototype.queryCommandSupported=function(e){return this.editorCommands.queryCommandSupported(e)},xN.prototype.show=function(){this.hidden&&(this.hidden=!1,this.inline?this.getBody().contentEditable="true":(hN.show(this.getContainer()),hN.hide(this.id)),this.load(),this.fire("show"))},xN.prototype.hide=function(){var e=this,t=e.getDoc();e.hidden||(CN&&t&&!e.inline&&t.execCommand("SelectAll"),e.save(),e.inline?(e.getBody().contentEditable="false",e===e.editorManager.focusedEditor&&(e.editorManager.focusedEditor=null)):(hN.hide(e.getContainer()),hN.setStyle(e.id,"display",e.orgDisplay)),e.hidden=!0,e.fire("hide"))},xN.prototype.isHidden=function(){return!!this.hidden},xN.prototype.setProgressState=function(e,t){this.fire("ProgressState",{state:e,time:t})},xN.prototype.load=function(e){var t,n=this.getElement();if(this.removed)return"";if(n){(e=e||{}).load=!0;var r=Qt(n)?n.value:n.innerHTML;return t=this.setContent(r,e),e.element=n,e.no_events||this.fire("LoadContent",e),e.element=n=null,t}},xN.prototype.save=function(e){var t,n,r=this,o=r.getElement();if(o&&r.initialized&&!r.removed)return(e=e||{}).save=!0,e.element=o,e.content=r.getContent(e),e.no_events||r.fire("SaveContent",e),"raw"===e.format&&r.fire("RawSaveContent",e),t=e.content,Qt(o)?o.value=t:(!e.is_removing&&r.inline||(o.innerHTML=t),(n=hN.getParent(r.id,"form"))&&yN(n.elements,function(e){if(e.name===r.id)return e.value=t,!1})),e.element=o=null,!1!==e.set_dirty&&r.setDirty(!1),t},xN.prototype.setContent=function(e,t){return Sg(this,e,t)},xN.prototype.getContent=function(e){return xg(this,e)},xN.prototype.insertContent=function(e,t){t&&(e=vN({content:e},t)),this.execCommand("mceInsertContent",!1,e)},xN.prototype.resetContent=function(e){e===undefined?Sg(this,this.startContent,{format:"raw"}):Sg(this,e),this.undoManager.reset(),this.setDirty(!1),this.nodeChanged()},xN.prototype.isDirty=function(){return!this.isNotDirty},xN.prototype.setDirty=function(e){var t=!this.isNotDirty;this.isNotDirty=!e,e&&e!==t&&this.fire("dirty")},xN.prototype.getContainer=function(){return this.container||(this.container=hN.get(this.editorContainer||this.id+"_parent")),this.container},xN.prototype.getContentAreaContainer=function(){return this.contentAreaContainer},xN.prototype.getElement=function(){return this.targetElm||(this.targetElm=hN.get(this.id)),this.targetElm},xN.prototype.getWin=function(){var e;return this.contentWindow||(e=this.iframeElement)&&(this.contentWindow=e.contentWindow),this.contentWindow},xN.prototype.getDoc=function(){var e;return this.contentDocument||(e=this.getWin())&&(this.contentDocument=e.document),this.contentDocument},xN.prototype.getBody=function(){var e=this.getDoc();return this.bodyElement||(e?e.body:null)},xN.prototype.convertURL=function(e,t,n){var r=this.settings;return r.urlconverter_callback?this.execCallback("urlconverter_callback",e,n,!0,t):!r.convert_urls||n&&"LINK"===n.nodeName||0===e.indexOf("file:")||0===e.length?e:r.relative_urls?this.documentBaseURI.toRelative(e):e=this.documentBaseURI.toAbsolute(e,r.remove_script_host)},xN.prototype.addVisual=function(e){var n,r=this,o=r.settings,i=r.dom;e=e||r.getBody(),r.hasVisual===undefined&&(r.hasVisual=o.visual),yN(i.select("table,a",e),function(e){var t;switch(e.nodeName){case"TABLE":return n=o.visual_table_class||"mce-item-table",void((t=i.getAttrib(e,"border"))&&"0"!==t||!r.hasVisual?i.removeClass(e,n):i.addClass(e,n));case"A":return void(i.getAttrib(e,"href")||(t=i.getAttrib(e,"name")||e.id,n=o.visual_anchor_class||"mce-item-anchor",t&&r.hasVisual?i.addClass(e,n):i.removeClass(e,n)))}}),r.fire("VisualAid",{element:e,hasVisual:r.hasVisual})},xN.prototype.remove=function(){kg(this)},xN.prototype.destroy=function(e){_g(this,e)},xN.prototype.uploadImages=function(e){return this.editorUpload.uploadImages(e)},xN.prototype._scanForImages=function(){return this.editorUpload.scanForImages()},xN.prototype.addButton=function(){throw new Error("editor.addButton has been removed in tinymce 5x, use editor.ui.registry.addButton or editor.ui.registry.addToggleButton or editor.ui.registry.addSplitButton instead")},xN.prototype.addSidebar=function(){throw new Error("editor.addSidebar has been removed in tinymce 5x, use editor.ui.registry.addSidebar instead")},xN.prototype.addMenuItem=function(){throw new Error("editor.addMenuItem has been removed in tinymce 5x, use editor.ui.registry.addMenuItem instead")},xN.prototype.addContextToolbar=function(){throw new Error("editor.addContextToolbar has been removed in tinymce 5x, use editor.ui.registry.addContextToolbar instead")},xN);function xN(e,t,n){var r=this;this.plugins={},this.contentCSS=[],this.contentStyles=[],this.loadedCSS={},this.isNotDirty=!1,this.editorManager=n,this.documentBaseUrl=n.documentBaseURL,vN(this,ZS),this.settings=Hg(this,e,this.documentBaseUrl,n.defaultSettings,t),this.settings.suffix&&(n.suffix=this.settings.suffix),this.suffix=n.suffix,this.settings.base_url&&n._setBaseUrl(this.settings.base_url),this.baseUri=n.baseURI,this.settings.referrer_policy&&(ba.ScriptLoader._setReferrerPolicy(this.settings.referrer_policy),ga.DOM.styleSheetLoader._setReferrerPolicy(this.settings.referrer_policy)),Ra.languageLoad=this.settings.language_load,Ra.baseURL=n.baseURL,this.id=e,this.setDirty(!1),this.documentBaseURI=new pN(this.settings.document_base_url,{base_uri:this.baseUri}),this.baseURI=this.baseUri,this.inline=!!this.settings.inline,this.shortcuts=new uN(this),this.editorCommands=new PS(this),this.settings.cache_suffix&&(rr.cacheSuffix=this.settings.cache_suffix.replace(/^[\?\&]+/,"")),this.ui={registry:cN()};var o=nN(this);this.mode=o,this.setMode=o.set,n.fire("SetupEditor",{editor:this}),this.execCallback("setup",this),this.$=na.overrideDefaults(function(){return{context:r.inline?r.getBody():r.getDoc(),element:r.getBody()}})}var SN,NN,EN=ga.DOM,kN=hr.explode,_N=hr.each,RN=hr.extend,TN=0,AN=!1,DN=[],ON=[],BN=function(t){var n=t.type;_N(MN.get(),function(e){switch(n){case"scroll":e.fire("ScrollWindow",t);break;case"resize":e.fire("ResizeWindow",t)}})},PN=function(e){e!==AN&&(e?na(window).on("resize scroll",BN):na(window).off("resize scroll",BN),AN=e)},LN=function(t){var e=ON;delete DN[t.id];for(var n=0;n<DN.length;n++)if(DN[n]===t){DN.splice(n,1);break}return ON=H(ON,function(e){return t!==e}),MN.activeEditor===t&&(MN.activeEditor=0<ON.length?ON[0]:null),MN.focusedEditor===t&&(MN.focusedEditor=null),e.length!==ON.length},IN="CSS1Compat"!==V.document.compatMode,MN=pe(pe({},jS),{baseURI:null,baseURL:null,defaultSettings:{},documentBaseURL:null,suffix:null,$:na,majorVersion:"5",minorVersion:"3.1",releaseDate:"2020-05-27",editors:DN,i18n:ka,activeEditor:null,focusedEditor:null,settings:{},setup:function(){var e,t,n="";t=pN.getDocumentBaseUrl(V.document.location),/^[^:]+:\/\/\/?[^\/]+\//.test(t)&&(t=t.replace(/[\?#].*$/,"").replace(/[\/\\][^\/]+$/,""),/[\/\\]$/.test(t)||(t+="/"));var r,o=window.tinymce||window.tinyMCEPreInit;if(o)e=o.base||o.baseURL,n=o.suffix;else{for(var i=V.document.getElementsByTagName("script"),a=0;a<i.length;a++){var u;if(""!==(u=i[a].src||"")){var s=u.substring(u.lastIndexOf("/"));if(/tinymce(\.full|\.jquery|)(\.min|\.dev|)\.js/.test(u)){-1!==s.indexOf(".min")&&(n=".min"),e=u.substring(0,u.lastIndexOf("/"));break}}}if(!e&&V.document.currentScript)-1!==(u=V.document.currentScript.src).indexOf(".min")&&(n=".min"),e=u.substring(0,u.lastIndexOf("/"))}this.baseURL=new pN(t).toAbsolute(e),this.documentBaseURL=t,this.baseURI=new pN(this.baseURL),this.suffix=n,(r=this).on("AddEditor",N(_m,r)),r.on("RemoveEditor",N(Rm,r))},overrideDefaults:function(e){var t,n;(t=e.base_url)&&this._setBaseUrl(t),n=e.suffix,e.suffix&&(this.suffix=n);var r=(this.defaultSettings=e).plugin_base_urls;r!==undefined&&oe(r,function(e,t){Ra.PluginManager.urls[t]=e})},init:function(r){var n,u,s=this;u=hr.makeMap("area base basefont br col frame hr img input isindex link meta param embed source wbr track colgroup option table tbody tfoot thead tr th td script noscript style textarea video audio iframe object menu"," ");var c=function(e){var t=e.id;return t||(t=(t=e.name)&&!EN.get(t)?e.name:EN.uniqueId(),e.setAttribute("id",t)),t},l=function(e,t){return t.constructor===RegExp?t.test(e.className):EN.hasClass(e,t)},f=function(e){n=e},e=function(){var o,i=0,a=[],n=function(e,t,n){var r=new wN(e,t,s);a.push(r),r.on("init",function(){++i===o.length&&f(a)}),r.targetElm=r.targetElm||n,r.render()};EN.unbind(window,"ready",e),function(e){var t=r[e];if(t)t.apply(s,Array.prototype.slice.call(arguments,2))}("onpageload"),o=na.unique(function(t){var e,n=[];if(rr.browser.isIE()&&rr.browser.version.major<11)return ch("TinyMCE does not support the browser you are using. For a list of supported browsers please see: https://www.tinymce.com/docs/get-started/system-requirements/"),[];if(IN)return ch("Failed to initialize the editor as the document is not in standards mode. TinyMCE requires standards mode."),[];if(t.types)return _N(t.types,function(e){n=n.concat(EN.select(e.selector))}),n;if(t.selector)return EN.select(t.selector);if(t.target)return[t.target];switch(t.mode){case"exact":0<(e=t.elements||"").length&&_N(kN(e),function(t){var e;(e=EN.get(t))?n.push(e):_N(V.document.forms,function(e){_N(e.elements,function(e){e.name===t&&(t="mce_editor_"+TN++,EN.setAttrib(e,"id",t),n.push(e))})})});break;case"textareas":case"specific_textareas":_N(EN.select("textarea"),function(e){t.editor_deselector&&l(e,t.editor_deselector)||t.editor_selector&&!l(e,t.editor_selector)||n.push(e)})}return n}(r)),r.types?_N(r.types,function(t){hr.each(o,function(e){return!EN.is(e,t.selector)||(n(c(e),RN({},r,t),e),!1)})}):(hr.each(o,function(e){var t;(t=s.get(e.id))&&t.initialized&&!(t.getContainer()||t.getBody()).parentNode&&(LN(t),t.unbindAllNativeEvents(),t.destroy(!0),t.removed=!0,t=null)}),0===(o=hr.grep(o,function(e){return!s.get(e.id)})).length?f([]):_N(o,function(e){var t;t=e,r.inline&&t.tagName.toLowerCase()in u?ch("Could not initialize inline editor on invalid inline target element",e):n(c(e),r,e)}))};return s.settings=r,EN.bind(window,"ready",e),new Mn(function(t){n?t(n):f=function(e){t(e)}})},get:function(t){return 0===arguments.length?ON.slice(0):q(t)?K(ON,function(e){return e.id===t}).getOr(null):O(t)&&ON[t]?ON[t]:null},add:function(e){var n=this;return DN[e.id]===e||(null===n.get(e.id)&&("length"!==e.id&&(DN[e.id]=e),DN.push(e),ON.push(e)),PN(!0),n.activeEditor=e,n.fire("AddEditor",{editor:e}),SN||(SN=function(e){var t=n.fire("BeforeUnload");if(t.returnValue)return e.preventDefault(),e.returnValue=t.returnValue,t.returnValue},window.addEventListener("beforeunload",SN))),e},createEditor:function(e,t){return this.add(new wN(e,t,this))},remove:function(e){var t,n,r=this;if(e){if(!q(e))return n=e,_(r.get(n.id))?null:(LN(n)&&r.fire("RemoveEditor",{editor:n}),0===ON.length&&window.removeEventListener("beforeunload",SN),n.remove(),PN(0<ON.length),n);_N(EN.select(e),function(e){(n=r.get(e.id))&&r.remove(n)})}else for(t=ON.length-1;0<=t;t--)r.remove(ON[t])},execCommand:function(e,t,n){var r=this.get(n);switch(e){case"mceAddEditor":return this.get(n)||new wN(n,this.settings,this).render(),!0;case"mceRemoveEditor":return r&&r.remove(),!0;case"mceToggleEditor":return r?(r.isHidden()?r.show():r.hide(),!0):(this.execCommand("mceAddEditor",0,n),!0)}return!!this.activeEditor&&this.activeEditor.execCommand(e,t,n)},triggerSave:function(){_N(ON,function(e){e.save()})},addI18n:function(e,t){ka.add(e,t)},translate:function(e){return ka.translate(e)},setActive:function(e){var t=this.activeEditor;this.activeEditor!==e&&(t&&t.fire("deactivate",{relatedTarget:e}),e.fire("activate",{relatedTarget:t})),this.activeEditor=e},_setBaseUrl:function(e){this.baseURL=new pN(this.documentBaseURL).toAbsolute(e.replace(/\/+$/,"")),this.baseURI=new pN(this.baseURL)}});function FN(n){return{walk:function(e,t){return jl(n,e,t)},split:Vm,normalize:function(t){return Wh(n,t).fold(x(!1),function(e){return t.setStart(e.startContainer,e.startOffset),t.setEnd(e.endContainer,e.endOffset),!0})}}}MN.setup(),(NN=FN=FN||{}).compareRanges=Uh,NN.getCaretRangeFromPoint=Bh,NN.getSelectedNode=ju,NN.getNode=Hu;var UN,zN,jN,HN,VN=FN,qN=(UN={},zN={},{load:function(r,o){var i='Script at URL "'+o+'" failed to load',a='Script at URL "'+o+"\" did not call `tinymce.Resource.add('"+r+"', data)` within 1 second";if(UN[r]!==undefined)return UN[r];var e=new Mn(function(e,t){var n=function(e,t,n){void 0===n&&(n=1e3);var r=!1,o=null,i=function(n){return function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r||(r=!0,null!==o&&(V.clearTimeout(o),o=null),n.apply(null,e))}},a=i(e),u=i(t);return{start:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];r||null!==o||(o=V.setTimeout(function(){return u.apply(null,e)},n))},resolve:a,reject:u}}(e,t);zN[r]=n.resolve,ba.ScriptLoader.loadScript(o,function(){return n.start(a)},function(){return n.reject(i)})});return UN[r]=e},add:function(e,t){zN[e]!==undefined&&(zN[e](t),delete zN[e]),UN[e]=Mn.resolve(t)}}),$N=Math.min,WN=Math.max,KN=Math.round,XN=function(e,t,n){var r,o,i,a,u,s;return r=t.x,o=t.y,i=e.w,a=e.h,u=t.w,s=t.h,"b"===(n=(n||"").split(""))[0]&&(o+=s),"r"===n[1]&&(r+=u),"c"===n[0]&&(o+=KN(s/2)),"c"===n[1]&&(r+=KN(u/2)),"b"===n[3]&&(o-=a),"r"===n[4]&&(r-=i),"c"===n[3]&&(o-=KN(a/2)),"c"===n[4]&&(r-=KN(i/2)),YN(r,o,i,a)},YN=function(e,t,n,r){return{x:e,y:t,w:n,h:r}},GN={inflate:function(e,t,n){return YN(e.x-t,e.y-n,e.w+2*t,e.h+2*n)},relativePosition:XN,findBestRelativePosition:function(e,t,n,r){var o,i;for(i=0;i<r.length;i++)if((o=XN(e,t,r[i])).x>=n.x&&o.x+o.w<=n.w+n.x&&o.y>=n.y&&o.y+o.h<=n.h+n.y)return r[i];return null},intersect:function(e,t){var n,r,o,i;return n=WN(e.x,t.x),r=WN(e.y,t.y),o=$N(e.x+e.w,t.x+t.w),i=$N(e.y+e.h,t.y+t.h),o-n<0||i-r<0?null:YN(n,r,o-n,i-r)},clamp:function(e,t,n){var r,o,i,a,u,s,c,l,f,d;return u=e.x,s=e.y,c=e.x+e.w,l=e.y+e.h,f=t.x+t.w,d=t.y+t.h,r=WN(0,t.x-u),o=WN(0,t.y-s),i=WN(0,c-f),a=WN(0,l-d),u+=r,s+=o,n&&(c+=r,l+=o,u-=i,s-=a),YN(u,s,(c-=i)-u,(l-=a)-s)},create:YN,fromClientRect:function(e){return YN(e.left,e.top,e.width,e.height)}},JN=hr.each,QN=hr.extend,ZN=function(){};ZN.extend=jN=function(n){var o,i=this.prototype,r=function(){var e,t,n;if(!HN&&(this.init&&this.init.apply(this,arguments),t=this.Mixins))for(e=t.length;e--;)(n=t[e]).init&&n.init.apply(this,arguments)},t=function(){return this};return HN=!0,o=new this,HN=!1,n.Mixins&&(JN(n.Mixins,function(e){for(var t in e)"init"!==t&&(n[t]=e[t])}),i.Mixins&&(n.Mixins=i.Mixins.concat(n.Mixins))),n.Methods&&JN(n.Methods.split(","),function(e){n[e]=t}),n.Properties&&JN(n.Properties.split(","),function(e){var t="_"+e;n[e]=function(e){return e!==undefined?(this[t]=e,this):this[t]}}),n.Statics&&JN(n.Statics,function(e,t){r[t]=e}),n.Defaults&&i.Defaults&&(n.Defaults=QN({},i.Defaults,n.Defaults)),oe(n,function(e,t){var n,r;"function"==typeof e&&i[t]?o[t]=(n=t,r=e,function(){var e,t=this._super;return this._super=i[n],e=r.apply(this,arguments),this._super=t,e}):o[t]=e}),r.prototype=o,(r.constructor=r).extend=jN,r};var eE=Math.min,tE=Math.max,nE=Math.round,rE={serialize:function(e){var t=JSON.stringify(e);return q(t)?t.replace(/[\u0080-\uFFFF]/g,function(e){var t=e.charCodeAt(0).toString(16);return"\\u"+"0000".substring(t.length)+t}):t},parse:function(e){try{return JSON.parse(e)}catch(t){}}},oE={callbacks:{},count:0,send:function(t){var n=this,r=ga.DOM,o=t.count!==undefined?t.count:n.count,i="tinymce_jsonp_"+o;n.callbacks[o]=function(e){r.remove(i),delete n.callbacks[o],t.callback(e)},r.add(r.doc.body,"script",{id:i,src:t.url,type:"text/javascript"}),n.count++}},iE=pe(pe({},jS),{send:function(e){var t,n=0,r=function(){!e.async||4===t.readyState||1e4<n++?(e.success&&n<1e4&&200===t.status?e.success.call(e.success_scope,""+t.responseText,t,e):e.error&&e.error.call(e.error_scope,1e4<n?"TIMED_OUT":"GENERAL",t,e),t=null):Xn.setTimeout(r,10)};if(e.scope=e.scope||this,e.success_scope=e.success_scope||e.scope,e.error_scope=e.error_scope||e.scope,e.async=!1!==e.async,e.data=e.data||"",iE.fire("beforeInitialize",{settings:e}),t=new V.XMLHttpRequest){if(t.overrideMimeType&&t.overrideMimeType(e.content_type),t.open(e.type||(e.data?"POST":"GET"),e.url,e.async),e.crossDomain&&(t.withCredentials=!0),e.content_type&&t.setRequestHeader("Content-Type",e.content_type),e.requestheaders&&hr.each(e.requestheaders,function(e){t.setRequestHeader(e.key,e.value)}),t.setRequestHeader("X-Requested-With","XMLHttpRequest"),(t=iE.fire("beforeSend",{xhr:t,settings:e}).xhr).send(e.data),!e.async)return r();Xn.setTimeout(r,10)}}}),aE=hr.extend,uE=(sE.sendRPC=function(e){return(new sE).send(e)},sE.prototype.send=function(e){var n=e.error,r=e.success,o=aE(this.settings,e);o.success=function(e,t){void 0===(e=rE.parse(e))&&(e={error:"JSON Parse error."}),e.error?n.call(o.error_scope||o.scope,e.error,t):r.call(o.success_scope||o.scope,e.result)},o.error=function(e,t){n&&n.call(o.error_scope||o.scope,e,t)},o.data=rE.serialize({id:e.id||"c"+this.count++,method:e.method,params:e.params}),o.content_type="application/json",iE.send(o)},sE);function sE(e){this.settings=aE({},e),this.count=0}var cE;try{var lE="__storage_test__";(cE=V.window.localStorage).setItem(lE,lE),cE.removeItem(lE)}catch(pE){cE=function(){return n={},r=[],e={getItem:function(e){var t=n[e];return t||null},setItem:function(e,t){r.push(e),n[e]=String(t)},key:function(e){return r[e]},removeItem:function(t){r=r.filter(function(e){return e===t}),delete n[t]},clear:function(){r=[],n={}},length:0},Object.defineProperty(e,"length",{get:function(){return r.length},configurable:!1,enumerable:!1}),e;var n,r,e}()}var fE,dE={geom:{Rect:GN},util:{Promise:Mn,Delay:Xn,Tools:hr,VK:Zh,URI:pN,Class:ZN,EventDispatcher:MS,Observable:jS,I18n:ka,XHR:iE,JSON:rE,JSONRequest:uE,JSONP:oE,LocalStorage:cE,Color:function(e){var n={},u=0,s=0,c=0,t=function(e){var t;return"object"==typeof e?"r"in e?(u=e.r,s=e.g,c=e.b):"v"in e&&function(e,t,n){var r,o,i,a;if(e=(parseInt(e,10)||0)%360,t=parseInt(t,10)/100,n=parseInt(n,10)/100,t=tE(0,eE(t,1)),n=tE(0,eE(n,1)),0!==t){switch(r=e/60,i=(o=n*t)*(1-Math.abs(r%2-1)),a=n-o,Math.floor(r)){case 0:u=o,s=i,c=0;break;case 1:u=i,s=o,c=0;break;case 2:u=0,s=o,c=i;break;case 3:u=0,s=i,c=o;break;case 4:u=i,s=0,c=o;break;case 5:u=o,s=0,c=i;break;default:u=s=c=0}u=nE(255*(u+a)),s=nE(255*(s+a)),c=nE(255*(c+a))}else u=s=c=nE(255*n)}(e.h,e.s,e.v):(t=/rgb\s*\(\s*([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)[^\)]*\)/gi.exec(e))?(u=parseInt(t[1],10),s=parseInt(t[2],10),c=parseInt(t[3],10)):(t=/#([0-F]{2})([0-F]{2})([0-F]{2})/gi.exec(e))?(u=parseInt(t[1],16),s=parseInt(t[2],16),c=parseInt(t[3],16)):(t=/#([0-F])([0-F])([0-F])/gi.exec(e))&&(u=parseInt(t[1]+t[1],16),s=parseInt(t[2]+t[2],16),c=parseInt(t[3]+t[3],16)),u=u<0?0:255<u?255:u,s=s<0?0:255<s?255:s,c=c<0?0:255<c?255:c,n};return e&&t(e),n.toRgb=function(){return{r:u,g:s,b:c}},n.toHsv=function(){return e=u,t=s,n=c,o=0,(i=eE(e/=255,eE(t/=255,n/=255)))===(a=tE(e,tE(t,n)))?{h:0,s:0,v:100*(o=i)}:(r=(a-i)/a,{h:nE(60*((e===i?3:n===i?1:5)-(e===i?t-n:n===i?e-t:n-e)/((o=a)-i))),s:nE(100*r),v:nE(100*o)});var e,t,n,r,o,i,a},n.toHex=function(){var e=function(e){return 1<(e=parseInt(e,10).toString(16)).length?e:"0"+e};return"#"+e(u)+e(s)+e(c)},n.parse=t,n}},dom:{EventUtils:ho,Sizzle:hi,DomQuery:na,TreeWalker:ra,TextSeeker:uu,DOMUtils:ga,ScriptLoader:ba,RangeUtils:VN,Serializer:Av,ControlSelection:nv,BookmarkManager:Jh,Selection:av,Event:ho.Event},html:{Styles:ao,Entities:$r,Node:df,Schema:no,SaxParser:kf,DomParser:Ev,Writer:gf,Serializer:hf},Env:rr,AddOnManager:Ra,Annotator:af,Formatter:Wv,UndoManager:Xv,EditorCommands:PS,WindowManager:rh,NotificationManager:eh,EditorObservable:ZS,Shortcuts:uN,Editor:wN,FocusManager:xm,EditorManager:MN,DOM:ga.DOM,ScriptLoader:ba.ScriptLoader,PluginManager:Ra.PluginManager,ThemeManager:Ra.ThemeManager,IconManager:$g,Resource:qN,trim:hr.trim,isArray:hr.isArray,is:hr.is,toArray:hr.toArray,makeMap:hr.makeMap,each:hr.each,map:hr.map,grep:hr.grep,inArray:hr.inArray,extend:hr.extend,create:hr.create,walk:hr.walk,createNS:hr.createNS,resolve:hr.resolve,explode:hr.explode,_addCacheSuffix:hr._addCacheSuffix,isOpera:rr.opera,isWebKit:rr.webkit,isIE:rr.ie,isGecko:rr.gecko,isMac:rr.mac},mE=hr.extend(MN,dE);fE=mE,window.tinymce=fE,window.tinyMCE=fE,function(e){if("object"==typeof module)try{module.exports=e}catch(t){}}(mE)}(window);
|
|
/**
|
|
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
|
|
* Licensed under the LGPL or a commercial license.
|
|
* For LGPL see License.txt in the project root for license information.
|
|
* For commercial licenses see https://www.tiny.cloud/
|
|
*
|
|
* Version: 5.3.1 (2020-05-27)
|
|
*/
|
|
(function (domGlobals) {
|
|
'use strict';
|
|
|
|
var noop = function () {
|
|
};
|
|
var noarg = function (f) {
|
|
return function () {
|
|
return f();
|
|
};
|
|
};
|
|
var compose = function (fa, fb) {
|
|
return function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
return fa(fb.apply(null, args));
|
|
};
|
|
};
|
|
var constant = function (value) {
|
|
return function () {
|
|
return value;
|
|
};
|
|
};
|
|
var identity = function (x) {
|
|
return x;
|
|
};
|
|
function curry(fn) {
|
|
var initialArgs = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
initialArgs[_i - 1] = arguments[_i];
|
|
}
|
|
return function () {
|
|
var restArgs = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
restArgs[_i] = arguments[_i];
|
|
}
|
|
var all = initialArgs.concat(restArgs);
|
|
return fn.apply(null, all);
|
|
};
|
|
}
|
|
var not = function (f) {
|
|
return function (t) {
|
|
return !f(t);
|
|
};
|
|
};
|
|
var die = function (msg) {
|
|
return function () {
|
|
throw new Error(msg);
|
|
};
|
|
};
|
|
var never = constant(false);
|
|
var always = constant(true);
|
|
|
|
var global$1 = tinymce.util.Tools.resolve('tinymce.ThemeManager');
|
|
|
|
var __assign = function () {
|
|
__assign = Object.assign || function __assign(t) {
|
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
s = arguments[i];
|
|
for (var p in s)
|
|
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
t[p] = s[p];
|
|
}
|
|
return t;
|
|
};
|
|
return __assign.apply(this, arguments);
|
|
};
|
|
function __rest(s, e) {
|
|
var t = {};
|
|
for (var p in s)
|
|
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
t[p] = s[p];
|
|
if (s != null && typeof Object.getOwnPropertySymbols === 'function')
|
|
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
t[p[i]] = s[p[i]];
|
|
}
|
|
return t;
|
|
}
|
|
function __spreadArrays() {
|
|
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
s += arguments[i].length;
|
|
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
r[k] = a[j];
|
|
return r;
|
|
}
|
|
|
|
var none = function () {
|
|
return NONE;
|
|
};
|
|
var NONE = function () {
|
|
var eq = function (o) {
|
|
return o.isNone();
|
|
};
|
|
var call = function (thunk) {
|
|
return thunk();
|
|
};
|
|
var id = function (n) {
|
|
return n;
|
|
};
|
|
var me = {
|
|
fold: function (n, _s) {
|
|
return n();
|
|
},
|
|
is: never,
|
|
isSome: never,
|
|
isNone: always,
|
|
getOr: id,
|
|
getOrThunk: call,
|
|
getOrDie: function (msg) {
|
|
throw new Error(msg || 'error: getOrDie called on none.');
|
|
},
|
|
getOrNull: constant(null),
|
|
getOrUndefined: constant(undefined),
|
|
or: id,
|
|
orThunk: call,
|
|
map: none,
|
|
each: noop,
|
|
bind: none,
|
|
exists: never,
|
|
forall: always,
|
|
filter: none,
|
|
equals: eq,
|
|
equals_: eq,
|
|
toArray: function () {
|
|
return [];
|
|
},
|
|
toString: constant('none()')
|
|
};
|
|
return me;
|
|
}();
|
|
var some = function (a) {
|
|
var constant_a = constant(a);
|
|
var self = function () {
|
|
return me;
|
|
};
|
|
var bind = function (f) {
|
|
return f(a);
|
|
};
|
|
var me = {
|
|
fold: function (n, s) {
|
|
return s(a);
|
|
},
|
|
is: function (v) {
|
|
return a === v;
|
|
},
|
|
isSome: always,
|
|
isNone: never,
|
|
getOr: constant_a,
|
|
getOrThunk: constant_a,
|
|
getOrDie: constant_a,
|
|
getOrNull: constant_a,
|
|
getOrUndefined: constant_a,
|
|
or: self,
|
|
orThunk: self,
|
|
map: function (f) {
|
|
return some(f(a));
|
|
},
|
|
each: function (f) {
|
|
f(a);
|
|
},
|
|
bind: bind,
|
|
exists: bind,
|
|
forall: bind,
|
|
filter: function (f) {
|
|
return f(a) ? me : NONE;
|
|
},
|
|
toArray: function () {
|
|
return [a];
|
|
},
|
|
toString: function () {
|
|
return 'some(' + a + ')';
|
|
},
|
|
equals: function (o) {
|
|
return o.is(a);
|
|
},
|
|
equals_: function (o, elementEq) {
|
|
return o.fold(never, function (b) {
|
|
return elementEq(a, b);
|
|
});
|
|
}
|
|
};
|
|
return me;
|
|
};
|
|
var from = function (value) {
|
|
return value === null || value === undefined ? NONE : some(value);
|
|
};
|
|
var Option = {
|
|
some: some,
|
|
none: none,
|
|
from: from
|
|
};
|
|
|
|
var value = function (o) {
|
|
var is = function (v) {
|
|
return o === v;
|
|
};
|
|
var or = function (_opt) {
|
|
return value(o);
|
|
};
|
|
var orThunk = function (_f) {
|
|
return value(o);
|
|
};
|
|
var map = function (f) {
|
|
return value(f(o));
|
|
};
|
|
var mapError = function (_f) {
|
|
return value(o);
|
|
};
|
|
var each = function (f) {
|
|
f(o);
|
|
};
|
|
var bind = function (f) {
|
|
return f(o);
|
|
};
|
|
var fold = function (_, onValue) {
|
|
return onValue(o);
|
|
};
|
|
var exists = function (f) {
|
|
return f(o);
|
|
};
|
|
var forall = function (f) {
|
|
return f(o);
|
|
};
|
|
var toOption = function () {
|
|
return Option.some(o);
|
|
};
|
|
return {
|
|
is: is,
|
|
isValue: always,
|
|
isError: never,
|
|
getOr: constant(o),
|
|
getOrThunk: constant(o),
|
|
getOrDie: constant(o),
|
|
or: or,
|
|
orThunk: orThunk,
|
|
fold: fold,
|
|
map: map,
|
|
mapError: mapError,
|
|
each: each,
|
|
bind: bind,
|
|
exists: exists,
|
|
forall: forall,
|
|
toOption: toOption
|
|
};
|
|
};
|
|
var error = function (message) {
|
|
var getOrThunk = function (f) {
|
|
return f();
|
|
};
|
|
var getOrDie = function () {
|
|
return die(String(message))();
|
|
};
|
|
var or = function (opt) {
|
|
return opt;
|
|
};
|
|
var orThunk = function (f) {
|
|
return f();
|
|
};
|
|
var map = function (_f) {
|
|
return error(message);
|
|
};
|
|
var mapError = function (f) {
|
|
return error(f(message));
|
|
};
|
|
var bind = function (_f) {
|
|
return error(message);
|
|
};
|
|
var fold = function (onError, _) {
|
|
return onError(message);
|
|
};
|
|
return {
|
|
is: never,
|
|
isValue: never,
|
|
isError: always,
|
|
getOr: identity,
|
|
getOrThunk: getOrThunk,
|
|
getOrDie: getOrDie,
|
|
or: or,
|
|
orThunk: orThunk,
|
|
fold: fold,
|
|
map: map,
|
|
mapError: mapError,
|
|
each: noop,
|
|
bind: bind,
|
|
exists: never,
|
|
forall: always,
|
|
toOption: Option.none
|
|
};
|
|
};
|
|
var fromOption = function (opt, err) {
|
|
return opt.fold(function () {
|
|
return error(err);
|
|
}, value);
|
|
};
|
|
var Result = {
|
|
value: value,
|
|
error: error,
|
|
fromOption: fromOption
|
|
};
|
|
|
|
var typeOf = function (x) {
|
|
var t = typeof x;
|
|
if (x === null) {
|
|
return 'null';
|
|
} else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
|
|
return 'array';
|
|
} else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
|
|
return 'string';
|
|
} else {
|
|
return t;
|
|
}
|
|
};
|
|
var isType = function (type) {
|
|
return function (value) {
|
|
return typeOf(value) === type;
|
|
};
|
|
};
|
|
var isSimpleType = function (type) {
|
|
return function (value) {
|
|
return typeof value === type;
|
|
};
|
|
};
|
|
var eq = function (t) {
|
|
return function (a) {
|
|
return t === a;
|
|
};
|
|
};
|
|
var isString = isType('string');
|
|
var isObject = isType('object');
|
|
var isArray = isType('array');
|
|
var isBoolean = isSimpleType('boolean');
|
|
var isUndefined = eq(undefined);
|
|
var isFunction = isSimpleType('function');
|
|
var isNumber = isSimpleType('number');
|
|
var isArrayOf = function (value, pred) {
|
|
if (isArray(value)) {
|
|
for (var i = 0, len = value.length; i < len; ++i) {
|
|
if (!pred(value[i])) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
var nativeSlice = Array.prototype.slice;
|
|
var nativeIndexOf = Array.prototype.indexOf;
|
|
var nativePush = Array.prototype.push;
|
|
var rawIndexOf = function (ts, t) {
|
|
return nativeIndexOf.call(ts, t);
|
|
};
|
|
var indexOf = function (xs, x) {
|
|
var r = rawIndexOf(xs, x);
|
|
return r === -1 ? Option.none() : Option.some(r);
|
|
};
|
|
var contains = function (xs, x) {
|
|
return rawIndexOf(xs, x) > -1;
|
|
};
|
|
var exists = function (xs, pred) {
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
if (pred(x, i)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
var range = function (num, f) {
|
|
var r = [];
|
|
for (var i = 0; i < num; i++) {
|
|
r.push(f(i));
|
|
}
|
|
return r;
|
|
};
|
|
var chunk = function (array, size) {
|
|
var r = [];
|
|
for (var i = 0; i < array.length; i += size) {
|
|
var s = nativeSlice.call(array, i, i + size);
|
|
r.push(s);
|
|
}
|
|
return r;
|
|
};
|
|
var map = function (xs, f) {
|
|
var len = xs.length;
|
|
var r = new Array(len);
|
|
for (var i = 0; i < len; i++) {
|
|
var x = xs[i];
|
|
r[i] = f(x, i);
|
|
}
|
|
return r;
|
|
};
|
|
var each = function (xs, f) {
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
f(x, i);
|
|
}
|
|
};
|
|
var eachr = function (xs, f) {
|
|
for (var i = xs.length - 1; i >= 0; i--) {
|
|
var x = xs[i];
|
|
f(x, i);
|
|
}
|
|
};
|
|
var partition = function (xs, pred) {
|
|
var pass = [];
|
|
var fail = [];
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
var arr = pred(x, i) ? pass : fail;
|
|
arr.push(x);
|
|
}
|
|
return {
|
|
pass: pass,
|
|
fail: fail
|
|
};
|
|
};
|
|
var filter = function (xs, pred) {
|
|
var r = [];
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
if (pred(x, i)) {
|
|
r.push(x);
|
|
}
|
|
}
|
|
return r;
|
|
};
|
|
var foldr = function (xs, f, acc) {
|
|
eachr(xs, function (x) {
|
|
acc = f(acc, x);
|
|
});
|
|
return acc;
|
|
};
|
|
var foldl = function (xs, f, acc) {
|
|
each(xs, function (x) {
|
|
acc = f(acc, x);
|
|
});
|
|
return acc;
|
|
};
|
|
var findUntil = function (xs, pred, until) {
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
if (pred(x, i)) {
|
|
return Option.some(x);
|
|
} else if (until(x, i)) {
|
|
break;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var find = function (xs, pred) {
|
|
return findUntil(xs, pred, never);
|
|
};
|
|
var findIndex = function (xs, pred) {
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
if (pred(x, i)) {
|
|
return Option.some(i);
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var flatten = function (xs) {
|
|
var r = [];
|
|
for (var i = 0, len = xs.length; i < len; ++i) {
|
|
if (!isArray(xs[i])) {
|
|
throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
|
|
}
|
|
nativePush.apply(r, xs[i]);
|
|
}
|
|
return r;
|
|
};
|
|
var bind = function (xs, f) {
|
|
return flatten(map(xs, f));
|
|
};
|
|
var forall = function (xs, pred) {
|
|
for (var i = 0, len = xs.length; i < len; ++i) {
|
|
var x = xs[i];
|
|
if (pred(x, i) !== true) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
var reverse = function (xs) {
|
|
var r = nativeSlice.call(xs, 0);
|
|
r.reverse();
|
|
return r;
|
|
};
|
|
var difference = function (a1, a2) {
|
|
return filter(a1, function (x) {
|
|
return !contains(a2, x);
|
|
});
|
|
};
|
|
var mapToObject = function (xs, f) {
|
|
var r = {};
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
r[String(x)] = f(x, i);
|
|
}
|
|
return r;
|
|
};
|
|
var pure = function (x) {
|
|
return [x];
|
|
};
|
|
var sort = function (xs, comparator) {
|
|
var copy = nativeSlice.call(xs, 0);
|
|
copy.sort(comparator);
|
|
return copy;
|
|
};
|
|
var head = function (xs) {
|
|
return xs.length === 0 ? Option.none() : Option.some(xs[0]);
|
|
};
|
|
var last = function (xs) {
|
|
return xs.length === 0 ? Option.none() : Option.some(xs[xs.length - 1]);
|
|
};
|
|
var from$1 = isFunction(Array.from) ? Array.from : function (x) {
|
|
return nativeSlice.call(x);
|
|
};
|
|
var findMap = function (arr, f) {
|
|
for (var i = 0; i < arr.length; i++) {
|
|
var r = f(arr[i], i);
|
|
if (r.isSome()) {
|
|
return r;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
|
|
var keys = Object.keys;
|
|
var hasOwnProperty = Object.hasOwnProperty;
|
|
var each$1 = function (obj, f) {
|
|
var props = keys(obj);
|
|
for (var k = 0, len = props.length; k < len; k++) {
|
|
var i = props[k];
|
|
var x = obj[i];
|
|
f(x, i);
|
|
}
|
|
};
|
|
var map$1 = function (obj, f) {
|
|
return tupleMap(obj, function (x, i) {
|
|
return {
|
|
k: i,
|
|
v: f(x, i)
|
|
};
|
|
});
|
|
};
|
|
var tupleMap = function (obj, f) {
|
|
var r = {};
|
|
each$1(obj, function (x, i) {
|
|
var tuple = f(x, i);
|
|
r[tuple.k] = tuple.v;
|
|
});
|
|
return r;
|
|
};
|
|
var objAcc = function (r) {
|
|
return function (x, i) {
|
|
r[i] = x;
|
|
};
|
|
};
|
|
var internalFilter = function (obj, pred, onTrue, onFalse) {
|
|
var r = {};
|
|
each$1(obj, function (x, i) {
|
|
(pred(x, i) ? onTrue : onFalse)(x, i);
|
|
});
|
|
return r;
|
|
};
|
|
var filter$1 = function (obj, pred) {
|
|
var t = {};
|
|
internalFilter(obj, pred, objAcc(t), noop);
|
|
return t;
|
|
};
|
|
var mapToArray = function (obj, f) {
|
|
var r = [];
|
|
each$1(obj, function (value, name) {
|
|
r.push(f(value, name));
|
|
});
|
|
return r;
|
|
};
|
|
var find$1 = function (obj, pred) {
|
|
var props = keys(obj);
|
|
for (var k = 0, len = props.length; k < len; k++) {
|
|
var i = props[k];
|
|
var x = obj[i];
|
|
if (pred(x, i, obj)) {
|
|
return Option.some(x);
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var values = function (obj) {
|
|
return mapToArray(obj, function (v) {
|
|
return v;
|
|
});
|
|
};
|
|
var get = function (obj, key) {
|
|
return has(obj, key) ? Option.from(obj[key]) : Option.none();
|
|
};
|
|
var has = function (obj, key) {
|
|
return hasOwnProperty.call(obj, key);
|
|
};
|
|
var hasNonNullableKey = function (obj, key) {
|
|
return has(obj, key) && obj[key] !== undefined && obj[key] !== null;
|
|
};
|
|
|
|
var generate = function (cases) {
|
|
if (!isArray(cases)) {
|
|
throw new Error('cases must be an array');
|
|
}
|
|
if (cases.length === 0) {
|
|
throw new Error('there must be at least one case');
|
|
}
|
|
var constructors = [];
|
|
var adt = {};
|
|
each(cases, function (acase, count) {
|
|
var keys$1 = keys(acase);
|
|
if (keys$1.length !== 1) {
|
|
throw new Error('one and only one name per case');
|
|
}
|
|
var key = keys$1[0];
|
|
var value = acase[key];
|
|
if (adt[key] !== undefined) {
|
|
throw new Error('duplicate key detected:' + key);
|
|
} else if (key === 'cata') {
|
|
throw new Error('cannot have a case named cata (sorry)');
|
|
} else if (!isArray(value)) {
|
|
throw new Error('case arguments must be an array');
|
|
}
|
|
constructors.push(key);
|
|
adt[key] = function () {
|
|
var argLength = arguments.length;
|
|
if (argLength !== value.length) {
|
|
throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
|
|
}
|
|
var args = new Array(argLength);
|
|
for (var i = 0; i < args.length; i++) {
|
|
args[i] = arguments[i];
|
|
}
|
|
var match = function (branches) {
|
|
var branchKeys = keys(branches);
|
|
if (constructors.length !== branchKeys.length) {
|
|
throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
|
|
}
|
|
var allReqd = forall(constructors, function (reqKey) {
|
|
return contains(branchKeys, reqKey);
|
|
});
|
|
if (!allReqd) {
|
|
throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
|
|
}
|
|
return branches[key].apply(null, args);
|
|
};
|
|
return {
|
|
fold: function () {
|
|
if (arguments.length !== cases.length) {
|
|
throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + arguments.length);
|
|
}
|
|
var target = arguments[count];
|
|
return target.apply(null, args);
|
|
},
|
|
match: match,
|
|
log: function (label) {
|
|
domGlobals.console.log(label, {
|
|
constructors: constructors,
|
|
constructor: key,
|
|
params: args
|
|
});
|
|
}
|
|
};
|
|
};
|
|
});
|
|
return adt;
|
|
};
|
|
var Adt = { generate: generate };
|
|
|
|
var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
var shallow = function (old, nu) {
|
|
return nu;
|
|
};
|
|
var deep = function (old, nu) {
|
|
var bothObjects = isObject(old) && isObject(nu);
|
|
return bothObjects ? deepMerge(old, nu) : nu;
|
|
};
|
|
var baseMerge = function (merger) {
|
|
return function () {
|
|
var objects = new Array(arguments.length);
|
|
for (var i = 0; i < objects.length; i++) {
|
|
objects[i] = arguments[i];
|
|
}
|
|
if (objects.length === 0) {
|
|
throw new Error('Can\'t merge zero objects');
|
|
}
|
|
var ret = {};
|
|
for (var j = 0; j < objects.length; j++) {
|
|
var curObject = objects[j];
|
|
for (var key in curObject) {
|
|
if (hasOwnProperty$1.call(curObject, key)) {
|
|
ret[key] = merger(ret[key], curObject[key]);
|
|
}
|
|
}
|
|
}
|
|
return ret;
|
|
};
|
|
};
|
|
var deepMerge = baseMerge(deep);
|
|
var merge = baseMerge(shallow);
|
|
|
|
var cached = function (f) {
|
|
var called = false;
|
|
var r;
|
|
return function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
if (!called) {
|
|
called = true;
|
|
r = f.apply(null, args);
|
|
}
|
|
return r;
|
|
};
|
|
};
|
|
|
|
var SimpleResultType;
|
|
(function (SimpleResultType) {
|
|
SimpleResultType[SimpleResultType['Error'] = 0] = 'Error';
|
|
SimpleResultType[SimpleResultType['Value'] = 1] = 'Value';
|
|
}(SimpleResultType || (SimpleResultType = {})));
|
|
var fold = function (res, onError, onValue) {
|
|
return res.stype === SimpleResultType.Error ? onError(res.serror) : onValue(res.svalue);
|
|
};
|
|
var partition$1 = function (results) {
|
|
var values = [];
|
|
var errors = [];
|
|
each(results, function (obj) {
|
|
fold(obj, function (err) {
|
|
return errors.push(err);
|
|
}, function (val) {
|
|
return values.push(val);
|
|
});
|
|
});
|
|
return {
|
|
values: values,
|
|
errors: errors
|
|
};
|
|
};
|
|
var mapError = function (res, f) {
|
|
if (res.stype === SimpleResultType.Error) {
|
|
return {
|
|
stype: SimpleResultType.Error,
|
|
serror: f(res.serror)
|
|
};
|
|
} else {
|
|
return res;
|
|
}
|
|
};
|
|
var map$2 = function (res, f) {
|
|
if (res.stype === SimpleResultType.Value) {
|
|
return {
|
|
stype: SimpleResultType.Value,
|
|
svalue: f(res.svalue)
|
|
};
|
|
} else {
|
|
return res;
|
|
}
|
|
};
|
|
var bind$1 = function (res, f) {
|
|
if (res.stype === SimpleResultType.Value) {
|
|
return f(res.svalue);
|
|
} else {
|
|
return res;
|
|
}
|
|
};
|
|
var bindError = function (res, f) {
|
|
if (res.stype === SimpleResultType.Error) {
|
|
return f(res.serror);
|
|
} else {
|
|
return res;
|
|
}
|
|
};
|
|
var svalue = function (v) {
|
|
return {
|
|
stype: SimpleResultType.Value,
|
|
svalue: v
|
|
};
|
|
};
|
|
var serror = function (e) {
|
|
return {
|
|
stype: SimpleResultType.Error,
|
|
serror: e
|
|
};
|
|
};
|
|
var toResult = function (res) {
|
|
return fold(res, Result.error, Result.value);
|
|
};
|
|
var fromResult = function (res) {
|
|
return res.fold(serror, svalue);
|
|
};
|
|
var SimpleResult = {
|
|
fromResult: fromResult,
|
|
toResult: toResult,
|
|
svalue: svalue,
|
|
partition: partition$1,
|
|
serror: serror,
|
|
bind: bind$1,
|
|
bindError: bindError,
|
|
map: map$2,
|
|
mapError: mapError,
|
|
fold: fold
|
|
};
|
|
|
|
var adt = Adt.generate([
|
|
{ strict: [] },
|
|
{ defaultedThunk: ['fallbackThunk'] },
|
|
{ asOption: [] },
|
|
{ asDefaultedOptionThunk: ['fallbackThunk'] },
|
|
{ mergeWithThunk: ['baseThunk'] }
|
|
]);
|
|
var defaulted = function (fallback) {
|
|
return adt.defaultedThunk(constant(fallback));
|
|
};
|
|
var mergeWith = function (base) {
|
|
return adt.mergeWithThunk(constant(base));
|
|
};
|
|
var strict = adt.strict;
|
|
var asOption = adt.asOption;
|
|
var defaultedThunk = adt.defaultedThunk;
|
|
var asDefaultedOptionThunk = adt.asDefaultedOptionThunk;
|
|
var mergeWithThunk = adt.mergeWithThunk;
|
|
|
|
var exclude = function (obj, fields) {
|
|
var r = {};
|
|
each$1(obj, function (v, k) {
|
|
if (!contains(fields, k)) {
|
|
r[k] = v;
|
|
}
|
|
});
|
|
return r;
|
|
};
|
|
|
|
var wrap = function (key, value) {
|
|
var _a;
|
|
return _a = {}, _a[key] = value, _a;
|
|
};
|
|
var wrapAll = function (keyvalues) {
|
|
var r = {};
|
|
each(keyvalues, function (kv) {
|
|
r[kv.key] = kv.value;
|
|
});
|
|
return r;
|
|
};
|
|
|
|
var comparison = Adt.generate([
|
|
{
|
|
bothErrors: [
|
|
'error1',
|
|
'error2'
|
|
]
|
|
},
|
|
{
|
|
firstError: [
|
|
'error1',
|
|
'value2'
|
|
]
|
|
},
|
|
{
|
|
secondError: [
|
|
'value1',
|
|
'error2'
|
|
]
|
|
},
|
|
{
|
|
bothValues: [
|
|
'value1',
|
|
'value2'
|
|
]
|
|
}
|
|
]);
|
|
var partition$2 = function (results) {
|
|
var errors = [];
|
|
var values = [];
|
|
each(results, function (result) {
|
|
result.fold(function (err) {
|
|
errors.push(err);
|
|
}, function (value) {
|
|
values.push(value);
|
|
});
|
|
});
|
|
return {
|
|
errors: errors,
|
|
values: values
|
|
};
|
|
};
|
|
|
|
var exclude$1 = function (obj, fields) {
|
|
return exclude(obj, fields);
|
|
};
|
|
var wrap$1 = function (key, value) {
|
|
return wrap(key, value);
|
|
};
|
|
var wrapAll$1 = function (keyvalues) {
|
|
return wrapAll(keyvalues);
|
|
};
|
|
var mergeValues = function (values, base) {
|
|
return values.length === 0 ? Result.value(base) : Result.value(deepMerge(base, merge.apply(undefined, values)));
|
|
};
|
|
var mergeErrors = function (errors) {
|
|
return Result.error(flatten(errors));
|
|
};
|
|
var consolidate = function (objs, base) {
|
|
var partitions = partition$2(objs);
|
|
return partitions.errors.length > 0 ? mergeErrors(partitions.errors) : mergeValues(partitions.values, base);
|
|
};
|
|
|
|
var mergeValues$1 = function (values, base) {
|
|
return values.length > 0 ? SimpleResult.svalue(deepMerge(base, merge.apply(undefined, values))) : SimpleResult.svalue(base);
|
|
};
|
|
var mergeErrors$1 = function (errors) {
|
|
return compose(SimpleResult.serror, flatten)(errors);
|
|
};
|
|
var consolidateObj = function (objects, base) {
|
|
var partition = SimpleResult.partition(objects);
|
|
return partition.errors.length > 0 ? mergeErrors$1(partition.errors) : mergeValues$1(partition.values, base);
|
|
};
|
|
var consolidateArr = function (objects) {
|
|
var partitions = SimpleResult.partition(objects);
|
|
return partitions.errors.length > 0 ? mergeErrors$1(partitions.errors) : SimpleResult.svalue(partitions.values);
|
|
};
|
|
var ResultCombine = {
|
|
consolidateObj: consolidateObj,
|
|
consolidateArr: consolidateArr
|
|
};
|
|
|
|
var formatObj = function (input) {
|
|
return isObject(input) && keys(input).length > 100 ? ' removed due to size' : JSON.stringify(input, null, 2);
|
|
};
|
|
var formatErrors = function (errors) {
|
|
var es = errors.length > 10 ? errors.slice(0, 10).concat([{
|
|
path: [],
|
|
getErrorInfo: function () {
|
|
return '... (only showing first ten failures)';
|
|
}
|
|
}]) : errors;
|
|
return map(es, function (e) {
|
|
return 'Failed path: (' + e.path.join(' > ') + ')\n' + e.getErrorInfo();
|
|
});
|
|
};
|
|
|
|
var nu = function (path, getErrorInfo) {
|
|
return SimpleResult.serror([{
|
|
path: path,
|
|
getErrorInfo: getErrorInfo
|
|
}]);
|
|
};
|
|
var missingStrict = function (path, key, obj) {
|
|
return nu(path, function () {
|
|
return 'Could not find valid *strict* value for "' + key + '" in ' + formatObj(obj);
|
|
});
|
|
};
|
|
var missingKey = function (path, key) {
|
|
return nu(path, function () {
|
|
return 'Choice schema did not contain choice key: "' + key + '"';
|
|
});
|
|
};
|
|
var missingBranch = function (path, branches, branch) {
|
|
return nu(path, function () {
|
|
return 'The chosen schema: "' + branch + '" did not exist in branches: ' + formatObj(branches);
|
|
});
|
|
};
|
|
var unsupportedFields = function (path, unsupported) {
|
|
return nu(path, function () {
|
|
return 'There are unsupported fields: [' + unsupported.join(', ') + '] specified';
|
|
});
|
|
};
|
|
var custom = function (path, err) {
|
|
return nu(path, function () {
|
|
return err;
|
|
});
|
|
};
|
|
|
|
var adt$1 = Adt.generate([
|
|
{
|
|
field: [
|
|
'key',
|
|
'okey',
|
|
'presence',
|
|
'prop'
|
|
]
|
|
},
|
|
{
|
|
state: [
|
|
'okey',
|
|
'instantiator'
|
|
]
|
|
}
|
|
]);
|
|
var strictAccess = function (path, obj, key) {
|
|
return get(obj, key).fold(function () {
|
|
return missingStrict(path, key, obj);
|
|
}, SimpleResult.svalue);
|
|
};
|
|
var fallbackAccess = function (obj, key, fallbackThunk) {
|
|
var v = get(obj, key).fold(function () {
|
|
return fallbackThunk(obj);
|
|
}, identity);
|
|
return SimpleResult.svalue(v);
|
|
};
|
|
var optionAccess = function (obj, key) {
|
|
return SimpleResult.svalue(get(obj, key));
|
|
};
|
|
var optionDefaultedAccess = function (obj, key, fallback) {
|
|
var opt = get(obj, key).map(function (val) {
|
|
return val === true ? fallback(obj) : val;
|
|
});
|
|
return SimpleResult.svalue(opt);
|
|
};
|
|
var cExtractOne = function (path, obj, field, strength) {
|
|
return field.fold(function (key, okey, presence, prop) {
|
|
var bundle = function (av) {
|
|
var result = prop.extract(path.concat([key]), strength, av);
|
|
return SimpleResult.map(result, function (res) {
|
|
return wrap(okey, strength(res));
|
|
});
|
|
};
|
|
var bundleAsOption = function (optValue) {
|
|
return optValue.fold(function () {
|
|
var outcome = wrap(okey, strength(Option.none()));
|
|
return SimpleResult.svalue(outcome);
|
|
}, function (ov) {
|
|
var result = prop.extract(path.concat([key]), strength, ov);
|
|
return SimpleResult.map(result, function (res) {
|
|
return wrap(okey, strength(Option.some(res)));
|
|
});
|
|
});
|
|
};
|
|
return function () {
|
|
return presence.fold(function () {
|
|
return SimpleResult.bind(strictAccess(path, obj, key), bundle);
|
|
}, function (fallbackThunk) {
|
|
return SimpleResult.bind(fallbackAccess(obj, key, fallbackThunk), bundle);
|
|
}, function () {
|
|
return SimpleResult.bind(optionAccess(obj, key), bundleAsOption);
|
|
}, function (fallbackThunk) {
|
|
return SimpleResult.bind(optionDefaultedAccess(obj, key, fallbackThunk), bundleAsOption);
|
|
}, function (baseThunk) {
|
|
var base = baseThunk(obj);
|
|
var result = SimpleResult.map(fallbackAccess(obj, key, constant({})), function (v) {
|
|
return deepMerge(base, v);
|
|
});
|
|
return SimpleResult.bind(result, bundle);
|
|
});
|
|
}();
|
|
}, function (okey, instantiator) {
|
|
var state = instantiator(obj);
|
|
return SimpleResult.svalue(wrap(okey, strength(state)));
|
|
});
|
|
};
|
|
var cExtract = function (path, obj, fields, strength) {
|
|
var results = map(fields, function (field) {
|
|
return cExtractOne(path, obj, field, strength);
|
|
});
|
|
return ResultCombine.consolidateObj(results, {});
|
|
};
|
|
var valueThunk = function (getDelegate) {
|
|
var extract = function (path, strength, val) {
|
|
return getDelegate().extract(path, strength, val);
|
|
};
|
|
var toString = function () {
|
|
return getDelegate().toString();
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var value$1 = function (validator) {
|
|
var extract = function (path, strength, val) {
|
|
return SimpleResult.bindError(validator(val, strength), function (err) {
|
|
return custom(path, err);
|
|
});
|
|
};
|
|
var toString = function () {
|
|
return 'val';
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var getSetKeys = function (obj) {
|
|
return keys(filter$1(obj, function (value) {
|
|
return value !== undefined && value !== null;
|
|
}));
|
|
};
|
|
var objOfOnly = function (fields) {
|
|
var delegate = objOf(fields);
|
|
var fieldNames = foldr(fields, function (acc, f) {
|
|
return f.fold(function (key) {
|
|
return deepMerge(acc, wrap$1(key, true));
|
|
}, constant(acc));
|
|
}, {});
|
|
var extract = function (path, strength, o) {
|
|
var keys = isBoolean(o) ? [] : getSetKeys(o);
|
|
var extra = filter(keys, function (k) {
|
|
return !hasNonNullableKey(fieldNames, k);
|
|
});
|
|
return extra.length === 0 ? delegate.extract(path, strength, o) : unsupportedFields(path, extra);
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: delegate.toString
|
|
};
|
|
};
|
|
var objOf = function (fields) {
|
|
var extract = function (path, strength, o) {
|
|
return cExtract(path, o, fields, strength);
|
|
};
|
|
var toString = function () {
|
|
var fieldStrings = map(fields, function (field) {
|
|
return field.fold(function (key, okey, presence, prop) {
|
|
return key + ' -> ' + prop.toString();
|
|
}, function (okey, _instantiator) {
|
|
return 'state(' + okey + ')';
|
|
});
|
|
});
|
|
return 'obj{\n' + fieldStrings.join('\n') + '}';
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var arrOf = function (prop) {
|
|
var extract = function (path, strength, array) {
|
|
var results = map(array, function (a, i) {
|
|
return prop.extract(path.concat(['[' + i + ']']), strength, a);
|
|
});
|
|
return ResultCombine.consolidateArr(results);
|
|
};
|
|
var toString = function () {
|
|
return 'array(' + prop.toString() + ')';
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var oneOf = function (props) {
|
|
var extract = function (path, strength, val) {
|
|
var errors = [];
|
|
for (var _i = 0, props_1 = props; _i < props_1.length; _i++) {
|
|
var prop = props_1[_i];
|
|
var res = prop.extract(path, strength, val);
|
|
if (res.stype === SimpleResultType.Value) {
|
|
return res;
|
|
}
|
|
errors.push(res);
|
|
}
|
|
return ResultCombine.consolidateArr(errors);
|
|
};
|
|
var toString = function () {
|
|
return 'oneOf(' + map(props, function (prop) {
|
|
return prop.toString();
|
|
}).join(', ') + ')';
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var setOf = function (validator, prop) {
|
|
var validateKeys = function (path, keys) {
|
|
return arrOf(value$1(validator)).extract(path, identity, keys);
|
|
};
|
|
var extract = function (path, strength, o) {
|
|
var keys$1 = keys(o);
|
|
var validatedKeys = validateKeys(path, keys$1);
|
|
return SimpleResult.bind(validatedKeys, function (validKeys) {
|
|
var schema = map(validKeys, function (vk) {
|
|
return adt$1.field(vk, vk, strict(), prop);
|
|
});
|
|
return objOf(schema).extract(path, strength, o);
|
|
});
|
|
};
|
|
var toString = function () {
|
|
return 'setOf(' + prop.toString() + ')';
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var anyValue = constant(value$1(SimpleResult.svalue));
|
|
var arrOfObj = compose(arrOf, objOf);
|
|
var state = adt$1.state;
|
|
var field = adt$1.field;
|
|
|
|
var chooseFrom = function (path, strength, input, branches, ch) {
|
|
var fields = get(branches, ch);
|
|
return fields.fold(function () {
|
|
return missingBranch(path, branches, ch);
|
|
}, function (vp) {
|
|
return vp.extract(path.concat(['branch: ' + ch]), strength, input);
|
|
});
|
|
};
|
|
var choose = function (key, branches) {
|
|
var extract = function (path, strength, input) {
|
|
var choice = get(input, key);
|
|
return choice.fold(function () {
|
|
return missingKey(path, key);
|
|
}, function (chosen) {
|
|
return chooseFrom(path, strength, input, branches, chosen);
|
|
});
|
|
};
|
|
var toString = function () {
|
|
return 'chooseOn(' + key + '). Possible values: ' + keys(branches);
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
|
|
var _anyValue = value$1(SimpleResult.svalue);
|
|
var arrOfObj$1 = function (objFields) {
|
|
return arrOfObj(objFields);
|
|
};
|
|
var arrOfVal = function () {
|
|
return arrOf(_anyValue);
|
|
};
|
|
var valueThunkOf = valueThunk;
|
|
var valueOf = function (validator) {
|
|
return value$1(function (v) {
|
|
return validator(v).fold(SimpleResult.serror, SimpleResult.svalue);
|
|
});
|
|
};
|
|
var setOf$1 = function (validator, prop) {
|
|
return setOf(function (v) {
|
|
return SimpleResult.fromResult(validator(v));
|
|
}, prop);
|
|
};
|
|
var extract = function (label, prop, strength, obj) {
|
|
var res = prop.extract([label], strength, obj);
|
|
return SimpleResult.mapError(res, function (errs) {
|
|
return {
|
|
input: obj,
|
|
errors: errs
|
|
};
|
|
});
|
|
};
|
|
var asRaw = function (label, prop, obj) {
|
|
return SimpleResult.toResult(extract(label, prop, identity, obj));
|
|
};
|
|
var getOrDie = function (extraction) {
|
|
return extraction.fold(function (errInfo) {
|
|
throw new Error(formatError(errInfo));
|
|
}, identity);
|
|
};
|
|
var asRawOrDie = function (label, prop, obj) {
|
|
return getOrDie(asRaw(label, prop, obj));
|
|
};
|
|
var formatError = function (errInfo) {
|
|
return 'Errors: \n' + formatErrors(errInfo.errors).join('\n') + '\n\nInput object: ' + formatObj(errInfo.input);
|
|
};
|
|
var chooseProcessor = function (key, branches) {
|
|
return choose(key, branches);
|
|
};
|
|
var choose$1 = function (key, branches) {
|
|
return choose(key, map$1(branches, objOf));
|
|
};
|
|
var anyValue$1 = constant(_anyValue);
|
|
var typedValue = function (validator, expectedType) {
|
|
return value$1(function (a) {
|
|
var actualType = typeof a;
|
|
return validator(a) ? SimpleResult.svalue(a) : SimpleResult.serror('Expected type: ' + expectedType + ' but got: ' + actualType);
|
|
});
|
|
};
|
|
var number = typedValue(isNumber, 'number');
|
|
var string = typedValue(isString, 'string');
|
|
var boolean = typedValue(isBoolean, 'boolean');
|
|
var functionProcessor = typedValue(isFunction, 'function');
|
|
var isPostMessageable = function (val) {
|
|
var every = function (iter, callbackFn) {
|
|
var result = iter.next();
|
|
while (!result.done) {
|
|
if (!callbackFn(result.value)) {
|
|
return false;
|
|
}
|
|
result = iter.next();
|
|
}
|
|
return true;
|
|
};
|
|
if (Object(val) !== val) {
|
|
return true;
|
|
}
|
|
switch ({}.toString.call(val).slice(8, -1)) {
|
|
case 'Boolean':
|
|
case 'Number':
|
|
case 'String':
|
|
case 'Date':
|
|
case 'RegExp':
|
|
case 'Blob':
|
|
case 'FileList':
|
|
case 'ImageData':
|
|
case 'ImageBitmap':
|
|
case 'ArrayBuffer':
|
|
return true;
|
|
case 'Array':
|
|
case 'Object':
|
|
return Object.keys(val).every(function (prop) {
|
|
return isPostMessageable(val[prop]);
|
|
});
|
|
case 'Map':
|
|
return every(val.keys(), isPostMessageable) && every(val.values(), isPostMessageable);
|
|
case 'Set':
|
|
return every(val.keys(), isPostMessageable);
|
|
default:
|
|
return false;
|
|
}
|
|
};
|
|
var postMessageable = value$1(function (a) {
|
|
return isPostMessageable(a) ? SimpleResult.svalue(a) : SimpleResult.serror('Expected value to be acceptable for sending via postMessage');
|
|
});
|
|
|
|
var validateEnum = function (values) {
|
|
return valueOf(function (value) {
|
|
return contains(values, value) ? Result.value(value) : Result.error('Unsupported value: "' + value + '", choose one of "' + values.join(', ') + '".');
|
|
});
|
|
};
|
|
var strict$1 = function (key) {
|
|
return field(key, key, strict(), anyValue());
|
|
};
|
|
var strictOf = function (key, schema) {
|
|
return field(key, key, strict(), schema);
|
|
};
|
|
var strictNumber = function (key) {
|
|
return strictOf(key, number);
|
|
};
|
|
var strictString = function (key) {
|
|
return strictOf(key, string);
|
|
};
|
|
var strictStringEnum = function (key, values) {
|
|
return field(key, key, strict(), validateEnum(values));
|
|
};
|
|
var strictBoolean = function (key) {
|
|
return strictOf(key, boolean);
|
|
};
|
|
var strictFunction = function (key) {
|
|
return strictOf(key, functionProcessor);
|
|
};
|
|
var forbid = function (key, message) {
|
|
return field(key, key, asOption(), value$1(function (_v) {
|
|
return SimpleResult.serror('The field: ' + key + ' is forbidden. ' + message);
|
|
}));
|
|
};
|
|
var strictObjOf = function (key, objSchema) {
|
|
return field(key, key, strict(), objOf(objSchema));
|
|
};
|
|
var strictArrayOfObj = function (key, objFields) {
|
|
return field(key, key, strict(), arrOfObj(objFields));
|
|
};
|
|
var strictArrayOf = function (key, schema) {
|
|
return field(key, key, strict(), arrOf(schema));
|
|
};
|
|
var option = function (key) {
|
|
return field(key, key, asOption(), anyValue());
|
|
};
|
|
var optionOf = function (key, schema) {
|
|
return field(key, key, asOption(), schema);
|
|
};
|
|
var optionNumber = function (key) {
|
|
return optionOf(key, number);
|
|
};
|
|
var optionString = function (key) {
|
|
return optionOf(key, string);
|
|
};
|
|
var optionFunction = function (key) {
|
|
return optionOf(key, functionProcessor);
|
|
};
|
|
var optionArrayOf = function (key, schema) {
|
|
return optionOf(key, arrOf(schema));
|
|
};
|
|
var optionObjOf = function (key, objSchema) {
|
|
return optionOf(key, objOf(objSchema));
|
|
};
|
|
var optionObjOfOnly = function (key, objSchema) {
|
|
return optionOf(key, objOfOnly(objSchema));
|
|
};
|
|
var defaulted$1 = function (key, fallback) {
|
|
return field(key, key, defaulted(fallback), anyValue());
|
|
};
|
|
var defaultedOf = function (key, fallback, schema) {
|
|
return field(key, key, defaulted(fallback), schema);
|
|
};
|
|
var defaultedNumber = function (key, fallback) {
|
|
return defaultedOf(key, fallback, number);
|
|
};
|
|
var defaultedString = function (key, fallback) {
|
|
return defaultedOf(key, fallback, string);
|
|
};
|
|
var defaultedStringEnum = function (key, fallback, values) {
|
|
return defaultedOf(key, fallback, validateEnum(values));
|
|
};
|
|
var defaultedBoolean = function (key, fallback) {
|
|
return defaultedOf(key, fallback, boolean);
|
|
};
|
|
var defaultedFunction = function (key, fallback) {
|
|
return defaultedOf(key, fallback, functionProcessor);
|
|
};
|
|
var defaultedPostMsg = function (key, fallback) {
|
|
return defaultedOf(key, fallback, postMessageable);
|
|
};
|
|
var defaultedArrayOf = function (key, fallback, schema) {
|
|
return defaultedOf(key, fallback, arrOf(schema));
|
|
};
|
|
var defaultedObjOf = function (key, fallback, objSchema) {
|
|
return defaultedOf(key, fallback, objOf(objSchema));
|
|
};
|
|
var state$1 = function (okey, instantiator) {
|
|
return state(okey, instantiator);
|
|
};
|
|
|
|
var Cell = function (initial) {
|
|
var value = initial;
|
|
var get = function () {
|
|
return value;
|
|
};
|
|
var set = function (v) {
|
|
value = v;
|
|
};
|
|
return {
|
|
get: get,
|
|
set: set
|
|
};
|
|
};
|
|
|
|
var fromHtml = function (html, scope) {
|
|
var doc = scope || domGlobals.document;
|
|
var div = doc.createElement('div');
|
|
div.innerHTML = html;
|
|
if (!div.hasChildNodes() || div.childNodes.length > 1) {
|
|
domGlobals.console.error('HTML does not have a single root node', html);
|
|
throw new Error('HTML must have a single root node');
|
|
}
|
|
return fromDom(div.childNodes[0]);
|
|
};
|
|
var fromTag = function (tag, scope) {
|
|
var doc = scope || domGlobals.document;
|
|
var node = doc.createElement(tag);
|
|
return fromDom(node);
|
|
};
|
|
var fromText = function (text, scope) {
|
|
var doc = scope || domGlobals.document;
|
|
var node = doc.createTextNode(text);
|
|
return fromDom(node);
|
|
};
|
|
var fromDom = function (node) {
|
|
if (node === null || node === undefined) {
|
|
throw new Error('Node cannot be null or undefined');
|
|
}
|
|
return { dom: constant(node) };
|
|
};
|
|
var fromPoint = function (docElm, x, y) {
|
|
var doc = docElm.dom();
|
|
return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
|
|
};
|
|
var Element = {
|
|
fromHtml: fromHtml,
|
|
fromTag: fromTag,
|
|
fromText: fromText,
|
|
fromDom: fromDom,
|
|
fromPoint: fromPoint
|
|
};
|
|
|
|
var compareDocumentPosition = function (a, b, match) {
|
|
return (a.compareDocumentPosition(b) & match) !== 0;
|
|
};
|
|
var documentPositionContainedBy = function (a, b) {
|
|
return compareDocumentPosition(a, b, domGlobals.Node.DOCUMENT_POSITION_CONTAINED_BY);
|
|
};
|
|
|
|
var firstMatch = function (regexes, s) {
|
|
for (var i = 0; i < regexes.length; i++) {
|
|
var x = regexes[i];
|
|
if (x.test(s)) {
|
|
return x;
|
|
}
|
|
}
|
|
return undefined;
|
|
};
|
|
var find$2 = function (regexes, agent) {
|
|
var r = firstMatch(regexes, agent);
|
|
if (!r) {
|
|
return {
|
|
major: 0,
|
|
minor: 0
|
|
};
|
|
}
|
|
var group = function (i) {
|
|
return Number(agent.replace(r, '$' + i));
|
|
};
|
|
return nu$1(group(1), group(2));
|
|
};
|
|
var detect = function (versionRegexes, agent) {
|
|
var cleanedAgent = String(agent).toLowerCase();
|
|
if (versionRegexes.length === 0) {
|
|
return unknown();
|
|
}
|
|
return find$2(versionRegexes, cleanedAgent);
|
|
};
|
|
var unknown = function () {
|
|
return nu$1(0, 0);
|
|
};
|
|
var nu$1 = function (major, minor) {
|
|
return {
|
|
major: major,
|
|
minor: minor
|
|
};
|
|
};
|
|
var Version = {
|
|
nu: nu$1,
|
|
detect: detect,
|
|
unknown: unknown
|
|
};
|
|
|
|
var edge = 'Edge';
|
|
var chrome = 'Chrome';
|
|
var ie = 'IE';
|
|
var opera = 'Opera';
|
|
var firefox = 'Firefox';
|
|
var safari = 'Safari';
|
|
var unknown$1 = function () {
|
|
return nu$2({
|
|
current: undefined,
|
|
version: Version.unknown()
|
|
});
|
|
};
|
|
var nu$2 = function (info) {
|
|
var current = info.current;
|
|
var version = info.version;
|
|
var isBrowser = function (name) {
|
|
return function () {
|
|
return current === name;
|
|
};
|
|
};
|
|
return {
|
|
current: current,
|
|
version: version,
|
|
isEdge: isBrowser(edge),
|
|
isChrome: isBrowser(chrome),
|
|
isIE: isBrowser(ie),
|
|
isOpera: isBrowser(opera),
|
|
isFirefox: isBrowser(firefox),
|
|
isSafari: isBrowser(safari)
|
|
};
|
|
};
|
|
var Browser = {
|
|
unknown: unknown$1,
|
|
nu: nu$2,
|
|
edge: constant(edge),
|
|
chrome: constant(chrome),
|
|
ie: constant(ie),
|
|
opera: constant(opera),
|
|
firefox: constant(firefox),
|
|
safari: constant(safari)
|
|
};
|
|
|
|
var windows = 'Windows';
|
|
var ios = 'iOS';
|
|
var android = 'Android';
|
|
var linux = 'Linux';
|
|
var osx = 'OSX';
|
|
var solaris = 'Solaris';
|
|
var freebsd = 'FreeBSD';
|
|
var chromeos = 'ChromeOS';
|
|
var unknown$2 = function () {
|
|
return nu$3({
|
|
current: undefined,
|
|
version: Version.unknown()
|
|
});
|
|
};
|
|
var nu$3 = function (info) {
|
|
var current = info.current;
|
|
var version = info.version;
|
|
var isOS = function (name) {
|
|
return function () {
|
|
return current === name;
|
|
};
|
|
};
|
|
return {
|
|
current: current,
|
|
version: version,
|
|
isWindows: isOS(windows),
|
|
isiOS: isOS(ios),
|
|
isAndroid: isOS(android),
|
|
isOSX: isOS(osx),
|
|
isLinux: isOS(linux),
|
|
isSolaris: isOS(solaris),
|
|
isFreeBSD: isOS(freebsd),
|
|
isChromeOS: isOS(chromeos)
|
|
};
|
|
};
|
|
var OperatingSystem = {
|
|
unknown: unknown$2,
|
|
nu: nu$3,
|
|
windows: constant(windows),
|
|
ios: constant(ios),
|
|
android: constant(android),
|
|
linux: constant(linux),
|
|
osx: constant(osx),
|
|
solaris: constant(solaris),
|
|
freebsd: constant(freebsd),
|
|
chromeos: constant(chromeos)
|
|
};
|
|
|
|
var DeviceType = function (os, browser, userAgent, mediaMatch) {
|
|
var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
|
|
var isiPhone = os.isiOS() && !isiPad;
|
|
var isMobile = os.isiOS() || os.isAndroid();
|
|
var isTouch = isMobile || mediaMatch('(pointer:coarse)');
|
|
var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
|
|
var isPhone = isiPhone || isMobile && !isTablet;
|
|
var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
|
|
var isDesktop = !isPhone && !isTablet && !iOSwebview;
|
|
return {
|
|
isiPad: constant(isiPad),
|
|
isiPhone: constant(isiPhone),
|
|
isTablet: constant(isTablet),
|
|
isPhone: constant(isPhone),
|
|
isTouch: constant(isTouch),
|
|
isAndroid: os.isAndroid,
|
|
isiOS: os.isiOS,
|
|
isWebView: constant(iOSwebview),
|
|
isDesktop: constant(isDesktop)
|
|
};
|
|
};
|
|
|
|
var detect$1 = function (candidates, userAgent) {
|
|
var agent = String(userAgent).toLowerCase();
|
|
return find(candidates, function (candidate) {
|
|
return candidate.search(agent);
|
|
});
|
|
};
|
|
var detectBrowser = function (browsers, userAgent) {
|
|
return detect$1(browsers, userAgent).map(function (browser) {
|
|
var version = Version.detect(browser.versionRegexes, userAgent);
|
|
return {
|
|
current: browser.name,
|
|
version: version
|
|
};
|
|
});
|
|
};
|
|
var detectOs = function (oses, userAgent) {
|
|
return detect$1(oses, userAgent).map(function (os) {
|
|
var version = Version.detect(os.versionRegexes, userAgent);
|
|
return {
|
|
current: os.name,
|
|
version: version
|
|
};
|
|
});
|
|
};
|
|
var UaString = {
|
|
detectBrowser: detectBrowser,
|
|
detectOs: detectOs
|
|
};
|
|
|
|
var checkRange = function (str, substr, start) {
|
|
return substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
|
|
};
|
|
var contains$1 = function (str, substr) {
|
|
return str.indexOf(substr) !== -1;
|
|
};
|
|
var endsWith = function (str, suffix) {
|
|
return checkRange(str, suffix, str.length - suffix.length);
|
|
};
|
|
var blank = function (r) {
|
|
return function (s) {
|
|
return s.replace(r, '');
|
|
};
|
|
};
|
|
var trim = blank(/^\s+|\s+$/g);
|
|
|
|
var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
|
|
var checkContains = function (target) {
|
|
return function (uastring) {
|
|
return contains$1(uastring, target);
|
|
};
|
|
};
|
|
var browsers = [
|
|
{
|
|
name: 'Edge',
|
|
versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
|
|
search: function (uastring) {
|
|
return contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
|
|
}
|
|
},
|
|
{
|
|
name: 'Chrome',
|
|
versionRegexes: [
|
|
/.*?chrome\/([0-9]+)\.([0-9]+).*/,
|
|
normalVersionRegex
|
|
],
|
|
search: function (uastring) {
|
|
return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
|
|
}
|
|
},
|
|
{
|
|
name: 'IE',
|
|
versionRegexes: [
|
|
/.*?msie\ ?([0-9]+)\.([0-9]+).*/,
|
|
/.*?rv:([0-9]+)\.([0-9]+).*/
|
|
],
|
|
search: function (uastring) {
|
|
return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
|
|
}
|
|
},
|
|
{
|
|
name: 'Opera',
|
|
versionRegexes: [
|
|
normalVersionRegex,
|
|
/.*?opera\/([0-9]+)\.([0-9]+).*/
|
|
],
|
|
search: checkContains('opera')
|
|
},
|
|
{
|
|
name: 'Firefox',
|
|
versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
|
|
search: checkContains('firefox')
|
|
},
|
|
{
|
|
name: 'Safari',
|
|
versionRegexes: [
|
|
normalVersionRegex,
|
|
/.*?cpu os ([0-9]+)_([0-9]+).*/
|
|
],
|
|
search: function (uastring) {
|
|
return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
|
|
}
|
|
}
|
|
];
|
|
var oses = [
|
|
{
|
|
name: 'Windows',
|
|
search: checkContains('win'),
|
|
versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
|
|
},
|
|
{
|
|
name: 'iOS',
|
|
search: function (uastring) {
|
|
return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
|
|
},
|
|
versionRegexes: [
|
|
/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
|
|
/.*cpu os ([0-9]+)_([0-9]+).*/,
|
|
/.*cpu iphone os ([0-9]+)_([0-9]+).*/
|
|
]
|
|
},
|
|
{
|
|
name: 'Android',
|
|
search: checkContains('android'),
|
|
versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
|
|
},
|
|
{
|
|
name: 'OSX',
|
|
search: checkContains('mac os x'),
|
|
versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
|
|
},
|
|
{
|
|
name: 'Linux',
|
|
search: checkContains('linux'),
|
|
versionRegexes: []
|
|
},
|
|
{
|
|
name: 'Solaris',
|
|
search: checkContains('sunos'),
|
|
versionRegexes: []
|
|
},
|
|
{
|
|
name: 'FreeBSD',
|
|
search: checkContains('freebsd'),
|
|
versionRegexes: []
|
|
},
|
|
{
|
|
name: 'ChromeOS',
|
|
search: checkContains('cros'),
|
|
versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
|
|
}
|
|
];
|
|
var PlatformInfo = {
|
|
browsers: constant(browsers),
|
|
oses: constant(oses)
|
|
};
|
|
|
|
var detect$2 = function (userAgent, mediaMatch) {
|
|
var browsers = PlatformInfo.browsers();
|
|
var oses = PlatformInfo.oses();
|
|
var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
|
|
var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
|
|
var deviceType = DeviceType(os, browser, userAgent, mediaMatch);
|
|
return {
|
|
browser: browser,
|
|
os: os,
|
|
deviceType: deviceType
|
|
};
|
|
};
|
|
var PlatformDetection = { detect: detect$2 };
|
|
|
|
var mediaMatch = function (query) {
|
|
return domGlobals.window.matchMedia(query).matches;
|
|
};
|
|
var platform = cached(function () {
|
|
return PlatformDetection.detect(domGlobals.navigator.userAgent, mediaMatch);
|
|
});
|
|
var detect$3 = function () {
|
|
return platform();
|
|
};
|
|
|
|
var DOCUMENT = 9;
|
|
var ELEMENT = 1;
|
|
var TEXT = 3;
|
|
|
|
var ELEMENT$1 = ELEMENT;
|
|
var DOCUMENT$1 = DOCUMENT;
|
|
var is = function (element, selector) {
|
|
var dom = element.dom();
|
|
if (dom.nodeType !== ELEMENT$1) {
|
|
return false;
|
|
} else {
|
|
var elem = dom;
|
|
if (elem.matches !== undefined) {
|
|
return elem.matches(selector);
|
|
} else if (elem.msMatchesSelector !== undefined) {
|
|
return elem.msMatchesSelector(selector);
|
|
} else if (elem.webkitMatchesSelector !== undefined) {
|
|
return elem.webkitMatchesSelector(selector);
|
|
} else if (elem.mozMatchesSelector !== undefined) {
|
|
return elem.mozMatchesSelector(selector);
|
|
} else {
|
|
throw new Error('Browser lacks native selectors');
|
|
}
|
|
}
|
|
};
|
|
var bypassSelector = function (dom) {
|
|
return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
|
|
};
|
|
var all = function (selector, scope) {
|
|
var base = scope === undefined ? domGlobals.document : scope.dom();
|
|
return bypassSelector(base) ? [] : map(base.querySelectorAll(selector), Element.fromDom);
|
|
};
|
|
var one = function (selector, scope) {
|
|
var base = scope === undefined ? domGlobals.document : scope.dom();
|
|
return bypassSelector(base) ? Option.none() : Option.from(base.querySelector(selector)).map(Element.fromDom);
|
|
};
|
|
|
|
var eq$1 = function (e1, e2) {
|
|
return e1.dom() === e2.dom();
|
|
};
|
|
var regularContains = function (e1, e2) {
|
|
var d1 = e1.dom();
|
|
var d2 = e2.dom();
|
|
return d1 === d2 ? false : d1.contains(d2);
|
|
};
|
|
var ieContains = function (e1, e2) {
|
|
return documentPositionContainedBy(e1.dom(), e2.dom());
|
|
};
|
|
var contains$2 = function (e1, e2) {
|
|
return detect$3().browser.isIE() ? ieContains(e1, e2) : regularContains(e1, e2);
|
|
};
|
|
|
|
var ensureIsRoot = function (isRoot) {
|
|
return isFunction(isRoot) ? isRoot : constant(false);
|
|
};
|
|
var ancestor = function (scope, transform, isRoot) {
|
|
var element = scope.dom();
|
|
var stop = ensureIsRoot(isRoot);
|
|
while (element.parentNode) {
|
|
element = element.parentNode;
|
|
var el = Element.fromDom(element);
|
|
var transformed = transform(el);
|
|
if (transformed.isSome()) {
|
|
return transformed;
|
|
} else if (stop(el)) {
|
|
break;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var closest = function (scope, transform, isRoot) {
|
|
var current = transform(scope);
|
|
var stop = ensureIsRoot(isRoot);
|
|
return current.orThunk(function () {
|
|
return stop(scope) ? Option.none() : ancestor(scope, transform, stop);
|
|
});
|
|
};
|
|
|
|
var isSource = function (component, simulatedEvent) {
|
|
return eq$1(component.element(), simulatedEvent.event().target());
|
|
};
|
|
|
|
var nu$4 = function (parts) {
|
|
if (!hasNonNullableKey(parts, 'can') && !hasNonNullableKey(parts, 'abort') && !hasNonNullableKey(parts, 'run')) {
|
|
throw new Error('EventHandler defined by: ' + JSON.stringify(parts, null, 2) + ' does not have can, abort, or run!');
|
|
}
|
|
return asRawOrDie('Extracting event.handler', objOfOnly([
|
|
defaulted$1('can', constant(true)),
|
|
defaulted$1('abort', constant(false)),
|
|
defaulted$1('run', noop)
|
|
]), parts);
|
|
};
|
|
var all$1 = function (handlers, f) {
|
|
return function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
return foldl(handlers, function (acc, handler) {
|
|
return acc && f(handler).apply(undefined, args);
|
|
}, true);
|
|
};
|
|
};
|
|
var any = function (handlers, f) {
|
|
return function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
return foldl(handlers, function (acc, handler) {
|
|
return acc || f(handler).apply(undefined, args);
|
|
}, false);
|
|
};
|
|
};
|
|
var read = function (handler) {
|
|
return isFunction(handler) ? {
|
|
can: constant(true),
|
|
abort: constant(false),
|
|
run: handler
|
|
} : handler;
|
|
};
|
|
var fuse = function (handlers) {
|
|
var can = all$1(handlers, function (handler) {
|
|
return handler.can;
|
|
});
|
|
var abort = any(handlers, function (handler) {
|
|
return handler.abort;
|
|
});
|
|
var run = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
each(handlers, function (handler) {
|
|
handler.run.apply(undefined, args);
|
|
});
|
|
};
|
|
return nu$4({
|
|
can: can,
|
|
abort: abort,
|
|
run: run
|
|
});
|
|
};
|
|
|
|
var touchstart = constant('touchstart');
|
|
var touchmove = constant('touchmove');
|
|
var touchend = constant('touchend');
|
|
var touchcancel = constant('touchcancel');
|
|
var mousedown = constant('mousedown');
|
|
var mousemove = constant('mousemove');
|
|
var mouseout = constant('mouseout');
|
|
var mouseup = constant('mouseup');
|
|
var mouseover = constant('mouseover');
|
|
var focusin = constant('focusin');
|
|
var focusout = constant('focusout');
|
|
var keydown = constant('keydown');
|
|
var keyup = constant('keyup');
|
|
var input = constant('input');
|
|
var change = constant('change');
|
|
var click = constant('click');
|
|
var transitionend = constant('transitionend');
|
|
var selectstart = constant('selectstart');
|
|
|
|
var alloy = { tap: constant('alloy.tap') };
|
|
var focus = constant('alloy.focus');
|
|
var postBlur = constant('alloy.blur.post');
|
|
var postPaste = constant('alloy.paste.post');
|
|
var receive = constant('alloy.receive');
|
|
var execute = constant('alloy.execute');
|
|
var focusItem = constant('alloy.focus.item');
|
|
var tap = alloy.tap;
|
|
var longpress = constant('alloy.longpress');
|
|
var sandboxClose = constant('alloy.sandbox.close');
|
|
var typeaheadCancel = constant('alloy.typeahead.cancel');
|
|
var systemInit = constant('alloy.system.init');
|
|
var documentTouchmove = constant('alloy.system.touchmove');
|
|
var documentTouchend = constant('alloy.system.touchend');
|
|
var windowScroll = constant('alloy.system.scroll');
|
|
var windowResize = constant('alloy.system.resize');
|
|
var attachedToDom = constant('alloy.system.attached');
|
|
var detachedFromDom = constant('alloy.system.detached');
|
|
var dismissRequested = constant('alloy.system.dismissRequested');
|
|
var repositionRequested = constant('alloy.system.repositionRequested');
|
|
var focusShifted = constant('alloy.focusmanager.shifted');
|
|
var slotVisibility = constant('alloy.slotcontainer.visibility');
|
|
var changeTab = constant('alloy.change.tab');
|
|
var dismissTab = constant('alloy.dismiss.tab');
|
|
var highlight = constant('alloy.highlight');
|
|
var dehighlight = constant('alloy.dehighlight');
|
|
|
|
var emit = function (component, event) {
|
|
dispatchWith(component, component.element(), event, {});
|
|
};
|
|
var emitWith = function (component, event, properties) {
|
|
dispatchWith(component, component.element(), event, properties);
|
|
};
|
|
var emitExecute = function (component) {
|
|
emit(component, execute());
|
|
};
|
|
var dispatch = function (component, target, event) {
|
|
dispatchWith(component, target, event, {});
|
|
};
|
|
var dispatchWith = function (component, target, event, properties) {
|
|
var data = __assign({ target: target }, properties);
|
|
component.getSystem().triggerEvent(event, target, map$1(data, constant));
|
|
};
|
|
var dispatchEvent = function (component, target, event, simulatedEvent) {
|
|
component.getSystem().triggerEvent(event, target, simulatedEvent.event());
|
|
};
|
|
|
|
var derive = function (configs) {
|
|
return wrapAll$1(configs);
|
|
};
|
|
var abort = function (name, predicate) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({ abort: predicate })
|
|
};
|
|
};
|
|
var can = function (name, predicate) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({ can: predicate })
|
|
};
|
|
};
|
|
var preventDefault = function (name) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({
|
|
run: function (component, simulatedEvent) {
|
|
simulatedEvent.event().prevent();
|
|
}
|
|
})
|
|
};
|
|
};
|
|
var run = function (name, handler) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({ run: handler })
|
|
};
|
|
};
|
|
var runActionExtra = function (name, action, extra) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({
|
|
run: function (component, simulatedEvent) {
|
|
action.apply(undefined, [
|
|
component,
|
|
simulatedEvent
|
|
].concat(extra));
|
|
}
|
|
})
|
|
};
|
|
};
|
|
var runOnName = function (name) {
|
|
return function (handler) {
|
|
return run(name, handler);
|
|
};
|
|
};
|
|
var runOnSourceName = function (name) {
|
|
return function (handler) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({
|
|
run: function (component, simulatedEvent) {
|
|
if (isSource(component, simulatedEvent)) {
|
|
handler(component, simulatedEvent);
|
|
}
|
|
}
|
|
})
|
|
};
|
|
};
|
|
};
|
|
var redirectToUid = function (name, uid) {
|
|
return run(name, function (component, simulatedEvent) {
|
|
component.getSystem().getByUid(uid).each(function (redirectee) {
|
|
dispatchEvent(redirectee, redirectee.element(), name, simulatedEvent);
|
|
});
|
|
});
|
|
};
|
|
var redirectToPart = function (name, detail, partName) {
|
|
var uid = detail.partUids[partName];
|
|
return redirectToUid(name, uid);
|
|
};
|
|
var runWithTarget = function (name, f) {
|
|
return run(name, function (component, simulatedEvent) {
|
|
var ev = simulatedEvent.event();
|
|
var target = component.getSystem().getByDom(ev.target()).fold(function () {
|
|
var closest$1 = closest(ev.target(), function (el) {
|
|
return component.getSystem().getByDom(el).toOption();
|
|
}, constant(false));
|
|
return closest$1.getOr(component);
|
|
}, function (c) {
|
|
return c;
|
|
});
|
|
f(component, target, simulatedEvent);
|
|
});
|
|
};
|
|
var cutter = function (name) {
|
|
return run(name, function (component, simulatedEvent) {
|
|
simulatedEvent.cut();
|
|
});
|
|
};
|
|
var stopper = function (name) {
|
|
return run(name, function (component, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
});
|
|
};
|
|
var runOnSource = function (name, f) {
|
|
return runOnSourceName(name)(f);
|
|
};
|
|
var runOnAttached = runOnSourceName(attachedToDom());
|
|
var runOnDetached = runOnSourceName(detachedFromDom());
|
|
var runOnInit = runOnSourceName(systemInit());
|
|
var runOnExecute = runOnName(execute());
|
|
|
|
var owner = function (element) {
|
|
return Element.fromDom(element.dom().ownerDocument);
|
|
};
|
|
var documentElement = function (element) {
|
|
return Element.fromDom(element.dom().ownerDocument.documentElement);
|
|
};
|
|
var defaultView = function (element) {
|
|
return Element.fromDom(element.dom().ownerDocument.defaultView);
|
|
};
|
|
var parent = function (element) {
|
|
return Option.from(element.dom().parentNode).map(Element.fromDom);
|
|
};
|
|
var offsetParent = function (element) {
|
|
return Option.from(element.dom().offsetParent).map(Element.fromDom);
|
|
};
|
|
var nextSibling = function (element) {
|
|
return Option.from(element.dom().nextSibling).map(Element.fromDom);
|
|
};
|
|
var children = function (element) {
|
|
return map(element.dom().childNodes, Element.fromDom);
|
|
};
|
|
var child = function (element, index) {
|
|
var cs = element.dom().childNodes;
|
|
return Option.from(cs[index]).map(Element.fromDom);
|
|
};
|
|
var firstChild = function (element) {
|
|
return child(element, 0);
|
|
};
|
|
|
|
var before = function (marker, element) {
|
|
var parent$1 = parent(marker);
|
|
parent$1.each(function (v) {
|
|
v.dom().insertBefore(element.dom(), marker.dom());
|
|
});
|
|
};
|
|
var after = function (marker, element) {
|
|
var sibling = nextSibling(marker);
|
|
sibling.fold(function () {
|
|
var parent$1 = parent(marker);
|
|
parent$1.each(function (v) {
|
|
append(v, element);
|
|
});
|
|
}, function (v) {
|
|
before(v, element);
|
|
});
|
|
};
|
|
var prepend = function (parent, element) {
|
|
var firstChild$1 = firstChild(parent);
|
|
firstChild$1.fold(function () {
|
|
append(parent, element);
|
|
}, function (v) {
|
|
parent.dom().insertBefore(element.dom(), v.dom());
|
|
});
|
|
};
|
|
var append = function (parent, element) {
|
|
parent.dom().appendChild(element.dom());
|
|
};
|
|
var appendAt = function (parent, element, index) {
|
|
child(parent, index).fold(function () {
|
|
append(parent, element);
|
|
}, function (v) {
|
|
before(v, element);
|
|
});
|
|
};
|
|
|
|
var before$1 = function (marker, elements) {
|
|
each(elements, function (x) {
|
|
before(marker, x);
|
|
});
|
|
};
|
|
var append$1 = function (parent, elements) {
|
|
each(elements, function (x) {
|
|
append(parent, x);
|
|
});
|
|
};
|
|
|
|
var empty = function (element) {
|
|
element.dom().textContent = '';
|
|
each(children(element), function (rogue) {
|
|
remove(rogue);
|
|
});
|
|
};
|
|
var remove = function (element) {
|
|
var dom = element.dom();
|
|
if (dom.parentNode !== null) {
|
|
dom.parentNode.removeChild(dom);
|
|
}
|
|
};
|
|
var unwrap = function (wrapper) {
|
|
var children$1 = children(wrapper);
|
|
if (children$1.length > 0) {
|
|
before$1(wrapper, children$1);
|
|
}
|
|
remove(wrapper);
|
|
};
|
|
|
|
var fromHtml$1 = function (html, scope) {
|
|
var doc = scope || domGlobals.document;
|
|
var div = doc.createElement('div');
|
|
div.innerHTML = html;
|
|
return children(Element.fromDom(div));
|
|
};
|
|
|
|
var get$1 = function (element) {
|
|
return element.dom().innerHTML;
|
|
};
|
|
var set = function (element, content) {
|
|
var owner$1 = owner(element);
|
|
var docDom = owner$1.dom();
|
|
var fragment = Element.fromDom(docDom.createDocumentFragment());
|
|
var contentElements = fromHtml$1(content, docDom);
|
|
append$1(fragment, contentElements);
|
|
empty(element);
|
|
append(element, fragment);
|
|
};
|
|
var getOuter = function (element) {
|
|
var container = Element.fromTag('div');
|
|
var clone = Element.fromDom(element.dom().cloneNode(true));
|
|
append(container, clone);
|
|
return get$1(container);
|
|
};
|
|
|
|
var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
|
|
|
|
var name = function (element) {
|
|
var r = element.dom().nodeName;
|
|
return r.toLowerCase();
|
|
};
|
|
var type = function (element) {
|
|
return element.dom().nodeType;
|
|
};
|
|
var isType$1 = function (t) {
|
|
return function (element) {
|
|
return type(element) === t;
|
|
};
|
|
};
|
|
var isElement = isType$1(ELEMENT);
|
|
var isText = isType$1(TEXT);
|
|
|
|
var rawSet = function (dom, key, value) {
|
|
if (isString(value) || isBoolean(value) || isNumber(value)) {
|
|
dom.setAttribute(key, value + '');
|
|
} else {
|
|
domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
|
|
throw new Error('Attribute value was not simple');
|
|
}
|
|
};
|
|
var set$1 = function (element, key, value) {
|
|
rawSet(element.dom(), key, value);
|
|
};
|
|
var setAll = function (element, attrs) {
|
|
var dom = element.dom();
|
|
each$1(attrs, function (v, k) {
|
|
rawSet(dom, k, v);
|
|
});
|
|
};
|
|
var get$2 = function (element, key) {
|
|
var v = element.dom().getAttribute(key);
|
|
return v === null ? undefined : v;
|
|
};
|
|
var getOpt = function (element, key) {
|
|
return Option.from(get$2(element, key));
|
|
};
|
|
var has$1 = function (element, key) {
|
|
var dom = element.dom();
|
|
return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;
|
|
};
|
|
var remove$1 = function (element, key) {
|
|
element.dom().removeAttribute(key);
|
|
};
|
|
|
|
var clone = function (original, isDeep) {
|
|
return Element.fromDom(original.dom().cloneNode(isDeep));
|
|
};
|
|
var shallow$1 = function (original) {
|
|
return clone(original, false);
|
|
};
|
|
|
|
var getHtml = function (element) {
|
|
var clone = shallow$1(element);
|
|
return getOuter(clone);
|
|
};
|
|
|
|
var element = function (elem) {
|
|
return getHtml(elem);
|
|
};
|
|
|
|
var isRecursive = function (component, originator, target) {
|
|
return eq$1(originator, component.element()) && !eq$1(originator, target);
|
|
};
|
|
var events = derive([can(focus(), function (component, simulatedEvent) {
|
|
var originator = simulatedEvent.event().originator();
|
|
var target = simulatedEvent.event().target();
|
|
if (isRecursive(component, originator, target)) {
|
|
domGlobals.console.warn(focus() + ' did not get interpreted by the desired target. ' + '\nOriginator: ' + element(originator) + '\nTarget: ' + element(target) + '\nCheck the ' + focus() + ' event handlers');
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
})]);
|
|
|
|
var DefaultEvents = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events
|
|
});
|
|
|
|
var unique = 0;
|
|
var generate$1 = function (prefix) {
|
|
var date = new Date();
|
|
var time = date.getTime();
|
|
var random = Math.floor(Math.random() * 1000000000);
|
|
unique++;
|
|
return prefix + '_' + random + unique + String(time);
|
|
};
|
|
|
|
var prefix = constant('alloy-id-');
|
|
var idAttr = constant('data-alloy-id');
|
|
|
|
var prefix$1 = prefix();
|
|
var idAttr$1 = idAttr();
|
|
var write = function (label, elem) {
|
|
var id = generate$1(prefix$1 + label);
|
|
writeOnly(elem, id);
|
|
return id;
|
|
};
|
|
var writeOnly = function (elem, uid) {
|
|
Object.defineProperty(elem.dom(), idAttr$1, {
|
|
value: uid,
|
|
writable: true
|
|
});
|
|
};
|
|
var read$1 = function (elem) {
|
|
var id = isElement(elem) ? elem.dom()[idAttr$1] : null;
|
|
return Option.from(id);
|
|
};
|
|
var generate$2 = function (prefix) {
|
|
return generate$1(prefix);
|
|
};
|
|
|
|
var make = identity;
|
|
|
|
var NoContextApi = function (getComp) {
|
|
var fail = function (event) {
|
|
return function () {
|
|
throw new Error('The component must be in a context to send: ' + event + (getComp ? '\n' + element(getComp().element()) + ' is not in context.' : ''));
|
|
};
|
|
};
|
|
return {
|
|
debugInfo: constant('fake'),
|
|
triggerEvent: fail('triggerEvent'),
|
|
triggerFocus: fail('triggerFocus'),
|
|
triggerEscape: fail('triggerEscape'),
|
|
build: fail('build'),
|
|
addToWorld: fail('addToWorld'),
|
|
removeFromWorld: fail('removeFromWorld'),
|
|
addToGui: fail('addToGui'),
|
|
removeFromGui: fail('removeFromGui'),
|
|
getByUid: fail('getByUid'),
|
|
getByDom: fail('getByDom'),
|
|
broadcast: fail('broadcast'),
|
|
broadcastOn: fail('broadcastOn'),
|
|
broadcastEvent: fail('broadcastEvent'),
|
|
isConnected: constant(false)
|
|
};
|
|
};
|
|
var singleton = NoContextApi();
|
|
|
|
var markAsBehaviourApi = function (f, apiName, apiFunction) {
|
|
var delegate = apiFunction.toString();
|
|
var endIndex = delegate.indexOf(')') + 1;
|
|
var openBracketIndex = delegate.indexOf('(');
|
|
var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
|
|
f.toFunctionAnnotation = function () {
|
|
return {
|
|
name: apiName,
|
|
parameters: cleanParameters(parameters.slice(0, 1).concat(parameters.slice(3)))
|
|
};
|
|
};
|
|
return f;
|
|
};
|
|
var cleanParameters = function (parameters) {
|
|
return map(parameters, function (p) {
|
|
return endsWith(p, '/*') ? p.substring(0, p.length - '/*'.length) : p;
|
|
});
|
|
};
|
|
var markAsExtraApi = function (f, extraName) {
|
|
var delegate = f.toString();
|
|
var endIndex = delegate.indexOf(')') + 1;
|
|
var openBracketIndex = delegate.indexOf('(');
|
|
var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
|
|
f.toFunctionAnnotation = function () {
|
|
return {
|
|
name: extraName,
|
|
parameters: cleanParameters(parameters)
|
|
};
|
|
};
|
|
return f;
|
|
};
|
|
var markAsSketchApi = function (f, apiFunction) {
|
|
var delegate = apiFunction.toString();
|
|
var endIndex = delegate.indexOf(')') + 1;
|
|
var openBracketIndex = delegate.indexOf('(');
|
|
var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
|
|
f.toFunctionAnnotation = function () {
|
|
return {
|
|
name: 'OVERRIDE',
|
|
parameters: cleanParameters(parameters.slice(1))
|
|
};
|
|
};
|
|
return f;
|
|
};
|
|
|
|
var premadeTag = generate$1('alloy-premade');
|
|
var premade = function (comp) {
|
|
return wrap$1(premadeTag, comp);
|
|
};
|
|
var getPremade = function (spec) {
|
|
return get(spec, premadeTag);
|
|
};
|
|
var makeApi = function (f) {
|
|
return markAsSketchApi(function (component) {
|
|
var rest = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
rest[_i - 1] = arguments[_i];
|
|
}
|
|
return f.apply(void 0, __spreadArrays([
|
|
component.getApis(),
|
|
component
|
|
], rest));
|
|
}, f);
|
|
};
|
|
|
|
var NoState = {
|
|
init: function () {
|
|
return nu$5({
|
|
readState: function () {
|
|
return 'No State required';
|
|
}
|
|
});
|
|
}
|
|
};
|
|
var nu$5 = function (spec) {
|
|
return spec;
|
|
};
|
|
|
|
var generateFrom = function (spec, all) {
|
|
var schema = map(all, function (a) {
|
|
return optionObjOf(a.name(), [
|
|
strict$1('config'),
|
|
defaulted$1('state', NoState)
|
|
]);
|
|
});
|
|
var validated = asRaw('component.behaviours', objOf(schema), spec.behaviours).fold(function (errInfo) {
|
|
throw new Error(formatError(errInfo) + '\nComplete spec:\n' + JSON.stringify(spec, null, 2));
|
|
}, function (v) {
|
|
return v;
|
|
});
|
|
return {
|
|
list: all,
|
|
data: map$1(validated, function (optBlobThunk) {
|
|
var output = optBlobThunk.map(function (blob) {
|
|
return {
|
|
config: blob.config,
|
|
state: blob.state.init(blob.config)
|
|
};
|
|
});
|
|
return function () {
|
|
return output;
|
|
};
|
|
})
|
|
};
|
|
};
|
|
var getBehaviours = function (bData) {
|
|
return bData.list;
|
|
};
|
|
var getData = function (bData) {
|
|
return bData.data;
|
|
};
|
|
|
|
var byInnerKey = function (data, tuple) {
|
|
var r = {};
|
|
each$1(data, function (detail, key) {
|
|
each$1(detail, function (value, indexKey) {
|
|
var chain = get(r, indexKey).getOr([]);
|
|
r[indexKey] = chain.concat([tuple(key, value)]);
|
|
});
|
|
});
|
|
return r;
|
|
};
|
|
|
|
var nu$6 = function (s) {
|
|
return {
|
|
classes: s.classes !== undefined ? s.classes : [],
|
|
attributes: s.attributes !== undefined ? s.attributes : {},
|
|
styles: s.styles !== undefined ? s.styles : {}
|
|
};
|
|
};
|
|
var merge$1 = function (defnA, mod) {
|
|
return __assign(__assign({}, defnA), {
|
|
attributes: __assign(__assign({}, defnA.attributes), mod.attributes),
|
|
styles: __assign(__assign({}, defnA.styles), mod.styles),
|
|
classes: defnA.classes.concat(mod.classes)
|
|
});
|
|
};
|
|
|
|
var combine = function (info, baseMod, behaviours, base) {
|
|
var modsByBehaviour = __assign({}, baseMod);
|
|
each(behaviours, function (behaviour) {
|
|
modsByBehaviour[behaviour.name()] = behaviour.exhibit(info, base);
|
|
});
|
|
var byAspect = byInnerKey(modsByBehaviour, function (name, modification) {
|
|
return {
|
|
name: name,
|
|
modification: modification
|
|
};
|
|
});
|
|
var combineObjects = function (objects) {
|
|
return foldr(objects, function (b, a) {
|
|
return __assign(__assign({}, a.modification), b);
|
|
}, {});
|
|
};
|
|
var combinedClasses = foldr(byAspect.classes, function (b, a) {
|
|
return a.modification.concat(b);
|
|
}, []);
|
|
var combinedAttributes = combineObjects(byAspect.attributes);
|
|
var combinedStyles = combineObjects(byAspect.styles);
|
|
return nu$6({
|
|
classes: combinedClasses,
|
|
attributes: combinedAttributes,
|
|
styles: combinedStyles
|
|
});
|
|
};
|
|
|
|
var sortKeys = function (label, keyName, array, order) {
|
|
try {
|
|
var sorted = sort(array, function (a, b) {
|
|
var aKey = a[keyName]();
|
|
var bKey = b[keyName]();
|
|
var aIndex = order.indexOf(aKey);
|
|
var bIndex = order.indexOf(bKey);
|
|
if (aIndex === -1) {
|
|
throw new Error('The ordering for ' + label + ' does not have an entry for ' + aKey + '.\nOrder specified: ' + JSON.stringify(order, null, 2));
|
|
}
|
|
if (bIndex === -1) {
|
|
throw new Error('The ordering for ' + label + ' does not have an entry for ' + bKey + '.\nOrder specified: ' + JSON.stringify(order, null, 2));
|
|
}
|
|
if (aIndex < bIndex) {
|
|
return -1;
|
|
} else if (bIndex < aIndex) {
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
});
|
|
return Result.value(sorted);
|
|
} catch (err) {
|
|
return Result.error([err]);
|
|
}
|
|
};
|
|
|
|
var uncurried = function (handler, purpose) {
|
|
return {
|
|
handler: handler,
|
|
purpose: constant(purpose)
|
|
};
|
|
};
|
|
var curried = function (handler, purpose) {
|
|
return {
|
|
cHandler: handler,
|
|
purpose: constant(purpose)
|
|
};
|
|
};
|
|
var curryArgs = function (descHandler, extraArgs) {
|
|
return curried(curry.apply(undefined, [descHandler.handler].concat(extraArgs)), descHandler.purpose());
|
|
};
|
|
var getCurried = function (descHandler) {
|
|
return descHandler.cHandler;
|
|
};
|
|
|
|
var behaviourTuple = function (name, handler) {
|
|
return {
|
|
name: constant(name),
|
|
handler: constant(handler)
|
|
};
|
|
};
|
|
var nameToHandlers = function (behaviours, info) {
|
|
var r = {};
|
|
each(behaviours, function (behaviour) {
|
|
r[behaviour.name()] = behaviour.handlers(info);
|
|
});
|
|
return r;
|
|
};
|
|
var groupByEvents = function (info, behaviours, base) {
|
|
var behaviourEvents = __assign(__assign({}, base), nameToHandlers(behaviours, info));
|
|
return byInnerKey(behaviourEvents, behaviourTuple);
|
|
};
|
|
var combine$1 = function (info, eventOrder, behaviours, base) {
|
|
var byEventName = groupByEvents(info, behaviours, base);
|
|
return combineGroups(byEventName, eventOrder);
|
|
};
|
|
var assemble = function (rawHandler) {
|
|
var handler = read(rawHandler);
|
|
return function (component, simulatedEvent) {
|
|
var rest = [];
|
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
rest[_i - 2] = arguments[_i];
|
|
}
|
|
var args = [
|
|
component,
|
|
simulatedEvent
|
|
].concat(rest);
|
|
if (handler.abort.apply(undefined, args)) {
|
|
simulatedEvent.stop();
|
|
} else if (handler.can.apply(undefined, args)) {
|
|
handler.run.apply(undefined, args);
|
|
}
|
|
};
|
|
};
|
|
var missingOrderError = function (eventName, tuples) {
|
|
return Result.error(['The event (' + eventName + ') has more than one behaviour that listens to it.\nWhen this occurs, you must ' + 'specify an event ordering for the behaviours in your spec (e.g. [ "listing", "toggling" ]).\nThe behaviours that ' + 'can trigger it are: ' + JSON.stringify(map(tuples, function (c) {
|
|
return c.name();
|
|
}), null, 2)]);
|
|
};
|
|
var fuse$1 = function (tuples, eventOrder, eventName) {
|
|
var order = eventOrder[eventName];
|
|
if (!order) {
|
|
return missingOrderError(eventName, tuples);
|
|
} else {
|
|
return sortKeys('Event: ' + eventName, 'name', tuples, order).map(function (sortedTuples) {
|
|
var handlers = map(sortedTuples, function (tuple) {
|
|
return tuple.handler();
|
|
});
|
|
return fuse(handlers);
|
|
});
|
|
}
|
|
};
|
|
var combineGroups = function (byEventName, eventOrder) {
|
|
var r = mapToArray(byEventName, function (tuples, eventName) {
|
|
var combined = tuples.length === 1 ? Result.value(tuples[0].handler()) : fuse$1(tuples, eventOrder, eventName);
|
|
return combined.map(function (handler) {
|
|
var assembled = assemble(handler);
|
|
var purpose = tuples.length > 1 ? filter(eventOrder[eventName], function (o) {
|
|
return exists(tuples, function (t) {
|
|
return t.name() === o;
|
|
});
|
|
}).join(' > ') : tuples[0].name();
|
|
return wrap$1(eventName, uncurried(assembled, purpose));
|
|
});
|
|
});
|
|
return consolidate(r, {});
|
|
};
|
|
|
|
var toInfo = function (spec) {
|
|
return asRaw('custom.definition', objOf([
|
|
field('dom', 'dom', strict(), objOf([
|
|
strict$1('tag'),
|
|
defaulted$1('styles', {}),
|
|
defaulted$1('classes', []),
|
|
defaulted$1('attributes', {}),
|
|
option('value'),
|
|
option('innerHtml')
|
|
])),
|
|
strict$1('components'),
|
|
strict$1('uid'),
|
|
defaulted$1('events', {}),
|
|
defaulted$1('apis', {}),
|
|
field('eventOrder', 'eventOrder', mergeWith({
|
|
'alloy.execute': [
|
|
'disabling',
|
|
'alloy.base.behaviour',
|
|
'toggling',
|
|
'typeaheadevents'
|
|
],
|
|
'alloy.focus': [
|
|
'alloy.base.behaviour',
|
|
'focusing',
|
|
'keying'
|
|
],
|
|
'alloy.system.init': [
|
|
'alloy.base.behaviour',
|
|
'disabling',
|
|
'toggling',
|
|
'representing'
|
|
],
|
|
'input': [
|
|
'alloy.base.behaviour',
|
|
'representing',
|
|
'streaming',
|
|
'invalidating'
|
|
],
|
|
'alloy.system.detached': [
|
|
'alloy.base.behaviour',
|
|
'representing',
|
|
'item-events',
|
|
'tooltipping'
|
|
],
|
|
'mousedown': [
|
|
'focusing',
|
|
'alloy.base.behaviour',
|
|
'item-type-events'
|
|
],
|
|
'touchstart': [
|
|
'focusing',
|
|
'alloy.base.behaviour',
|
|
'item-type-events'
|
|
],
|
|
'mouseover': [
|
|
'item-type-events',
|
|
'tooltipping'
|
|
],
|
|
'alloy.receive': [
|
|
'receiving',
|
|
'reflecting',
|
|
'tooltipping'
|
|
]
|
|
}), anyValue$1()),
|
|
option('domModification')
|
|
]), spec);
|
|
};
|
|
var toDefinition = function (detail) {
|
|
return __assign(__assign({}, detail.dom), {
|
|
uid: detail.uid,
|
|
domChildren: map(detail.components, function (comp) {
|
|
return comp.element();
|
|
})
|
|
});
|
|
};
|
|
var toModification = function (detail) {
|
|
return detail.domModification.fold(function () {
|
|
return nu$6({});
|
|
}, nu$6);
|
|
};
|
|
var toEvents = function (info) {
|
|
return info.events;
|
|
};
|
|
|
|
var read$2 = function (element, attr) {
|
|
var value = get$2(element, attr);
|
|
return value === undefined || value === '' ? [] : value.split(' ');
|
|
};
|
|
var add = function (element, attr, id) {
|
|
var old = read$2(element, attr);
|
|
var nu = old.concat([id]);
|
|
set$1(element, attr, nu.join(' '));
|
|
return true;
|
|
};
|
|
var remove$2 = function (element, attr, id) {
|
|
var nu = filter(read$2(element, attr), function (v) {
|
|
return v !== id;
|
|
});
|
|
if (nu.length > 0) {
|
|
set$1(element, attr, nu.join(' '));
|
|
} else {
|
|
remove$1(element, attr);
|
|
}
|
|
return false;
|
|
};
|
|
|
|
var supports = function (element) {
|
|
return element.dom().classList !== undefined;
|
|
};
|
|
var get$3 = function (element) {
|
|
return read$2(element, 'class');
|
|
};
|
|
var add$1 = function (element, clazz) {
|
|
return add(element, 'class', clazz);
|
|
};
|
|
var remove$3 = function (element, clazz) {
|
|
return remove$2(element, 'class', clazz);
|
|
};
|
|
|
|
var add$2 = function (element, clazz) {
|
|
if (supports(element)) {
|
|
element.dom().classList.add(clazz);
|
|
} else {
|
|
add$1(element, clazz);
|
|
}
|
|
};
|
|
var cleanClass = function (element) {
|
|
var classList = supports(element) ? element.dom().classList : get$3(element);
|
|
if (classList.length === 0) {
|
|
remove$1(element, 'class');
|
|
}
|
|
};
|
|
var remove$4 = function (element, clazz) {
|
|
if (supports(element)) {
|
|
var classList = element.dom().classList;
|
|
classList.remove(clazz);
|
|
} else {
|
|
remove$3(element, clazz);
|
|
}
|
|
cleanClass(element);
|
|
};
|
|
var has$2 = function (element, clazz) {
|
|
return supports(element) && element.dom().classList.contains(clazz);
|
|
};
|
|
|
|
var add$3 = function (element, classes) {
|
|
each(classes, function (x) {
|
|
add$2(element, x);
|
|
});
|
|
};
|
|
var remove$5 = function (element, classes) {
|
|
each(classes, function (x) {
|
|
remove$4(element, x);
|
|
});
|
|
};
|
|
|
|
var isSupported = function (dom) {
|
|
return dom.style !== undefined && isFunction(dom.style.getPropertyValue);
|
|
};
|
|
|
|
var inBody = function (element) {
|
|
var dom = isText(element) ? element.dom().parentNode : element.dom();
|
|
return dom !== undefined && dom !== null && dom.ownerDocument.body.contains(dom);
|
|
};
|
|
var body = function () {
|
|
return getBody(Element.fromDom(domGlobals.document));
|
|
};
|
|
var getBody = function (doc) {
|
|
var b = doc.dom().body;
|
|
if (b === null || b === undefined) {
|
|
throw new Error('Body is not available yet');
|
|
}
|
|
return Element.fromDom(b);
|
|
};
|
|
|
|
var internalSet = function (dom, property, value) {
|
|
if (!isString(value)) {
|
|
domGlobals.console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
|
|
throw new Error('CSS value must be a string: ' + value);
|
|
}
|
|
if (isSupported(dom)) {
|
|
dom.style.setProperty(property, value);
|
|
}
|
|
};
|
|
var internalRemove = function (dom, property) {
|
|
if (isSupported(dom)) {
|
|
dom.style.removeProperty(property);
|
|
}
|
|
};
|
|
var set$2 = function (element, property, value) {
|
|
var dom = element.dom();
|
|
internalSet(dom, property, value);
|
|
};
|
|
var setAll$1 = function (element, css) {
|
|
var dom = element.dom();
|
|
each$1(css, function (v, k) {
|
|
internalSet(dom, k, v);
|
|
});
|
|
};
|
|
var setOptions = function (element, css) {
|
|
var dom = element.dom();
|
|
each$1(css, function (v, k) {
|
|
v.fold(function () {
|
|
internalRemove(dom, k);
|
|
}, function (value) {
|
|
internalSet(dom, k, value);
|
|
});
|
|
});
|
|
};
|
|
var get$4 = function (element, property) {
|
|
var dom = element.dom();
|
|
var styles = domGlobals.window.getComputedStyle(dom);
|
|
var r = styles.getPropertyValue(property);
|
|
return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
|
|
};
|
|
var getUnsafeProperty = function (dom, property) {
|
|
return isSupported(dom) ? dom.style.getPropertyValue(property) : '';
|
|
};
|
|
var getRaw = function (element, property) {
|
|
var dom = element.dom();
|
|
var raw = getUnsafeProperty(dom, property);
|
|
return Option.from(raw).filter(function (r) {
|
|
return r.length > 0;
|
|
});
|
|
};
|
|
var getAllRaw = function (element) {
|
|
var css = {};
|
|
var dom = element.dom();
|
|
if (isSupported(dom)) {
|
|
for (var i = 0; i < dom.style.length; i++) {
|
|
var ruleName = dom.style.item(i);
|
|
css[ruleName] = dom.style[ruleName];
|
|
}
|
|
}
|
|
return css;
|
|
};
|
|
var isValidValue = function (tag, property, value) {
|
|
var element = Element.fromTag(tag);
|
|
set$2(element, property, value);
|
|
var style = getRaw(element, property);
|
|
return style.isSome();
|
|
};
|
|
var remove$6 = function (element, property) {
|
|
var dom = element.dom();
|
|
internalRemove(dom, property);
|
|
if (getOpt(element, 'style').map(trim).is('')) {
|
|
remove$1(element, 'style');
|
|
}
|
|
};
|
|
var reflow = function (e) {
|
|
return e.dom().offsetWidth;
|
|
};
|
|
|
|
var get$5 = function (element) {
|
|
return element.dom().value;
|
|
};
|
|
var set$3 = function (element, value) {
|
|
if (value === undefined) {
|
|
throw new Error('Value.set was undefined');
|
|
}
|
|
element.dom().value = value;
|
|
};
|
|
|
|
var renderToDom = function (definition) {
|
|
var subject = Element.fromTag(definition.tag);
|
|
setAll(subject, definition.attributes);
|
|
add$3(subject, definition.classes);
|
|
setAll$1(subject, definition.styles);
|
|
definition.innerHtml.each(function (html) {
|
|
return set(subject, html);
|
|
});
|
|
var children = definition.domChildren;
|
|
append$1(subject, children);
|
|
definition.value.each(function (value) {
|
|
set$3(subject, value);
|
|
});
|
|
if (!definition.uid) {
|
|
debugger;
|
|
}
|
|
writeOnly(subject, definition.uid);
|
|
return subject;
|
|
};
|
|
|
|
var getBehaviours$1 = function (spec) {
|
|
var behaviours = get(spec, 'behaviours').getOr({});
|
|
var keys$1 = filter(keys(behaviours), function (k) {
|
|
return behaviours[k] !== undefined;
|
|
});
|
|
return map(keys$1, function (k) {
|
|
return behaviours[k].me;
|
|
});
|
|
};
|
|
var generateFrom$1 = function (spec, all) {
|
|
return generateFrom(spec, all);
|
|
};
|
|
var generate$3 = function (spec) {
|
|
var all = getBehaviours$1(spec);
|
|
return generateFrom$1(spec, all);
|
|
};
|
|
|
|
var getDomDefinition = function (info, bList, bData) {
|
|
var definition = toDefinition(info);
|
|
var infoModification = toModification(info);
|
|
var baseModification = { 'alloy.base.modification': infoModification };
|
|
var modification = bList.length > 0 ? combine(bData, baseModification, bList, definition) : infoModification;
|
|
return merge$1(definition, modification);
|
|
};
|
|
var getEvents = function (info, bList, bData) {
|
|
var baseEvents = { 'alloy.base.behaviour': toEvents(info) };
|
|
return combine$1(bData, info.eventOrder, bList, baseEvents).getOrDie();
|
|
};
|
|
var build = function (spec) {
|
|
var getMe = function () {
|
|
return me;
|
|
};
|
|
var systemApi = Cell(singleton);
|
|
var info = getOrDie(toInfo(spec));
|
|
var bBlob = generate$3(spec);
|
|
var bList = getBehaviours(bBlob);
|
|
var bData = getData(bBlob);
|
|
var modDefinition = getDomDefinition(info, bList, bData);
|
|
var item = renderToDom(modDefinition);
|
|
var events = getEvents(info, bList, bData);
|
|
var subcomponents = Cell(info.components);
|
|
var connect = function (newApi) {
|
|
systemApi.set(newApi);
|
|
};
|
|
var disconnect = function () {
|
|
systemApi.set(NoContextApi(getMe));
|
|
};
|
|
var syncComponents = function () {
|
|
var children$1 = children(item);
|
|
var subs = bind(children$1, function (child) {
|
|
return systemApi.get().getByDom(child).fold(function () {
|
|
return [];
|
|
}, function (c) {
|
|
return [c];
|
|
});
|
|
});
|
|
subcomponents.set(subs);
|
|
};
|
|
var config = function (behaviour) {
|
|
var b = bData;
|
|
var f = isFunction(b[behaviour.name()]) ? b[behaviour.name()] : function () {
|
|
throw new Error('Could not find ' + behaviour.name() + ' in ' + JSON.stringify(spec, null, 2));
|
|
};
|
|
return f();
|
|
};
|
|
var hasConfigured = function (behaviour) {
|
|
return isFunction(bData[behaviour.name()]);
|
|
};
|
|
var getApis = function () {
|
|
return info.apis;
|
|
};
|
|
var readState = function (behaviourName) {
|
|
return bData[behaviourName]().map(function (b) {
|
|
return b.state.readState();
|
|
}).getOr('not enabled');
|
|
};
|
|
var me = {
|
|
getSystem: systemApi.get,
|
|
config: config,
|
|
hasConfigured: hasConfigured,
|
|
spec: constant(spec),
|
|
readState: readState,
|
|
getApis: getApis,
|
|
connect: connect,
|
|
disconnect: disconnect,
|
|
element: constant(item),
|
|
syncComponents: syncComponents,
|
|
components: subcomponents.get,
|
|
events: constant(events)
|
|
};
|
|
return me;
|
|
};
|
|
|
|
var buildSubcomponents = function (spec) {
|
|
var components = get(spec, 'components').getOr([]);
|
|
return map(components, build$1);
|
|
};
|
|
var buildFromSpec = function (userSpec) {
|
|
var _a = make(userSpec), specEvents = _a.events, spec = __rest(_a, ['events']);
|
|
var components = buildSubcomponents(spec);
|
|
var completeSpec = __assign(__assign({}, spec), {
|
|
events: __assign(__assign({}, DefaultEvents), specEvents),
|
|
components: components
|
|
});
|
|
return Result.value(build(completeSpec));
|
|
};
|
|
var text = function (textContent) {
|
|
var element = Element.fromText(textContent);
|
|
return external({ element: element });
|
|
};
|
|
var external = function (spec) {
|
|
var extSpec = asRawOrDie('external.component', objOfOnly([
|
|
strict$1('element'),
|
|
option('uid')
|
|
]), spec);
|
|
var systemApi = Cell(NoContextApi());
|
|
var connect = function (newApi) {
|
|
systemApi.set(newApi);
|
|
};
|
|
var disconnect = function () {
|
|
systemApi.set(NoContextApi(function () {
|
|
return me;
|
|
}));
|
|
};
|
|
extSpec.uid.each(function (uid) {
|
|
writeOnly(extSpec.element, uid);
|
|
});
|
|
var me = {
|
|
getSystem: systemApi.get,
|
|
config: Option.none,
|
|
hasConfigured: constant(false),
|
|
connect: connect,
|
|
disconnect: disconnect,
|
|
getApis: function () {
|
|
return {};
|
|
},
|
|
element: constant(extSpec.element),
|
|
spec: constant(spec),
|
|
readState: constant('No state'),
|
|
syncComponents: noop,
|
|
components: constant([]),
|
|
events: constant({})
|
|
};
|
|
return premade(me);
|
|
};
|
|
var uids = generate$2;
|
|
var build$1 = function (spec) {
|
|
return getPremade(spec).fold(function () {
|
|
var userSpecWithUid = spec.hasOwnProperty('uid') ? spec : __assign({ uid: uids('') }, spec);
|
|
return buildFromSpec(userSpecWithUid).getOrDie();
|
|
}, function (prebuilt) {
|
|
return prebuilt;
|
|
});
|
|
};
|
|
var premade$1 = premade;
|
|
|
|
function Dimension (name, getOffset) {
|
|
var set = function (element, h) {
|
|
if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
|
|
throw new Error(name + '.set accepts only positive integer values. Value was ' + h);
|
|
}
|
|
var dom = element.dom();
|
|
if (isSupported(dom)) {
|
|
dom.style[name] = h + 'px';
|
|
}
|
|
};
|
|
var get = function (element) {
|
|
var r = getOffset(element);
|
|
if (r <= 0 || r === null) {
|
|
var css = get$4(element, name);
|
|
return parseFloat(css) || 0;
|
|
}
|
|
return r;
|
|
};
|
|
var getOuter = get;
|
|
var aggregate = function (element, properties) {
|
|
return foldl(properties, function (acc, property) {
|
|
var val = get$4(element, property);
|
|
var value = val === undefined ? 0 : parseInt(val, 10);
|
|
return isNaN(value) ? acc : acc + value;
|
|
}, 0);
|
|
};
|
|
var max = function (element, value, properties) {
|
|
var cumulativeInclusions = aggregate(element, properties);
|
|
var absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0;
|
|
return absoluteMax;
|
|
};
|
|
return {
|
|
set: set,
|
|
get: get,
|
|
getOuter: getOuter,
|
|
aggregate: aggregate,
|
|
max: max
|
|
};
|
|
}
|
|
|
|
var api = Dimension('height', function (element) {
|
|
var dom = element.dom();
|
|
return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;
|
|
});
|
|
var get$6 = function (element) {
|
|
return api.get(element);
|
|
};
|
|
var getOuter$1 = function (element) {
|
|
return api.getOuter(element);
|
|
};
|
|
var setMax = function (element, value) {
|
|
var inclusions = [
|
|
'margin-top',
|
|
'border-top-width',
|
|
'padding-top',
|
|
'padding-bottom',
|
|
'border-bottom-width',
|
|
'margin-bottom'
|
|
];
|
|
var absMax = api.max(element, value, inclusions);
|
|
set$2(element, 'max-height', absMax + 'px');
|
|
};
|
|
|
|
var r = function (left, top) {
|
|
var translate = function (x, y) {
|
|
return r(left + x, top + y);
|
|
};
|
|
return {
|
|
left: constant(left),
|
|
top: constant(top),
|
|
translate: translate
|
|
};
|
|
};
|
|
var Position = r;
|
|
|
|
var boxPosition = function (dom) {
|
|
var box = dom.getBoundingClientRect();
|
|
return Position(box.left, box.top);
|
|
};
|
|
var firstDefinedOrZero = function (a, b) {
|
|
if (a !== undefined) {
|
|
return a;
|
|
} else {
|
|
return b !== undefined ? b : 0;
|
|
}
|
|
};
|
|
var absolute = function (element) {
|
|
var doc = element.dom().ownerDocument;
|
|
var body = doc.body;
|
|
var win = doc.defaultView;
|
|
var html = doc.documentElement;
|
|
if (body === element.dom()) {
|
|
return Position(body.offsetLeft, body.offsetTop);
|
|
}
|
|
var scrollTop = firstDefinedOrZero(win.pageYOffset, html.scrollTop);
|
|
var scrollLeft = firstDefinedOrZero(win.pageXOffset, html.scrollLeft);
|
|
var clientTop = firstDefinedOrZero(html.clientTop, body.clientTop);
|
|
var clientLeft = firstDefinedOrZero(html.clientLeft, body.clientLeft);
|
|
return viewport(element).translate(scrollLeft - clientLeft, scrollTop - clientTop);
|
|
};
|
|
var viewport = function (element) {
|
|
var dom = element.dom();
|
|
var doc = dom.ownerDocument;
|
|
var body = doc.body;
|
|
if (body === dom) {
|
|
return Position(body.offsetLeft, body.offsetTop);
|
|
}
|
|
if (!inBody(element)) {
|
|
return Position(0, 0);
|
|
}
|
|
return boxPosition(dom);
|
|
};
|
|
|
|
var api$1 = Dimension('width', function (element) {
|
|
return element.dom().offsetWidth;
|
|
});
|
|
var set$4 = function (element, h) {
|
|
return api$1.set(element, h);
|
|
};
|
|
var get$7 = function (element) {
|
|
return api$1.get(element);
|
|
};
|
|
var getOuter$2 = function (element) {
|
|
return api$1.getOuter(element);
|
|
};
|
|
var setMax$1 = function (element, value) {
|
|
var inclusions = [
|
|
'margin-left',
|
|
'border-left-width',
|
|
'padding-left',
|
|
'padding-right',
|
|
'border-right-width',
|
|
'margin-right'
|
|
];
|
|
var absMax = api$1.max(element, value, inclusions);
|
|
set$2(element, 'max-width', absMax + 'px');
|
|
};
|
|
|
|
var mkEvent = function (target, x, y, stop, prevent, kill, raw) {
|
|
return {
|
|
target: constant(target),
|
|
x: constant(x),
|
|
y: constant(y),
|
|
stop: stop,
|
|
prevent: prevent,
|
|
kill: kill,
|
|
raw: constant(raw)
|
|
};
|
|
};
|
|
var fromRawEvent = function (rawEvent) {
|
|
var target = Element.fromDom(rawEvent.target);
|
|
var stop = function () {
|
|
return rawEvent.stopPropagation();
|
|
};
|
|
var prevent = function () {
|
|
return rawEvent.preventDefault();
|
|
};
|
|
var kill = compose(prevent, stop);
|
|
return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);
|
|
};
|
|
var handle = function (filter, handler) {
|
|
return function (rawEvent) {
|
|
if (filter(rawEvent)) {
|
|
handler(fromRawEvent(rawEvent));
|
|
}
|
|
};
|
|
};
|
|
var binder = function (element, event, filter, handler, useCapture) {
|
|
var wrapped = handle(filter, handler);
|
|
element.dom().addEventListener(event, wrapped, useCapture);
|
|
return { unbind: curry(unbind, element, event, wrapped, useCapture) };
|
|
};
|
|
var bind$2 = function (element, event, filter, handler) {
|
|
return binder(element, event, filter, handler, false);
|
|
};
|
|
var capture = function (element, event, filter, handler) {
|
|
return binder(element, event, filter, handler, true);
|
|
};
|
|
var unbind = function (element, event, handler, useCapture) {
|
|
element.dom().removeEventListener(event, handler, useCapture);
|
|
};
|
|
|
|
var get$8 = function (_DOC) {
|
|
var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
|
|
var x = doc.body.scrollLeft || doc.documentElement.scrollLeft;
|
|
var y = doc.body.scrollTop || doc.documentElement.scrollTop;
|
|
return Position(x, y);
|
|
};
|
|
var to = function (x, y, _DOC) {
|
|
var doc = _DOC !== undefined ? _DOC.dom() : domGlobals.document;
|
|
var win = doc.defaultView;
|
|
win.scrollTo(x, y);
|
|
};
|
|
|
|
var get$9 = function (_win) {
|
|
var win = _win === undefined ? domGlobals.window : _win;
|
|
return Option.from(win['visualViewport']);
|
|
};
|
|
var bounds = function (x, y, width, height) {
|
|
return {
|
|
x: x,
|
|
y: y,
|
|
width: width,
|
|
height: height,
|
|
right: x + width,
|
|
bottom: y + height
|
|
};
|
|
};
|
|
var getBounds = function (_win) {
|
|
var win = _win === undefined ? domGlobals.window : _win;
|
|
var doc = win.document;
|
|
var scroll = get$8(Element.fromDom(doc));
|
|
return get$9(win).fold(function () {
|
|
var html = win.document.documentElement;
|
|
var width = html.clientWidth;
|
|
var height = html.clientHeight;
|
|
return bounds(scroll.left(), scroll.top(), width, height);
|
|
}, function (visualViewport) {
|
|
return bounds(Math.max(visualViewport.pageLeft, scroll.left()), Math.max(visualViewport.pageTop, scroll.top()), visualViewport.width, visualViewport.height);
|
|
});
|
|
};
|
|
|
|
var walkUp = function (navigation, doc) {
|
|
var frame = navigation.view(doc);
|
|
return frame.fold(constant([]), function (f) {
|
|
var parent = navigation.owner(f);
|
|
var rest = walkUp(navigation, parent);
|
|
return [f].concat(rest);
|
|
});
|
|
};
|
|
var pathTo = function (element, navigation) {
|
|
var d = navigation.owner(element);
|
|
var paths = walkUp(navigation, d);
|
|
return Option.some(paths);
|
|
};
|
|
|
|
var view = function (doc) {
|
|
var element = doc.dom() === domGlobals.document ? Option.none() : Option.from(doc.dom().defaultView.frameElement);
|
|
return element.map(Element.fromDom);
|
|
};
|
|
var owner$1 = function (element) {
|
|
return owner(element);
|
|
};
|
|
|
|
var Navigation = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
view: view,
|
|
owner: owner$1
|
|
});
|
|
|
|
var find$3 = function (element) {
|
|
var doc = Element.fromDom(domGlobals.document);
|
|
var scroll = get$8(doc);
|
|
var path = pathTo(element, Navigation);
|
|
return path.fold(curry(absolute, element), function (frames) {
|
|
var offset = viewport(element);
|
|
var r = foldr(frames, function (b, a) {
|
|
var loc = viewport(a);
|
|
return {
|
|
left: b.left + loc.left(),
|
|
top: b.top + loc.top()
|
|
};
|
|
}, {
|
|
left: 0,
|
|
top: 0
|
|
});
|
|
return Position(r.left + offset.left() + scroll.left(), r.top + offset.top() + scroll.top());
|
|
});
|
|
};
|
|
|
|
var pointed = function (point, width, height) {
|
|
return {
|
|
point: point,
|
|
width: width,
|
|
height: height
|
|
};
|
|
};
|
|
var rect = function (x, y, width, height) {
|
|
return {
|
|
x: x,
|
|
y: y,
|
|
width: width,
|
|
height: height
|
|
};
|
|
};
|
|
var bounds$1 = function (x, y, width, height) {
|
|
return {
|
|
x: x,
|
|
y: y,
|
|
width: width,
|
|
height: height,
|
|
right: x + width,
|
|
bottom: y + height
|
|
};
|
|
};
|
|
var box = function (element) {
|
|
var xy = absolute(element);
|
|
var w = getOuter$2(element);
|
|
var h = getOuter$1(element);
|
|
return bounds$1(xy.left(), xy.top(), w, h);
|
|
};
|
|
var absolute$1 = function (element) {
|
|
var position = find$3(element);
|
|
var width = getOuter$2(element);
|
|
var height = getOuter$1(element);
|
|
return bounds$1(position.left(), position.top(), width, height);
|
|
};
|
|
var win = function () {
|
|
return getBounds(domGlobals.window);
|
|
};
|
|
|
|
function ClosestOrAncestor (is, ancestor, scope, a, isRoot) {
|
|
return is(scope, a) ? Option.some(scope) : isFunction(isRoot) && isRoot(scope) ? Option.none() : ancestor(scope, a, isRoot);
|
|
}
|
|
|
|
var ancestor$1 = function (scope, predicate, isRoot) {
|
|
var element = scope.dom();
|
|
var stop = isFunction(isRoot) ? isRoot : constant(false);
|
|
while (element.parentNode) {
|
|
element = element.parentNode;
|
|
var el = Element.fromDom(element);
|
|
if (predicate(el)) {
|
|
return Option.some(el);
|
|
} else if (stop(el)) {
|
|
break;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var closest$1 = function (scope, predicate, isRoot) {
|
|
var is = function (s, test) {
|
|
return test(s);
|
|
};
|
|
return ClosestOrAncestor(is, ancestor$1, scope, predicate, isRoot);
|
|
};
|
|
var descendant = function (scope, predicate) {
|
|
var descend = function (node) {
|
|
for (var i = 0; i < node.childNodes.length; i++) {
|
|
var child_1 = Element.fromDom(node.childNodes[i]);
|
|
if (predicate(child_1)) {
|
|
return Option.some(child_1);
|
|
}
|
|
var res = descend(node.childNodes[i]);
|
|
if (res.isSome()) {
|
|
return res;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
return descend(scope.dom());
|
|
};
|
|
|
|
var closest$2 = function (scope, predicate, isRoot) {
|
|
return closest$1(scope, predicate, isRoot).isSome();
|
|
};
|
|
|
|
var ancestor$2 = function (scope, selector, isRoot) {
|
|
return ancestor$1(scope, function (e) {
|
|
return is(e, selector);
|
|
}, isRoot);
|
|
};
|
|
var descendant$1 = function (scope, selector) {
|
|
return one(selector, scope);
|
|
};
|
|
var closest$3 = function (scope, selector, isRoot) {
|
|
var is$1 = function (element, selector) {
|
|
return is(element, selector);
|
|
};
|
|
return ClosestOrAncestor(is$1, ancestor$2, scope, selector, isRoot);
|
|
};
|
|
|
|
var find$4 = function (queryElem) {
|
|
var dependent = closest$1(queryElem, function (elem) {
|
|
if (!isElement(elem)) {
|
|
return false;
|
|
}
|
|
var id = get$2(elem, 'id');
|
|
return id !== undefined && id.indexOf('aria-owns') > -1;
|
|
});
|
|
return dependent.bind(function (dep) {
|
|
var id = get$2(dep, 'id');
|
|
var doc = owner(dep);
|
|
return descendant$1(doc, '[aria-owns="' + id + '"]');
|
|
});
|
|
};
|
|
var manager = function () {
|
|
var ariaId = generate$1('aria-owns');
|
|
var link = function (elem) {
|
|
set$1(elem, 'aria-owns', ariaId);
|
|
};
|
|
var unlink = function (elem) {
|
|
remove$1(elem, 'aria-owns');
|
|
};
|
|
return {
|
|
id: ariaId,
|
|
link: link,
|
|
unlink: unlink
|
|
};
|
|
};
|
|
|
|
var isAriaPartOf = function (component, queryElem) {
|
|
return find$4(queryElem).exists(function (owner) {
|
|
return isPartOf(component, owner);
|
|
});
|
|
};
|
|
var isPartOf = function (component, queryElem) {
|
|
return closest$2(queryElem, function (el) {
|
|
return eq$1(el, component.element());
|
|
}, constant(false)) || isAriaPartOf(component, queryElem);
|
|
};
|
|
|
|
var unknown$3 = 'unknown';
|
|
var EventConfiguration;
|
|
(function (EventConfiguration) {
|
|
EventConfiguration[EventConfiguration['STOP'] = 0] = 'STOP';
|
|
EventConfiguration[EventConfiguration['NORMAL'] = 1] = 'NORMAL';
|
|
EventConfiguration[EventConfiguration['LOGGING'] = 2] = 'LOGGING';
|
|
}(EventConfiguration || (EventConfiguration = {})));
|
|
var eventConfig = Cell({});
|
|
var makeEventLogger = function (eventName, initialTarget) {
|
|
var sequence = [];
|
|
var startTime = new Date().getTime();
|
|
return {
|
|
logEventCut: function (_name, target, purpose) {
|
|
sequence.push({
|
|
outcome: 'cut',
|
|
target: target,
|
|
purpose: purpose
|
|
});
|
|
},
|
|
logEventStopped: function (_name, target, purpose) {
|
|
sequence.push({
|
|
outcome: 'stopped',
|
|
target: target,
|
|
purpose: purpose
|
|
});
|
|
},
|
|
logNoParent: function (_name, target, purpose) {
|
|
sequence.push({
|
|
outcome: 'no-parent',
|
|
target: target,
|
|
purpose: purpose
|
|
});
|
|
},
|
|
logEventNoHandlers: function (_name, target) {
|
|
sequence.push({
|
|
outcome: 'no-handlers-left',
|
|
target: target
|
|
});
|
|
},
|
|
logEventResponse: function (_name, target, purpose) {
|
|
sequence.push({
|
|
outcome: 'response',
|
|
purpose: purpose,
|
|
target: target
|
|
});
|
|
},
|
|
write: function () {
|
|
var finishTime = new Date().getTime();
|
|
if (contains([
|
|
'mousemove',
|
|
'mouseover',
|
|
'mouseout',
|
|
systemInit()
|
|
], eventName)) {
|
|
return;
|
|
}
|
|
domGlobals.console.log(eventName, {
|
|
event: eventName,
|
|
time: finishTime - startTime,
|
|
target: initialTarget.dom(),
|
|
sequence: map(sequence, function (s) {
|
|
if (!contains([
|
|
'cut',
|
|
'stopped',
|
|
'response'
|
|
], s.outcome)) {
|
|
return s.outcome;
|
|
} else {
|
|
return '{' + s.purpose + '} ' + s.outcome + ' at (' + element(s.target) + ')';
|
|
}
|
|
})
|
|
});
|
|
}
|
|
};
|
|
};
|
|
var processEvent = function (eventName, initialTarget, f) {
|
|
var status = get(eventConfig.get(), eventName).orThunk(function () {
|
|
var patterns = keys(eventConfig.get());
|
|
return findMap(patterns, function (p) {
|
|
return eventName.indexOf(p) > -1 ? Option.some(eventConfig.get()[p]) : Option.none();
|
|
});
|
|
}).getOr(EventConfiguration.NORMAL);
|
|
switch (status) {
|
|
case EventConfiguration.NORMAL:
|
|
return f(noLogger());
|
|
case EventConfiguration.LOGGING: {
|
|
var logger = makeEventLogger(eventName, initialTarget);
|
|
var output = f(logger);
|
|
logger.write();
|
|
return output;
|
|
}
|
|
case EventConfiguration.STOP:
|
|
return true;
|
|
}
|
|
};
|
|
var path = [
|
|
'alloy/data/Fields',
|
|
'alloy/debugging/Debugging'
|
|
];
|
|
var getTrace = function () {
|
|
var err = new Error();
|
|
if (err.stack !== undefined) {
|
|
var lines = err.stack.split('\n');
|
|
return find(lines, function (line) {
|
|
return line.indexOf('alloy') > 0 && !exists(path, function (p) {
|
|
return line.indexOf(p) > -1;
|
|
});
|
|
}).getOr(unknown$3);
|
|
} else {
|
|
return unknown$3;
|
|
}
|
|
};
|
|
var ignoreEvent = {
|
|
logEventCut: noop,
|
|
logEventStopped: noop,
|
|
logNoParent: noop,
|
|
logEventNoHandlers: noop,
|
|
logEventResponse: noop,
|
|
write: noop
|
|
};
|
|
var monitorEvent = function (eventName, initialTarget, f) {
|
|
return processEvent(eventName, initialTarget, f);
|
|
};
|
|
var noLogger = constant(ignoreEvent);
|
|
|
|
var menuFields = constant([
|
|
strict$1('menu'),
|
|
strict$1('selectedMenu')
|
|
]);
|
|
var itemFields = constant([
|
|
strict$1('item'),
|
|
strict$1('selectedItem')
|
|
]);
|
|
var schema = constant(objOf(itemFields().concat(menuFields())));
|
|
var itemSchema = constant(objOf(itemFields()));
|
|
|
|
var _initSize = strictObjOf('initSize', [
|
|
strict$1('numColumns'),
|
|
strict$1('numRows')
|
|
]);
|
|
var itemMarkers = function () {
|
|
return strictOf('markers', itemSchema());
|
|
};
|
|
var tieredMenuMarkers = function () {
|
|
return strictObjOf('markers', [strict$1('backgroundMenu')].concat(menuFields()).concat(itemFields()));
|
|
};
|
|
var markers = function (required) {
|
|
return strictObjOf('markers', map(required, strict$1));
|
|
};
|
|
var onPresenceHandler = function (label, fieldName, presence) {
|
|
var trace = getTrace();
|
|
return field(fieldName, fieldName, presence, valueOf(function (f) {
|
|
return Result.value(function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
return f.apply(undefined, args);
|
|
});
|
|
}));
|
|
};
|
|
var onHandler = function (fieldName) {
|
|
return onPresenceHandler('onHandler', fieldName, defaulted(noop));
|
|
};
|
|
var onKeyboardHandler = function (fieldName) {
|
|
return onPresenceHandler('onKeyboardHandler', fieldName, defaulted(Option.none));
|
|
};
|
|
var onStrictHandler = function (fieldName) {
|
|
return onPresenceHandler('onHandler', fieldName, strict());
|
|
};
|
|
var onStrictKeyboardHandler = function (fieldName) {
|
|
return onPresenceHandler('onKeyboardHandler', fieldName, strict());
|
|
};
|
|
var output = function (name, value) {
|
|
return state$1(name, constant(value));
|
|
};
|
|
var snapshot = function (name) {
|
|
return state$1(name, identity);
|
|
};
|
|
var initSize = constant(_initSize);
|
|
|
|
var nu$7 = function (x, y, bubble, direction, boundsRestriction, label) {
|
|
return {
|
|
x: constant(x),
|
|
y: constant(y),
|
|
bubble: constant(bubble),
|
|
direction: constant(direction),
|
|
boundsRestriction: constant(boundsRestriction),
|
|
label: constant(label)
|
|
};
|
|
};
|
|
|
|
var adt$2 = Adt.generate([
|
|
{ southeast: [] },
|
|
{ southwest: [] },
|
|
{ northeast: [] },
|
|
{ northwest: [] },
|
|
{ south: [] },
|
|
{ north: [] },
|
|
{ east: [] },
|
|
{ west: [] }
|
|
]);
|
|
var cata = function (subject, southeast, southwest, northeast, northwest, south, north, east, west) {
|
|
return subject.fold(southeast, southwest, northeast, northwest, south, north, east, west);
|
|
};
|
|
var cataVertical = function (subject, south, middle, north) {
|
|
return subject.fold(south, south, north, north, south, north, middle, middle);
|
|
};
|
|
var cataHorizontal = function (subject, east, middle, west) {
|
|
return subject.fold(east, west, east, west, middle, middle, east, west);
|
|
};
|
|
var southeast = adt$2.southeast;
|
|
var southwest = adt$2.southwest;
|
|
var northeast = adt$2.northeast;
|
|
var northwest = adt$2.northwest;
|
|
var south = adt$2.south;
|
|
var north = adt$2.north;
|
|
var east = adt$2.east;
|
|
var west = adt$2.west;
|
|
|
|
var getRestriction = function (anchor, restriction) {
|
|
switch (restriction) {
|
|
case 1:
|
|
return anchor.x;
|
|
case 0:
|
|
return anchor.x + anchor.width;
|
|
case 2:
|
|
return anchor.y;
|
|
case 3:
|
|
return anchor.y + anchor.height;
|
|
}
|
|
};
|
|
var boundsRestriction = function (anchor, restrictions) {
|
|
return mapToObject([
|
|
'left',
|
|
'right',
|
|
'top',
|
|
'bottom'
|
|
], function (dir) {
|
|
return get(restrictions, dir).map(function (restriction) {
|
|
return getRestriction(anchor, restriction);
|
|
});
|
|
});
|
|
};
|
|
var adjustBounds = function (bounds, boundsRestrictions, bubbleOffsets) {
|
|
var applyRestriction = function (dir, current) {
|
|
var bubbleOffset = dir === 'top' || dir === 'bottom' ? bubbleOffsets.top() : bubbleOffsets.left();
|
|
return get(boundsRestrictions, dir).bind(identity).bind(function (restriction) {
|
|
if (dir === 'left' || dir === 'top') {
|
|
return restriction >= current ? Option.some(restriction) : Option.none();
|
|
} else {
|
|
return restriction <= current ? Option.some(restriction) : Option.none();
|
|
}
|
|
}).map(function (restriction) {
|
|
return restriction + bubbleOffset;
|
|
}).getOr(current);
|
|
};
|
|
var adjustedLeft = applyRestriction('left', bounds.x);
|
|
var adjustedTop = applyRestriction('top', bounds.y);
|
|
var adjustedRight = applyRestriction('right', bounds.right);
|
|
var adjustedBottom = applyRestriction('bottom', bounds.bottom);
|
|
return bounds$1(adjustedLeft, adjustedTop, adjustedRight - adjustedLeft, adjustedBottom - adjustedTop);
|
|
};
|
|
|
|
var eastX = function (anchor) {
|
|
return anchor.x;
|
|
};
|
|
var middleX = function (anchor, element) {
|
|
return anchor.x + anchor.width / 2 - element.width / 2;
|
|
};
|
|
var westX = function (anchor, element) {
|
|
return anchor.x + anchor.width - element.width;
|
|
};
|
|
var northY = function (anchor, element) {
|
|
return anchor.y - element.height;
|
|
};
|
|
var southY = function (anchor) {
|
|
return anchor.y + anchor.height;
|
|
};
|
|
var centreY = function (anchor, element) {
|
|
return anchor.y + anchor.height / 2 - element.height / 2;
|
|
};
|
|
var eastEdgeX = function (anchor) {
|
|
return anchor.x + anchor.width;
|
|
};
|
|
var westEdgeX = function (anchor, element) {
|
|
return anchor.x - element.width;
|
|
};
|
|
var southeast$1 = function (anchor, element, bubbles) {
|
|
return nu$7(eastX(anchor), southY(anchor), bubbles.southeast(), southeast(), boundsRestriction(anchor, {
|
|
left: 1,
|
|
top: 3
|
|
}), 'layout-se');
|
|
};
|
|
var southwest$1 = function (anchor, element, bubbles) {
|
|
return nu$7(westX(anchor, element), southY(anchor), bubbles.southwest(), southwest(), boundsRestriction(anchor, {
|
|
right: 0,
|
|
top: 3
|
|
}), 'layout-sw');
|
|
};
|
|
var northeast$1 = function (anchor, element, bubbles) {
|
|
return nu$7(eastX(anchor), northY(anchor, element), bubbles.northeast(), northeast(), boundsRestriction(anchor, {
|
|
left: 1,
|
|
bottom: 2
|
|
}), 'layout-ne');
|
|
};
|
|
var northwest$1 = function (anchor, element, bubbles) {
|
|
return nu$7(westX(anchor, element), northY(anchor, element), bubbles.northwest(), northwest(), boundsRestriction(anchor, {
|
|
right: 0,
|
|
bottom: 2
|
|
}), 'layout-nw');
|
|
};
|
|
var north$1 = function (anchor, element, bubbles) {
|
|
return nu$7(middleX(anchor, element), northY(anchor, element), bubbles.north(), north(), boundsRestriction(anchor, { bottom: 2 }), 'layout-n');
|
|
};
|
|
var south$1 = function (anchor, element, bubbles) {
|
|
return nu$7(middleX(anchor, element), southY(anchor), bubbles.south(), south(), boundsRestriction(anchor, { top: 3 }), 'layout-s');
|
|
};
|
|
var east$1 = function (anchor, element, bubbles) {
|
|
return nu$7(eastEdgeX(anchor), centreY(anchor, element), bubbles.east(), east(), boundsRestriction(anchor, { left: 0 }), 'layout-e');
|
|
};
|
|
var west$1 = function (anchor, element, bubbles) {
|
|
return nu$7(westEdgeX(anchor, element), centreY(anchor, element), bubbles.west(), west(), boundsRestriction(anchor, { right: 1 }), 'layout-w');
|
|
};
|
|
var all$2 = function () {
|
|
return [
|
|
southeast$1,
|
|
southwest$1,
|
|
northeast$1,
|
|
northwest$1,
|
|
south$1,
|
|
north$1,
|
|
east$1,
|
|
west$1
|
|
];
|
|
};
|
|
var allRtl = function () {
|
|
return [
|
|
southwest$1,
|
|
southeast$1,
|
|
northwest$1,
|
|
northeast$1,
|
|
south$1,
|
|
north$1,
|
|
east$1,
|
|
west$1
|
|
];
|
|
};
|
|
var aboveOrBelow = function () {
|
|
return [
|
|
northeast$1,
|
|
northwest$1,
|
|
southeast$1,
|
|
southwest$1,
|
|
north$1,
|
|
south$1
|
|
];
|
|
};
|
|
var aboveOrBelowRtl = function () {
|
|
return [
|
|
northwest$1,
|
|
northeast$1,
|
|
southwest$1,
|
|
southeast$1,
|
|
north$1,
|
|
south$1
|
|
];
|
|
};
|
|
var belowOrAbove = function () {
|
|
return [
|
|
southeast$1,
|
|
southwest$1,
|
|
northeast$1,
|
|
northwest$1,
|
|
south$1,
|
|
north$1
|
|
];
|
|
};
|
|
var belowOrAboveRtl = function () {
|
|
return [
|
|
southwest$1,
|
|
southeast$1,
|
|
northwest$1,
|
|
northeast$1,
|
|
south$1,
|
|
north$1
|
|
];
|
|
};
|
|
|
|
var executeEvent = function (bConfig, bState, executor) {
|
|
return runOnExecute(function (component) {
|
|
executor(component, bConfig, bState);
|
|
});
|
|
};
|
|
var loadEvent = function (bConfig, bState, f) {
|
|
return runOnInit(function (component, _simulatedEvent) {
|
|
f(component, bConfig, bState);
|
|
});
|
|
};
|
|
var create = function (schema, name, active, apis, extra, state) {
|
|
var configSchema = objOfOnly(schema);
|
|
var schemaSchema = optionObjOf(name, [optionObjOfOnly('config', schema)]);
|
|
return doCreate(configSchema, schemaSchema, name, active, apis, extra, state);
|
|
};
|
|
var createModes = function (modes, name, active, apis, extra, state) {
|
|
var configSchema = modes;
|
|
var schemaSchema = optionObjOf(name, [optionOf('config', modes)]);
|
|
return doCreate(configSchema, schemaSchema, name, active, apis, extra, state);
|
|
};
|
|
var wrapApi = function (bName, apiFunction, apiName) {
|
|
var f = function (component) {
|
|
var rest = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
rest[_i - 1] = arguments[_i];
|
|
}
|
|
var args = [component].concat(rest);
|
|
return component.config({ name: constant(bName) }).fold(function () {
|
|
throw new Error('We could not find any behaviour configuration for: ' + bName + '. Using API: ' + apiName);
|
|
}, function (info) {
|
|
var rest = Array.prototype.slice.call(args, 1);
|
|
return apiFunction.apply(undefined, [
|
|
component,
|
|
info.config,
|
|
info.state
|
|
].concat(rest));
|
|
});
|
|
};
|
|
return markAsBehaviourApi(f, apiName, apiFunction);
|
|
};
|
|
var revokeBehaviour = function (name) {
|
|
return {
|
|
key: name,
|
|
value: undefined
|
|
};
|
|
};
|
|
var doCreate = function (configSchema, schemaSchema, name, active, apis, extra, state) {
|
|
var getConfig = function (info) {
|
|
return hasNonNullableKey(info, name) ? info[name]() : Option.none();
|
|
};
|
|
var wrappedApis = map$1(apis, function (apiF, apiName) {
|
|
return wrapApi(name, apiF, apiName);
|
|
});
|
|
var wrappedExtra = map$1(extra, function (extraF, extraName) {
|
|
return markAsExtraApi(extraF, extraName);
|
|
});
|
|
var me = __assign(__assign(__assign({}, wrappedExtra), wrappedApis), {
|
|
revoke: curry(revokeBehaviour, name),
|
|
config: function (spec) {
|
|
var prepared = asRawOrDie(name + '-config', configSchema, spec);
|
|
return {
|
|
key: name,
|
|
value: {
|
|
config: prepared,
|
|
me: me,
|
|
configAsRaw: cached(function () {
|
|
return asRawOrDie(name + '-config', configSchema, spec);
|
|
}),
|
|
initialConfig: spec,
|
|
state: state
|
|
}
|
|
};
|
|
},
|
|
schema: function () {
|
|
return schemaSchema;
|
|
},
|
|
exhibit: function (info, base) {
|
|
return getConfig(info).bind(function (behaviourInfo) {
|
|
return get(active, 'exhibit').map(function (exhibitor) {
|
|
return exhibitor(base, behaviourInfo.config, behaviourInfo.state);
|
|
});
|
|
}).getOr(nu$6({}));
|
|
},
|
|
name: function () {
|
|
return name;
|
|
},
|
|
handlers: function (info) {
|
|
return getConfig(info).map(function (behaviourInfo) {
|
|
var getEvents = get(active, 'events').getOr(function () {
|
|
return {};
|
|
});
|
|
return getEvents(behaviourInfo.config, behaviourInfo.state);
|
|
}).getOr({});
|
|
}
|
|
});
|
|
return me;
|
|
};
|
|
|
|
var derive$1 = function (capabilities) {
|
|
return wrapAll$1(capabilities);
|
|
};
|
|
var simpleSchema = objOfOnly([
|
|
strict$1('fields'),
|
|
strict$1('name'),
|
|
defaulted$1('active', {}),
|
|
defaulted$1('apis', {}),
|
|
defaulted$1('state', NoState),
|
|
defaulted$1('extra', {})
|
|
]);
|
|
var create$1 = function (data) {
|
|
var value = asRawOrDie('Creating behaviour: ' + data.name, simpleSchema, data);
|
|
return create(value.fields, value.name, value.active, value.apis, value.extra, value.state);
|
|
};
|
|
var modeSchema = objOfOnly([
|
|
strict$1('branchKey'),
|
|
strict$1('branches'),
|
|
strict$1('name'),
|
|
defaulted$1('active', {}),
|
|
defaulted$1('apis', {}),
|
|
defaulted$1('state', NoState),
|
|
defaulted$1('extra', {})
|
|
]);
|
|
var createModes$1 = function (data) {
|
|
var value = asRawOrDie('Creating behaviour: ' + data.name, modeSchema, data);
|
|
return createModes(choose$1(value.branchKey, value.branches), value.name, value.active, value.apis, value.extra, value.state);
|
|
};
|
|
var revoke = constant(undefined);
|
|
|
|
var chooseChannels = function (channels, message) {
|
|
return message.universal() ? channels : filter(channels, function (ch) {
|
|
return contains(message.channels(), ch);
|
|
});
|
|
};
|
|
var events$1 = function (receiveConfig) {
|
|
return derive([run(receive(), function (component, message) {
|
|
var channelMap = receiveConfig.channels;
|
|
var channels = keys(channelMap);
|
|
var receivingData = message;
|
|
var targetChannels = chooseChannels(channels, receivingData);
|
|
each(targetChannels, function (ch) {
|
|
var channelInfo = channelMap[ch];
|
|
var channelSchema = channelInfo.schema;
|
|
var data = asRawOrDie('channel[' + ch + '] data\nReceiver: ' + element(component.element()), channelSchema, receivingData.data());
|
|
channelInfo.onReceive(component, data);
|
|
});
|
|
})]);
|
|
};
|
|
|
|
var ActiveReceiving = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$1
|
|
});
|
|
|
|
var ReceivingSchema = [strictOf('channels', setOf$1(Result.value, objOfOnly([
|
|
onStrictHandler('onReceive'),
|
|
defaulted$1('schema', anyValue$1())
|
|
])))];
|
|
|
|
var Receiving = create$1({
|
|
fields: ReceivingSchema,
|
|
name: 'receiving',
|
|
active: ActiveReceiving
|
|
});
|
|
|
|
var exhibit = function (base, posConfig) {
|
|
return nu$6({
|
|
classes: [],
|
|
styles: posConfig.useFixed() ? {} : { position: 'relative' }
|
|
});
|
|
};
|
|
|
|
var ActivePosition = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit
|
|
});
|
|
|
|
var focus$1 = function (element) {
|
|
return element.dom().focus();
|
|
};
|
|
var blur = function (element) {
|
|
return element.dom().blur();
|
|
};
|
|
var hasFocus = function (element) {
|
|
var doc = owner(element).dom();
|
|
return element.dom() === doc.activeElement;
|
|
};
|
|
var active = function (_doc) {
|
|
var doc = _doc !== undefined ? _doc.dom() : domGlobals.document;
|
|
return Option.from(doc.activeElement).map(Element.fromDom);
|
|
};
|
|
var search = function (element) {
|
|
return active(owner(element)).filter(function (e) {
|
|
return element.dom().contains(e.dom());
|
|
});
|
|
};
|
|
|
|
var preserve = function (f, container) {
|
|
var ownerDoc = owner(container);
|
|
var refocus = active(ownerDoc).bind(function (focused) {
|
|
var hasFocus = function (elem) {
|
|
return eq$1(focused, elem);
|
|
};
|
|
return hasFocus(container) ? Option.some(container) : descendant(container, hasFocus);
|
|
});
|
|
var result = f(container);
|
|
refocus.each(function (oldFocus) {
|
|
active(ownerDoc).filter(function (newFocus) {
|
|
return eq$1(newFocus, oldFocus);
|
|
}).fold(function () {
|
|
focus$1(oldFocus);
|
|
}, noop);
|
|
});
|
|
return result;
|
|
};
|
|
|
|
var NuPositionCss = function (position, left, top, right, bottom) {
|
|
return {
|
|
position: constant(position),
|
|
left: constant(left),
|
|
top: constant(top),
|
|
right: constant(right),
|
|
bottom: constant(bottom)
|
|
};
|
|
};
|
|
var applyPositionCss = function (element, position) {
|
|
var addPx = function (num) {
|
|
return num + 'px';
|
|
};
|
|
setOptions(element, {
|
|
position: Option.some(position.position()),
|
|
left: position.left().map(addPx),
|
|
top: position.top().map(addPx),
|
|
right: position.right().map(addPx),
|
|
bottom: position.bottom().map(addPx)
|
|
});
|
|
};
|
|
|
|
var adt$3 = Adt.generate([
|
|
{ none: [] },
|
|
{
|
|
relative: [
|
|
'x',
|
|
'y',
|
|
'width',
|
|
'height'
|
|
]
|
|
},
|
|
{
|
|
fixed: [
|
|
'x',
|
|
'y',
|
|
'width',
|
|
'height'
|
|
]
|
|
}
|
|
]);
|
|
var positionWithDirection = function (posName, decision, x, y, width, height) {
|
|
var decisionX = decision.x - x;
|
|
var decisionY = decision.y - y;
|
|
var decisionWidth = decision.width;
|
|
var decisionHeight = decision.height;
|
|
var decisionRight = width - (decisionX + decisionWidth);
|
|
var decisionBottom = height - (decisionY + decisionHeight);
|
|
var left = Option.some(decisionX);
|
|
var top = Option.some(decisionY);
|
|
var right = Option.some(decisionRight);
|
|
var bottom = Option.some(decisionBottom);
|
|
var none = Option.none();
|
|
return cata(decision.direction, function () {
|
|
return NuPositionCss(posName, left, top, none, none);
|
|
}, function () {
|
|
return NuPositionCss(posName, none, top, right, none);
|
|
}, function () {
|
|
return NuPositionCss(posName, left, none, none, bottom);
|
|
}, function () {
|
|
return NuPositionCss(posName, none, none, right, bottom);
|
|
}, function () {
|
|
return NuPositionCss(posName, left, top, none, none);
|
|
}, function () {
|
|
return NuPositionCss(posName, left, none, none, bottom);
|
|
}, function () {
|
|
return NuPositionCss(posName, left, top, none, none);
|
|
}, function () {
|
|
return NuPositionCss(posName, none, top, right, none);
|
|
});
|
|
};
|
|
var reposition = function (origin, decision) {
|
|
return origin.fold(function () {
|
|
return NuPositionCss('absolute', Option.some(decision.x), Option.some(decision.y), Option.none(), Option.none());
|
|
}, function (x, y, width, height) {
|
|
return positionWithDirection('absolute', decision, x, y, width, height);
|
|
}, function (x, y, width, height) {
|
|
return positionWithDirection('fixed', decision, x, y, width, height);
|
|
});
|
|
};
|
|
var toBox = function (origin, element) {
|
|
var rel = curry(find$3, element);
|
|
var position = origin.fold(rel, rel, function () {
|
|
var scroll = get$8();
|
|
return find$3(element).translate(-scroll.left(), -scroll.top());
|
|
});
|
|
var width = getOuter$2(element);
|
|
var height = getOuter$1(element);
|
|
return bounds$1(position.left(), position.top(), width, height);
|
|
};
|
|
var viewport$1 = function (origin, getBounds) {
|
|
return getBounds.fold(function () {
|
|
return origin.fold(win, win, bounds$1);
|
|
}, function (b) {
|
|
return origin.fold(b, b, function () {
|
|
var bounds = b();
|
|
var pos = translate(origin, bounds.x, bounds.y);
|
|
return bounds$1(pos.left(), pos.top(), bounds.width, bounds.height);
|
|
});
|
|
});
|
|
};
|
|
var translate = function (origin, x, y) {
|
|
var pos = Position(x, y);
|
|
var removeScroll = function () {
|
|
var outerScroll = get$8();
|
|
return pos.translate(-outerScroll.left(), -outerScroll.top());
|
|
};
|
|
return origin.fold(constant(pos), constant(pos), removeScroll);
|
|
};
|
|
var cata$1 = function (subject, onNone, onRelative, onFixed) {
|
|
return subject.fold(onNone, onRelative, onFixed);
|
|
};
|
|
var none$1 = adt$3.none;
|
|
var relative = adt$3.relative;
|
|
var fixed = adt$3.fixed;
|
|
|
|
var anchor = function (anchorBox, origin) {
|
|
return {
|
|
anchorBox: constant(anchorBox),
|
|
origin: constant(origin)
|
|
};
|
|
};
|
|
var box$1 = function (anchorBox, origin) {
|
|
return anchor(anchorBox, origin);
|
|
};
|
|
|
|
var cycleBy = function (value, delta, min, max) {
|
|
var r = value + delta;
|
|
return r > max ? min : r < min ? max : r;
|
|
};
|
|
var clamp = function (value, min, max) {
|
|
return Math.min(Math.max(value, min), max);
|
|
};
|
|
|
|
var adt$4 = Adt.generate([
|
|
{ fit: ['reposition'] },
|
|
{
|
|
nofit: [
|
|
'reposition',
|
|
'deltaW',
|
|
'deltaH'
|
|
]
|
|
}
|
|
]);
|
|
var calcReposition = function (newX, newY, width, height, bounds) {
|
|
var boundsX = bounds.x;
|
|
var boundsY = bounds.y;
|
|
var boundsWidth = bounds.width;
|
|
var boundsHeight = bounds.height;
|
|
var xInBounds = newX >= boundsX;
|
|
var yInBounds = newY >= boundsY;
|
|
var originInBounds = xInBounds && yInBounds;
|
|
var xFit = newX + width <= boundsX + boundsWidth;
|
|
var yFit = newY + height <= boundsY + boundsHeight;
|
|
var sizeInBounds = xFit && yFit;
|
|
var deltaW = Math.abs(Math.min(width, xInBounds ? boundsX + boundsWidth - newX : boundsX - (newX + width)));
|
|
var deltaH = Math.abs(Math.min(height, yInBounds ? boundsY + boundsHeight - newY : boundsY - (newY + height)));
|
|
var maxX = Math.max(bounds.x, bounds.right - width);
|
|
var maxY = Math.max(bounds.y, bounds.bottom - height);
|
|
var limitX = clamp(newX, bounds.x, maxX);
|
|
var limitY = clamp(newY, bounds.y, maxY);
|
|
return {
|
|
originInBounds: originInBounds,
|
|
sizeInBounds: sizeInBounds,
|
|
limitX: limitX,
|
|
limitY: limitY,
|
|
deltaW: deltaW,
|
|
deltaH: deltaH
|
|
};
|
|
};
|
|
var attempt = function (candidate, width, height, bounds) {
|
|
var candidateX = candidate.x();
|
|
var candidateY = candidate.y();
|
|
var bubbleOffsets = candidate.bubble().offset();
|
|
var bubbleLeft = bubbleOffsets.left();
|
|
var bubbleTop = bubbleOffsets.top();
|
|
var adjustedBounds = adjustBounds(bounds, candidate.boundsRestriction(), bubbleOffsets);
|
|
var boundsY = adjustedBounds.y;
|
|
var boundsBottom = adjustedBounds.bottom;
|
|
var boundsX = adjustedBounds.x;
|
|
var boundsRight = adjustedBounds.right;
|
|
var newX = candidateX + bubbleLeft;
|
|
var newY = candidateY + bubbleTop;
|
|
var _a = calcReposition(newX, newY, width, height, adjustedBounds), originInBounds = _a.originInBounds, sizeInBounds = _a.sizeInBounds, limitX = _a.limitX, limitY = _a.limitY, deltaW = _a.deltaW, deltaH = _a.deltaH;
|
|
var upAvailable = constant(limitY + deltaH - boundsY);
|
|
var downAvailable = constant(boundsBottom - limitY);
|
|
var maxHeight = cataVertical(candidate.direction(), downAvailable, downAvailable, upAvailable);
|
|
var westAvailable = constant(limitX + deltaW - boundsX);
|
|
var eastAvailable = constant(boundsRight - limitX);
|
|
var maxWidth = cataHorizontal(candidate.direction(), eastAvailable, eastAvailable, westAvailable);
|
|
var reposition = {
|
|
x: limitX,
|
|
y: limitY,
|
|
width: deltaW,
|
|
height: deltaH,
|
|
maxHeight: maxHeight,
|
|
maxWidth: maxWidth,
|
|
direction: candidate.direction(),
|
|
classes: {
|
|
on: candidate.bubble().classesOn(),
|
|
off: candidate.bubble().classesOff()
|
|
},
|
|
label: candidate.label(),
|
|
candidateYforTest: newY
|
|
};
|
|
return originInBounds && sizeInBounds ? adt$4.fit(reposition) : adt$4.nofit(reposition, deltaW, deltaH);
|
|
};
|
|
var attempts = function (candidates, anchorBox, elementBox, bubbles, bounds) {
|
|
var panelWidth = elementBox.width;
|
|
var panelHeight = elementBox.height;
|
|
var attemptBestFit = function (layout, reposition, deltaW, deltaH) {
|
|
var next = layout(anchorBox, elementBox, bubbles);
|
|
var attemptLayout = attempt(next, panelWidth, panelHeight, bounds);
|
|
return attemptLayout.fold(adt$4.fit, function (newReposition, newDeltaW, newDeltaH) {
|
|
var improved = newDeltaH > deltaH || newDeltaW > deltaW;
|
|
return improved ? adt$4.nofit(newReposition, newDeltaW, newDeltaH) : adt$4.nofit(reposition, deltaW, deltaH);
|
|
});
|
|
};
|
|
var abc = foldl(candidates, function (b, a) {
|
|
var bestNext = curry(attemptBestFit, a);
|
|
return b.fold(adt$4.fit, bestNext);
|
|
}, adt$4.nofit({
|
|
x: anchorBox.x,
|
|
y: anchorBox.y,
|
|
width: elementBox.width,
|
|
height: elementBox.height,
|
|
maxHeight: elementBox.height,
|
|
maxWidth: elementBox.width,
|
|
direction: southeast(),
|
|
classes: {
|
|
on: [],
|
|
off: []
|
|
},
|
|
label: 'none',
|
|
candidateYforTest: anchorBox.y
|
|
}, -1, -1));
|
|
return abc.fold(identity, identity);
|
|
};
|
|
|
|
var elementSize = function (p) {
|
|
return {
|
|
width: getOuter$2(p),
|
|
height: getOuter$1(p)
|
|
};
|
|
};
|
|
var layout = function (anchorBox, element, bubbles, options) {
|
|
remove$6(element, 'max-height');
|
|
remove$6(element, 'max-width');
|
|
var elementBox = elementSize(element);
|
|
return attempts(options.preference, anchorBox, elementBox, bubbles, options.bounds);
|
|
};
|
|
var setClasses = function (element, decision) {
|
|
var classInfo = decision.classes;
|
|
remove$5(element, classInfo.off);
|
|
add$3(element, classInfo.on);
|
|
};
|
|
var setHeight = function (element, decision, options) {
|
|
var maxHeightFunction = options.maxHeightFunction;
|
|
maxHeightFunction(element, decision.maxHeight);
|
|
};
|
|
var setWidth = function (element, decision, options) {
|
|
var maxWidthFunction = options.maxWidthFunction;
|
|
maxWidthFunction(element, decision.maxWidth);
|
|
};
|
|
var position = function (element, decision, options) {
|
|
applyPositionCss(element, reposition(options.origin, decision));
|
|
};
|
|
|
|
var setMaxHeight = function (element, maxHeight) {
|
|
setMax(element, Math.floor(maxHeight));
|
|
};
|
|
var anchored = constant(function (element, available) {
|
|
setMaxHeight(element, available);
|
|
setAll$1(element, {
|
|
'overflow-x': 'hidden',
|
|
'overflow-y': 'auto'
|
|
});
|
|
});
|
|
var expandable = constant(function (element, available) {
|
|
setMaxHeight(element, available);
|
|
});
|
|
|
|
var defaultOr = function (options, key, dephault) {
|
|
return options[key] === undefined ? dephault : options[key];
|
|
};
|
|
var simple = function (anchor, element, bubble, layouts, getBounds, overrideOptions) {
|
|
var maxHeightFunction = defaultOr(overrideOptions, 'maxHeightFunction', anchored());
|
|
var maxWidthFunction = defaultOr(overrideOptions, 'maxWidthFunction', noop);
|
|
var anchorBox = anchor.anchorBox();
|
|
var origin = anchor.origin();
|
|
var options = {
|
|
bounds: viewport$1(origin, getBounds),
|
|
origin: origin,
|
|
preference: layouts,
|
|
maxHeightFunction: maxHeightFunction,
|
|
maxWidthFunction: maxWidthFunction
|
|
};
|
|
go(anchorBox, element, bubble, options);
|
|
};
|
|
var go = function (anchorBox, element, bubble, options) {
|
|
var decision = layout(anchorBox, element, bubble, options);
|
|
position(element, decision, options);
|
|
setClasses(element, decision);
|
|
setHeight(element, decision, options);
|
|
setWidth(element, decision, options);
|
|
};
|
|
|
|
var allAlignments = [
|
|
'valignCentre',
|
|
'alignLeft',
|
|
'alignRight',
|
|
'alignCentre',
|
|
'top',
|
|
'bottom',
|
|
'left',
|
|
'right'
|
|
];
|
|
var nu$8 = function (width, yoffset, classes) {
|
|
var getClasses = function (prop) {
|
|
return get(classes, prop).getOr([]);
|
|
};
|
|
var make = function (xDelta, yDelta, alignmentsOn) {
|
|
var alignmentsOff = difference(allAlignments, alignmentsOn);
|
|
return {
|
|
offset: function () {
|
|
return Position(xDelta, yDelta);
|
|
},
|
|
classesOn: function () {
|
|
return bind(alignmentsOn, getClasses);
|
|
},
|
|
classesOff: function () {
|
|
return bind(alignmentsOff, getClasses);
|
|
}
|
|
};
|
|
};
|
|
return {
|
|
southeast: function () {
|
|
return make(-width, yoffset, [
|
|
'top',
|
|
'alignLeft'
|
|
]);
|
|
},
|
|
southwest: function () {
|
|
return make(width, yoffset, [
|
|
'top',
|
|
'alignRight'
|
|
]);
|
|
},
|
|
south: function () {
|
|
return make(-width / 2, yoffset, [
|
|
'top',
|
|
'alignCentre'
|
|
]);
|
|
},
|
|
northeast: function () {
|
|
return make(-width, -yoffset, [
|
|
'bottom',
|
|
'alignLeft'
|
|
]);
|
|
},
|
|
northwest: function () {
|
|
return make(width, -yoffset, [
|
|
'bottom',
|
|
'alignRight'
|
|
]);
|
|
},
|
|
north: function () {
|
|
return make(-width / 2, -yoffset, [
|
|
'bottom',
|
|
'alignCentre'
|
|
]);
|
|
},
|
|
east: function () {
|
|
return make(width, -yoffset / 2, [
|
|
'valignCentre',
|
|
'left'
|
|
]);
|
|
},
|
|
west: function () {
|
|
return make(-width, -yoffset / 2, [
|
|
'valignCentre',
|
|
'right'
|
|
]);
|
|
},
|
|
innerNorthwest: function () {
|
|
return make(-width, yoffset, [
|
|
'top',
|
|
'alignRight'
|
|
]);
|
|
},
|
|
innerNortheast: function () {
|
|
return make(width, yoffset, [
|
|
'top',
|
|
'alignLeft'
|
|
]);
|
|
},
|
|
innerNorth: function () {
|
|
return make(-width / 2, yoffset, [
|
|
'top',
|
|
'alignCentre'
|
|
]);
|
|
},
|
|
innerSouthwest: function () {
|
|
return make(-width, -yoffset, [
|
|
'bottom',
|
|
'alignRight'
|
|
]);
|
|
},
|
|
innerSoutheast: function () {
|
|
return make(width, -yoffset, [
|
|
'bottom',
|
|
'alignLeft'
|
|
]);
|
|
},
|
|
innerSouth: function () {
|
|
return make(-width / 2, -yoffset, [
|
|
'bottom',
|
|
'alignCentre'
|
|
]);
|
|
},
|
|
innerWest: function () {
|
|
return make(width, -yoffset / 2, [
|
|
'valignCentre',
|
|
'right'
|
|
]);
|
|
},
|
|
innerEast: function () {
|
|
return make(-width, -yoffset / 2, [
|
|
'valignCentre',
|
|
'left'
|
|
]);
|
|
}
|
|
};
|
|
};
|
|
var fallback = function () {
|
|
return nu$8(0, 0, {});
|
|
};
|
|
|
|
var nu$9 = function (x) {
|
|
return x;
|
|
};
|
|
|
|
var onDirection = function (isLtr, isRtl) {
|
|
return function (element) {
|
|
return getDirection(element) === 'rtl' ? isRtl : isLtr;
|
|
};
|
|
};
|
|
var getDirection = function (element) {
|
|
return get$4(element, 'direction') === 'rtl' ? 'rtl' : 'ltr';
|
|
};
|
|
|
|
var AttributeValue;
|
|
(function (AttributeValue) {
|
|
AttributeValue['TopToBottom'] = 'toptobottom';
|
|
AttributeValue['BottomToTop'] = 'bottomtotop';
|
|
}(AttributeValue || (AttributeValue = {})));
|
|
var Attribute = 'data-alloy-vertical-dir';
|
|
var isBottomToTopDir = function (el) {
|
|
return closest$2(el, function (current) {
|
|
return isElement(current) && get$2(current, Attribute) === AttributeValue.BottomToTop;
|
|
});
|
|
};
|
|
|
|
var schema$1 = function () {
|
|
return optionObjOf('layouts', [
|
|
strict$1('onLtr'),
|
|
strict$1('onRtl'),
|
|
option('onBottomLtr'),
|
|
option('onBottomRtl')
|
|
]);
|
|
};
|
|
var get$a = function (elem, info, defaultLtr, defaultRtl, defaultBottomLtr, defaultBottomRtl, dirElement) {
|
|
var isBottomToTop = dirElement.map(isBottomToTopDir).getOr(false);
|
|
var customLtr = info.layouts.map(function (ls) {
|
|
return ls.onLtr(elem);
|
|
});
|
|
var customRtl = info.layouts.map(function (ls) {
|
|
return ls.onRtl(elem);
|
|
});
|
|
var ltr = isBottomToTop ? info.layouts.bind(function (ls) {
|
|
return ls.onBottomLtr.map(function (f) {
|
|
return f(elem);
|
|
});
|
|
}).or(customLtr).getOr(defaultBottomLtr) : customLtr.getOr(defaultLtr);
|
|
var rtl = isBottomToTop ? info.layouts.bind(function (ls) {
|
|
return ls.onBottomRtl.map(function (f) {
|
|
return f(elem);
|
|
});
|
|
}).or(customRtl).getOr(defaultBottomRtl) : customRtl.getOr(defaultRtl);
|
|
var f = onDirection(ltr, rtl);
|
|
return f(elem);
|
|
};
|
|
|
|
var placement = function (component, anchorInfo, origin) {
|
|
var hotspot = anchorInfo.hotspot;
|
|
var anchorBox = toBox(origin, hotspot.element());
|
|
var layouts = get$a(component.element(), anchorInfo, belowOrAbove(), belowOrAboveRtl(), aboveOrBelow(), aboveOrBelowRtl(), Option.some(anchorInfo.hotspot.element()));
|
|
return Option.some(nu$9({
|
|
anchorBox: anchorBox,
|
|
bubble: anchorInfo.bubble.getOr(fallback()),
|
|
overrides: anchorInfo.overrides,
|
|
layouts: layouts,
|
|
placer: Option.none()
|
|
}));
|
|
};
|
|
var HotspotAnchor = [
|
|
strict$1('hotspot'),
|
|
option('bubble'),
|
|
defaulted$1('overrides', {}),
|
|
schema$1(),
|
|
output('placement', placement)
|
|
];
|
|
|
|
var placement$1 = function (component, anchorInfo, origin) {
|
|
var pos = translate(origin, anchorInfo.x, anchorInfo.y);
|
|
var anchorBox = bounds$1(pos.left(), pos.top(), anchorInfo.width, anchorInfo.height);
|
|
var layouts = get$a(component.element(), anchorInfo, all$2(), allRtl(), all$2(), allRtl(), Option.none());
|
|
return Option.some(nu$9({
|
|
anchorBox: anchorBox,
|
|
bubble: anchorInfo.bubble,
|
|
overrides: anchorInfo.overrides,
|
|
layouts: layouts,
|
|
placer: Option.none()
|
|
}));
|
|
};
|
|
var MakeshiftAnchor = [
|
|
strict$1('x'),
|
|
strict$1('y'),
|
|
defaulted$1('height', 0),
|
|
defaulted$1('width', 0),
|
|
defaulted$1('bubble', fallback()),
|
|
defaulted$1('overrides', {}),
|
|
schema$1(),
|
|
output('placement', placement$1)
|
|
];
|
|
|
|
var zeroWidth = '\uFEFF';
|
|
var nbsp = '\xA0';
|
|
|
|
var create$2 = function (start, soffset, finish, foffset) {
|
|
return {
|
|
start: constant(start),
|
|
soffset: constant(soffset),
|
|
finish: constant(finish),
|
|
foffset: constant(foffset)
|
|
};
|
|
};
|
|
var SimRange = { create: create$2 };
|
|
|
|
var adt$5 = Adt.generate([
|
|
{ before: ['element'] },
|
|
{
|
|
on: [
|
|
'element',
|
|
'offset'
|
|
]
|
|
},
|
|
{ after: ['element'] }
|
|
]);
|
|
var cata$2 = function (subject, onBefore, onOn, onAfter) {
|
|
return subject.fold(onBefore, onOn, onAfter);
|
|
};
|
|
var getStart = function (situ) {
|
|
return situ.fold(identity, identity, identity);
|
|
};
|
|
var before$2 = adt$5.before;
|
|
var on = adt$5.on;
|
|
var after$1 = adt$5.after;
|
|
var Situ = {
|
|
before: before$2,
|
|
on: on,
|
|
after: after$1,
|
|
cata: cata$2,
|
|
getStart: getStart
|
|
};
|
|
|
|
var adt$6 = Adt.generate([
|
|
{ domRange: ['rng'] },
|
|
{
|
|
relative: [
|
|
'startSitu',
|
|
'finishSitu'
|
|
]
|
|
},
|
|
{
|
|
exact: [
|
|
'start',
|
|
'soffset',
|
|
'finish',
|
|
'foffset'
|
|
]
|
|
}
|
|
]);
|
|
var exactFromRange = function (simRange) {
|
|
return adt$6.exact(simRange.start(), simRange.soffset(), simRange.finish(), simRange.foffset());
|
|
};
|
|
var getStart$1 = function (selection) {
|
|
return selection.match({
|
|
domRange: function (rng) {
|
|
return Element.fromDom(rng.startContainer);
|
|
},
|
|
relative: function (startSitu, _finishSitu) {
|
|
return Situ.getStart(startSitu);
|
|
},
|
|
exact: function (start, _soffset, _finish, _foffset) {
|
|
return start;
|
|
}
|
|
});
|
|
};
|
|
var domRange = adt$6.domRange;
|
|
var relative$1 = adt$6.relative;
|
|
var exact = adt$6.exact;
|
|
var getWin = function (selection) {
|
|
var start = getStart$1(selection);
|
|
return defaultView(start);
|
|
};
|
|
var range$1 = SimRange.create;
|
|
var Selection = {
|
|
domRange: domRange,
|
|
relative: relative$1,
|
|
exact: exact,
|
|
exactFromRange: exactFromRange,
|
|
getWin: getWin,
|
|
range: range$1
|
|
};
|
|
|
|
var setStart = function (rng, situ) {
|
|
situ.fold(function (e) {
|
|
rng.setStartBefore(e.dom());
|
|
}, function (e, o) {
|
|
rng.setStart(e.dom(), o);
|
|
}, function (e) {
|
|
rng.setStartAfter(e.dom());
|
|
});
|
|
};
|
|
var setFinish = function (rng, situ) {
|
|
situ.fold(function (e) {
|
|
rng.setEndBefore(e.dom());
|
|
}, function (e, o) {
|
|
rng.setEnd(e.dom(), o);
|
|
}, function (e) {
|
|
rng.setEndAfter(e.dom());
|
|
});
|
|
};
|
|
var relativeToNative = function (win, startSitu, finishSitu) {
|
|
var range = win.document.createRange();
|
|
setStart(range, startSitu);
|
|
setFinish(range, finishSitu);
|
|
return range;
|
|
};
|
|
var exactToNative = function (win, start, soffset, finish, foffset) {
|
|
var rng = win.document.createRange();
|
|
rng.setStart(start.dom(), soffset);
|
|
rng.setEnd(finish.dom(), foffset);
|
|
return rng;
|
|
};
|
|
var toRect = function (rect) {
|
|
return {
|
|
left: constant(rect.left),
|
|
top: constant(rect.top),
|
|
right: constant(rect.right),
|
|
bottom: constant(rect.bottom),
|
|
width: constant(rect.width),
|
|
height: constant(rect.height)
|
|
};
|
|
};
|
|
var getFirstRect = function (rng) {
|
|
var rects = rng.getClientRects();
|
|
var rect = rects.length > 0 ? rects[0] : rng.getBoundingClientRect();
|
|
return rect.width > 0 || rect.height > 0 ? Option.some(rect).map(toRect) : Option.none();
|
|
};
|
|
|
|
var adt$7 = Adt.generate([
|
|
{
|
|
ltr: [
|
|
'start',
|
|
'soffset',
|
|
'finish',
|
|
'foffset'
|
|
]
|
|
},
|
|
{
|
|
rtl: [
|
|
'start',
|
|
'soffset',
|
|
'finish',
|
|
'foffset'
|
|
]
|
|
}
|
|
]);
|
|
var fromRange = function (win, type, range) {
|
|
return type(Element.fromDom(range.startContainer), range.startOffset, Element.fromDom(range.endContainer), range.endOffset);
|
|
};
|
|
var getRanges = function (win, selection) {
|
|
return selection.match({
|
|
domRange: function (rng) {
|
|
return {
|
|
ltr: constant(rng),
|
|
rtl: Option.none
|
|
};
|
|
},
|
|
relative: function (startSitu, finishSitu) {
|
|
return {
|
|
ltr: cached(function () {
|
|
return relativeToNative(win, startSitu, finishSitu);
|
|
}),
|
|
rtl: cached(function () {
|
|
return Option.some(relativeToNative(win, finishSitu, startSitu));
|
|
})
|
|
};
|
|
},
|
|
exact: function (start, soffset, finish, foffset) {
|
|
return {
|
|
ltr: cached(function () {
|
|
return exactToNative(win, start, soffset, finish, foffset);
|
|
}),
|
|
rtl: cached(function () {
|
|
return Option.some(exactToNative(win, finish, foffset, start, soffset));
|
|
})
|
|
};
|
|
}
|
|
});
|
|
};
|
|
var doDiagnose = function (win, ranges) {
|
|
var rng = ranges.ltr();
|
|
if (rng.collapsed) {
|
|
var reversed = ranges.rtl().filter(function (rev) {
|
|
return rev.collapsed === false;
|
|
});
|
|
return reversed.map(function (rev) {
|
|
return adt$7.rtl(Element.fromDom(rev.endContainer), rev.endOffset, Element.fromDom(rev.startContainer), rev.startOffset);
|
|
}).getOrThunk(function () {
|
|
return fromRange(win, adt$7.ltr, rng);
|
|
});
|
|
} else {
|
|
return fromRange(win, adt$7.ltr, rng);
|
|
}
|
|
};
|
|
var diagnose = function (win, selection) {
|
|
var ranges = getRanges(win, selection);
|
|
return doDiagnose(win, ranges);
|
|
};
|
|
var asLtrRange = function (win, selection) {
|
|
var diagnosis = diagnose(win, selection);
|
|
return diagnosis.match({
|
|
ltr: function (start, soffset, finish, foffset) {
|
|
var rng = win.document.createRange();
|
|
rng.setStart(start.dom(), soffset);
|
|
rng.setEnd(finish.dom(), foffset);
|
|
return rng;
|
|
},
|
|
rtl: function (start, soffset, finish, foffset) {
|
|
var rng = win.document.createRange();
|
|
rng.setStart(finish.dom(), foffset);
|
|
rng.setEnd(start.dom(), soffset);
|
|
return rng;
|
|
}
|
|
});
|
|
};
|
|
var ltr = adt$7.ltr;
|
|
var rtl = adt$7.rtl;
|
|
|
|
function NodeValue (is, name) {
|
|
var get = function (element) {
|
|
if (!is(element)) {
|
|
throw new Error('Can only get ' + name + ' value of a ' + name + ' node');
|
|
}
|
|
return getOption(element).getOr('');
|
|
};
|
|
var getOption = function (element) {
|
|
return is(element) ? Option.from(element.dom().nodeValue) : Option.none();
|
|
};
|
|
var set = function (element, value) {
|
|
if (!is(element)) {
|
|
throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');
|
|
}
|
|
element.dom().nodeValue = value;
|
|
};
|
|
return {
|
|
get: get,
|
|
getOption: getOption,
|
|
set: set
|
|
};
|
|
}
|
|
|
|
var api$2 = NodeValue(isText, 'text');
|
|
var get$b = function (element) {
|
|
return api$2.get(element);
|
|
};
|
|
var getOption = function (element) {
|
|
return api$2.getOption(element);
|
|
};
|
|
|
|
var getEnd = function (element) {
|
|
return name(element) === 'img' ? 1 : getOption(element).fold(function () {
|
|
return children(element).length;
|
|
}, function (v) {
|
|
return v.length;
|
|
});
|
|
};
|
|
var isTextNodeWithCursorPosition = function (el) {
|
|
return getOption(el).filter(function (text) {
|
|
return text.trim().length !== 0 || text.indexOf(nbsp) > -1;
|
|
}).isSome();
|
|
};
|
|
var elementsWithCursorPosition = [
|
|
'img',
|
|
'br'
|
|
];
|
|
var isCursorPosition = function (elem) {
|
|
var hasCursorPosition = isTextNodeWithCursorPosition(elem);
|
|
return hasCursorPosition || contains(elementsWithCursorPosition, name(elem));
|
|
};
|
|
|
|
var last$1 = function (element) {
|
|
return descendantRtl(element, isCursorPosition);
|
|
};
|
|
var descendantRtl = function (scope, predicate) {
|
|
var descend = function (element) {
|
|
var children$1 = children(element);
|
|
for (var i = children$1.length - 1; i >= 0; i--) {
|
|
var child = children$1[i];
|
|
if (predicate(child)) {
|
|
return Option.some(child);
|
|
}
|
|
var res = descend(child);
|
|
if (res.isSome()) {
|
|
return res;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
return descend(scope);
|
|
};
|
|
|
|
var descendants = function (scope, selector) {
|
|
return all(selector, scope);
|
|
};
|
|
|
|
var makeRange = function (start, soffset, finish, foffset) {
|
|
var doc = owner(start);
|
|
var rng = doc.dom().createRange();
|
|
rng.setStart(start.dom(), soffset);
|
|
rng.setEnd(finish.dom(), foffset);
|
|
return rng;
|
|
};
|
|
var after$2 = function (start, soffset, finish, foffset) {
|
|
var r = makeRange(start, soffset, finish, foffset);
|
|
var same = eq$1(start, finish) && soffset === foffset;
|
|
return r.collapsed && !same;
|
|
};
|
|
|
|
var readRange = function (selection) {
|
|
if (selection.rangeCount > 0) {
|
|
var firstRng = selection.getRangeAt(0);
|
|
var lastRng = selection.getRangeAt(selection.rangeCount - 1);
|
|
return Option.some(SimRange.create(Element.fromDom(firstRng.startContainer), firstRng.startOffset, Element.fromDom(lastRng.endContainer), lastRng.endOffset));
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
};
|
|
var doGetExact = function (selection) {
|
|
var anchor = Element.fromDom(selection.anchorNode);
|
|
var focus = Element.fromDom(selection.focusNode);
|
|
return after$2(anchor, selection.anchorOffset, focus, selection.focusOffset) ? Option.some(SimRange.create(anchor, selection.anchorOffset, focus, selection.focusOffset)) : readRange(selection);
|
|
};
|
|
var getExact = function (win) {
|
|
return Option.from(win.getSelection()).filter(function (sel) {
|
|
return sel.rangeCount > 0;
|
|
}).bind(doGetExact);
|
|
};
|
|
var getFirstRect$1 = function (win, selection) {
|
|
var rng = asLtrRange(win, selection);
|
|
return getFirstRect(rng);
|
|
};
|
|
|
|
var point = function (element, offset) {
|
|
return {
|
|
element: element,
|
|
offset: offset
|
|
};
|
|
};
|
|
var descendOnce = function (element, offset) {
|
|
var children$1 = children(element);
|
|
if (children$1.length === 0) {
|
|
return point(element, offset);
|
|
} else if (offset < children$1.length) {
|
|
return point(children$1[offset], 0);
|
|
} else {
|
|
var last = children$1[children$1.length - 1];
|
|
var len = isText(last) ? get$b(last).length : children(last).length;
|
|
return point(last, len);
|
|
}
|
|
};
|
|
|
|
var adt$8 = Adt.generate([
|
|
{ screen: ['point'] },
|
|
{
|
|
absolute: [
|
|
'point',
|
|
'scrollLeft',
|
|
'scrollTop'
|
|
]
|
|
}
|
|
]);
|
|
var toFixed = function (pos) {
|
|
return pos.fold(identity, function (point, scrollLeft, scrollTop) {
|
|
return point.translate(-scrollLeft, -scrollTop);
|
|
});
|
|
};
|
|
var toAbsolute = function (pos) {
|
|
return pos.fold(identity, identity);
|
|
};
|
|
var sum = function (points) {
|
|
return foldl(points, function (b, a) {
|
|
return b.translate(a.left(), a.top());
|
|
}, Position(0, 0));
|
|
};
|
|
var sumAsFixed = function (positions) {
|
|
var points = map(positions, toFixed);
|
|
return sum(points);
|
|
};
|
|
var sumAsAbsolute = function (positions) {
|
|
var points = map(positions, toAbsolute);
|
|
return sum(points);
|
|
};
|
|
var screen = adt$8.screen;
|
|
var absolute$2 = adt$8.absolute;
|
|
|
|
var getOffset = function (component, origin, anchorInfo) {
|
|
var win = defaultView(anchorInfo.root).dom();
|
|
var hasSameOwner = function (frame) {
|
|
var frameOwner = owner(frame);
|
|
var compOwner = owner(component.element());
|
|
return eq$1(frameOwner, compOwner);
|
|
};
|
|
return Option.from(win.frameElement).map(Element.fromDom).filter(hasSameOwner).map(absolute);
|
|
};
|
|
var getRootPoint = function (component, origin, anchorInfo) {
|
|
var doc = owner(component.element());
|
|
var outerScroll = get$8(doc);
|
|
var offset = getOffset(component, origin, anchorInfo).getOr(outerScroll);
|
|
return absolute$2(offset, outerScroll.left(), outerScroll.top());
|
|
};
|
|
|
|
var capRect = function (left, top, width, height) {
|
|
var newLeft = left, newTop = top, newWidth = width, newHeight = height;
|
|
if (left < 0) {
|
|
newLeft = 0;
|
|
newWidth = width + left;
|
|
}
|
|
if (top < 0) {
|
|
newTop = 0;
|
|
newHeight = height + top;
|
|
}
|
|
var point = screen(Position(newLeft, newTop));
|
|
return Option.some(pointed(point, newWidth, newHeight));
|
|
};
|
|
var calcNewAnchor = function (optBox, rootPoint, anchorInfo, origin, elem) {
|
|
return optBox.map(function (box) {
|
|
var points = [
|
|
rootPoint,
|
|
box.point
|
|
];
|
|
var topLeft = cata$1(origin, function () {
|
|
return sumAsAbsolute(points);
|
|
}, function () {
|
|
return sumAsAbsolute(points);
|
|
}, function () {
|
|
return sumAsFixed(points);
|
|
});
|
|
var anchorBox = rect(topLeft.left(), topLeft.top(), box.width, box.height);
|
|
var layoutsLtr = anchorInfo.showAbove ? aboveOrBelow() : belowOrAbove();
|
|
var layoutsRtl = anchorInfo.showAbove ? belowOrAboveRtl() : belowOrAboveRtl();
|
|
var layouts = get$a(elem, anchorInfo, layoutsLtr, layoutsRtl, layoutsLtr, layoutsRtl, Option.none());
|
|
return nu$9({
|
|
anchorBox: anchorBox,
|
|
bubble: anchorInfo.bubble.getOr(fallback()),
|
|
overrides: anchorInfo.overrides,
|
|
layouts: layouts,
|
|
placer: Option.none()
|
|
});
|
|
});
|
|
};
|
|
|
|
var point$1 = function (element, offset) {
|
|
return {
|
|
element: element,
|
|
offset: offset
|
|
};
|
|
};
|
|
var descendOnce$1 = function (element, offset) {
|
|
return isText(element) ? point$1(element, offset) : descendOnce(element, offset);
|
|
};
|
|
var getAnchorSelection = function (win, anchorInfo) {
|
|
var getSelection = anchorInfo.getSelection.getOrThunk(function () {
|
|
return function () {
|
|
return getExact(win);
|
|
};
|
|
});
|
|
return getSelection().map(function (sel) {
|
|
var modStart = descendOnce$1(sel.start(), sel.soffset());
|
|
var modFinish = descendOnce$1(sel.finish(), sel.foffset());
|
|
return Selection.range(modStart.element, modStart.offset, modFinish.element, modFinish.offset);
|
|
});
|
|
};
|
|
var placement$2 = function (component, anchorInfo, origin) {
|
|
var win = defaultView(anchorInfo.root).dom();
|
|
var rootPoint = getRootPoint(component, origin, anchorInfo);
|
|
var selectionBox = getAnchorSelection(win, anchorInfo).bind(function (sel) {
|
|
var optRect = getFirstRect$1(win, Selection.exactFromRange(sel)).orThunk(function () {
|
|
var x = Element.fromText(zeroWidth);
|
|
before(sel.start(), x);
|
|
return getFirstRect$1(win, Selection.exact(x, 0, x, 1)).map(function (rect) {
|
|
remove(x);
|
|
return rect;
|
|
});
|
|
});
|
|
return optRect.bind(function (rawRect) {
|
|
return capRect(rawRect.left(), rawRect.top(), rawRect.width(), rawRect.height());
|
|
});
|
|
});
|
|
var targetElement = getAnchorSelection(win, anchorInfo).bind(function (sel) {
|
|
return isElement(sel.start()) ? Option.some(sel.start()) : parent(sel.start());
|
|
});
|
|
var elem = targetElement.getOr(component.element());
|
|
return calcNewAnchor(selectionBox, rootPoint, anchorInfo, origin, elem);
|
|
};
|
|
var SelectionAnchor = [
|
|
option('getSelection'),
|
|
strict$1('root'),
|
|
option('bubble'),
|
|
schema$1(),
|
|
defaulted$1('overrides', {}),
|
|
defaulted$1('showAbove', false),
|
|
output('placement', placement$2)
|
|
];
|
|
|
|
var placement$3 = function (component, anchorInfo, origin) {
|
|
var rootPoint = getRootPoint(component, origin, anchorInfo);
|
|
return anchorInfo.node.bind(function (target) {
|
|
var rect = target.dom().getBoundingClientRect();
|
|
var nodeBox = capRect(rect.left, rect.top, rect.width, rect.height);
|
|
var elem = anchorInfo.node.getOr(component.element());
|
|
return calcNewAnchor(nodeBox, rootPoint, anchorInfo, origin, elem);
|
|
});
|
|
};
|
|
var NodeAnchor = [
|
|
strict$1('node'),
|
|
strict$1('root'),
|
|
option('bubble'),
|
|
schema$1(),
|
|
defaulted$1('overrides', {}),
|
|
defaulted$1('showAbove', false),
|
|
output('placement', placement$3)
|
|
];
|
|
|
|
var eastX$1 = function (anchor) {
|
|
return anchor.x + anchor.width;
|
|
};
|
|
var westX$1 = function (anchor, element) {
|
|
return anchor.x - element.width;
|
|
};
|
|
var northY$1 = function (anchor, element) {
|
|
return anchor.y - element.height + anchor.height;
|
|
};
|
|
var southY$1 = function (anchor) {
|
|
return anchor.y;
|
|
};
|
|
var southeast$2 = function (anchor, element, bubbles) {
|
|
return nu$7(eastX$1(anchor), southY$1(anchor), bubbles.southeast(), southeast(), boundsRestriction(anchor, {
|
|
left: 0,
|
|
top: 2
|
|
}), 'link-layout-se');
|
|
};
|
|
var southwest$2 = function (anchor, element, bubbles) {
|
|
return nu$7(westX$1(anchor, element), southY$1(anchor), bubbles.southwest(), southwest(), boundsRestriction(anchor, {
|
|
right: 1,
|
|
top: 2
|
|
}), 'link-layout-sw');
|
|
};
|
|
var northeast$2 = function (anchor, element, bubbles) {
|
|
return nu$7(eastX$1(anchor), northY$1(anchor, element), bubbles.northeast(), northeast(), boundsRestriction(anchor, {
|
|
left: 0,
|
|
bottom: 3
|
|
}), 'link-layout-ne');
|
|
};
|
|
var northwest$2 = function (anchor, element, bubbles) {
|
|
return nu$7(westX$1(anchor, element), northY$1(anchor, element), bubbles.northwest(), northwest(), boundsRestriction(anchor, {
|
|
right: 1,
|
|
bottom: 3
|
|
}), 'link-layout-nw');
|
|
};
|
|
var all$3 = function () {
|
|
return [
|
|
southeast$2,
|
|
southwest$2,
|
|
northeast$2,
|
|
northwest$2
|
|
];
|
|
};
|
|
var allRtl$1 = function () {
|
|
return [
|
|
southwest$2,
|
|
southeast$2,
|
|
northwest$2,
|
|
northeast$2
|
|
];
|
|
};
|
|
|
|
var placement$4 = function (component, submenuInfo, origin) {
|
|
var anchorBox = toBox(origin, submenuInfo.item.element());
|
|
var layouts = get$a(component.element(), submenuInfo, all$3(), allRtl$1(), all$3(), allRtl$1(), Option.none());
|
|
return Option.some(nu$9({
|
|
anchorBox: anchorBox,
|
|
bubble: fallback(),
|
|
overrides: submenuInfo.overrides,
|
|
layouts: layouts,
|
|
placer: Option.none()
|
|
}));
|
|
};
|
|
var SubmenuAnchor = [
|
|
strict$1('item'),
|
|
schema$1(),
|
|
defaulted$1('overrides', {}),
|
|
output('placement', placement$4)
|
|
];
|
|
|
|
var AnchorSchema = choose$1('anchor', {
|
|
selection: SelectionAnchor,
|
|
node: NodeAnchor,
|
|
hotspot: HotspotAnchor,
|
|
submenu: SubmenuAnchor,
|
|
makeshift: MakeshiftAnchor
|
|
});
|
|
|
|
var getFixedOrigin = function () {
|
|
var html = domGlobals.document.documentElement;
|
|
return fixed(0, 0, html.clientWidth, html.clientHeight);
|
|
};
|
|
var getRelativeOrigin = function (component) {
|
|
var position = absolute(component.element());
|
|
var bounds = component.element().dom().getBoundingClientRect();
|
|
return relative(position.left(), position.top(), bounds.width, bounds.height);
|
|
};
|
|
var place = function (component, origin, anchoring, getBounds, placee) {
|
|
var anchor = box$1(anchoring.anchorBox, origin);
|
|
simple(anchor, placee.element(), anchoring.bubble, anchoring.layouts, getBounds, anchoring.overrides);
|
|
};
|
|
var position$1 = function (component, posConfig, posState, anchor, placee) {
|
|
positionWithin(component, posConfig, posState, anchor, placee, Option.none());
|
|
};
|
|
var positionWithin = function (component, posConfig, posState, anchor, placee, boxElement) {
|
|
var boundsBox = boxElement.map(box);
|
|
return positionWithinBounds(component, posConfig, posState, anchor, placee, boundsBox);
|
|
};
|
|
var positionWithinBounds = function (component, posConfig, posState, anchor, placee, bounds) {
|
|
var anchorage = asRawOrDie('positioning anchor.info', AnchorSchema, anchor);
|
|
preserve(function () {
|
|
set$2(placee.element(), 'position', 'fixed');
|
|
var oldVisibility = getRaw(placee.element(), 'visibility');
|
|
set$2(placee.element(), 'visibility', 'hidden');
|
|
var origin = posConfig.useFixed() ? getFixedOrigin() : getRelativeOrigin(component);
|
|
var placer = anchorage.placement;
|
|
var getBounds = bounds.map(constant).or(posConfig.getBounds);
|
|
placer(component, anchorage, origin).each(function (anchoring) {
|
|
var doPlace = anchoring.placer.getOr(place);
|
|
doPlace(component, origin, anchoring, getBounds, placee);
|
|
});
|
|
oldVisibility.fold(function () {
|
|
remove$6(placee.element(), 'visibility');
|
|
}, function (vis) {
|
|
set$2(placee.element(), 'visibility', vis);
|
|
});
|
|
if (getRaw(placee.element(), 'left').isNone() && getRaw(placee.element(), 'top').isNone() && getRaw(placee.element(), 'right').isNone() && getRaw(placee.element(), 'bottom').isNone() && getRaw(placee.element(), 'position').is('fixed')) {
|
|
remove$6(placee.element(), 'position');
|
|
}
|
|
}, placee.element());
|
|
};
|
|
var getMode = function (component, pConfig, _pState) {
|
|
return pConfig.useFixed() ? 'fixed' : 'absolute';
|
|
};
|
|
|
|
var PositionApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
position: position$1,
|
|
positionWithin: positionWithin,
|
|
positionWithinBounds: positionWithinBounds,
|
|
getMode: getMode
|
|
});
|
|
|
|
var PositionSchema = [
|
|
defaulted$1('useFixed', never),
|
|
option('getBounds')
|
|
];
|
|
|
|
var Positioning = create$1({
|
|
fields: PositionSchema,
|
|
name: 'positioning',
|
|
active: ActivePosition,
|
|
apis: PositionApis
|
|
});
|
|
|
|
var fireDetaching = function (component) {
|
|
emit(component, detachedFromDom());
|
|
var children = component.components();
|
|
each(children, fireDetaching);
|
|
};
|
|
var fireAttaching = function (component) {
|
|
var children = component.components();
|
|
each(children, fireAttaching);
|
|
emit(component, attachedToDom());
|
|
};
|
|
var attach = function (parent, child) {
|
|
append(parent.element(), child.element());
|
|
};
|
|
var detachChildren = function (component) {
|
|
each(component.components(), function (childComp) {
|
|
return remove(childComp.element());
|
|
});
|
|
empty(component.element());
|
|
component.syncComponents();
|
|
};
|
|
var replaceChildren = function (component, newChildren) {
|
|
var subs = component.components();
|
|
detachChildren(component);
|
|
var deleted = difference(subs, newChildren);
|
|
each(deleted, function (comp) {
|
|
fireDetaching(comp);
|
|
component.getSystem().removeFromWorld(comp);
|
|
});
|
|
each(newChildren, function (childComp) {
|
|
if (!childComp.getSystem().isConnected()) {
|
|
component.getSystem().addToWorld(childComp);
|
|
attach(component, childComp);
|
|
if (inBody(component.element())) {
|
|
fireAttaching(childComp);
|
|
}
|
|
} else {
|
|
attach(component, childComp);
|
|
}
|
|
component.syncComponents();
|
|
});
|
|
};
|
|
|
|
var attach$1 = function (parent, child) {
|
|
attachWith(parent, child, append);
|
|
};
|
|
var attachWith = function (parent, child, insertion) {
|
|
parent.getSystem().addToWorld(child);
|
|
insertion(parent.element(), child.element());
|
|
if (inBody(parent.element())) {
|
|
fireAttaching(child);
|
|
}
|
|
parent.syncComponents();
|
|
};
|
|
var doDetach = function (component) {
|
|
fireDetaching(component);
|
|
remove(component.element());
|
|
component.getSystem().removeFromWorld(component);
|
|
};
|
|
var detach = function (component) {
|
|
var parent$1 = parent(component.element()).bind(function (p) {
|
|
return component.getSystem().getByDom(p).toOption();
|
|
});
|
|
doDetach(component);
|
|
parent$1.each(function (p) {
|
|
p.syncComponents();
|
|
});
|
|
};
|
|
var detachChildren$1 = function (component) {
|
|
var subs = component.components();
|
|
each(subs, doDetach);
|
|
empty(component.element());
|
|
component.syncComponents();
|
|
};
|
|
var attachSystem = function (element, guiSystem) {
|
|
attachSystemWith(element, guiSystem, append);
|
|
};
|
|
var attachSystemAfter = function (element, guiSystem) {
|
|
attachSystemWith(element, guiSystem, after);
|
|
};
|
|
var attachSystemWith = function (element, guiSystem, inserter) {
|
|
inserter(element, guiSystem.element());
|
|
var children$1 = children(guiSystem.element());
|
|
each(children$1, function (child) {
|
|
guiSystem.getByDom(child).each(fireAttaching);
|
|
});
|
|
};
|
|
var detachSystem = function (guiSystem) {
|
|
var children$1 = children(guiSystem.element());
|
|
each(children$1, function (child) {
|
|
guiSystem.getByDom(child).each(fireDetaching);
|
|
});
|
|
remove(guiSystem.element());
|
|
};
|
|
|
|
var rebuild = function (sandbox, sConfig, sState, data) {
|
|
sState.get().each(function (_data) {
|
|
detachChildren$1(sandbox);
|
|
});
|
|
var point = sConfig.getAttachPoint(sandbox);
|
|
attach$1(point, sandbox);
|
|
var built = sandbox.getSystem().build(data);
|
|
attach$1(sandbox, built);
|
|
sState.set(built);
|
|
return built;
|
|
};
|
|
var open = function (sandbox, sConfig, sState, data) {
|
|
var newState = rebuild(sandbox, sConfig, sState, data);
|
|
sConfig.onOpen(sandbox, newState);
|
|
return newState;
|
|
};
|
|
var setContent = function (sandbox, sConfig, sState, data) {
|
|
return sState.get().map(function () {
|
|
return rebuild(sandbox, sConfig, sState, data);
|
|
});
|
|
};
|
|
var openWhileCloaked = function (sandbox, sConfig, sState, data, transaction) {
|
|
cloak(sandbox, sConfig);
|
|
open(sandbox, sConfig, sState, data);
|
|
transaction();
|
|
decloak(sandbox, sConfig);
|
|
};
|
|
var close = function (sandbox, sConfig, sState) {
|
|
sState.get().each(function (data) {
|
|
detachChildren$1(sandbox);
|
|
detach(sandbox);
|
|
sConfig.onClose(sandbox, data);
|
|
sState.clear();
|
|
});
|
|
};
|
|
var isOpen = function (_sandbox, _sConfig, sState) {
|
|
return sState.isOpen();
|
|
};
|
|
var isPartOf$1 = function (sandbox, sConfig, sState, queryElem) {
|
|
return isOpen(sandbox, sConfig, sState) && sState.get().exists(function (data) {
|
|
return sConfig.isPartOf(sandbox, data, queryElem);
|
|
});
|
|
};
|
|
var getState = function (_sandbox, _sConfig, sState) {
|
|
return sState.get();
|
|
};
|
|
var store = function (sandbox, cssKey, attr, newValue) {
|
|
getRaw(sandbox.element(), cssKey).fold(function () {
|
|
remove$1(sandbox.element(), attr);
|
|
}, function (v) {
|
|
set$1(sandbox.element(), attr, v);
|
|
});
|
|
set$2(sandbox.element(), cssKey, newValue);
|
|
};
|
|
var restore = function (sandbox, cssKey, attr) {
|
|
getOpt(sandbox.element(), attr).fold(function () {
|
|
return remove$6(sandbox.element(), cssKey);
|
|
}, function (oldValue) {
|
|
return set$2(sandbox.element(), cssKey, oldValue);
|
|
});
|
|
};
|
|
var cloak = function (sandbox, sConfig, _sState) {
|
|
var sink = sConfig.getAttachPoint(sandbox);
|
|
set$2(sandbox.element(), 'position', Positioning.getMode(sink));
|
|
store(sandbox, 'visibility', sConfig.cloakVisibilityAttr, 'hidden');
|
|
};
|
|
var hasPosition = function (element) {
|
|
return exists([
|
|
'top',
|
|
'left',
|
|
'right',
|
|
'bottom'
|
|
], function (pos) {
|
|
return getRaw(element, pos).isSome();
|
|
});
|
|
};
|
|
var decloak = function (sandbox, sConfig, _sState) {
|
|
if (!hasPosition(sandbox.element())) {
|
|
remove$6(sandbox.element(), 'position');
|
|
}
|
|
restore(sandbox, 'visibility', sConfig.cloakVisibilityAttr);
|
|
};
|
|
|
|
var SandboxApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
cloak: cloak,
|
|
decloak: decloak,
|
|
open: open,
|
|
openWhileCloaked: openWhileCloaked,
|
|
close: close,
|
|
isOpen: isOpen,
|
|
isPartOf: isPartOf$1,
|
|
getState: getState,
|
|
setContent: setContent
|
|
});
|
|
|
|
var events$2 = function (sandboxConfig, sandboxState) {
|
|
return derive([run(sandboxClose(), function (sandbox, _simulatedEvent) {
|
|
close(sandbox, sandboxConfig, sandboxState);
|
|
})]);
|
|
};
|
|
|
|
var ActiveSandbox = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$2
|
|
});
|
|
|
|
var SandboxSchema = [
|
|
onHandler('onOpen'),
|
|
onHandler('onClose'),
|
|
strict$1('isPartOf'),
|
|
strict$1('getAttachPoint'),
|
|
defaulted$1('cloakVisibilityAttr', 'data-precloak-visibility')
|
|
];
|
|
|
|
var init = function () {
|
|
var contents = Cell(Option.none());
|
|
var readState = constant('not-implemented');
|
|
var isOpen = function () {
|
|
return contents.get().isSome();
|
|
};
|
|
var set = function (comp) {
|
|
contents.set(Option.some(comp));
|
|
};
|
|
var get = function () {
|
|
return contents.get();
|
|
};
|
|
var clear = function () {
|
|
contents.set(Option.none());
|
|
};
|
|
return nu$5({
|
|
readState: readState,
|
|
isOpen: isOpen,
|
|
clear: clear,
|
|
set: set,
|
|
get: get
|
|
});
|
|
};
|
|
|
|
var SandboxState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
init: init
|
|
});
|
|
|
|
var Sandboxing = create$1({
|
|
fields: SandboxSchema,
|
|
name: 'sandboxing',
|
|
active: ActiveSandbox,
|
|
apis: SandboxApis,
|
|
state: SandboxState
|
|
});
|
|
|
|
var dismissPopups = constant('dismiss.popups');
|
|
var repositionPopups = constant('reposition.popups');
|
|
var mouseReleased = constant('mouse.released');
|
|
|
|
var schema$2 = objOfOnly([
|
|
defaulted$1('isExtraPart', constant(false)),
|
|
optionObjOf('fireEventInstead', [defaulted$1('event', dismissRequested())])
|
|
]);
|
|
var receivingChannel = function (rawSpec) {
|
|
var _a;
|
|
var detail = asRawOrDie('Dismissal', schema$2, rawSpec);
|
|
return _a = {}, _a[dismissPopups()] = {
|
|
schema: objOfOnly([strict$1('target')]),
|
|
onReceive: function (sandbox, data) {
|
|
if (Sandboxing.isOpen(sandbox)) {
|
|
var isPart = Sandboxing.isPartOf(sandbox, data.target) || detail.isExtraPart(sandbox, data.target);
|
|
if (!isPart) {
|
|
detail.fireEventInstead.fold(function () {
|
|
return Sandboxing.close(sandbox);
|
|
}, function (fe) {
|
|
return emit(sandbox, fe.event);
|
|
});
|
|
}
|
|
}
|
|
}
|
|
}, _a;
|
|
};
|
|
|
|
var schema$3 = objOfOnly([
|
|
optionObjOf('fireEventInstead', [defaulted$1('event', repositionRequested())]),
|
|
strictFunction('doReposition')
|
|
]);
|
|
var receivingChannel$1 = function (rawSpec) {
|
|
var _a;
|
|
var detail = asRawOrDie('Reposition', schema$3, rawSpec);
|
|
return _a = {}, _a[repositionPopups()] = {
|
|
onReceive: function (sandbox) {
|
|
if (Sandboxing.isOpen(sandbox)) {
|
|
detail.fireEventInstead.fold(function () {
|
|
return detail.doReposition(sandbox);
|
|
}, function (fe) {
|
|
return emit(sandbox, fe.event);
|
|
});
|
|
}
|
|
}
|
|
}, _a;
|
|
};
|
|
|
|
var onLoad = function (component, repConfig, repState) {
|
|
repConfig.store.manager.onLoad(component, repConfig, repState);
|
|
};
|
|
var onUnload = function (component, repConfig, repState) {
|
|
repConfig.store.manager.onUnload(component, repConfig, repState);
|
|
};
|
|
var setValue = function (component, repConfig, repState, data) {
|
|
repConfig.store.manager.setValue(component, repConfig, repState, data);
|
|
};
|
|
var getValue = function (component, repConfig, repState) {
|
|
return repConfig.store.manager.getValue(component, repConfig, repState);
|
|
};
|
|
var getState$1 = function (component, repConfig, repState) {
|
|
return repState;
|
|
};
|
|
|
|
var RepresentApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
onLoad: onLoad,
|
|
onUnload: onUnload,
|
|
setValue: setValue,
|
|
getValue: getValue,
|
|
getState: getState$1
|
|
});
|
|
|
|
var events$3 = function (repConfig, repState) {
|
|
var es = repConfig.resetOnDom ? [
|
|
runOnAttached(function (comp, _se) {
|
|
onLoad(comp, repConfig, repState);
|
|
}),
|
|
runOnDetached(function (comp, _se) {
|
|
onUnload(comp, repConfig, repState);
|
|
})
|
|
] : [loadEvent(repConfig, repState, onLoad)];
|
|
return derive(es);
|
|
};
|
|
|
|
var ActiveRepresenting = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$3
|
|
});
|
|
|
|
var memory = function () {
|
|
var data = Cell(null);
|
|
var readState = function () {
|
|
return {
|
|
mode: 'memory',
|
|
value: data.get()
|
|
};
|
|
};
|
|
var isNotSet = function () {
|
|
return data.get() === null;
|
|
};
|
|
var clear = function () {
|
|
data.set(null);
|
|
};
|
|
return nu$5({
|
|
set: data.set,
|
|
get: data.get,
|
|
isNotSet: isNotSet,
|
|
clear: clear,
|
|
readState: readState
|
|
});
|
|
};
|
|
var manual = function () {
|
|
var readState = function () {
|
|
};
|
|
return nu$5({ readState: readState });
|
|
};
|
|
var dataset = function () {
|
|
var dataByValue = Cell({});
|
|
var dataByText = Cell({});
|
|
var readState = function () {
|
|
return {
|
|
mode: 'dataset',
|
|
dataByValue: dataByValue.get(),
|
|
dataByText: dataByText.get()
|
|
};
|
|
};
|
|
var clear = function () {
|
|
dataByValue.set({});
|
|
dataByText.set({});
|
|
};
|
|
var lookup = function (itemString) {
|
|
return get(dataByValue.get(), itemString).orThunk(function () {
|
|
return get(dataByText.get(), itemString);
|
|
});
|
|
};
|
|
var update = function (items) {
|
|
var currentDataByValue = dataByValue.get();
|
|
var currentDataByText = dataByText.get();
|
|
var newDataByValue = {};
|
|
var newDataByText = {};
|
|
each(items, function (item) {
|
|
newDataByValue[item.value] = item;
|
|
get(item, 'meta').each(function (meta) {
|
|
get(meta, 'text').each(function (text) {
|
|
newDataByText[text] = item;
|
|
});
|
|
});
|
|
});
|
|
dataByValue.set(__assign(__assign({}, currentDataByValue), newDataByValue));
|
|
dataByText.set(__assign(__assign({}, currentDataByText), newDataByText));
|
|
};
|
|
return nu$5({
|
|
readState: readState,
|
|
lookup: lookup,
|
|
update: update,
|
|
clear: clear
|
|
});
|
|
};
|
|
var init$1 = function (spec) {
|
|
return spec.store.manager.state(spec);
|
|
};
|
|
|
|
var RepresentState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
memory: memory,
|
|
dataset: dataset,
|
|
manual: manual,
|
|
init: init$1
|
|
});
|
|
|
|
var setValue$1 = function (component, repConfig, repState, data) {
|
|
var store = repConfig.store;
|
|
repState.update([data]);
|
|
store.setValue(component, data);
|
|
repConfig.onSetValue(component, data);
|
|
};
|
|
var getValue$1 = function (component, repConfig, repState) {
|
|
var store = repConfig.store;
|
|
var key = store.getDataKey(component);
|
|
return repState.lookup(key).fold(function () {
|
|
return store.getFallbackEntry(key);
|
|
}, function (data) {
|
|
return data;
|
|
});
|
|
};
|
|
var onLoad$1 = function (component, repConfig, repState) {
|
|
var store = repConfig.store;
|
|
store.initialValue.each(function (data) {
|
|
setValue$1(component, repConfig, repState, data);
|
|
});
|
|
};
|
|
var onUnload$1 = function (component, repConfig, repState) {
|
|
repState.clear();
|
|
};
|
|
var DatasetStore = [
|
|
option('initialValue'),
|
|
strict$1('getFallbackEntry'),
|
|
strict$1('getDataKey'),
|
|
strict$1('setValue'),
|
|
output('manager', {
|
|
setValue: setValue$1,
|
|
getValue: getValue$1,
|
|
onLoad: onLoad$1,
|
|
onUnload: onUnload$1,
|
|
state: dataset
|
|
})
|
|
];
|
|
|
|
var getValue$2 = function (component, repConfig, _repState) {
|
|
return repConfig.store.getValue(component);
|
|
};
|
|
var setValue$2 = function (component, repConfig, _repState, data) {
|
|
repConfig.store.setValue(component, data);
|
|
repConfig.onSetValue(component, data);
|
|
};
|
|
var onLoad$2 = function (component, repConfig, _repState) {
|
|
repConfig.store.initialValue.each(function (data) {
|
|
repConfig.store.setValue(component, data);
|
|
});
|
|
};
|
|
var ManualStore = [
|
|
strict$1('getValue'),
|
|
defaulted$1('setValue', noop),
|
|
option('initialValue'),
|
|
output('manager', {
|
|
setValue: setValue$2,
|
|
getValue: getValue$2,
|
|
onLoad: onLoad$2,
|
|
onUnload: noop,
|
|
state: NoState.init
|
|
})
|
|
];
|
|
|
|
var setValue$3 = function (component, repConfig, repState, data) {
|
|
repState.set(data);
|
|
repConfig.onSetValue(component, data);
|
|
};
|
|
var getValue$3 = function (component, repConfig, repState) {
|
|
return repState.get();
|
|
};
|
|
var onLoad$3 = function (component, repConfig, repState) {
|
|
repConfig.store.initialValue.each(function (initVal) {
|
|
if (repState.isNotSet()) {
|
|
repState.set(initVal);
|
|
}
|
|
});
|
|
};
|
|
var onUnload$2 = function (component, repConfig, repState) {
|
|
repState.clear();
|
|
};
|
|
var MemoryStore = [
|
|
option('initialValue'),
|
|
output('manager', {
|
|
setValue: setValue$3,
|
|
getValue: getValue$3,
|
|
onLoad: onLoad$3,
|
|
onUnload: onUnload$2,
|
|
state: memory
|
|
})
|
|
];
|
|
|
|
var RepresentSchema = [
|
|
defaultedOf('store', { mode: 'memory' }, choose$1('mode', {
|
|
memory: MemoryStore,
|
|
manual: ManualStore,
|
|
dataset: DatasetStore
|
|
})),
|
|
onHandler('onSetValue'),
|
|
defaulted$1('resetOnDom', false)
|
|
];
|
|
|
|
var Representing = create$1({
|
|
fields: RepresentSchema,
|
|
name: 'representing',
|
|
active: ActiveRepresenting,
|
|
apis: RepresentApis,
|
|
extra: {
|
|
setValueFrom: function (component, source) {
|
|
var value = Representing.getValue(source);
|
|
Representing.setValue(component, value);
|
|
}
|
|
},
|
|
state: RepresentState
|
|
});
|
|
|
|
var field$1 = function (name, forbidden) {
|
|
return defaultedObjOf(name, {}, map(forbidden, function (f) {
|
|
return forbid(f.name(), 'Cannot configure ' + f.name() + ' for ' + name);
|
|
}).concat([state$1('dump', identity)]));
|
|
};
|
|
var get$c = function (data) {
|
|
return data.dump;
|
|
};
|
|
var augment = function (data, original) {
|
|
return __assign(__assign({}, data.dump), derive$1(original));
|
|
};
|
|
var SketchBehaviours = {
|
|
field: field$1,
|
|
augment: augment,
|
|
get: get$c
|
|
};
|
|
|
|
var _placeholder = 'placeholder';
|
|
var adt$9 = Adt.generate([
|
|
{
|
|
single: [
|
|
'required',
|
|
'valueThunk'
|
|
]
|
|
},
|
|
{
|
|
multiple: [
|
|
'required',
|
|
'valueThunks'
|
|
]
|
|
}
|
|
]);
|
|
var isSubstituted = function (spec) {
|
|
return has(spec, 'uiType');
|
|
};
|
|
var subPlaceholder = function (owner, detail, compSpec, placeholders) {
|
|
if (owner.exists(function (o) {
|
|
return o !== compSpec.owner;
|
|
})) {
|
|
return adt$9.single(true, constant(compSpec));
|
|
}
|
|
return get(placeholders, compSpec.name).fold(function () {
|
|
throw new Error('Unknown placeholder component: ' + compSpec.name + '\nKnown: [' + keys(placeholders) + ']\nNamespace: ' + owner.getOr('none') + '\nSpec: ' + JSON.stringify(compSpec, null, 2));
|
|
}, function (newSpec) {
|
|
return newSpec.replace();
|
|
});
|
|
};
|
|
var scan = function (owner, detail, compSpec, placeholders) {
|
|
if (isSubstituted(compSpec) && compSpec.uiType === _placeholder) {
|
|
return subPlaceholder(owner, detail, compSpec, placeholders);
|
|
} else {
|
|
return adt$9.single(false, constant(compSpec));
|
|
}
|
|
};
|
|
var substitute = function (owner, detail, compSpec, placeholders) {
|
|
var base = scan(owner, detail, compSpec, placeholders);
|
|
return base.fold(function (req, valueThunk) {
|
|
var value = isSubstituted(compSpec) ? valueThunk(detail, compSpec.config, compSpec.validated) : valueThunk(detail);
|
|
var childSpecs = get(value, 'components').getOr([]);
|
|
var substituted = bind(childSpecs, function (c) {
|
|
return substitute(owner, detail, c, placeholders);
|
|
});
|
|
return [__assign(__assign({}, value), { components: substituted })];
|
|
}, function (req, valuesThunk) {
|
|
if (isSubstituted(compSpec)) {
|
|
var values = valuesThunk(detail, compSpec.config, compSpec.validated);
|
|
var preprocessor = compSpec.validated.preprocess.getOr(identity);
|
|
return preprocessor(values);
|
|
} else {
|
|
return valuesThunk(detail);
|
|
}
|
|
});
|
|
};
|
|
var substituteAll = function (owner, detail, components, placeholders) {
|
|
return bind(components, function (c) {
|
|
return substitute(owner, detail, c, placeholders);
|
|
});
|
|
};
|
|
var oneReplace = function (label, replacements) {
|
|
var called = false;
|
|
var used = function () {
|
|
return called;
|
|
};
|
|
var replace = function () {
|
|
if (called) {
|
|
throw new Error('Trying to use the same placeholder more than once: ' + label);
|
|
}
|
|
called = true;
|
|
return replacements;
|
|
};
|
|
var required = function () {
|
|
return replacements.fold(function (req, _) {
|
|
return req;
|
|
}, function (req, _) {
|
|
return req;
|
|
});
|
|
};
|
|
return {
|
|
name: constant(label),
|
|
required: required,
|
|
used: used,
|
|
replace: replace
|
|
};
|
|
};
|
|
var substitutePlaces = function (owner, detail, components, placeholders) {
|
|
var ps = map$1(placeholders, function (ph, name) {
|
|
return oneReplace(name, ph);
|
|
});
|
|
var outcome = substituteAll(owner, detail, components, ps);
|
|
each$1(ps, function (p) {
|
|
if (p.used() === false && p.required()) {
|
|
throw new Error('Placeholder: ' + p.name() + ' was not found in components list\nNamespace: ' + owner.getOr('none') + '\nComponents: ' + JSON.stringify(detail.components, null, 2));
|
|
}
|
|
});
|
|
return outcome;
|
|
};
|
|
var single = adt$9.single;
|
|
var multiple = adt$9.multiple;
|
|
var placeholder = constant(_placeholder);
|
|
|
|
var adt$a = Adt.generate([
|
|
{ required: ['data'] },
|
|
{ external: ['data'] },
|
|
{ optional: ['data'] },
|
|
{ group: ['data'] }
|
|
]);
|
|
var fFactory = defaulted$1('factory', { sketch: identity });
|
|
var fSchema = defaulted$1('schema', []);
|
|
var fName = strict$1('name');
|
|
var fPname = field('pname', 'pname', defaultedThunk(function (typeSpec) {
|
|
return '<alloy.' + generate$1(typeSpec.name) + '>';
|
|
}), anyValue$1());
|
|
var fGroupSchema = state$1('schema', function () {
|
|
return [option('preprocess')];
|
|
});
|
|
var fDefaults = defaulted$1('defaults', constant({}));
|
|
var fOverrides = defaulted$1('overrides', constant({}));
|
|
var requiredSpec = objOf([
|
|
fFactory,
|
|
fSchema,
|
|
fName,
|
|
fPname,
|
|
fDefaults,
|
|
fOverrides
|
|
]);
|
|
var externalSpec = objOf([
|
|
fFactory,
|
|
fSchema,
|
|
fName,
|
|
fDefaults,
|
|
fOverrides
|
|
]);
|
|
var optionalSpec = objOf([
|
|
fFactory,
|
|
fSchema,
|
|
fName,
|
|
fPname,
|
|
fDefaults,
|
|
fOverrides
|
|
]);
|
|
var groupSpec = objOf([
|
|
fFactory,
|
|
fGroupSchema,
|
|
fName,
|
|
strict$1('unit'),
|
|
fPname,
|
|
fDefaults,
|
|
fOverrides
|
|
]);
|
|
var asNamedPart = function (part) {
|
|
return part.fold(Option.some, Option.none, Option.some, Option.some);
|
|
};
|
|
var name$1 = function (part) {
|
|
var get = function (data) {
|
|
return data.name;
|
|
};
|
|
return part.fold(get, get, get, get);
|
|
};
|
|
var asCommon = function (part) {
|
|
return part.fold(identity, identity, identity, identity);
|
|
};
|
|
var convert = function (adtConstructor, partSchema) {
|
|
return function (spec) {
|
|
var data = asRawOrDie('Converting part type', partSchema, spec);
|
|
return adtConstructor(data);
|
|
};
|
|
};
|
|
var required = convert(adt$a.required, requiredSpec);
|
|
var external$1 = convert(adt$a.external, externalSpec);
|
|
var optional = convert(adt$a.optional, optionalSpec);
|
|
var group = convert(adt$a.group, groupSpec);
|
|
var original = constant('entirety');
|
|
|
|
var PartType = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
required: required,
|
|
external: external$1,
|
|
optional: optional,
|
|
group: group,
|
|
asNamedPart: asNamedPart,
|
|
name: name$1,
|
|
asCommon: asCommon,
|
|
original: original
|
|
});
|
|
|
|
var combine$2 = function (detail, data, partSpec, partValidated) {
|
|
return deepMerge(data.defaults(detail, partSpec, partValidated), partSpec, { uid: detail.partUids[data.name] }, data.overrides(detail, partSpec, partValidated));
|
|
};
|
|
var subs = function (owner, detail, parts) {
|
|
var internals = {};
|
|
var externals = {};
|
|
each(parts, function (part) {
|
|
part.fold(function (data) {
|
|
internals[data.pname] = single(true, function (detail, partSpec, partValidated) {
|
|
return data.factory.sketch(combine$2(detail, data, partSpec, partValidated));
|
|
});
|
|
}, function (data) {
|
|
var partSpec = detail.parts[data.name];
|
|
externals[data.name] = constant(data.factory.sketch(combine$2(detail, data, partSpec[original()]), partSpec));
|
|
}, function (data) {
|
|
internals[data.pname] = single(false, function (detail, partSpec, partValidated) {
|
|
return data.factory.sketch(combine$2(detail, data, partSpec, partValidated));
|
|
});
|
|
}, function (data) {
|
|
internals[data.pname] = multiple(true, function (detail, _partSpec, _partValidated) {
|
|
var units = detail[data.name];
|
|
return map(units, function (u) {
|
|
return data.factory.sketch(deepMerge(data.defaults(detail, u, _partValidated), u, data.overrides(detail, u)));
|
|
});
|
|
});
|
|
});
|
|
});
|
|
return {
|
|
internals: constant(internals),
|
|
externals: constant(externals)
|
|
};
|
|
};
|
|
|
|
var generate$4 = function (owner, parts) {
|
|
var r = {};
|
|
each(parts, function (part) {
|
|
asNamedPart(part).each(function (np) {
|
|
var g = doGenerateOne(owner, np.pname);
|
|
r[np.name] = function (config) {
|
|
var validated = asRawOrDie('Part: ' + np.name + ' in ' + owner, objOf(np.schema), config);
|
|
return __assign(__assign({}, g), {
|
|
config: config,
|
|
validated: validated
|
|
});
|
|
};
|
|
});
|
|
});
|
|
return r;
|
|
};
|
|
var doGenerateOne = function (owner, pname) {
|
|
return {
|
|
uiType: placeholder(),
|
|
owner: owner,
|
|
name: pname
|
|
};
|
|
};
|
|
var generateOne = function (owner, pname, config) {
|
|
return {
|
|
uiType: placeholder(),
|
|
owner: owner,
|
|
name: pname,
|
|
config: config,
|
|
validated: {}
|
|
};
|
|
};
|
|
var schemas = function (parts) {
|
|
return bind(parts, function (part) {
|
|
return part.fold(Option.none, Option.some, Option.none, Option.none).map(function (data) {
|
|
return strictObjOf(data.name, data.schema.concat([snapshot(original())]));
|
|
}).toArray();
|
|
});
|
|
};
|
|
var names = function (parts) {
|
|
return map(parts, name$1);
|
|
};
|
|
var substitutes = function (owner, detail, parts) {
|
|
return subs(owner, detail, parts);
|
|
};
|
|
var components = function (owner, detail, internals) {
|
|
return substitutePlaces(Option.some(owner), detail, detail.components, internals);
|
|
};
|
|
var getPart = function (component, detail, partKey) {
|
|
var uid = detail.partUids[partKey];
|
|
return component.getSystem().getByUid(uid).toOption();
|
|
};
|
|
var getPartOrDie = function (component, detail, partKey) {
|
|
return getPart(component, detail, partKey).getOrDie('Could not find part: ' + partKey);
|
|
};
|
|
var getParts = function (component, detail, partKeys) {
|
|
var r = {};
|
|
var uids = detail.partUids;
|
|
var system = component.getSystem();
|
|
each(partKeys, function (pk) {
|
|
r[pk] = constant(system.getByUid(uids[pk]));
|
|
});
|
|
return r;
|
|
};
|
|
var getAllParts = function (component, detail) {
|
|
var system = component.getSystem();
|
|
return map$1(detail.partUids, function (pUid, _k) {
|
|
return constant(system.getByUid(pUid));
|
|
});
|
|
};
|
|
var getAllPartNames = function (detail) {
|
|
return keys(detail.partUids);
|
|
};
|
|
var getPartsOrDie = function (component, detail, partKeys) {
|
|
var r = {};
|
|
var uids = detail.partUids;
|
|
var system = component.getSystem();
|
|
each(partKeys, function (pk) {
|
|
r[pk] = constant(system.getByUid(uids[pk]).getOrDie());
|
|
});
|
|
return r;
|
|
};
|
|
var defaultUids = function (baseUid, partTypes) {
|
|
var partNames = names(partTypes);
|
|
return wrapAll$1(map(partNames, function (pn) {
|
|
return {
|
|
key: pn,
|
|
value: baseUid + '-' + pn
|
|
};
|
|
}));
|
|
};
|
|
var defaultUidsSchema = function (partTypes) {
|
|
return field('partUids', 'partUids', mergeWithThunk(function (spec) {
|
|
return defaultUids(spec.uid, partTypes);
|
|
}), anyValue$1());
|
|
};
|
|
|
|
var AlloyParts = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
generate: generate$4,
|
|
generateOne: generateOne,
|
|
schemas: schemas,
|
|
names: names,
|
|
substitutes: substitutes,
|
|
components: components,
|
|
defaultUids: defaultUids,
|
|
defaultUidsSchema: defaultUidsSchema,
|
|
getAllParts: getAllParts,
|
|
getAllPartNames: getAllPartNames,
|
|
getPart: getPart,
|
|
getPartOrDie: getPartOrDie,
|
|
getParts: getParts,
|
|
getPartsOrDie: getPartsOrDie
|
|
});
|
|
|
|
var base = function (partSchemas, partUidsSchemas) {
|
|
var ps = partSchemas.length > 0 ? [strictObjOf('parts', partSchemas)] : [];
|
|
return ps.concat([
|
|
strict$1('uid'),
|
|
defaulted$1('dom', {}),
|
|
defaulted$1('components', []),
|
|
snapshot('originalSpec'),
|
|
defaulted$1('debug.sketcher', {})
|
|
]).concat(partUidsSchemas);
|
|
};
|
|
var asRawOrDie$1 = function (label, schema, spec, partSchemas, partUidsSchemas) {
|
|
var baseS = base(partSchemas, partUidsSchemas);
|
|
return asRawOrDie(label + ' [SpecSchema]', objOfOnly(baseS.concat(schema)), spec);
|
|
};
|
|
|
|
var single$1 = function (owner, schema, factory, spec) {
|
|
var specWithUid = supplyUid(spec);
|
|
var detail = asRawOrDie$1(owner, schema, specWithUid, [], []);
|
|
return factory(detail, specWithUid);
|
|
};
|
|
var composite = function (owner, schema, partTypes, factory, spec) {
|
|
var specWithUid = supplyUid(spec);
|
|
var partSchemas = schemas(partTypes);
|
|
var partUidsSchema = defaultUidsSchema(partTypes);
|
|
var detail = asRawOrDie$1(owner, schema, specWithUid, partSchemas, [partUidsSchema]);
|
|
var subs = substitutes(owner, detail, partTypes);
|
|
var components$1 = components(owner, detail, subs.internals());
|
|
return factory(detail, components$1, specWithUid, subs.externals());
|
|
};
|
|
var hasUid = function (spec) {
|
|
return has(spec, 'uid');
|
|
};
|
|
var supplyUid = function (spec) {
|
|
return hasUid(spec) ? spec : __assign(__assign({}, spec), { uid: generate$2('uid') });
|
|
};
|
|
|
|
function isSketchSpec(spec) {
|
|
return spec.uid !== undefined;
|
|
}
|
|
var singleSchema = objOfOnly([
|
|
strict$1('name'),
|
|
strict$1('factory'),
|
|
strict$1('configFields'),
|
|
defaulted$1('apis', {}),
|
|
defaulted$1('extraApis', {})
|
|
]);
|
|
var compositeSchema = objOfOnly([
|
|
strict$1('name'),
|
|
strict$1('factory'),
|
|
strict$1('configFields'),
|
|
strict$1('partFields'),
|
|
defaulted$1('apis', {}),
|
|
defaulted$1('extraApis', {})
|
|
]);
|
|
var single$2 = function (rawConfig) {
|
|
var config = asRawOrDie('Sketcher for ' + rawConfig.name, singleSchema, rawConfig);
|
|
var sketch = function (spec) {
|
|
return single$1(config.name, config.configFields, config.factory, spec);
|
|
};
|
|
var apis = map$1(config.apis, makeApi);
|
|
var extraApis = map$1(config.extraApis, function (f, k) {
|
|
return markAsExtraApi(f, k);
|
|
});
|
|
return __assign(__assign({
|
|
name: constant(config.name),
|
|
configFields: constant(config.configFields),
|
|
sketch: sketch
|
|
}, apis), extraApis);
|
|
};
|
|
var composite$1 = function (rawConfig) {
|
|
var config = asRawOrDie('Sketcher for ' + rawConfig.name, compositeSchema, rawConfig);
|
|
var sketch = function (spec) {
|
|
return composite(config.name, config.configFields, config.partFields, config.factory, spec);
|
|
};
|
|
var parts = generate$4(config.name, config.partFields);
|
|
var apis = map$1(config.apis, makeApi);
|
|
var extraApis = map$1(config.extraApis, function (f, k) {
|
|
return markAsExtraApi(f, k);
|
|
});
|
|
return __assign(__assign({
|
|
name: constant(config.name),
|
|
partFields: constant(config.partFields),
|
|
configFields: constant(config.configFields),
|
|
sketch: sketch,
|
|
parts: constant(parts)
|
|
}, apis), extraApis);
|
|
};
|
|
|
|
var cat = function (arr) {
|
|
var r = [];
|
|
var push = function (x) {
|
|
r.push(x);
|
|
};
|
|
for (var i = 0; i < arr.length; i++) {
|
|
arr[i].each(push);
|
|
}
|
|
return r;
|
|
};
|
|
var sequence = function (arr) {
|
|
var r = [];
|
|
for (var i = 0; i < arr.length; i++) {
|
|
var x = arr[i];
|
|
if (x.isSome()) {
|
|
r.push(x.getOrDie());
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
}
|
|
return Option.some(r);
|
|
};
|
|
var lift2 = function (oa, ob, f) {
|
|
return oa.isSome() && ob.isSome() ? Option.some(f(oa.getOrDie(), ob.getOrDie())) : Option.none();
|
|
};
|
|
var lift3 = function (oa, ob, oc, f) {
|
|
return oa.isSome() && ob.isSome() && oc.isSome() ? Option.some(f(oa.getOrDie(), ob.getOrDie(), oc.getOrDie())) : Option.none();
|
|
};
|
|
|
|
var inside = function (target) {
|
|
return name(target) === 'input' && get$2(target, 'type') !== 'radio' || name(target) === 'textarea';
|
|
};
|
|
|
|
var getCurrent = function (component, composeConfig, _composeState) {
|
|
return composeConfig.find(component);
|
|
};
|
|
|
|
var ComposeApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
getCurrent: getCurrent
|
|
});
|
|
|
|
var ComposeSchema = [strict$1('find')];
|
|
|
|
var Composing = create$1({
|
|
fields: ComposeSchema,
|
|
name: 'composing',
|
|
apis: ComposeApis
|
|
});
|
|
|
|
var dehighlightAllExcept = function (component, hConfig, hState, skip) {
|
|
var highlighted = descendants(component.element(), '.' + hConfig.highlightClass);
|
|
each(highlighted, function (h) {
|
|
if (!exists(skip, function (skipComp) {
|
|
return skipComp.element() === h;
|
|
})) {
|
|
remove$4(h, hConfig.highlightClass);
|
|
component.getSystem().getByDom(h).each(function (target) {
|
|
hConfig.onDehighlight(component, target);
|
|
emit(target, dehighlight());
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var dehighlightAll = function (component, hConfig, hState) {
|
|
return dehighlightAllExcept(component, hConfig, hState, []);
|
|
};
|
|
var dehighlight$1 = function (component, hConfig, hState, target) {
|
|
if (isHighlighted(component, hConfig, hState, target)) {
|
|
remove$4(target.element(), hConfig.highlightClass);
|
|
hConfig.onDehighlight(component, target);
|
|
emit(target, dehighlight());
|
|
}
|
|
};
|
|
var highlight$1 = function (component, hConfig, hState, target) {
|
|
dehighlightAllExcept(component, hConfig, hState, [target]);
|
|
if (!isHighlighted(component, hConfig, hState, target)) {
|
|
add$2(target.element(), hConfig.highlightClass);
|
|
hConfig.onHighlight(component, target);
|
|
emit(target, highlight());
|
|
}
|
|
};
|
|
var highlightFirst = function (component, hConfig, hState) {
|
|
getFirst(component, hConfig).each(function (firstComp) {
|
|
highlight$1(component, hConfig, hState, firstComp);
|
|
});
|
|
};
|
|
var highlightLast = function (component, hConfig, hState) {
|
|
getLast(component, hConfig).each(function (lastComp) {
|
|
highlight$1(component, hConfig, hState, lastComp);
|
|
});
|
|
};
|
|
var highlightAt = function (component, hConfig, hState, index) {
|
|
getByIndex(component, hConfig, hState, index).fold(function (err) {
|
|
throw new Error(err);
|
|
}, function (firstComp) {
|
|
highlight$1(component, hConfig, hState, firstComp);
|
|
});
|
|
};
|
|
var highlightBy = function (component, hConfig, hState, predicate) {
|
|
var candidates = getCandidates(component, hConfig);
|
|
var targetComp = find(candidates, predicate);
|
|
targetComp.each(function (c) {
|
|
highlight$1(component, hConfig, hState, c);
|
|
});
|
|
};
|
|
var isHighlighted = function (component, hConfig, hState, queryTarget) {
|
|
return has$2(queryTarget.element(), hConfig.highlightClass);
|
|
};
|
|
var getHighlighted = function (component, hConfig, _hState) {
|
|
return descendant$1(component.element(), '.' + hConfig.highlightClass).bind(function (e) {
|
|
return component.getSystem().getByDom(e).toOption();
|
|
});
|
|
};
|
|
var getByIndex = function (component, hConfig, hState, index) {
|
|
var items = descendants(component.element(), '.' + hConfig.itemClass);
|
|
return Option.from(items[index]).fold(function () {
|
|
return Result.error('No element found with index ' + index);
|
|
}, component.getSystem().getByDom);
|
|
};
|
|
var getFirst = function (component, hConfig, _hState) {
|
|
return descendant$1(component.element(), '.' + hConfig.itemClass).bind(function (e) {
|
|
return component.getSystem().getByDom(e).toOption();
|
|
});
|
|
};
|
|
var getLast = function (component, hConfig, _hState) {
|
|
var items = descendants(component.element(), '.' + hConfig.itemClass);
|
|
var last = items.length > 0 ? Option.some(items[items.length - 1]) : Option.none();
|
|
return last.bind(function (c) {
|
|
return component.getSystem().getByDom(c).toOption();
|
|
});
|
|
};
|
|
var getDelta = function (component, hConfig, hState, delta) {
|
|
var items = descendants(component.element(), '.' + hConfig.itemClass);
|
|
var current = findIndex(items, function (item) {
|
|
return has$2(item, hConfig.highlightClass);
|
|
});
|
|
return current.bind(function (selected) {
|
|
var dest = cycleBy(selected, delta, 0, items.length - 1);
|
|
return component.getSystem().getByDom(items[dest]).toOption();
|
|
});
|
|
};
|
|
var getPrevious = function (component, hConfig, hState) {
|
|
return getDelta(component, hConfig, hState, -1);
|
|
};
|
|
var getNext = function (component, hConfig, hState) {
|
|
return getDelta(component, hConfig, hState, +1);
|
|
};
|
|
var getCandidates = function (component, hConfig, _hState) {
|
|
var items = descendants(component.element(), '.' + hConfig.itemClass);
|
|
return cat(map(items, function (i) {
|
|
return component.getSystem().getByDom(i).toOption();
|
|
}));
|
|
};
|
|
|
|
var HighlightApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
dehighlightAll: dehighlightAll,
|
|
dehighlight: dehighlight$1,
|
|
highlight: highlight$1,
|
|
highlightFirst: highlightFirst,
|
|
highlightLast: highlightLast,
|
|
highlightAt: highlightAt,
|
|
highlightBy: highlightBy,
|
|
isHighlighted: isHighlighted,
|
|
getHighlighted: getHighlighted,
|
|
getFirst: getFirst,
|
|
getLast: getLast,
|
|
getPrevious: getPrevious,
|
|
getNext: getNext,
|
|
getCandidates: getCandidates
|
|
});
|
|
|
|
var HighlightSchema = [
|
|
strict$1('highlightClass'),
|
|
strict$1('itemClass'),
|
|
onHandler('onHighlight'),
|
|
onHandler('onDehighlight')
|
|
];
|
|
|
|
var Highlighting = create$1({
|
|
fields: HighlightSchema,
|
|
name: 'highlighting',
|
|
apis: HighlightApis
|
|
});
|
|
|
|
var BACKSPACE = function () {
|
|
return [8];
|
|
};
|
|
var TAB = function () {
|
|
return [9];
|
|
};
|
|
var ENTER = function () {
|
|
return [13];
|
|
};
|
|
var ESCAPE = function () {
|
|
return [27];
|
|
};
|
|
var SPACE = function () {
|
|
return [32];
|
|
};
|
|
var LEFT = function () {
|
|
return [37];
|
|
};
|
|
var UP = function () {
|
|
return [38];
|
|
};
|
|
var RIGHT = function () {
|
|
return [39];
|
|
};
|
|
var DOWN = function () {
|
|
return [40];
|
|
};
|
|
|
|
var cyclePrev = function (values, index, predicate) {
|
|
var before = reverse(values.slice(0, index));
|
|
var after = reverse(values.slice(index + 1));
|
|
return find(before.concat(after), predicate);
|
|
};
|
|
var tryPrev = function (values, index, predicate) {
|
|
var before = reverse(values.slice(0, index));
|
|
return find(before, predicate);
|
|
};
|
|
var cycleNext = function (values, index, predicate) {
|
|
var before = values.slice(0, index);
|
|
var after = values.slice(index + 1);
|
|
return find(after.concat(before), predicate);
|
|
};
|
|
var tryNext = function (values, index, predicate) {
|
|
var after = values.slice(index + 1);
|
|
return find(after, predicate);
|
|
};
|
|
|
|
var inSet = function (keys) {
|
|
return function (event) {
|
|
var raw = event.raw();
|
|
return contains(keys, raw.which);
|
|
};
|
|
};
|
|
var and = function (preds) {
|
|
return function (event) {
|
|
return forall(preds, function (pred) {
|
|
return pred(event);
|
|
});
|
|
};
|
|
};
|
|
var isShift = function (event) {
|
|
var raw = event.raw();
|
|
return raw.shiftKey === true;
|
|
};
|
|
var isControl = function (event) {
|
|
var raw = event.raw();
|
|
return raw.ctrlKey === true;
|
|
};
|
|
var isNotShift = not(isShift);
|
|
|
|
var rule = function (matches, action) {
|
|
return {
|
|
matches: matches,
|
|
classification: action
|
|
};
|
|
};
|
|
var choose$2 = function (transitions, event) {
|
|
var transition = find(transitions, function (t) {
|
|
return t.matches(event);
|
|
});
|
|
return transition.map(function (t) {
|
|
return t.classification;
|
|
});
|
|
};
|
|
|
|
var reportFocusShifting = function (component, prevFocus, newFocus) {
|
|
var noChange = prevFocus.exists(function (p) {
|
|
return newFocus.exists(function (n) {
|
|
return eq$1(n, p);
|
|
});
|
|
});
|
|
if (!noChange) {
|
|
emitWith(component, focusShifted(), {
|
|
prevFocus: prevFocus,
|
|
newFocus: newFocus
|
|
});
|
|
}
|
|
};
|
|
var dom = function () {
|
|
var get = function (component) {
|
|
return search(component.element());
|
|
};
|
|
var set = function (component, focusee) {
|
|
var prevFocus = get(component);
|
|
component.getSystem().triggerFocus(focusee, component.element());
|
|
var newFocus = get(component);
|
|
reportFocusShifting(component, prevFocus, newFocus);
|
|
};
|
|
return {
|
|
get: get,
|
|
set: set
|
|
};
|
|
};
|
|
var highlights = function () {
|
|
var get = function (component) {
|
|
return Highlighting.getHighlighted(component).map(function (item) {
|
|
return item.element();
|
|
});
|
|
};
|
|
var set = function (component, element) {
|
|
var prevFocus = get(component);
|
|
component.getSystem().getByDom(element).fold(noop, function (item) {
|
|
Highlighting.highlight(component, item);
|
|
});
|
|
var newFocus = get(component);
|
|
reportFocusShifting(component, prevFocus, newFocus);
|
|
};
|
|
return {
|
|
get: get,
|
|
set: set
|
|
};
|
|
};
|
|
|
|
var FocusInsideModes;
|
|
(function (FocusInsideModes) {
|
|
FocusInsideModes['OnFocusMode'] = 'onFocus';
|
|
FocusInsideModes['OnEnterOrSpaceMode'] = 'onEnterOrSpace';
|
|
FocusInsideModes['OnApiMode'] = 'onApi';
|
|
}(FocusInsideModes || (FocusInsideModes = {})));
|
|
|
|
var typical = function (infoSchema, stateInit, getKeydownRules, getKeyupRules, optFocusIn) {
|
|
var schema = function () {
|
|
return infoSchema.concat([
|
|
defaulted$1('focusManager', dom()),
|
|
defaultedOf('focusInside', 'onFocus', valueOf(function (val) {
|
|
return contains([
|
|
'onFocus',
|
|
'onEnterOrSpace',
|
|
'onApi'
|
|
], val) ? Result.value(val) : Result.error('Invalid value for focusInside');
|
|
})),
|
|
output('handler', me),
|
|
output('state', stateInit),
|
|
output('sendFocusIn', optFocusIn)
|
|
]);
|
|
};
|
|
var processKey = function (component, simulatedEvent, getRules, keyingConfig, keyingState) {
|
|
var rules = getRules(component, simulatedEvent, keyingConfig, keyingState);
|
|
return choose$2(rules, simulatedEvent.event()).bind(function (rule) {
|
|
return rule(component, simulatedEvent, keyingConfig, keyingState);
|
|
});
|
|
};
|
|
var toEvents = function (keyingConfig, keyingState) {
|
|
var onFocusHandler = keyingConfig.focusInside !== FocusInsideModes.OnFocusMode ? Option.none() : optFocusIn(keyingConfig).map(function (focusIn) {
|
|
return run(focus(), function (component, simulatedEvent) {
|
|
focusIn(component, keyingConfig, keyingState);
|
|
simulatedEvent.stop();
|
|
});
|
|
});
|
|
var tryGoInsideComponent = function (component, simulatedEvent) {
|
|
var isEnterOrSpace = inSet(SPACE().concat(ENTER()))(simulatedEvent.event());
|
|
if (keyingConfig.focusInside === FocusInsideModes.OnEnterOrSpaceMode && isEnterOrSpace && isSource(component, simulatedEvent)) {
|
|
optFocusIn(keyingConfig).each(function (focusIn) {
|
|
focusIn(component, keyingConfig, keyingState);
|
|
simulatedEvent.stop();
|
|
});
|
|
}
|
|
};
|
|
var keyboardEvents = [
|
|
run(keydown(), function (component, simulatedEvent) {
|
|
processKey(component, simulatedEvent, getKeydownRules, keyingConfig, keyingState).fold(function () {
|
|
tryGoInsideComponent(component, simulatedEvent);
|
|
}, function (_) {
|
|
simulatedEvent.stop();
|
|
});
|
|
}),
|
|
run(keyup(), function (component, simulatedEvent) {
|
|
processKey(component, simulatedEvent, getKeyupRules, keyingConfig, keyingState).each(function (_) {
|
|
simulatedEvent.stop();
|
|
});
|
|
})
|
|
];
|
|
return derive(onFocusHandler.toArray().concat(keyboardEvents));
|
|
};
|
|
var me = {
|
|
schema: schema,
|
|
processKey: processKey,
|
|
toEvents: toEvents
|
|
};
|
|
return me;
|
|
};
|
|
|
|
var create$3 = function (cyclicField) {
|
|
var schema = [
|
|
option('onEscape'),
|
|
option('onEnter'),
|
|
defaulted$1('selector', '[data-alloy-tabstop="true"]:not(:disabled)'),
|
|
defaulted$1('firstTabstop', 0),
|
|
defaulted$1('useTabstopAt', constant(true)),
|
|
option('visibilitySelector')
|
|
].concat([cyclicField]);
|
|
var isVisible = function (tabbingConfig, element) {
|
|
var target = tabbingConfig.visibilitySelector.bind(function (sel) {
|
|
return closest$3(element, sel);
|
|
}).getOr(element);
|
|
return get$6(target) > 0;
|
|
};
|
|
var findInitial = function (component, tabbingConfig) {
|
|
var tabstops = descendants(component.element(), tabbingConfig.selector);
|
|
var visibles = filter(tabstops, function (elem) {
|
|
return isVisible(tabbingConfig, elem);
|
|
});
|
|
return Option.from(visibles[tabbingConfig.firstTabstop]);
|
|
};
|
|
var findCurrent = function (component, tabbingConfig) {
|
|
return tabbingConfig.focusManager.get(component).bind(function (elem) {
|
|
return closest$3(elem, tabbingConfig.selector);
|
|
});
|
|
};
|
|
var isTabstop = function (tabbingConfig, element) {
|
|
return isVisible(tabbingConfig, element) && tabbingConfig.useTabstopAt(element);
|
|
};
|
|
var focusIn = function (component, tabbingConfig, _tabbingState) {
|
|
findInitial(component, tabbingConfig).each(function (target) {
|
|
tabbingConfig.focusManager.set(component, target);
|
|
});
|
|
};
|
|
var goFromTabstop = function (component, tabstops, stopIndex, tabbingConfig, cycle) {
|
|
return cycle(tabstops, stopIndex, function (elem) {
|
|
return isTabstop(tabbingConfig, elem);
|
|
}).fold(function () {
|
|
return tabbingConfig.cyclic ? Option.some(true) : Option.none();
|
|
}, function (target) {
|
|
tabbingConfig.focusManager.set(component, target);
|
|
return Option.some(true);
|
|
});
|
|
};
|
|
var go = function (component, _simulatedEvent, tabbingConfig, cycle) {
|
|
var tabstops = descendants(component.element(), tabbingConfig.selector);
|
|
return findCurrent(component, tabbingConfig).bind(function (tabstop) {
|
|
var optStopIndex = findIndex(tabstops, curry(eq$1, tabstop));
|
|
return optStopIndex.bind(function (stopIndex) {
|
|
return goFromTabstop(component, tabstops, stopIndex, tabbingConfig, cycle);
|
|
});
|
|
});
|
|
};
|
|
var goBackwards = function (component, simulatedEvent, tabbingConfig) {
|
|
var navigate = tabbingConfig.cyclic ? cyclePrev : tryPrev;
|
|
return go(component, simulatedEvent, tabbingConfig, navigate);
|
|
};
|
|
var goForwards = function (component, simulatedEvent, tabbingConfig) {
|
|
var navigate = tabbingConfig.cyclic ? cycleNext : tryNext;
|
|
return go(component, simulatedEvent, tabbingConfig, navigate);
|
|
};
|
|
var execute = function (component, simulatedEvent, tabbingConfig) {
|
|
return tabbingConfig.onEnter.bind(function (f) {
|
|
return f(component, simulatedEvent);
|
|
});
|
|
};
|
|
var exit = function (component, simulatedEvent, tabbingConfig) {
|
|
return tabbingConfig.onEscape.bind(function (f) {
|
|
return f(component, simulatedEvent);
|
|
});
|
|
};
|
|
var getKeydownRules = constant([
|
|
rule(and([
|
|
isShift,
|
|
inSet(TAB())
|
|
]), goBackwards),
|
|
rule(inSet(TAB()), goForwards),
|
|
rule(inSet(ESCAPE()), exit),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(ENTER())
|
|
]), execute)
|
|
]);
|
|
var getKeyupRules = constant([]);
|
|
return typical(schema, NoState.init, getKeydownRules, getKeyupRules, function () {
|
|
return Option.some(focusIn);
|
|
});
|
|
};
|
|
|
|
var AcyclicType = create$3(state$1('cyclic', constant(false)));
|
|
|
|
var CyclicType = create$3(state$1('cyclic', constant(true)));
|
|
|
|
var doDefaultExecute = function (component, _simulatedEvent, focused) {
|
|
dispatch(component, focused, execute());
|
|
return Option.some(true);
|
|
};
|
|
var defaultExecute = function (component, simulatedEvent, focused) {
|
|
var isComplex = inside(focused) && inSet(SPACE())(simulatedEvent.event());
|
|
return isComplex ? Option.none() : doDefaultExecute(component, simulatedEvent, focused);
|
|
};
|
|
var stopEventForFirefox = function (_component, _simulatedEvent) {
|
|
return Option.some(true);
|
|
};
|
|
|
|
var schema$4 = [
|
|
defaulted$1('execute', defaultExecute),
|
|
defaulted$1('useSpace', false),
|
|
defaulted$1('useEnter', true),
|
|
defaulted$1('useControlEnter', false),
|
|
defaulted$1('useDown', false)
|
|
];
|
|
var execute$1 = function (component, simulatedEvent, executeConfig) {
|
|
return executeConfig.execute(component, simulatedEvent, component.element());
|
|
};
|
|
var getKeydownRules = function (component, _simulatedEvent, executeConfig, _executeState) {
|
|
var spaceExec = executeConfig.useSpace && !inside(component.element()) ? SPACE() : [];
|
|
var enterExec = executeConfig.useEnter ? ENTER() : [];
|
|
var downExec = executeConfig.useDown ? DOWN() : [];
|
|
var execKeys = spaceExec.concat(enterExec).concat(downExec);
|
|
return [rule(inSet(execKeys), execute$1)].concat(executeConfig.useControlEnter ? [rule(and([
|
|
isControl,
|
|
inSet(ENTER())
|
|
]), execute$1)] : []);
|
|
};
|
|
var getKeyupRules = function (component, _simulatedEvent, executeConfig, _executeState) {
|
|
return executeConfig.useSpace && !inside(component.element()) ? [rule(inSet(SPACE()), stopEventForFirefox)] : [];
|
|
};
|
|
var ExecutionType = typical(schema$4, NoState.init, getKeydownRules, getKeyupRules, function () {
|
|
return Option.none();
|
|
});
|
|
|
|
var flatgrid = function () {
|
|
var dimensions = Cell(Option.none());
|
|
var setGridSize = function (numRows, numColumns) {
|
|
dimensions.set(Option.some({
|
|
numRows: numRows,
|
|
numColumns: numColumns
|
|
}));
|
|
};
|
|
var getNumRows = function () {
|
|
return dimensions.get().map(function (d) {
|
|
return d.numRows;
|
|
});
|
|
};
|
|
var getNumColumns = function () {
|
|
return dimensions.get().map(function (d) {
|
|
return d.numColumns;
|
|
});
|
|
};
|
|
return nu$5({
|
|
readState: function () {
|
|
return dimensions.get().map(function (d) {
|
|
return {
|
|
numRows: String(d.numRows),
|
|
numColumns: String(d.numColumns)
|
|
};
|
|
}).getOr({
|
|
numRows: '?',
|
|
numColumns: '?'
|
|
});
|
|
},
|
|
setGridSize: setGridSize,
|
|
getNumRows: getNumRows,
|
|
getNumColumns: getNumColumns
|
|
});
|
|
};
|
|
var init$2 = function (spec) {
|
|
return spec.state(spec);
|
|
};
|
|
|
|
var KeyingState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
flatgrid: flatgrid,
|
|
init: init$2
|
|
});
|
|
|
|
var useH = function (movement) {
|
|
return function (component, simulatedEvent, config, state) {
|
|
var move = movement(component.element());
|
|
return use(move, component, simulatedEvent, config, state);
|
|
};
|
|
};
|
|
var west$2 = function (moveLeft, moveRight) {
|
|
var movement = onDirection(moveLeft, moveRight);
|
|
return useH(movement);
|
|
};
|
|
var east$2 = function (moveLeft, moveRight) {
|
|
var movement = onDirection(moveRight, moveLeft);
|
|
return useH(movement);
|
|
};
|
|
var useV = function (move) {
|
|
return function (component, simulatedEvent, config, state) {
|
|
return use(move, component, simulatedEvent, config, state);
|
|
};
|
|
};
|
|
var use = function (move, component, simulatedEvent, config, state) {
|
|
var outcome = config.focusManager.get(component).bind(function (focused) {
|
|
return move(component.element(), focused, config, state);
|
|
});
|
|
return outcome.map(function (newFocus) {
|
|
config.focusManager.set(component, newFocus);
|
|
return true;
|
|
});
|
|
};
|
|
var north$2 = useV;
|
|
var south$2 = useV;
|
|
var move = useV;
|
|
|
|
var isHidden = function (dom) {
|
|
return dom.offsetWidth <= 0 && dom.offsetHeight <= 0;
|
|
};
|
|
var isVisible = function (element) {
|
|
return !isHidden(element.dom());
|
|
};
|
|
|
|
var locate = function (candidates, predicate) {
|
|
return findIndex(candidates, predicate).map(function (index) {
|
|
return {
|
|
index: constant(index),
|
|
candidates: constant(candidates)
|
|
};
|
|
});
|
|
};
|
|
|
|
var locateVisible = function (container, current, selector) {
|
|
var predicate = function (x) {
|
|
return eq$1(x, current);
|
|
};
|
|
var candidates = descendants(container, selector);
|
|
var visible = filter(candidates, isVisible);
|
|
return locate(visible, predicate);
|
|
};
|
|
var findIndex$1 = function (elements, target) {
|
|
return findIndex(elements, function (elem) {
|
|
return eq$1(target, elem);
|
|
});
|
|
};
|
|
|
|
var withGrid = function (values, index, numCols, f) {
|
|
var oldRow = Math.floor(index / numCols);
|
|
var oldColumn = index % numCols;
|
|
return f(oldRow, oldColumn).bind(function (address) {
|
|
var newIndex = address.row() * numCols + address.column();
|
|
return newIndex >= 0 && newIndex < values.length ? Option.some(values[newIndex]) : Option.none();
|
|
});
|
|
};
|
|
var cycleHorizontal = function (values, index, numRows, numCols, delta) {
|
|
return withGrid(values, index, numCols, function (oldRow, oldColumn) {
|
|
var onLastRow = oldRow === numRows - 1;
|
|
var colsInRow = onLastRow ? values.length - oldRow * numCols : numCols;
|
|
var newColumn = cycleBy(oldColumn, delta, 0, colsInRow - 1);
|
|
return Option.some({
|
|
row: constant(oldRow),
|
|
column: constant(newColumn)
|
|
});
|
|
});
|
|
};
|
|
var cycleVertical = function (values, index, numRows, numCols, delta) {
|
|
return withGrid(values, index, numCols, function (oldRow, oldColumn) {
|
|
var newRow = cycleBy(oldRow, delta, 0, numRows - 1);
|
|
var onLastRow = newRow === numRows - 1;
|
|
var colsInRow = onLastRow ? values.length - newRow * numCols : numCols;
|
|
var newCol = clamp(oldColumn, 0, colsInRow - 1);
|
|
return Option.some({
|
|
row: constant(newRow),
|
|
column: constant(newCol)
|
|
});
|
|
});
|
|
};
|
|
var cycleRight = function (values, index, numRows, numCols) {
|
|
return cycleHorizontal(values, index, numRows, numCols, +1);
|
|
};
|
|
var cycleLeft = function (values, index, numRows, numCols) {
|
|
return cycleHorizontal(values, index, numRows, numCols, -1);
|
|
};
|
|
var cycleUp = function (values, index, numRows, numCols) {
|
|
return cycleVertical(values, index, numRows, numCols, -1);
|
|
};
|
|
var cycleDown = function (values, index, numRows, numCols) {
|
|
return cycleVertical(values, index, numRows, numCols, +1);
|
|
};
|
|
|
|
var schema$5 = [
|
|
strict$1('selector'),
|
|
defaulted$1('execute', defaultExecute),
|
|
onKeyboardHandler('onEscape'),
|
|
defaulted$1('captureTab', false),
|
|
initSize()
|
|
];
|
|
var focusIn = function (component, gridConfig, _gridState) {
|
|
descendant$1(component.element(), gridConfig.selector).each(function (first) {
|
|
gridConfig.focusManager.set(component, first);
|
|
});
|
|
};
|
|
var findCurrent = function (component, gridConfig) {
|
|
return gridConfig.focusManager.get(component).bind(function (elem) {
|
|
return closest$3(elem, gridConfig.selector);
|
|
});
|
|
};
|
|
var execute$2 = function (component, simulatedEvent, gridConfig, _gridState) {
|
|
return findCurrent(component, gridConfig).bind(function (focused) {
|
|
return gridConfig.execute(component, simulatedEvent, focused);
|
|
});
|
|
};
|
|
var doMove = function (cycle) {
|
|
return function (element, focused, gridConfig, gridState) {
|
|
return locateVisible(element, focused, gridConfig.selector).bind(function (identified) {
|
|
return cycle(identified.candidates(), identified.index(), gridState.getNumRows().getOr(gridConfig.initSize.numRows), gridState.getNumColumns().getOr(gridConfig.initSize.numColumns));
|
|
});
|
|
};
|
|
};
|
|
var handleTab = function (_component, _simulatedEvent, gridConfig) {
|
|
return gridConfig.captureTab ? Option.some(true) : Option.none();
|
|
};
|
|
var doEscape = function (component, simulatedEvent, gridConfig) {
|
|
return gridConfig.onEscape(component, simulatedEvent);
|
|
};
|
|
var moveLeft = doMove(cycleLeft);
|
|
var moveRight = doMove(cycleRight);
|
|
var moveNorth = doMove(cycleUp);
|
|
var moveSouth = doMove(cycleDown);
|
|
var getKeydownRules$1 = constant([
|
|
rule(inSet(LEFT()), west$2(moveLeft, moveRight)),
|
|
rule(inSet(RIGHT()), east$2(moveLeft, moveRight)),
|
|
rule(inSet(UP()), north$2(moveNorth)),
|
|
rule(inSet(DOWN()), south$2(moveSouth)),
|
|
rule(and([
|
|
isShift,
|
|
inSet(TAB())
|
|
]), handleTab),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(TAB())
|
|
]), handleTab),
|
|
rule(inSet(ESCAPE()), doEscape),
|
|
rule(inSet(SPACE().concat(ENTER())), execute$2)
|
|
]);
|
|
var getKeyupRules$1 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
|
|
var FlatgridType = typical(schema$5, flatgrid, getKeydownRules$1, getKeyupRules$1, function () {
|
|
return Option.some(focusIn);
|
|
});
|
|
|
|
var horizontal = function (container, selector, current, delta) {
|
|
var isDisabledButton = function (candidate) {
|
|
return name(candidate) === 'button' && get$2(candidate, 'disabled') === 'disabled';
|
|
};
|
|
var tryCycle = function (initial, index, candidates) {
|
|
var newIndex = cycleBy(index, delta, 0, candidates.length - 1);
|
|
if (newIndex === initial) {
|
|
return Option.none();
|
|
} else {
|
|
return isDisabledButton(candidates[newIndex]) ? tryCycle(initial, newIndex, candidates) : Option.from(candidates[newIndex]);
|
|
}
|
|
};
|
|
return locateVisible(container, current, selector).bind(function (identified) {
|
|
var index = identified.index();
|
|
var candidates = identified.candidates();
|
|
return tryCycle(index, index, candidates);
|
|
});
|
|
};
|
|
|
|
var schema$6 = [
|
|
strict$1('selector'),
|
|
defaulted$1('getInitial', Option.none),
|
|
defaulted$1('execute', defaultExecute),
|
|
onKeyboardHandler('onEscape'),
|
|
defaulted$1('executeOnMove', false),
|
|
defaulted$1('allowVertical', true)
|
|
];
|
|
var findCurrent$1 = function (component, flowConfig) {
|
|
return flowConfig.focusManager.get(component).bind(function (elem) {
|
|
return closest$3(elem, flowConfig.selector);
|
|
});
|
|
};
|
|
var execute$3 = function (component, simulatedEvent, flowConfig) {
|
|
return findCurrent$1(component, flowConfig).bind(function (focused) {
|
|
return flowConfig.execute(component, simulatedEvent, focused);
|
|
});
|
|
};
|
|
var focusIn$1 = function (component, flowConfig, _state) {
|
|
flowConfig.getInitial(component).orThunk(function () {
|
|
return descendant$1(component.element(), flowConfig.selector);
|
|
}).each(function (first) {
|
|
flowConfig.focusManager.set(component, first);
|
|
});
|
|
};
|
|
var moveLeft$1 = function (element, focused, info) {
|
|
return horizontal(element, info.selector, focused, -1);
|
|
};
|
|
var moveRight$1 = function (element, focused, info) {
|
|
return horizontal(element, info.selector, focused, +1);
|
|
};
|
|
var doMove$1 = function (movement) {
|
|
return function (component, simulatedEvent, flowConfig, flowState) {
|
|
return movement(component, simulatedEvent, flowConfig, flowState).bind(function () {
|
|
return flowConfig.executeOnMove ? execute$3(component, simulatedEvent, flowConfig) : Option.some(true);
|
|
});
|
|
};
|
|
};
|
|
var doEscape$1 = function (component, simulatedEvent, flowConfig) {
|
|
return flowConfig.onEscape(component, simulatedEvent);
|
|
};
|
|
var getKeydownRules$2 = function (_component, _se, flowConfig, _flowState) {
|
|
var westMovers = LEFT().concat(flowConfig.allowVertical ? UP() : []);
|
|
var eastMovers = RIGHT().concat(flowConfig.allowVertical ? DOWN() : []);
|
|
return [
|
|
rule(inSet(westMovers), doMove$1(west$2(moveLeft$1, moveRight$1))),
|
|
rule(inSet(eastMovers), doMove$1(east$2(moveLeft$1, moveRight$1))),
|
|
rule(inSet(ENTER()), execute$3),
|
|
rule(inSet(SPACE()), execute$3),
|
|
rule(inSet(ESCAPE()), doEscape$1)
|
|
];
|
|
};
|
|
var getKeyupRules$2 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
|
|
var FlowType = typical(schema$6, NoState.init, getKeydownRules$2, getKeyupRules$2, function () {
|
|
return Option.some(focusIn$1);
|
|
});
|
|
|
|
var toCell = function (matrix, rowIndex, columnIndex) {
|
|
return Option.from(matrix[rowIndex]).bind(function (row) {
|
|
return Option.from(row[columnIndex]).map(function (cell) {
|
|
return {
|
|
rowIndex: rowIndex,
|
|
columnIndex: columnIndex,
|
|
cell: cell
|
|
};
|
|
});
|
|
});
|
|
};
|
|
var cycleHorizontal$1 = function (matrix, rowIndex, startCol, deltaCol) {
|
|
var row = matrix[rowIndex];
|
|
var colsInRow = row.length;
|
|
var newColIndex = cycleBy(startCol, deltaCol, 0, colsInRow - 1);
|
|
return toCell(matrix, rowIndex, newColIndex);
|
|
};
|
|
var cycleVertical$1 = function (matrix, colIndex, startRow, deltaRow) {
|
|
var nextRowIndex = cycleBy(startRow, deltaRow, 0, matrix.length - 1);
|
|
var colsInNextRow = matrix[nextRowIndex].length;
|
|
var nextColIndex = clamp(colIndex, 0, colsInNextRow - 1);
|
|
return toCell(matrix, nextRowIndex, nextColIndex);
|
|
};
|
|
var moveHorizontal = function (matrix, rowIndex, startCol, deltaCol) {
|
|
var row = matrix[rowIndex];
|
|
var colsInRow = row.length;
|
|
var newColIndex = clamp(startCol + deltaCol, 0, colsInRow - 1);
|
|
return toCell(matrix, rowIndex, newColIndex);
|
|
};
|
|
var moveVertical = function (matrix, colIndex, startRow, deltaRow) {
|
|
var nextRowIndex = clamp(startRow + deltaRow, 0, matrix.length - 1);
|
|
var colsInNextRow = matrix[nextRowIndex].length;
|
|
var nextColIndex = clamp(colIndex, 0, colsInNextRow - 1);
|
|
return toCell(matrix, nextRowIndex, nextColIndex);
|
|
};
|
|
var cycleRight$1 = function (matrix, startRow, startCol) {
|
|
return cycleHorizontal$1(matrix, startRow, startCol, +1);
|
|
};
|
|
var cycleLeft$1 = function (matrix, startRow, startCol) {
|
|
return cycleHorizontal$1(matrix, startRow, startCol, -1);
|
|
};
|
|
var cycleUp$1 = function (matrix, startRow, startCol) {
|
|
return cycleVertical$1(matrix, startCol, startRow, -1);
|
|
};
|
|
var cycleDown$1 = function (matrix, startRow, startCol) {
|
|
return cycleVertical$1(matrix, startCol, startRow, +1);
|
|
};
|
|
var moveLeft$2 = function (matrix, startRow, startCol) {
|
|
return moveHorizontal(matrix, startRow, startCol, -1);
|
|
};
|
|
var moveRight$2 = function (matrix, startRow, startCol) {
|
|
return moveHorizontal(matrix, startRow, startCol, +1);
|
|
};
|
|
var moveUp = function (matrix, startRow, startCol) {
|
|
return moveVertical(matrix, startCol, startRow, -1);
|
|
};
|
|
var moveDown = function (matrix, startRow, startCol) {
|
|
return moveVertical(matrix, startCol, startRow, +1);
|
|
};
|
|
|
|
var schema$7 = [
|
|
strictObjOf('selectors', [
|
|
strict$1('row'),
|
|
strict$1('cell')
|
|
]),
|
|
defaulted$1('cycles', true),
|
|
defaulted$1('previousSelector', Option.none),
|
|
defaulted$1('execute', defaultExecute)
|
|
];
|
|
var focusIn$2 = function (component, matrixConfig, _state) {
|
|
var focused = matrixConfig.previousSelector(component).orThunk(function () {
|
|
var selectors = matrixConfig.selectors;
|
|
return descendant$1(component.element(), selectors.cell);
|
|
});
|
|
focused.each(function (cell) {
|
|
matrixConfig.focusManager.set(component, cell);
|
|
});
|
|
};
|
|
var execute$4 = function (component, simulatedEvent, matrixConfig) {
|
|
return search(component.element()).bind(function (focused) {
|
|
return matrixConfig.execute(component, simulatedEvent, focused);
|
|
});
|
|
};
|
|
var toMatrix = function (rows, matrixConfig) {
|
|
return map(rows, function (row) {
|
|
return descendants(row, matrixConfig.selectors.cell);
|
|
});
|
|
};
|
|
var doMove$2 = function (ifCycle, ifMove) {
|
|
return function (element, focused, matrixConfig) {
|
|
var move = matrixConfig.cycles ? ifCycle : ifMove;
|
|
return closest$3(focused, matrixConfig.selectors.row).bind(function (inRow) {
|
|
var cellsInRow = descendants(inRow, matrixConfig.selectors.cell);
|
|
return findIndex$1(cellsInRow, focused).bind(function (colIndex) {
|
|
var allRows = descendants(element, matrixConfig.selectors.row);
|
|
return findIndex$1(allRows, inRow).bind(function (rowIndex) {
|
|
var matrix = toMatrix(allRows, matrixConfig);
|
|
return move(matrix, rowIndex, colIndex).map(function (next) {
|
|
return next.cell;
|
|
});
|
|
});
|
|
});
|
|
});
|
|
};
|
|
};
|
|
var moveLeft$3 = doMove$2(cycleLeft$1, moveLeft$2);
|
|
var moveRight$3 = doMove$2(cycleRight$1, moveRight$2);
|
|
var moveNorth$1 = doMove$2(cycleUp$1, moveUp);
|
|
var moveSouth$1 = doMove$2(cycleDown$1, moveDown);
|
|
var getKeydownRules$3 = constant([
|
|
rule(inSet(LEFT()), west$2(moveLeft$3, moveRight$3)),
|
|
rule(inSet(RIGHT()), east$2(moveLeft$3, moveRight$3)),
|
|
rule(inSet(UP()), north$2(moveNorth$1)),
|
|
rule(inSet(DOWN()), south$2(moveSouth$1)),
|
|
rule(inSet(SPACE().concat(ENTER())), execute$4)
|
|
]);
|
|
var getKeyupRules$3 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
|
|
var MatrixType = typical(schema$7, NoState.init, getKeydownRules$3, getKeyupRules$3, function () {
|
|
return Option.some(focusIn$2);
|
|
});
|
|
|
|
var schema$8 = [
|
|
strict$1('selector'),
|
|
defaulted$1('execute', defaultExecute),
|
|
defaulted$1('moveOnTab', false)
|
|
];
|
|
var execute$5 = function (component, simulatedEvent, menuConfig) {
|
|
return menuConfig.focusManager.get(component).bind(function (focused) {
|
|
return menuConfig.execute(component, simulatedEvent, focused);
|
|
});
|
|
};
|
|
var focusIn$3 = function (component, menuConfig, _state) {
|
|
descendant$1(component.element(), menuConfig.selector).each(function (first) {
|
|
menuConfig.focusManager.set(component, first);
|
|
});
|
|
};
|
|
var moveUp$1 = function (element, focused, info) {
|
|
return horizontal(element, info.selector, focused, -1);
|
|
};
|
|
var moveDown$1 = function (element, focused, info) {
|
|
return horizontal(element, info.selector, focused, +1);
|
|
};
|
|
var fireShiftTab = function (component, simulatedEvent, menuConfig, menuState) {
|
|
return menuConfig.moveOnTab ? move(moveUp$1)(component, simulatedEvent, menuConfig, menuState) : Option.none();
|
|
};
|
|
var fireTab = function (component, simulatedEvent, menuConfig, menuState) {
|
|
return menuConfig.moveOnTab ? move(moveDown$1)(component, simulatedEvent, menuConfig, menuState) : Option.none();
|
|
};
|
|
var getKeydownRules$4 = constant([
|
|
rule(inSet(UP()), move(moveUp$1)),
|
|
rule(inSet(DOWN()), move(moveDown$1)),
|
|
rule(and([
|
|
isShift,
|
|
inSet(TAB())
|
|
]), fireShiftTab),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(TAB())
|
|
]), fireTab),
|
|
rule(inSet(ENTER()), execute$5),
|
|
rule(inSet(SPACE()), execute$5)
|
|
]);
|
|
var getKeyupRules$4 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
|
|
var MenuType = typical(schema$8, NoState.init, getKeydownRules$4, getKeyupRules$4, function () {
|
|
return Option.some(focusIn$3);
|
|
});
|
|
|
|
var schema$9 = [
|
|
onKeyboardHandler('onSpace'),
|
|
onKeyboardHandler('onEnter'),
|
|
onKeyboardHandler('onShiftEnter'),
|
|
onKeyboardHandler('onLeft'),
|
|
onKeyboardHandler('onRight'),
|
|
onKeyboardHandler('onTab'),
|
|
onKeyboardHandler('onShiftTab'),
|
|
onKeyboardHandler('onUp'),
|
|
onKeyboardHandler('onDown'),
|
|
onKeyboardHandler('onEscape'),
|
|
defaulted$1('stopSpaceKeyup', false),
|
|
option('focusIn')
|
|
];
|
|
var getKeydownRules$5 = function (component, simulatedEvent, specialInfo) {
|
|
return [
|
|
rule(inSet(SPACE()), specialInfo.onSpace),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(ENTER())
|
|
]), specialInfo.onEnter),
|
|
rule(and([
|
|
isShift,
|
|
inSet(ENTER())
|
|
]), specialInfo.onShiftEnter),
|
|
rule(and([
|
|
isShift,
|
|
inSet(TAB())
|
|
]), specialInfo.onShiftTab),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(TAB())
|
|
]), specialInfo.onTab),
|
|
rule(inSet(UP()), specialInfo.onUp),
|
|
rule(inSet(DOWN()), specialInfo.onDown),
|
|
rule(inSet(LEFT()), specialInfo.onLeft),
|
|
rule(inSet(RIGHT()), specialInfo.onRight),
|
|
rule(inSet(SPACE()), specialInfo.onSpace),
|
|
rule(inSet(ESCAPE()), specialInfo.onEscape)
|
|
];
|
|
};
|
|
var getKeyupRules$5 = function (component, simulatedEvent, specialInfo) {
|
|
return specialInfo.stopSpaceKeyup ? [rule(inSet(SPACE()), stopEventForFirefox)] : [];
|
|
};
|
|
var SpecialType = typical(schema$9, NoState.init, getKeydownRules$5, getKeyupRules$5, function (specialInfo) {
|
|
return specialInfo.focusIn;
|
|
});
|
|
|
|
var acyclic = AcyclicType.schema();
|
|
var cyclic = CyclicType.schema();
|
|
var flow = FlowType.schema();
|
|
var flatgrid$1 = FlatgridType.schema();
|
|
var matrix = MatrixType.schema();
|
|
var execution = ExecutionType.schema();
|
|
var menu = MenuType.schema();
|
|
var special = SpecialType.schema();
|
|
|
|
var KeyboardBranches = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
acyclic: acyclic,
|
|
cyclic: cyclic,
|
|
flow: flow,
|
|
flatgrid: flatgrid$1,
|
|
matrix: matrix,
|
|
execution: execution,
|
|
menu: menu,
|
|
special: special
|
|
});
|
|
|
|
var isFlatgridState = function (keyState) {
|
|
return hasNonNullableKey(keyState, 'setGridSize');
|
|
};
|
|
var Keying = createModes$1({
|
|
branchKey: 'mode',
|
|
branches: KeyboardBranches,
|
|
name: 'keying',
|
|
active: {
|
|
events: function (keyingConfig, keyingState) {
|
|
var handler = keyingConfig.handler;
|
|
return handler.toEvents(keyingConfig, keyingState);
|
|
}
|
|
},
|
|
apis: {
|
|
focusIn: function (component, keyConfig, keyState) {
|
|
keyConfig.sendFocusIn(keyConfig).fold(function () {
|
|
component.getSystem().triggerFocus(component.element(), component.element());
|
|
}, function (sendFocusIn) {
|
|
sendFocusIn(component, keyConfig, keyState);
|
|
});
|
|
},
|
|
setGridSize: function (component, keyConfig, keyState, numRows, numColumns) {
|
|
if (!isFlatgridState(keyState)) {
|
|
domGlobals.console.error('Layout does not support setGridSize');
|
|
} else {
|
|
keyState.setGridSize(numRows, numColumns);
|
|
}
|
|
}
|
|
},
|
|
state: KeyingState
|
|
});
|
|
|
|
var set$5 = function (component, replaceConfig, replaceState, data) {
|
|
preserve(function () {
|
|
var newChildren = map(data, component.getSystem().build);
|
|
replaceChildren(component, newChildren);
|
|
}, component.element());
|
|
};
|
|
var insert = function (component, replaceConfig, insertion, childSpec) {
|
|
var child = component.getSystem().build(childSpec);
|
|
attachWith(component, child, insertion);
|
|
};
|
|
var append$2 = function (component, replaceConfig, replaceState, appendee) {
|
|
insert(component, replaceConfig, append, appendee);
|
|
};
|
|
var prepend$1 = function (component, replaceConfig, replaceState, prependee) {
|
|
insert(component, replaceConfig, prepend, prependee);
|
|
};
|
|
var remove$7 = function (component, replaceConfig, replaceState, removee) {
|
|
var children = contents(component);
|
|
var foundChild = find(children, function (child) {
|
|
return eq$1(removee.element(), child.element());
|
|
});
|
|
foundChild.each(detach);
|
|
};
|
|
var contents = function (component, _replaceConfig) {
|
|
return component.components();
|
|
};
|
|
var replaceAt = function (component, replaceConfig, replaceState, replaceeIndex, replacer) {
|
|
var children = contents(component);
|
|
return Option.from(children[replaceeIndex]).map(function (replacee) {
|
|
remove$7(component, replaceConfig, replaceState, replacee);
|
|
replacer.each(function (r) {
|
|
insert(component, replaceConfig, function (p, c) {
|
|
appendAt(p, c, replaceeIndex);
|
|
}, r);
|
|
});
|
|
return replacee;
|
|
});
|
|
};
|
|
var replaceBy = function (component, replaceConfig, replaceState, replaceePred, replacer) {
|
|
var children = contents(component);
|
|
return findIndex(children, replaceePred).bind(function (replaceeIndex) {
|
|
return replaceAt(component, replaceConfig, replaceState, replaceeIndex, replacer);
|
|
});
|
|
};
|
|
|
|
var ReplaceApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
append: append$2,
|
|
prepend: prepend$1,
|
|
remove: remove$7,
|
|
replaceAt: replaceAt,
|
|
replaceBy: replaceBy,
|
|
set: set$5,
|
|
contents: contents
|
|
});
|
|
|
|
var Replacing = create$1({
|
|
fields: [],
|
|
name: 'replacing',
|
|
apis: ReplaceApis
|
|
});
|
|
|
|
var events$4 = function (name, eventHandlers) {
|
|
var events = derive(eventHandlers);
|
|
return create$1({
|
|
fields: [strict$1('enabled')],
|
|
name: name,
|
|
active: { events: constant(events) }
|
|
});
|
|
};
|
|
var config = function (name, eventHandlers) {
|
|
var me = events$4(name, eventHandlers);
|
|
return {
|
|
key: name,
|
|
value: {
|
|
config: {},
|
|
me: me,
|
|
configAsRaw: constant({}),
|
|
initialConfig: {},
|
|
state: NoState
|
|
}
|
|
};
|
|
};
|
|
|
|
var focus$2 = function (component, focusConfig) {
|
|
if (!focusConfig.ignore) {
|
|
focus$1(component.element());
|
|
focusConfig.onFocus(component);
|
|
}
|
|
};
|
|
var blur$1 = function (component, focusConfig) {
|
|
if (!focusConfig.ignore) {
|
|
blur(component.element());
|
|
}
|
|
};
|
|
var isFocused = function (component) {
|
|
return hasFocus(component.element());
|
|
};
|
|
|
|
var FocusApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
focus: focus$2,
|
|
blur: blur$1,
|
|
isFocused: isFocused
|
|
});
|
|
|
|
var exhibit$1 = function (base, focusConfig) {
|
|
var mod = focusConfig.ignore ? {} : { attributes: { tabindex: '-1' } };
|
|
return nu$6(mod);
|
|
};
|
|
var events$5 = function (focusConfig) {
|
|
return derive([run(focus(), function (component, simulatedEvent) {
|
|
focus$2(component, focusConfig);
|
|
simulatedEvent.stop();
|
|
})].concat(focusConfig.stopMousedown ? [run(mousedown(), function (_, simulatedEvent) {
|
|
simulatedEvent.event().prevent();
|
|
})] : []));
|
|
};
|
|
|
|
var ActiveFocus = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit$1,
|
|
events: events$5
|
|
});
|
|
|
|
var FocusSchema = [
|
|
onHandler('onFocus'),
|
|
defaulted$1('stopMousedown', false),
|
|
defaulted$1('ignore', false)
|
|
];
|
|
|
|
var Focusing = create$1({
|
|
fields: FocusSchema,
|
|
name: 'focusing',
|
|
active: ActiveFocus,
|
|
apis: FocusApis
|
|
});
|
|
|
|
var updateAriaState = function (component, toggleConfig, toggleState) {
|
|
var ariaInfo = toggleConfig.aria;
|
|
ariaInfo.update(component, ariaInfo, toggleState.get());
|
|
};
|
|
var updateClass = function (component, toggleConfig, toggleState) {
|
|
toggleConfig.toggleClass.each(function (toggleClass) {
|
|
if (toggleState.get()) {
|
|
add$2(component.element(), toggleClass);
|
|
} else {
|
|
remove$4(component.element(), toggleClass);
|
|
}
|
|
});
|
|
};
|
|
var toggle = function (component, toggleConfig, toggleState) {
|
|
set$6(component, toggleConfig, toggleState, !toggleState.get());
|
|
};
|
|
var on$1 = function (component, toggleConfig, toggleState) {
|
|
toggleState.set(true);
|
|
updateClass(component, toggleConfig, toggleState);
|
|
updateAriaState(component, toggleConfig, toggleState);
|
|
};
|
|
var off = function (component, toggleConfig, toggleState) {
|
|
toggleState.set(false);
|
|
updateClass(component, toggleConfig, toggleState);
|
|
updateAriaState(component, toggleConfig, toggleState);
|
|
};
|
|
var set$6 = function (component, toggleConfig, toggleState, state) {
|
|
var action = state ? on$1 : off;
|
|
action(component, toggleConfig, toggleState);
|
|
};
|
|
var isOn = function (component, toggleConfig, toggleState) {
|
|
return toggleState.get();
|
|
};
|
|
var onLoad$4 = function (component, toggleConfig, toggleState) {
|
|
set$6(component, toggleConfig, toggleState, toggleConfig.selected);
|
|
};
|
|
|
|
var ToggleApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
onLoad: onLoad$4,
|
|
toggle: toggle,
|
|
isOn: isOn,
|
|
on: on$1,
|
|
off: off,
|
|
set: set$6
|
|
});
|
|
|
|
var exhibit$2 = function () {
|
|
return nu$6({});
|
|
};
|
|
var events$6 = function (toggleConfig, toggleState) {
|
|
var execute = executeEvent(toggleConfig, toggleState, toggle);
|
|
var load = loadEvent(toggleConfig, toggleState, onLoad$4);
|
|
return derive(flatten([
|
|
toggleConfig.toggleOnExecute ? [execute] : [],
|
|
[load]
|
|
]));
|
|
};
|
|
|
|
var ActiveToggle = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit$2,
|
|
events: events$6
|
|
});
|
|
|
|
var SetupBehaviourCellState = function (initialState) {
|
|
var init = function () {
|
|
var cell = Cell(initialState);
|
|
var get = function () {
|
|
return cell.get();
|
|
};
|
|
var set = function (newState) {
|
|
return cell.set(newState);
|
|
};
|
|
var clear = function () {
|
|
return cell.set(initialState);
|
|
};
|
|
var readState = function () {
|
|
return cell.get();
|
|
};
|
|
return {
|
|
get: get,
|
|
set: set,
|
|
clear: clear,
|
|
readState: readState
|
|
};
|
|
};
|
|
return { init: init };
|
|
};
|
|
|
|
var updatePressed = function (component, ariaInfo, status) {
|
|
set$1(component.element(), 'aria-pressed', status);
|
|
if (ariaInfo.syncWithExpanded) {
|
|
updateExpanded(component, ariaInfo, status);
|
|
}
|
|
};
|
|
var updateSelected = function (component, ariaInfo, status) {
|
|
set$1(component.element(), 'aria-selected', status);
|
|
};
|
|
var updateChecked = function (component, ariaInfo, status) {
|
|
set$1(component.element(), 'aria-checked', status);
|
|
};
|
|
var updateExpanded = function (component, ariaInfo, status) {
|
|
set$1(component.element(), 'aria-expanded', status);
|
|
};
|
|
|
|
var ToggleSchema = [
|
|
defaulted$1('selected', false),
|
|
option('toggleClass'),
|
|
defaulted$1('toggleOnExecute', true),
|
|
defaultedOf('aria', { mode: 'none' }, choose$1('mode', {
|
|
pressed: [
|
|
defaulted$1('syncWithExpanded', false),
|
|
output('update', updatePressed)
|
|
],
|
|
checked: [output('update', updateChecked)],
|
|
expanded: [output('update', updateExpanded)],
|
|
selected: [output('update', updateSelected)],
|
|
none: [output('update', noop)]
|
|
}))
|
|
];
|
|
|
|
var Toggling = create$1({
|
|
fields: ToggleSchema,
|
|
name: 'toggling',
|
|
active: ActiveToggle,
|
|
apis: ToggleApis,
|
|
state: SetupBehaviourCellState(false)
|
|
});
|
|
|
|
var pointerEvents = function () {
|
|
var onClick = function (component, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
emitExecute(component);
|
|
};
|
|
return [
|
|
run(click(), onClick),
|
|
run(tap(), onClick),
|
|
cutter(touchstart()),
|
|
cutter(mousedown())
|
|
];
|
|
};
|
|
var events$7 = function (optAction) {
|
|
var executeHandler = function (action) {
|
|
return runOnExecute(function (component, simulatedEvent) {
|
|
action(component);
|
|
simulatedEvent.stop();
|
|
});
|
|
};
|
|
return derive(flatten([
|
|
optAction.map(executeHandler).toArray(),
|
|
pointerEvents()
|
|
]));
|
|
};
|
|
|
|
var hoverEvent = 'alloy.item-hover';
|
|
var focusEvent = 'alloy.item-focus';
|
|
var onHover = function (item) {
|
|
if (search(item.element()).isNone() || Focusing.isFocused(item)) {
|
|
if (!Focusing.isFocused(item)) {
|
|
Focusing.focus(item);
|
|
}
|
|
emitWith(item, hoverEvent, { item: item });
|
|
}
|
|
};
|
|
var onFocus = function (item) {
|
|
emitWith(item, focusEvent, { item: item });
|
|
};
|
|
var hover = constant(hoverEvent);
|
|
var focus$3 = constant(focusEvent);
|
|
|
|
var builder = function (detail) {
|
|
return {
|
|
dom: detail.dom,
|
|
domModification: __assign(__assign({}, detail.domModification), { attributes: __assign(__assign(__assign({ 'role': detail.toggling.isSome() ? 'menuitemcheckbox' : 'menuitem' }, detail.domModification.attributes), { 'aria-haspopup': detail.hasSubmenu }), detail.hasSubmenu ? { 'aria-expanded': false } : {}) }),
|
|
behaviours: SketchBehaviours.augment(detail.itemBehaviours, [
|
|
detail.toggling.fold(Toggling.revoke, function (tConfig) {
|
|
return Toggling.config(__assign({ aria: { mode: 'checked' } }, tConfig));
|
|
}),
|
|
Focusing.config({
|
|
ignore: detail.ignoreFocus,
|
|
stopMousedown: detail.ignoreFocus,
|
|
onFocus: function (component) {
|
|
onFocus(component);
|
|
}
|
|
}),
|
|
Keying.config({ mode: 'execution' }),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: detail.data
|
|
}
|
|
}),
|
|
config('item-type-events', __spreadArrays(pointerEvents(), [
|
|
run(mouseover(), onHover),
|
|
run(focusItem(), Focusing.focus)
|
|
]))
|
|
]),
|
|
components: detail.components,
|
|
eventOrder: detail.eventOrder
|
|
};
|
|
};
|
|
var schema$a = [
|
|
strict$1('data'),
|
|
strict$1('components'),
|
|
strict$1('dom'),
|
|
defaulted$1('hasSubmenu', false),
|
|
option('toggling'),
|
|
SketchBehaviours.field('itemBehaviours', [
|
|
Toggling,
|
|
Focusing,
|
|
Keying,
|
|
Representing
|
|
]),
|
|
defaulted$1('ignoreFocus', false),
|
|
defaulted$1('domModification', {}),
|
|
output('builder', builder),
|
|
defaulted$1('eventOrder', {})
|
|
];
|
|
|
|
var builder$1 = function (detail) {
|
|
return {
|
|
dom: detail.dom,
|
|
components: detail.components,
|
|
events: derive([stopper(focusItem())])
|
|
};
|
|
};
|
|
var schema$b = [
|
|
strict$1('dom'),
|
|
strict$1('components'),
|
|
output('builder', builder$1)
|
|
];
|
|
|
|
var owner$2 = function () {
|
|
return 'item-widget';
|
|
};
|
|
var parts = constant([required({
|
|
name: 'widget',
|
|
overrides: function (detail) {
|
|
return {
|
|
behaviours: derive$1([Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (_component) {
|
|
return detail.data;
|
|
},
|
|
setValue: function () {
|
|
}
|
|
}
|
|
})])
|
|
};
|
|
}
|
|
})]);
|
|
|
|
var builder$2 = function (detail) {
|
|
var subs = substitutes(owner$2(), detail, parts());
|
|
var components$1 = components(owner$2(), detail, subs.internals());
|
|
var focusWidget = function (component) {
|
|
return getPart(component, detail, 'widget').map(function (widget) {
|
|
Keying.focusIn(widget);
|
|
return widget;
|
|
});
|
|
};
|
|
var onHorizontalArrow = function (component, simulatedEvent) {
|
|
return inside(simulatedEvent.event().target()) ? Option.none() : function () {
|
|
if (detail.autofocus) {
|
|
simulatedEvent.setSource(component.element());
|
|
return Option.none();
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
}();
|
|
};
|
|
return {
|
|
dom: detail.dom,
|
|
components: components$1,
|
|
domModification: detail.domModification,
|
|
events: derive([
|
|
runOnExecute(function (component, simulatedEvent) {
|
|
focusWidget(component).each(function (_widget) {
|
|
simulatedEvent.stop();
|
|
});
|
|
}),
|
|
run(mouseover(), onHover),
|
|
run(focusItem(), function (component, _simulatedEvent) {
|
|
if (detail.autofocus) {
|
|
focusWidget(component);
|
|
} else {
|
|
Focusing.focus(component);
|
|
}
|
|
})
|
|
]),
|
|
behaviours: SketchBehaviours.augment(detail.widgetBehaviours, [
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: detail.data
|
|
}
|
|
}),
|
|
Focusing.config({
|
|
ignore: detail.ignoreFocus,
|
|
onFocus: function (component) {
|
|
onFocus(component);
|
|
}
|
|
}),
|
|
Keying.config({
|
|
mode: 'special',
|
|
focusIn: detail.autofocus ? function (component) {
|
|
focusWidget(component);
|
|
} : revoke(),
|
|
onLeft: onHorizontalArrow,
|
|
onRight: onHorizontalArrow,
|
|
onEscape: function (component, simulatedEvent) {
|
|
if (!Focusing.isFocused(component) && !detail.autofocus) {
|
|
Focusing.focus(component);
|
|
return Option.some(true);
|
|
} else if (detail.autofocus) {
|
|
simulatedEvent.setSource(component.element());
|
|
return Option.none();
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
}
|
|
})
|
|
])
|
|
};
|
|
};
|
|
var schema$c = [
|
|
strict$1('uid'),
|
|
strict$1('data'),
|
|
strict$1('components'),
|
|
strict$1('dom'),
|
|
defaulted$1('autofocus', false),
|
|
defaulted$1('ignoreFocus', false),
|
|
SketchBehaviours.field('widgetBehaviours', [
|
|
Representing,
|
|
Focusing,
|
|
Keying
|
|
]),
|
|
defaulted$1('domModification', {}),
|
|
defaultUidsSchema(parts()),
|
|
output('builder', builder$2)
|
|
];
|
|
|
|
var itemSchema$1 = choose$1('type', {
|
|
widget: schema$c,
|
|
item: schema$a,
|
|
separator: schema$b
|
|
});
|
|
var configureGrid = function (detail, movementInfo) {
|
|
return {
|
|
mode: 'flatgrid',
|
|
selector: '.' + detail.markers.item,
|
|
initSize: {
|
|
numColumns: movementInfo.initSize.numColumns,
|
|
numRows: movementInfo.initSize.numRows
|
|
},
|
|
focusManager: detail.focusManager
|
|
};
|
|
};
|
|
var configureMatrix = function (detail, movementInfo) {
|
|
return {
|
|
mode: 'matrix',
|
|
selectors: {
|
|
row: movementInfo.rowSelector,
|
|
cell: '.' + detail.markers.item
|
|
},
|
|
focusManager: detail.focusManager
|
|
};
|
|
};
|
|
var configureMenu = function (detail, movementInfo) {
|
|
return {
|
|
mode: 'menu',
|
|
selector: '.' + detail.markers.item,
|
|
moveOnTab: movementInfo.moveOnTab,
|
|
focusManager: detail.focusManager
|
|
};
|
|
};
|
|
var parts$1 = constant([group({
|
|
factory: {
|
|
sketch: function (spec) {
|
|
var itemInfo = asRawOrDie('menu.spec item', itemSchema$1, spec);
|
|
return itemInfo.builder(itemInfo);
|
|
}
|
|
},
|
|
name: 'items',
|
|
unit: 'item',
|
|
defaults: function (detail, u) {
|
|
return u.hasOwnProperty('uid') ? u : __assign(__assign({}, u), { uid: generate$2('item') });
|
|
},
|
|
overrides: function (detail, u) {
|
|
return {
|
|
type: u.type,
|
|
ignoreFocus: detail.fakeFocus,
|
|
domModification: { classes: [detail.markers.item] }
|
|
};
|
|
}
|
|
})]);
|
|
var schema$d = constant([
|
|
strict$1('value'),
|
|
strict$1('items'),
|
|
strict$1('dom'),
|
|
strict$1('components'),
|
|
defaulted$1('eventOrder', {}),
|
|
field$1('menuBehaviours', [
|
|
Highlighting,
|
|
Representing,
|
|
Composing,
|
|
Keying
|
|
]),
|
|
defaultedOf('movement', {
|
|
mode: 'menu',
|
|
moveOnTab: true
|
|
}, choose$1('mode', {
|
|
grid: [
|
|
initSize(),
|
|
output('config', configureGrid)
|
|
],
|
|
matrix: [
|
|
output('config', configureMatrix),
|
|
strict$1('rowSelector')
|
|
],
|
|
menu: [
|
|
defaulted$1('moveOnTab', true),
|
|
output('config', configureMenu)
|
|
]
|
|
})),
|
|
itemMarkers(),
|
|
defaulted$1('fakeFocus', false),
|
|
defaulted$1('focusManager', dom()),
|
|
onHandler('onHighlight')
|
|
]);
|
|
|
|
var focus$4 = constant('alloy.menu-focus');
|
|
|
|
var make$1 = function (detail, components, _spec, _externals) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
markers: detail.markers,
|
|
behaviours: augment(detail.menuBehaviours, [
|
|
Highlighting.config({
|
|
highlightClass: detail.markers.selectedItem,
|
|
itemClass: detail.markers.item,
|
|
onHighlight: detail.onHighlight
|
|
}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: detail.value
|
|
}
|
|
}),
|
|
Composing.config({ find: Option.some }),
|
|
Keying.config(detail.movement.config(detail, detail.movement))
|
|
]),
|
|
events: derive([
|
|
run(focus$3(), function (menu, simulatedEvent) {
|
|
var event = simulatedEvent.event();
|
|
menu.getSystem().getByDom(event.target()).each(function (item) {
|
|
Highlighting.highlight(menu, item);
|
|
simulatedEvent.stop();
|
|
emitWith(menu, focus$4(), {
|
|
menu: menu,
|
|
item: item
|
|
});
|
|
});
|
|
}),
|
|
run(hover(), function (menu, simulatedEvent) {
|
|
var item = simulatedEvent.event().item();
|
|
Highlighting.highlight(menu, item);
|
|
})
|
|
]),
|
|
components: components,
|
|
eventOrder: detail.eventOrder,
|
|
domModification: { attributes: { role: 'menu' } }
|
|
};
|
|
};
|
|
|
|
var Menu = composite$1({
|
|
name: 'Menu',
|
|
configFields: schema$d(),
|
|
partFields: parts$1(),
|
|
factory: make$1
|
|
});
|
|
|
|
var transpose = function (obj) {
|
|
return tupleMap(obj, function (v, k) {
|
|
return {
|
|
k: v,
|
|
v: k
|
|
};
|
|
});
|
|
};
|
|
var trace = function (items, byItem, byMenu, finish) {
|
|
return get(byMenu, finish).bind(function (triggerItem) {
|
|
return get(items, triggerItem).bind(function (triggerMenu) {
|
|
var rest = trace(items, byItem, byMenu, triggerMenu);
|
|
return Option.some([triggerMenu].concat(rest));
|
|
});
|
|
}).getOr([]);
|
|
};
|
|
var generate$5 = function (menus, expansions) {
|
|
var items = {};
|
|
each$1(menus, function (menuItems, menu) {
|
|
each(menuItems, function (item) {
|
|
items[item] = menu;
|
|
});
|
|
});
|
|
var byItem = expansions;
|
|
var byMenu = transpose(expansions);
|
|
var menuPaths = map$1(byMenu, function (_triggerItem, submenu) {
|
|
return [submenu].concat(trace(items, byItem, byMenu, submenu));
|
|
});
|
|
return map$1(items, function (menu) {
|
|
return get(menuPaths, menu).getOr([menu]);
|
|
});
|
|
};
|
|
|
|
var init$3 = function () {
|
|
var expansions = Cell({});
|
|
var menus = Cell({});
|
|
var paths = Cell({});
|
|
var primary = Cell(Option.none());
|
|
var directory = Cell({});
|
|
var clear = function () {
|
|
expansions.set({});
|
|
menus.set({});
|
|
paths.set({});
|
|
primary.set(Option.none());
|
|
};
|
|
var isClear = function () {
|
|
return primary.get().isNone();
|
|
};
|
|
var setMenuBuilt = function (menuName, built) {
|
|
var _a;
|
|
menus.set(__assign(__assign({}, menus.get()), (_a = {}, _a[menuName] = {
|
|
type: 'prepared',
|
|
menu: built
|
|
}, _a)));
|
|
};
|
|
var setContents = function (sPrimary, sMenus, sExpansions, dir) {
|
|
primary.set(Option.some(sPrimary));
|
|
expansions.set(sExpansions);
|
|
menus.set(sMenus);
|
|
directory.set(dir);
|
|
var sPaths = generate$5(dir, sExpansions);
|
|
paths.set(sPaths);
|
|
};
|
|
var getTriggeringItem = function (menuValue) {
|
|
return find$1(expansions.get(), function (v, _k) {
|
|
return v === menuValue;
|
|
});
|
|
};
|
|
var getTriggerData = function (menuValue, getItemByValue, path) {
|
|
return getPreparedMenu(menuValue).bind(function (menu) {
|
|
return getTriggeringItem(menuValue).bind(function (triggeringItemValue) {
|
|
return getItemByValue(triggeringItemValue).map(function (triggeredItem) {
|
|
return {
|
|
triggeredMenu: menu,
|
|
triggeringItem: triggeredItem,
|
|
triggeringPath: path
|
|
};
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var getTriggeringPath = function (itemValue, getItemByValue) {
|
|
var extraPath = filter(lookupItem(itemValue).toArray(), function (menuValue) {
|
|
return getPreparedMenu(menuValue).isSome();
|
|
});
|
|
return get(paths.get(), itemValue).bind(function (path) {
|
|
var revPath = reverse(extraPath.concat(path));
|
|
var triggers = bind(revPath, function (menuValue, menuIndex) {
|
|
return getTriggerData(menuValue, getItemByValue, revPath.slice(0, menuIndex + 1)).fold(function () {
|
|
return primary.get().is(menuValue) ? [] : [Option.none()];
|
|
}, function (data) {
|
|
return [Option.some(data)];
|
|
});
|
|
});
|
|
return sequence(triggers);
|
|
});
|
|
};
|
|
var expand = function (itemValue) {
|
|
return get(expansions.get(), itemValue).map(function (menu) {
|
|
var current = get(paths.get(), itemValue).getOr([]);
|
|
return [menu].concat(current);
|
|
});
|
|
};
|
|
var collapse = function (itemValue) {
|
|
return get(paths.get(), itemValue).bind(function (path) {
|
|
return path.length > 1 ? Option.some(path.slice(1)) : Option.none();
|
|
});
|
|
};
|
|
var refresh = function (itemValue) {
|
|
return get(paths.get(), itemValue);
|
|
};
|
|
var getPreparedMenu = function (menuValue) {
|
|
return lookupMenu(menuValue).bind(extractPreparedMenu);
|
|
};
|
|
var lookupMenu = function (menuValue) {
|
|
return get(menus.get(), menuValue);
|
|
};
|
|
var lookupItem = function (itemValue) {
|
|
return get(expansions.get(), itemValue);
|
|
};
|
|
var otherMenus = function (path) {
|
|
var menuValues = directory.get();
|
|
return difference(keys(menuValues), path);
|
|
};
|
|
var getPrimary = function () {
|
|
return primary.get().bind(getPreparedMenu);
|
|
};
|
|
var getMenus = function () {
|
|
return menus.get();
|
|
};
|
|
return {
|
|
setMenuBuilt: setMenuBuilt,
|
|
setContents: setContents,
|
|
expand: expand,
|
|
refresh: refresh,
|
|
collapse: collapse,
|
|
lookupMenu: lookupMenu,
|
|
lookupItem: lookupItem,
|
|
otherMenus: otherMenus,
|
|
getPrimary: getPrimary,
|
|
getMenus: getMenus,
|
|
clear: clear,
|
|
isClear: isClear,
|
|
getTriggeringPath: getTriggeringPath
|
|
};
|
|
};
|
|
var extractPreparedMenu = function (prep) {
|
|
return prep.type === 'prepared' ? Option.some(prep.menu) : Option.none();
|
|
};
|
|
var LayeredState = {
|
|
init: init$3,
|
|
extractPreparedMenu: extractPreparedMenu
|
|
};
|
|
|
|
var make$2 = function (detail, _rawUiSpec) {
|
|
var submenuParentItems = Cell(Option.none());
|
|
var buildMenus = function (container, primaryName, menus) {
|
|
return map$1(menus, function (spec, name) {
|
|
var makeSketch = function () {
|
|
return Menu.sketch(__assign(__assign({ dom: spec.dom }, spec), {
|
|
value: name,
|
|
items: spec.items,
|
|
markers: detail.markers,
|
|
fakeFocus: detail.fakeFocus,
|
|
onHighlight: detail.onHighlight,
|
|
focusManager: detail.fakeFocus ? highlights() : dom()
|
|
}));
|
|
};
|
|
return name === primaryName ? {
|
|
type: 'prepared',
|
|
menu: container.getSystem().build(makeSketch())
|
|
} : {
|
|
type: 'notbuilt',
|
|
nbMenu: makeSketch
|
|
};
|
|
});
|
|
};
|
|
var layeredState = LayeredState.init();
|
|
var setup = function (container) {
|
|
var componentMap = buildMenus(container, detail.data.primary, detail.data.menus);
|
|
var directory = toDirectory();
|
|
layeredState.setContents(detail.data.primary, componentMap, detail.data.expansions, directory);
|
|
return layeredState.getPrimary();
|
|
};
|
|
var getItemValue = function (item) {
|
|
return Representing.getValue(item).value;
|
|
};
|
|
var getItemByValue = function (_container, menus, itemValue) {
|
|
return findMap(menus, function (menu) {
|
|
if (!menu.getSystem().isConnected()) {
|
|
return Option.none();
|
|
}
|
|
var candidates = Highlighting.getCandidates(menu);
|
|
return find(candidates, function (c) {
|
|
return getItemValue(c) === itemValue;
|
|
});
|
|
});
|
|
};
|
|
var toDirectory = function (_container) {
|
|
return map$1(detail.data.menus, function (data, _menuName) {
|
|
return bind(data.items, function (item) {
|
|
return item.type === 'separator' ? [] : [item.data.value];
|
|
});
|
|
});
|
|
};
|
|
var setActiveMenu = function (container, menu) {
|
|
Highlighting.highlight(container, menu);
|
|
Highlighting.getHighlighted(menu).orThunk(function () {
|
|
return Highlighting.getFirst(menu);
|
|
}).each(function (item) {
|
|
dispatch(container, item.element(), focusItem());
|
|
});
|
|
};
|
|
var getMenus = function (state, menuValues) {
|
|
return cat(map(menuValues, function (mv) {
|
|
return state.lookupMenu(mv).bind(function (prep) {
|
|
return prep.type === 'prepared' ? Option.some(prep.menu) : Option.none();
|
|
});
|
|
}));
|
|
};
|
|
var closeOthers = function (container, state, path) {
|
|
var others = getMenus(state, state.otherMenus(path));
|
|
each(others, function (o) {
|
|
remove$5(o.element(), [detail.markers.backgroundMenu]);
|
|
if (!detail.stayInDom) {
|
|
Replacing.remove(container, o);
|
|
}
|
|
});
|
|
};
|
|
var getSubmenuParents = function (container) {
|
|
return submenuParentItems.get().getOrThunk(function () {
|
|
var r = {};
|
|
var items = descendants(container.element(), '.' + detail.markers.item);
|
|
var parentItems = filter(items, function (i) {
|
|
return get$2(i, 'aria-haspopup') === 'true';
|
|
});
|
|
each(parentItems, function (i) {
|
|
container.getSystem().getByDom(i).each(function (itemComp) {
|
|
var key = getItemValue(itemComp);
|
|
r[key] = itemComp;
|
|
});
|
|
});
|
|
submenuParentItems.set(Option.some(r));
|
|
return r;
|
|
});
|
|
};
|
|
var updateAriaExpansions = function (container, path) {
|
|
var parentItems = getSubmenuParents(container);
|
|
each$1(parentItems, function (v, k) {
|
|
var expanded = contains(path, k);
|
|
set$1(v.element(), 'aria-expanded', expanded);
|
|
});
|
|
};
|
|
var updateMenuPath = function (container, state, path) {
|
|
return Option.from(path[0]).bind(function (latestMenuName) {
|
|
return state.lookupMenu(latestMenuName).bind(function (menuPrep) {
|
|
if (menuPrep.type === 'notbuilt') {
|
|
return Option.none();
|
|
} else {
|
|
var activeMenu = menuPrep.menu;
|
|
var rest = getMenus(state, path.slice(1));
|
|
each(rest, function (r) {
|
|
add$2(r.element(), detail.markers.backgroundMenu);
|
|
});
|
|
if (!inBody(activeMenu.element())) {
|
|
Replacing.append(container, premade$1(activeMenu));
|
|
}
|
|
remove$5(activeMenu.element(), [detail.markers.backgroundMenu]);
|
|
setActiveMenu(container, activeMenu);
|
|
closeOthers(container, state, path);
|
|
return Option.some(activeMenu);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
var ExpandHighlightDecision;
|
|
(function (ExpandHighlightDecision) {
|
|
ExpandHighlightDecision[ExpandHighlightDecision['HighlightSubmenu'] = 0] = 'HighlightSubmenu';
|
|
ExpandHighlightDecision[ExpandHighlightDecision['HighlightParent'] = 1] = 'HighlightParent';
|
|
}(ExpandHighlightDecision || (ExpandHighlightDecision = {})));
|
|
var buildIfRequired = function (container, menuName, menuPrep) {
|
|
if (menuPrep.type === 'notbuilt') {
|
|
var menu = container.getSystem().build(menuPrep.nbMenu());
|
|
layeredState.setMenuBuilt(menuName, menu);
|
|
return menu;
|
|
} else {
|
|
return menuPrep.menu;
|
|
}
|
|
};
|
|
var expandRight = function (container, item, decision) {
|
|
if (decision === void 0) {
|
|
decision = ExpandHighlightDecision.HighlightSubmenu;
|
|
}
|
|
var value = getItemValue(item);
|
|
return layeredState.expand(value).bind(function (path) {
|
|
updateAriaExpansions(container, path);
|
|
return Option.from(path[0]).bind(function (menuName) {
|
|
return layeredState.lookupMenu(menuName).bind(function (activeMenuPrep) {
|
|
var activeMenu = buildIfRequired(container, menuName, activeMenuPrep);
|
|
if (!inBody(activeMenu.element())) {
|
|
Replacing.append(container, premade$1(activeMenu));
|
|
}
|
|
detail.onOpenSubmenu(container, item, activeMenu, reverse(path));
|
|
if (decision === ExpandHighlightDecision.HighlightSubmenu) {
|
|
Highlighting.highlightFirst(activeMenu);
|
|
return updateMenuPath(container, layeredState, path);
|
|
} else {
|
|
Highlighting.dehighlightAll(activeMenu);
|
|
return Option.some(item);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var collapseLeft = function (container, item) {
|
|
var value = getItemValue(item);
|
|
return layeredState.collapse(value).bind(function (path) {
|
|
updateAriaExpansions(container, path);
|
|
return updateMenuPath(container, layeredState, path).map(function (activeMenu) {
|
|
detail.onCollapseMenu(container, item, activeMenu);
|
|
return activeMenu;
|
|
});
|
|
});
|
|
};
|
|
var updateView = function (container, item) {
|
|
var value = getItemValue(item);
|
|
return layeredState.refresh(value).bind(function (path) {
|
|
updateAriaExpansions(container, path);
|
|
return updateMenuPath(container, layeredState, path);
|
|
});
|
|
};
|
|
var onRight = function (container, item) {
|
|
return inside(item.element()) ? Option.none() : expandRight(container, item, ExpandHighlightDecision.HighlightSubmenu);
|
|
};
|
|
var onLeft = function (container, item) {
|
|
return inside(item.element()) ? Option.none() : collapseLeft(container, item);
|
|
};
|
|
var onEscape = function (container, item) {
|
|
return collapseLeft(container, item).orThunk(function () {
|
|
return detail.onEscape(container, item).map(function () {
|
|
return container;
|
|
});
|
|
});
|
|
};
|
|
var keyOnItem = function (f) {
|
|
return function (container, simulatedEvent) {
|
|
return closest$3(simulatedEvent.getSource(), '.' + detail.markers.item).bind(function (target) {
|
|
return container.getSystem().getByDom(target).toOption().bind(function (item) {
|
|
return f(container, item).map(function () {
|
|
return true;
|
|
});
|
|
});
|
|
});
|
|
};
|
|
};
|
|
var events = derive([
|
|
run(focus$4(), function (sandbox, simulatedEvent) {
|
|
var item = simulatedEvent.event().item();
|
|
layeredState.lookupItem(getItemValue(item)).each(function () {
|
|
var menu = simulatedEvent.event().menu();
|
|
Highlighting.highlight(sandbox, menu);
|
|
var value = getItemValue(simulatedEvent.event().item());
|
|
layeredState.refresh(value).each(function (path) {
|
|
return closeOthers(sandbox, layeredState, path);
|
|
});
|
|
});
|
|
}),
|
|
runOnExecute(function (component, simulatedEvent) {
|
|
var target = simulatedEvent.event().target();
|
|
component.getSystem().getByDom(target).each(function (item) {
|
|
var itemValue = getItemValue(item);
|
|
if (itemValue.indexOf('collapse-item') === 0) {
|
|
collapseLeft(component, item);
|
|
}
|
|
expandRight(component, item, ExpandHighlightDecision.HighlightSubmenu).fold(function () {
|
|
detail.onExecute(component, item);
|
|
}, function () {
|
|
});
|
|
});
|
|
}),
|
|
runOnAttached(function (container, _simulatedEvent) {
|
|
setup(container).each(function (primary) {
|
|
Replacing.append(container, premade$1(primary));
|
|
detail.onOpenMenu(container, primary);
|
|
if (detail.highlightImmediately) {
|
|
setActiveMenu(container, primary);
|
|
}
|
|
});
|
|
})
|
|
].concat(detail.navigateOnHover ? [run(hover(), function (sandbox, simulatedEvent) {
|
|
var item = simulatedEvent.event().item();
|
|
updateView(sandbox, item);
|
|
expandRight(sandbox, item, ExpandHighlightDecision.HighlightParent);
|
|
detail.onHover(sandbox, item);
|
|
})] : []));
|
|
var getActiveItem = function (container) {
|
|
return Highlighting.getHighlighted(container).bind(Highlighting.getHighlighted);
|
|
};
|
|
var collapseMenuApi = function (container) {
|
|
getActiveItem(container).each(function (currentItem) {
|
|
collapseLeft(container, currentItem);
|
|
});
|
|
};
|
|
var highlightPrimary = function (container) {
|
|
layeredState.getPrimary().each(function (primary) {
|
|
setActiveMenu(container, primary);
|
|
});
|
|
};
|
|
var extractMenuFromContainer = function (container) {
|
|
return Option.from(container.components()[0]).filter(function (comp) {
|
|
return get$2(comp.element(), 'role') === 'menu';
|
|
});
|
|
};
|
|
var repositionMenus = function (container) {
|
|
var maybeActivePrimary = layeredState.getPrimary().bind(function (primary) {
|
|
return getActiveItem(container).bind(function (currentItem) {
|
|
var itemValue = getItemValue(currentItem);
|
|
var allMenus = values(layeredState.getMenus());
|
|
var preparedMenus = cat(map(allMenus, LayeredState.extractPreparedMenu));
|
|
return layeredState.getTriggeringPath(itemValue, function (v) {
|
|
return getItemByValue(container, preparedMenus, v);
|
|
});
|
|
}).map(function (triggeringPath) {
|
|
return {
|
|
primary: primary,
|
|
triggeringPath: triggeringPath
|
|
};
|
|
});
|
|
});
|
|
maybeActivePrimary.fold(function () {
|
|
extractMenuFromContainer(container).each(function (primaryMenu) {
|
|
detail.onRepositionMenu(container, primaryMenu, []);
|
|
});
|
|
}, function (_a) {
|
|
var primary = _a.primary, triggeringPath = _a.triggeringPath;
|
|
detail.onRepositionMenu(container, primary, triggeringPath);
|
|
});
|
|
};
|
|
var apis = {
|
|
collapseMenu: collapseMenuApi,
|
|
highlightPrimary: highlightPrimary,
|
|
repositionMenus: repositionMenus
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
markers: detail.markers,
|
|
behaviours: augment(detail.tmenuBehaviours, [
|
|
Keying.config({
|
|
mode: 'special',
|
|
onRight: keyOnItem(onRight),
|
|
onLeft: keyOnItem(onLeft),
|
|
onEscape: keyOnItem(onEscape),
|
|
focusIn: function (container, _keyInfo) {
|
|
layeredState.getPrimary().each(function (primary) {
|
|
dispatch(container, primary.element(), focusItem());
|
|
});
|
|
}
|
|
}),
|
|
Highlighting.config({
|
|
highlightClass: detail.markers.selectedMenu,
|
|
itemClass: detail.markers.menu
|
|
}),
|
|
Composing.config({
|
|
find: function (container) {
|
|
return Highlighting.getHighlighted(container);
|
|
}
|
|
}),
|
|
Replacing.config({})
|
|
]),
|
|
eventOrder: detail.eventOrder,
|
|
apis: apis,
|
|
events: events
|
|
};
|
|
};
|
|
var collapseItem = constant('collapse-item');
|
|
|
|
var tieredData = function (primary, menus, expansions) {
|
|
return {
|
|
primary: primary,
|
|
menus: menus,
|
|
expansions: expansions
|
|
};
|
|
};
|
|
var singleData = function (name, menu) {
|
|
return {
|
|
primary: name,
|
|
menus: wrap$1(name, menu),
|
|
expansions: {}
|
|
};
|
|
};
|
|
var collapseItem$1 = function (text) {
|
|
return {
|
|
value: generate$1(collapseItem()),
|
|
meta: { text: text }
|
|
};
|
|
};
|
|
var tieredMenu = single$2({
|
|
name: 'TieredMenu',
|
|
configFields: [
|
|
onStrictKeyboardHandler('onExecute'),
|
|
onStrictKeyboardHandler('onEscape'),
|
|
onStrictHandler('onOpenMenu'),
|
|
onStrictHandler('onOpenSubmenu'),
|
|
onHandler('onRepositionMenu'),
|
|
onHandler('onCollapseMenu'),
|
|
defaulted$1('highlightImmediately', true),
|
|
strictObjOf('data', [
|
|
strict$1('primary'),
|
|
strict$1('menus'),
|
|
strict$1('expansions')
|
|
]),
|
|
defaulted$1('fakeFocus', false),
|
|
onHandler('onHighlight'),
|
|
onHandler('onHover'),
|
|
tieredMenuMarkers(),
|
|
strict$1('dom'),
|
|
defaulted$1('navigateOnHover', true),
|
|
defaulted$1('stayInDom', false),
|
|
field$1('tmenuBehaviours', [
|
|
Keying,
|
|
Highlighting,
|
|
Composing,
|
|
Replacing
|
|
]),
|
|
defaulted$1('eventOrder', {})
|
|
],
|
|
apis: {
|
|
collapseMenu: function (apis, tmenu) {
|
|
apis.collapseMenu(tmenu);
|
|
},
|
|
highlightPrimary: function (apis, tmenu) {
|
|
apis.highlightPrimary(tmenu);
|
|
},
|
|
repositionMenus: function (apis, tmenu) {
|
|
apis.repositionMenus(tmenu);
|
|
}
|
|
},
|
|
factory: make$2,
|
|
extraApis: {
|
|
tieredData: tieredData,
|
|
singleData: singleData,
|
|
collapseItem: collapseItem$1
|
|
}
|
|
});
|
|
|
|
var makeMenu = function (detail, menuSandbox, anchor, menuSpec, getBounds) {
|
|
var lazySink = function () {
|
|
return detail.lazySink(menuSandbox);
|
|
};
|
|
var layouts = menuSpec.type === 'horizontal' ? {
|
|
layouts: {
|
|
onLtr: function () {
|
|
return belowOrAbove();
|
|
},
|
|
onRtl: function () {
|
|
return belowOrAboveRtl();
|
|
}
|
|
}
|
|
} : {};
|
|
var isFirstTierSubmenu = function (triggeringPaths) {
|
|
return triggeringPaths.length === 2;
|
|
};
|
|
var getSubmenuLayouts = function (triggeringPaths) {
|
|
return isFirstTierSubmenu(triggeringPaths) ? layouts : {};
|
|
};
|
|
return tieredMenu.sketch({
|
|
dom: { tag: 'div' },
|
|
data: menuSpec.data,
|
|
markers: menuSpec.menu.markers,
|
|
highlightImmediately: menuSpec.menu.highlightImmediately,
|
|
onEscape: function () {
|
|
Sandboxing.close(menuSandbox);
|
|
detail.onEscape.map(function (handler) {
|
|
return handler(menuSandbox);
|
|
});
|
|
return Option.some(true);
|
|
},
|
|
onExecute: function () {
|
|
return Option.some(true);
|
|
},
|
|
onOpenMenu: function (tmenu, menu) {
|
|
Positioning.positionWithinBounds(lazySink().getOrDie(), anchor, menu, getBounds());
|
|
},
|
|
onOpenSubmenu: function (tmenu, item, submenu, triggeringPaths) {
|
|
var sink = lazySink().getOrDie();
|
|
Positioning.position(sink, __assign({
|
|
anchor: 'submenu',
|
|
item: item
|
|
}, getSubmenuLayouts(triggeringPaths)), submenu);
|
|
},
|
|
onRepositionMenu: function (tmenu, primaryMenu, submenuTriggers) {
|
|
var sink = lazySink().getOrDie();
|
|
Positioning.positionWithinBounds(sink, anchor, primaryMenu, getBounds());
|
|
each(submenuTriggers, function (st) {
|
|
var submenuLayouts = getSubmenuLayouts(st.triggeringPath);
|
|
Positioning.position(sink, __assign({
|
|
anchor: 'submenu',
|
|
item: st.triggeringItem
|
|
}, submenuLayouts), st.triggeredMenu);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var factory = function (detail, spec) {
|
|
var isPartOfRelated = function (sandbox, queryElem) {
|
|
var related = detail.getRelated(sandbox);
|
|
return related.exists(function (rel) {
|
|
return isPartOf(rel, queryElem);
|
|
});
|
|
};
|
|
var setContent = function (sandbox, thing) {
|
|
Sandboxing.setContent(sandbox, thing);
|
|
};
|
|
var showAt = function (sandbox, anchor, thing) {
|
|
showWithin(sandbox, anchor, thing, Option.none());
|
|
};
|
|
var showWithin = function (sandbox, anchor, thing, boxElement) {
|
|
showWithinBounds(sandbox, anchor, thing, function () {
|
|
return boxElement.map(function (elem) {
|
|
return box(elem);
|
|
});
|
|
});
|
|
};
|
|
var showWithinBounds = function (sandbox, anchor, thing, getBounds) {
|
|
var sink = detail.lazySink(sandbox).getOrDie();
|
|
Sandboxing.openWhileCloaked(sandbox, thing, function () {
|
|
return Positioning.positionWithinBounds(sink, anchor, sandbox, getBounds());
|
|
});
|
|
Representing.setValue(sandbox, Option.some({
|
|
mode: 'position',
|
|
anchor: anchor,
|
|
getBounds: getBounds
|
|
}));
|
|
};
|
|
var showMenuAt = function (sandbox, anchor, menuSpec) {
|
|
showMenuWithinBounds(sandbox, anchor, menuSpec, function () {
|
|
return Option.none();
|
|
});
|
|
};
|
|
var showMenuWithinBounds = function (sandbox, anchor, menuSpec, getBounds) {
|
|
var menu = makeMenu(detail, sandbox, anchor, menuSpec, getBounds);
|
|
Sandboxing.open(sandbox, menu);
|
|
Representing.setValue(sandbox, Option.some({
|
|
mode: 'menu',
|
|
menu: menu
|
|
}));
|
|
};
|
|
var hide = function (sandbox) {
|
|
if (Sandboxing.isOpen(sandbox)) {
|
|
Representing.setValue(sandbox, Option.none());
|
|
Sandboxing.close(sandbox);
|
|
}
|
|
};
|
|
var getContent = function (sandbox) {
|
|
return Sandboxing.getState(sandbox);
|
|
};
|
|
var reposition = function (sandbox) {
|
|
if (Sandboxing.isOpen(sandbox)) {
|
|
Representing.getValue(sandbox).each(function (state) {
|
|
switch (state.mode) {
|
|
case 'menu':
|
|
Sandboxing.getState(sandbox).each(function (tmenu) {
|
|
tieredMenu.repositionMenus(tmenu);
|
|
});
|
|
break;
|
|
case 'position':
|
|
var sink = detail.lazySink(sandbox).getOrDie();
|
|
Positioning.positionWithinBounds(sink, state.anchor, sandbox, state.getBounds());
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
};
|
|
var apis = {
|
|
setContent: setContent,
|
|
showAt: showAt,
|
|
showWithin: showWithin,
|
|
showWithinBounds: showWithinBounds,
|
|
showMenuAt: showMenuAt,
|
|
showMenuWithinBounds: showMenuWithinBounds,
|
|
hide: hide,
|
|
getContent: getContent,
|
|
reposition: reposition,
|
|
isOpen: Sandboxing.isOpen
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
behaviours: augment(detail.inlineBehaviours, [
|
|
Sandboxing.config({
|
|
isPartOf: function (sandbox, data, queryElem) {
|
|
return isPartOf(data, queryElem) || isPartOfRelated(sandbox, queryElem);
|
|
},
|
|
getAttachPoint: function (sandbox) {
|
|
return detail.lazySink(sandbox).getOrDie();
|
|
},
|
|
onOpen: function (sandbox) {
|
|
detail.onShow(sandbox);
|
|
},
|
|
onClose: function (sandbox) {
|
|
detail.onHide(sandbox);
|
|
}
|
|
}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: Option.none()
|
|
}
|
|
}),
|
|
Receiving.config({
|
|
channels: __assign(__assign({}, receivingChannel(__assign({ isExtraPart: spec.isExtraPart }, detail.fireDismissalEventInstead.map(function (fe) {
|
|
return { fireEventInstead: { event: fe.event } };
|
|
}).getOr({})))), receivingChannel$1(__assign(__assign({}, detail.fireRepositionEventInstead.map(function (fe) {
|
|
return { fireEventInstead: { event: fe.event } };
|
|
}).getOr({})), { doReposition: reposition })))
|
|
})
|
|
]),
|
|
eventOrder: detail.eventOrder,
|
|
apis: apis
|
|
};
|
|
};
|
|
var InlineView = single$2({
|
|
name: 'InlineView',
|
|
configFields: [
|
|
strict$1('lazySink'),
|
|
onHandler('onShow'),
|
|
onHandler('onHide'),
|
|
optionFunction('onEscape'),
|
|
field$1('inlineBehaviours', [
|
|
Sandboxing,
|
|
Representing,
|
|
Receiving
|
|
]),
|
|
optionObjOf('fireDismissalEventInstead', [defaulted$1('event', dismissRequested())]),
|
|
optionObjOf('fireRepositionEventInstead', [defaulted$1('event', repositionRequested())]),
|
|
defaulted$1('getRelated', Option.none),
|
|
defaulted$1('isExtraPart', never),
|
|
defaulted$1('eventOrder', Option.none)
|
|
],
|
|
factory: factory,
|
|
apis: {
|
|
showAt: function (apis, component, anchor, thing) {
|
|
apis.showAt(component, anchor, thing);
|
|
},
|
|
showWithin: function (apis, component, anchor, thing, boxElement) {
|
|
apis.showWithin(component, anchor, thing, boxElement);
|
|
},
|
|
showWithinBounds: function (apis, component, anchor, thing, bounds) {
|
|
apis.showWithinBounds(component, anchor, thing, bounds);
|
|
},
|
|
showMenuAt: function (apis, component, anchor, menuSpec) {
|
|
apis.showMenuAt(component, anchor, menuSpec);
|
|
},
|
|
showMenuWithinBounds: function (apis, component, anchor, menuSpec, bounds) {
|
|
apis.showMenuWithinBounds(component, anchor, menuSpec, bounds);
|
|
},
|
|
hide: function (apis, component) {
|
|
apis.hide(component);
|
|
},
|
|
isOpen: function (apis, component) {
|
|
return apis.isOpen(component);
|
|
},
|
|
getContent: function (apis, component) {
|
|
return apis.getContent(component);
|
|
},
|
|
setContent: function (apis, component, thing) {
|
|
apis.setContent(component, thing);
|
|
},
|
|
reposition: function (apis, component) {
|
|
apis.reposition(component);
|
|
}
|
|
}
|
|
});
|
|
|
|
var westEdgeX$1 = function (anchor) {
|
|
return anchor.x;
|
|
};
|
|
var middleX$1 = function (anchor, element) {
|
|
return anchor.x + anchor.width / 2 - element.width / 2;
|
|
};
|
|
var eastEdgeX$1 = function (anchor, element) {
|
|
return anchor.x + anchor.width - element.width;
|
|
};
|
|
var northY$2 = function (anchor) {
|
|
return anchor.y;
|
|
};
|
|
var southY$2 = function (anchor, element) {
|
|
return anchor.y + anchor.height - element.height;
|
|
};
|
|
var southeast$3 = function (anchor, element, bubbles) {
|
|
return nu$7(eastEdgeX$1(anchor, element), southY$2(anchor, element), bubbles.innerSoutheast(), northwest(), boundsRestriction(anchor, {
|
|
right: 0,
|
|
bottom: 3
|
|
}), 'layout-inner-se');
|
|
};
|
|
var southwest$3 = function (anchor, element, bubbles) {
|
|
return nu$7(westEdgeX$1(anchor), southY$2(anchor, element), bubbles.innerSouthwest(), northeast(), boundsRestriction(anchor, {
|
|
left: 1,
|
|
bottom: 3
|
|
}), 'layout-inner-sw');
|
|
};
|
|
var northeast$3 = function (anchor, element, bubbles) {
|
|
return nu$7(eastEdgeX$1(anchor, element), northY$2(anchor), bubbles.innerNortheast(), southwest(), boundsRestriction(anchor, {
|
|
right: 0,
|
|
top: 2
|
|
}), 'layout-inner-ne');
|
|
};
|
|
var northwest$3 = function (anchor, element, bubbles) {
|
|
return nu$7(westEdgeX$1(anchor), northY$2(anchor), bubbles.innerNorthwest(), southeast(), boundsRestriction(anchor, {
|
|
left: 1,
|
|
top: 2
|
|
}), 'layout-inner-nw');
|
|
};
|
|
var north$3 = function (anchor, element, bubbles) {
|
|
return nu$7(middleX$1(anchor, element), northY$2(anchor), bubbles.innerNorth(), south(), boundsRestriction(anchor, { top: 2 }), 'layout-inner-n');
|
|
};
|
|
var south$3 = function (anchor, element, bubbles) {
|
|
return nu$7(middleX$1(anchor, element), southY$2(anchor, element), bubbles.innerSouth(), north(), boundsRestriction(anchor, { bottom: 3 }), 'layout-inner-s');
|
|
};
|
|
|
|
var global$2 = tinymce.util.Tools.resolve('tinymce.util.Delay');
|
|
|
|
var factory$1 = function (detail) {
|
|
var events = events$7(detail.action);
|
|
var tag = detail.dom.tag;
|
|
var lookupAttr = function (attr) {
|
|
return get(detail.dom, 'attributes').bind(function (attrs) {
|
|
return get(attrs, attr);
|
|
});
|
|
};
|
|
var getModAttributes = function () {
|
|
if (tag === 'button') {
|
|
var type = lookupAttr('type').getOr('button');
|
|
var roleAttrs = lookupAttr('role').map(function (role) {
|
|
return { role: role };
|
|
}).getOr({});
|
|
return __assign({ type: type }, roleAttrs);
|
|
} else {
|
|
var role = lookupAttr('role').getOr('button');
|
|
return { role: role };
|
|
}
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: detail.components,
|
|
events: events,
|
|
behaviours: SketchBehaviours.augment(detail.buttonBehaviours, [
|
|
Focusing.config({}),
|
|
Keying.config({
|
|
mode: 'execution',
|
|
useSpace: true,
|
|
useEnter: true
|
|
})
|
|
]),
|
|
domModification: { attributes: getModAttributes() },
|
|
eventOrder: detail.eventOrder
|
|
};
|
|
};
|
|
var Button = single$2({
|
|
name: 'Button',
|
|
factory: factory$1,
|
|
configFields: [
|
|
defaulted$1('uid', undefined),
|
|
strict$1('dom'),
|
|
defaulted$1('components', []),
|
|
SketchBehaviours.field('buttonBehaviours', [
|
|
Focusing,
|
|
Keying
|
|
]),
|
|
option('action'),
|
|
option('role'),
|
|
defaulted$1('eventOrder', {})
|
|
]
|
|
});
|
|
|
|
var record = function (spec) {
|
|
var uid = isSketchSpec(spec) && hasNonNullableKey(spec, 'uid') ? spec.uid : generate$2('memento');
|
|
var get = function (anyInSystem) {
|
|
return anyInSystem.getSystem().getByUid(uid).getOrDie();
|
|
};
|
|
var getOpt = function (anyInSystem) {
|
|
return anyInSystem.getSystem().getByUid(uid).toOption();
|
|
};
|
|
var asSpec = function () {
|
|
return __assign(__assign({}, spec), { uid: uid });
|
|
};
|
|
return {
|
|
get: get,
|
|
getOpt: getOpt,
|
|
asSpec: asSpec
|
|
};
|
|
};
|
|
|
|
var defaultIcon = function (icons) {
|
|
return Option.from(icons()['temporary-placeholder']).getOr('!not found!');
|
|
};
|
|
var get$d = function (name, icons) {
|
|
return Option.from(icons()[name]).getOrThunk(function () {
|
|
return defaultIcon(icons);
|
|
});
|
|
};
|
|
var getOr = function (name, icons, fallback) {
|
|
return Option.from(icons()[name]).or(fallback).getOrThunk(function () {
|
|
return defaultIcon(icons);
|
|
});
|
|
};
|
|
var getFirst$1 = function (names, icons) {
|
|
return findMap(names, function (name) {
|
|
return Option.from(icons()[name]);
|
|
}).getOrThunk(function () {
|
|
return defaultIcon(icons);
|
|
});
|
|
};
|
|
|
|
var notificationIconMap = {
|
|
success: 'checkmark',
|
|
error: 'warning',
|
|
err: 'error',
|
|
warning: 'warning',
|
|
warn: 'warning',
|
|
info: 'info'
|
|
};
|
|
var factory$2 = function (detail) {
|
|
var memBannerText = record({
|
|
dom: {
|
|
tag: 'p',
|
|
innerHtml: detail.translationProvider(detail.text)
|
|
},
|
|
behaviours: derive$1([Replacing.config({})])
|
|
});
|
|
var renderPercentBar = function (percent) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-bar'],
|
|
attributes: { style: 'width: ' + percent + '%' }
|
|
}
|
|
};
|
|
};
|
|
var renderPercentText = function (percent) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-text'],
|
|
innerHtml: percent + '%'
|
|
}
|
|
};
|
|
};
|
|
var memBannerProgress = record({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: detail.progress ? [
|
|
'tox-progress-bar',
|
|
'tox-progress-indicator'
|
|
] : ['tox-progress-bar']
|
|
},
|
|
components: [
|
|
{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-bar-container']
|
|
},
|
|
components: [renderPercentBar(0)]
|
|
},
|
|
renderPercentText(0)
|
|
],
|
|
behaviours: derive$1([Replacing.config({})])
|
|
});
|
|
var updateProgress = function (comp, percent) {
|
|
if (comp.getSystem().isConnected()) {
|
|
memBannerProgress.getOpt(comp).each(function (progress) {
|
|
Replacing.set(progress, [
|
|
{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-bar-container']
|
|
},
|
|
components: [renderPercentBar(percent)]
|
|
},
|
|
renderPercentText(percent)
|
|
]);
|
|
});
|
|
}
|
|
};
|
|
var updateText = function (comp, text$1) {
|
|
if (comp.getSystem().isConnected()) {
|
|
var banner = memBannerText.get(comp);
|
|
Replacing.set(banner, [text(text$1)]);
|
|
}
|
|
};
|
|
var apis = {
|
|
updateProgress: updateProgress,
|
|
updateText: updateText
|
|
};
|
|
var iconChoices = flatten([
|
|
detail.icon.toArray(),
|
|
detail.level.toArray(),
|
|
detail.level.bind(function (level) {
|
|
return Option.from(notificationIconMap[level]);
|
|
}).toArray()
|
|
]);
|
|
return {
|
|
uid: detail.uid,
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { role: 'alert' },
|
|
classes: detail.level.map(function (level) {
|
|
return [
|
|
'tox-notification',
|
|
'tox-notification--in',
|
|
'tox-notification--' + level
|
|
];
|
|
}).getOr([
|
|
'tox-notification',
|
|
'tox-notification--in'
|
|
])
|
|
},
|
|
components: [
|
|
{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-notification__icon'],
|
|
innerHtml: getFirst$1(iconChoices, detail.iconProvider)
|
|
}
|
|
},
|
|
{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-notification__body']
|
|
},
|
|
components: [memBannerText.asSpec()],
|
|
behaviours: derive$1([Replacing.config({})])
|
|
}
|
|
].concat(detail.progress ? [memBannerProgress.asSpec()] : []).concat(!detail.closeButton ? [] : [Button.sketch({
|
|
dom: {
|
|
tag: 'button',
|
|
classes: [
|
|
'tox-notification__dismiss',
|
|
'tox-button',
|
|
'tox-button--naked',
|
|
'tox-button--icon'
|
|
]
|
|
},
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-icon'],
|
|
innerHtml: get$d('close', detail.iconProvider),
|
|
attributes: { 'aria-label': detail.translationProvider('Close') }
|
|
}
|
|
}],
|
|
action: function (comp) {
|
|
detail.onAction(comp);
|
|
}
|
|
})]),
|
|
apis: apis
|
|
};
|
|
};
|
|
var Notification = single$2({
|
|
name: 'Notification',
|
|
factory: factory$2,
|
|
configFields: [
|
|
option('level'),
|
|
strict$1('progress'),
|
|
strict$1('icon'),
|
|
strict$1('onAction'),
|
|
strict$1('text'),
|
|
strict$1('iconProvider'),
|
|
strict$1('translationProvider'),
|
|
defaultedBoolean('closeButton', true)
|
|
],
|
|
apis: {
|
|
updateProgress: function (apis, comp, percent) {
|
|
apis.updateProgress(comp, percent);
|
|
},
|
|
updateText: function (apis, comp, text) {
|
|
apis.updateText(comp, text);
|
|
}
|
|
}
|
|
});
|
|
|
|
function NotificationManagerImpl (editor, extras, uiMothership) {
|
|
var backstage = extras.backstage;
|
|
var getLayoutDirection = function (rel) {
|
|
switch (rel) {
|
|
case 'bc-bc':
|
|
return south$3;
|
|
case 'tc-tc':
|
|
return north$3;
|
|
case 'tc-bc':
|
|
return north$1;
|
|
case 'bc-tc':
|
|
default:
|
|
return south$1;
|
|
}
|
|
};
|
|
var prePositionNotifications = function (notifications) {
|
|
each(notifications, function (notification) {
|
|
return notification.moveTo(0, 0);
|
|
});
|
|
};
|
|
var positionNotifications = function (notifications) {
|
|
if (notifications.length > 0) {
|
|
head(notifications).each(function (firstItem) {
|
|
return firstItem.moveRel(null, 'banner');
|
|
});
|
|
each(notifications, function (notification, index) {
|
|
if (index > 0) {
|
|
notification.moveRel(notifications[index - 1].getEl(), 'bc-tc');
|
|
}
|
|
});
|
|
}
|
|
};
|
|
var reposition = function (notifications) {
|
|
prePositionNotifications(notifications);
|
|
positionNotifications(notifications);
|
|
};
|
|
var open = function (settings, closeCallback) {
|
|
var hideCloseButton = !settings.closeButton && settings.timeout && (settings.timeout > 0 || settings.timeout < 0);
|
|
var close = function () {
|
|
closeCallback();
|
|
InlineView.hide(notificationWrapper);
|
|
};
|
|
var notification = build$1(Notification.sketch({
|
|
text: settings.text,
|
|
level: contains([
|
|
'success',
|
|
'error',
|
|
'warning',
|
|
'warn',
|
|
'info'
|
|
], settings.type) ? settings.type : undefined,
|
|
progress: settings.progressBar === true,
|
|
icon: Option.from(settings.icon),
|
|
closeButton: !hideCloseButton,
|
|
onAction: close,
|
|
iconProvider: backstage.shared.providers.icons,
|
|
translationProvider: backstage.shared.providers.translate
|
|
}));
|
|
var notificationWrapper = build$1(InlineView.sketch(__assign({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-notifications-container']
|
|
},
|
|
lazySink: extras.backstage.shared.getSink,
|
|
fireDismissalEventInstead: {}
|
|
}, backstage.shared.header.isPositionedAtTop() ? {} : { fireRepositionEventInstead: {} })));
|
|
uiMothership.add(notificationWrapper);
|
|
if (settings.timeout > 0) {
|
|
global$2.setTimeout(function () {
|
|
close();
|
|
}, settings.timeout);
|
|
}
|
|
return {
|
|
close: close,
|
|
moveTo: function (x, y) {
|
|
InlineView.showAt(notificationWrapper, {
|
|
anchor: 'makeshift',
|
|
x: x,
|
|
y: y
|
|
}, premade$1(notification));
|
|
},
|
|
moveRel: function (element, rel) {
|
|
if (rel !== 'banner') {
|
|
var layoutDirection_1 = getLayoutDirection(rel);
|
|
var nodeAnchor = {
|
|
anchor: 'node',
|
|
root: body(),
|
|
node: Option.some(Element.fromDom(element)),
|
|
layouts: {
|
|
onRtl: function () {
|
|
return [layoutDirection_1];
|
|
},
|
|
onLtr: function () {
|
|
return [layoutDirection_1];
|
|
}
|
|
}
|
|
};
|
|
InlineView.showAt(notificationWrapper, nodeAnchor, premade$1(notification));
|
|
} else {
|
|
InlineView.showAt(notificationWrapper, extras.backstage.shared.anchors.banner(), premade$1(notification));
|
|
}
|
|
},
|
|
text: function (nuText) {
|
|
Notification.updateText(notification, nuText);
|
|
},
|
|
settings: settings,
|
|
getEl: function () {
|
|
return notification.element().dom();
|
|
},
|
|
progressBar: {
|
|
value: function (percent) {
|
|
Notification.updateProgress(notification, percent);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
var close = function (notification) {
|
|
notification.close();
|
|
};
|
|
var getArgs = function (notification) {
|
|
return notification.settings;
|
|
};
|
|
return {
|
|
open: open,
|
|
close: close,
|
|
reposition: reposition,
|
|
getArgs: getArgs
|
|
};
|
|
}
|
|
|
|
var first = function (fn, rate) {
|
|
var timer = null;
|
|
var cancel = function () {
|
|
if (timer !== null) {
|
|
domGlobals.clearTimeout(timer);
|
|
timer = null;
|
|
}
|
|
};
|
|
var throttle = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
if (timer === null) {
|
|
timer = domGlobals.setTimeout(function () {
|
|
fn.apply(null, args);
|
|
timer = null;
|
|
}, rate);
|
|
}
|
|
};
|
|
return {
|
|
cancel: cancel,
|
|
throttle: throttle
|
|
};
|
|
};
|
|
var last$2 = function (fn, rate) {
|
|
var timer = null;
|
|
var cancel = function () {
|
|
if (timer !== null) {
|
|
domGlobals.clearTimeout(timer);
|
|
timer = null;
|
|
}
|
|
};
|
|
var throttle = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
if (timer !== null) {
|
|
domGlobals.clearTimeout(timer);
|
|
}
|
|
timer = domGlobals.setTimeout(function () {
|
|
fn.apply(null, args);
|
|
timer = null;
|
|
}, rate);
|
|
};
|
|
return {
|
|
cancel: cancel,
|
|
throttle: throttle
|
|
};
|
|
};
|
|
|
|
var global$3 = tinymce.util.Tools.resolve('tinymce.dom.TextSeeker');
|
|
|
|
var isBoundary = function (dom, node) {
|
|
return dom.isBlock(node) || contains([
|
|
'BR',
|
|
'IMG',
|
|
'HR',
|
|
'INPUT'
|
|
], node.nodeName) || dom.getContentEditable(node) === 'false';
|
|
};
|
|
var repeatLeft = function (dom, node, offset, process, rootNode) {
|
|
var search = global$3(dom, function (node) {
|
|
return isBoundary(dom, node);
|
|
});
|
|
return Option.from(search.backwards(node, offset, process, rootNode));
|
|
};
|
|
|
|
var autocompleteSelector = '[data-mce-autocompleter]';
|
|
var create$4 = function (editor, range) {
|
|
return detect$4(Element.fromDom(editor.selection.getNode())).getOrThunk(function () {
|
|
var wrapper = Element.fromHtml('<span data-mce-autocompleter="1" data-mce-bogus="1"></span>', editor.getDoc());
|
|
append(wrapper, Element.fromDom(range.extractContents()));
|
|
range.insertNode(wrapper.dom());
|
|
parent(wrapper).each(function (elm) {
|
|
return elm.dom().normalize();
|
|
});
|
|
last$1(wrapper).map(function (last) {
|
|
editor.selection.setCursorLocation(last.dom(), getEnd(last));
|
|
});
|
|
return wrapper;
|
|
});
|
|
};
|
|
var detect$4 = function (elm) {
|
|
return closest$3(elm, autocompleteSelector);
|
|
};
|
|
|
|
var isValidTextRange = function (rng) {
|
|
return rng.collapsed && rng.startContainer.nodeType === 3;
|
|
};
|
|
var getText = function (rng) {
|
|
return rng.toString().replace(/\u00A0/g, ' ').replace(/\uFEFF/g, '');
|
|
};
|
|
var isWhitespace = function (chr) {
|
|
return chr !== '' && ' \xA0\f\n\r\t\x0B'.indexOf(chr) !== -1;
|
|
};
|
|
|
|
var stripTriggerChar = function (text, triggerCh) {
|
|
return text.substring(triggerCh.length);
|
|
};
|
|
var findChar = function (text, index, ch) {
|
|
var i;
|
|
for (i = index - 1; i >= 0; i--) {
|
|
var char = text.charAt(i);
|
|
if (isWhitespace(char)) {
|
|
return Option.none();
|
|
}
|
|
if (char === ch) {
|
|
break;
|
|
}
|
|
}
|
|
return Option.some(i);
|
|
};
|
|
var findStart = function (dom, initRange, ch, minChars) {
|
|
if (minChars === void 0) {
|
|
minChars = 0;
|
|
}
|
|
if (!isValidTextRange(initRange)) {
|
|
return Option.none();
|
|
}
|
|
var findTriggerChIndex = function (element, offset, text) {
|
|
return findChar(text, offset, ch).getOr(offset);
|
|
};
|
|
var root = dom.getParent(initRange.startContainer, dom.isBlock) || dom.getRoot();
|
|
return repeatLeft(dom, initRange.startContainer, initRange.startOffset, findTriggerChIndex, root).bind(function (spot) {
|
|
var range = initRange.cloneRange();
|
|
range.setStart(spot.container, spot.offset);
|
|
range.setEnd(initRange.endContainer, initRange.endOffset);
|
|
if (range.collapsed) {
|
|
return Option.none();
|
|
}
|
|
var text = getText(range);
|
|
var triggerCharIndex = text.lastIndexOf(ch);
|
|
if (triggerCharIndex !== 0 || stripTriggerChar(text, ch).length < minChars) {
|
|
return Option.none();
|
|
} else {
|
|
return Option.some({
|
|
text: stripTriggerChar(text, ch),
|
|
range: range,
|
|
triggerChar: ch
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var getContext = function (dom, initRange, ch, minChars) {
|
|
if (minChars === void 0) {
|
|
minChars = 0;
|
|
}
|
|
return detect$4(Element.fromDom(initRange.startContainer)).fold(function () {
|
|
return findStart(dom, initRange, ch, minChars);
|
|
}, function (elm) {
|
|
var range = dom.createRng();
|
|
range.selectNode(elm.dom());
|
|
var text = getText(range);
|
|
return Option.some({
|
|
range: range,
|
|
text: stripTriggerChar(text, ch),
|
|
triggerChar: ch
|
|
});
|
|
});
|
|
};
|
|
|
|
var setup = function (api, editor) {
|
|
editor.on('keypress compositionend', api.onKeypress.throttle);
|
|
editor.on('remove', api.onKeypress.cancel);
|
|
var redirectKeyToItem = function (item, e) {
|
|
emitWith(item, keydown(), { raw: e });
|
|
};
|
|
editor.on('keydown', function (e) {
|
|
var getItem = function () {
|
|
return api.getView().bind(Highlighting.getHighlighted);
|
|
};
|
|
if (e.which === 8) {
|
|
api.onKeypress.throttle(e);
|
|
}
|
|
if (api.isActive()) {
|
|
if (e.which === 27) {
|
|
api.cancelIfNecessary();
|
|
}
|
|
if (api.isMenuOpen()) {
|
|
if (e.which === 13) {
|
|
getItem().each(emitExecute);
|
|
e.preventDefault();
|
|
} else if (e.which === 40) {
|
|
getItem().fold(function () {
|
|
api.getView().each(Highlighting.highlightFirst);
|
|
}, function (item) {
|
|
redirectKeyToItem(item, e);
|
|
});
|
|
e.preventDefault();
|
|
e.stopImmediatePropagation();
|
|
} else if (e.which === 37 || e.which === 38 || e.which === 39) {
|
|
getItem().each(function (item) {
|
|
redirectKeyToItem(item, e);
|
|
e.preventDefault();
|
|
e.stopImmediatePropagation();
|
|
});
|
|
}
|
|
} else {
|
|
if (e.which === 13 || e.which === 38 || e.which === 40) {
|
|
api.cancelIfNecessary();
|
|
}
|
|
}
|
|
}
|
|
});
|
|
editor.on('NodeChange', function (e) {
|
|
if (api.isActive() && !api.isProcessingAction() && detect$4(Element.fromDom(e.element)).isNone()) {
|
|
api.cancelIfNecessary();
|
|
}
|
|
});
|
|
};
|
|
var AutocompleterEditorEvents = { setup: setup };
|
|
|
|
var global$4 = tinymce.util.Tools.resolve('tinymce.util.Promise');
|
|
|
|
var point$2 = function (container, offset) {
|
|
return {
|
|
container: container,
|
|
offset: offset
|
|
};
|
|
};
|
|
|
|
var isText$1 = function (node) {
|
|
return node.nodeType === domGlobals.Node.TEXT_NODE;
|
|
};
|
|
var isElement$1 = function (node) {
|
|
return node.nodeType === domGlobals.Node.ELEMENT_NODE;
|
|
};
|
|
var toLast = function (node) {
|
|
if (isText$1(node)) {
|
|
return point$2(node, node.data.length);
|
|
} else {
|
|
var children = node.childNodes;
|
|
return children.length > 0 ? toLast(children[children.length - 1]) : point$2(node, children.length);
|
|
}
|
|
};
|
|
var toLeaf = function (node, offset) {
|
|
var children = node.childNodes;
|
|
if (children.length > 0 && offset < children.length) {
|
|
return toLeaf(children[offset], 0);
|
|
} else if (children.length > 0 && isElement$1(node) && children.length === offset) {
|
|
return toLast(children[children.length - 1]);
|
|
} else {
|
|
return point$2(node, offset);
|
|
}
|
|
};
|
|
|
|
var isPreviousCharContent = function (dom, leaf) {
|
|
return repeatLeft(dom, leaf.container, leaf.offset, function (element, offset) {
|
|
return offset === 0 ? -1 : offset;
|
|
}, dom.getRoot()).filter(function (spot) {
|
|
var char = spot.container.data.charAt(spot.offset - 1);
|
|
return !isWhitespace(char);
|
|
}).isSome();
|
|
};
|
|
var isStartOfWord = function (dom) {
|
|
return function (rng) {
|
|
var leaf = toLeaf(rng.startContainer, rng.startOffset);
|
|
return !isPreviousCharContent(dom, leaf);
|
|
};
|
|
};
|
|
var getTriggerContext = function (dom, initRange, database) {
|
|
return findMap(database.triggerChars, function (ch) {
|
|
return getContext(dom, initRange, ch);
|
|
});
|
|
};
|
|
var lookup = function (editor, getDatabase) {
|
|
var database = getDatabase();
|
|
var rng = editor.selection.getRng();
|
|
return getTriggerContext(editor.dom, rng, database).bind(function (context) {
|
|
return lookupWithContext(editor, getDatabase, context);
|
|
});
|
|
};
|
|
var lookupWithContext = function (editor, getDatabase, context, fetchOptions) {
|
|
if (fetchOptions === void 0) {
|
|
fetchOptions = {};
|
|
}
|
|
var database = getDatabase();
|
|
var rng = editor.selection.getRng();
|
|
var startText = rng.startContainer.nodeValue;
|
|
var autocompleters = filter(database.lookupByChar(context.triggerChar), function (autocompleter) {
|
|
return context.text.length >= autocompleter.minChars && autocompleter.matches.getOrThunk(function () {
|
|
return isStartOfWord(editor.dom);
|
|
})(context.range, startText, context.text);
|
|
});
|
|
if (autocompleters.length === 0) {
|
|
return Option.none();
|
|
}
|
|
var lookupData = global$4.all(map(autocompleters, function (ac) {
|
|
var fetchResult = ac.fetch(context.text, ac.maxResults, fetchOptions);
|
|
return fetchResult.then(function (results) {
|
|
return {
|
|
matchText: context.text,
|
|
items: results,
|
|
columns: ac.columns,
|
|
onAction: ac.onAction
|
|
};
|
|
});
|
|
}));
|
|
return Option.some({
|
|
lookupData: lookupData,
|
|
context: context
|
|
});
|
|
};
|
|
|
|
var separatorMenuItemSchema = objOf([
|
|
strictString('type'),
|
|
optionString('text')
|
|
]);
|
|
var createSeparatorMenuItem = function (spec) {
|
|
return asRaw('separatormenuitem', separatorMenuItemSchema, spec);
|
|
};
|
|
|
|
var autocompleterItemSchema = objOf([
|
|
state$1('type', function () {
|
|
return 'autocompleteitem';
|
|
}),
|
|
state$1('active', function () {
|
|
return false;
|
|
}),
|
|
state$1('disabled', function () {
|
|
return false;
|
|
}),
|
|
defaulted$1('meta', {}),
|
|
strictString('value'),
|
|
optionString('text'),
|
|
optionString('icon')
|
|
]);
|
|
var autocompleterSchema = objOf([
|
|
strictString('type'),
|
|
strictString('ch'),
|
|
defaultedNumber('minChars', 1),
|
|
defaulted$1('columns', 1),
|
|
defaultedNumber('maxResults', 10),
|
|
optionFunction('matches'),
|
|
strictFunction('fetch'),
|
|
strictFunction('onAction')
|
|
]);
|
|
var createSeparatorItem = function (spec) {
|
|
return asRaw('Autocompleter.Separator', separatorMenuItemSchema, spec);
|
|
};
|
|
var createAutocompleterItem = function (spec) {
|
|
return asRaw('Autocompleter.Item', autocompleterItemSchema, spec);
|
|
};
|
|
var createAutocompleter = function (spec) {
|
|
return asRaw('Autocompleter', autocompleterSchema, spec);
|
|
};
|
|
|
|
var stringArray = function (a) {
|
|
var all = {};
|
|
each(a, function (key) {
|
|
all[key] = {};
|
|
});
|
|
return keys(all);
|
|
};
|
|
|
|
var register = function (editor) {
|
|
var popups = editor.ui.registry.getAll().popups;
|
|
var dataset = map$1(popups, function (popup) {
|
|
return createAutocompleter(popup).fold(function (err) {
|
|
throw new Error(formatError(err));
|
|
}, function (x) {
|
|
return x;
|
|
});
|
|
});
|
|
var triggerChars = stringArray(mapToArray(dataset, function (v) {
|
|
return v.ch;
|
|
}));
|
|
var datasetValues = values(dataset);
|
|
var lookupByChar = function (ch) {
|
|
return filter(datasetValues, function (dv) {
|
|
return dv.ch === ch;
|
|
});
|
|
};
|
|
return {
|
|
dataset: dataset,
|
|
triggerChars: triggerChars,
|
|
lookupByChar: lookupByChar
|
|
};
|
|
};
|
|
|
|
var commonMenuItemFields = [
|
|
defaultedBoolean('disabled', false),
|
|
optionString('text'),
|
|
optionString('shortcut'),
|
|
field('value', 'value', defaultedThunk(function () {
|
|
return generate$1('menuitem-value');
|
|
}), anyValue$1()),
|
|
defaulted$1('meta', {})
|
|
];
|
|
|
|
var menuItemSchema = objOf([
|
|
strictString('type'),
|
|
defaultedFunction('onSetup', function () {
|
|
return noop;
|
|
}),
|
|
defaultedFunction('onAction', noop),
|
|
optionString('icon')
|
|
].concat(commonMenuItemFields));
|
|
var createMenuItem = function (spec) {
|
|
return asRaw('menuitem', menuItemSchema, spec);
|
|
};
|
|
|
|
var nestedMenuItemSchema = objOf([
|
|
strictString('type'),
|
|
strictFunction('getSubmenuItems'),
|
|
defaultedFunction('onSetup', function () {
|
|
return noop;
|
|
}),
|
|
optionString('icon')
|
|
].concat(commonMenuItemFields));
|
|
var createNestedMenuItem = function (spec) {
|
|
return asRaw('nestedmenuitem', nestedMenuItemSchema, spec);
|
|
};
|
|
|
|
var toggleMenuItemSchema = objOf([
|
|
strictString('type'),
|
|
optionString('icon'),
|
|
defaultedBoolean('active', false),
|
|
defaultedFunction('onSetup', function () {
|
|
return noop;
|
|
}),
|
|
strictFunction('onAction')
|
|
].concat(commonMenuItemFields));
|
|
var createToggleMenuItem = function (spec) {
|
|
return asRaw('togglemenuitem', toggleMenuItemSchema, spec);
|
|
};
|
|
|
|
var choiceMenuItemSchema = objOf([
|
|
strictString('type'),
|
|
defaultedBoolean('active', false),
|
|
optionString('icon')
|
|
].concat(commonMenuItemFields));
|
|
var createChoiceMenuItem = function (spec) {
|
|
return asRaw('choicemenuitem', choiceMenuItemSchema, spec);
|
|
};
|
|
|
|
var fancyTypes = [
|
|
'inserttable',
|
|
'colorswatch'
|
|
];
|
|
var fancyMenuItemSchema = objOf([
|
|
strictString('type'),
|
|
strictStringEnum('fancytype', fancyTypes),
|
|
defaultedFunction('onAction', noop)
|
|
]);
|
|
var createFancyMenuItem = function (spec) {
|
|
return asRaw('fancymenuitem', fancyMenuItemSchema, spec);
|
|
};
|
|
|
|
var detectSize = function (comp, margin, selectorClass) {
|
|
var descendants$1 = descendants(comp.element(), '.' + selectorClass);
|
|
if (descendants$1.length > 0) {
|
|
var columnLength = findIndex(descendants$1, function (c) {
|
|
var thisTop = c.dom().getBoundingClientRect().top;
|
|
var cTop = descendants$1[0].dom().getBoundingClientRect().top;
|
|
return Math.abs(thisTop - cTop) > margin;
|
|
}).getOr(descendants$1.length);
|
|
return Option.some({
|
|
numColumns: columnLength,
|
|
numRows: Math.ceil(descendants$1.length / columnLength)
|
|
});
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
};
|
|
|
|
var namedEvents = function (name, handlers) {
|
|
return derive$1([config(name, handlers)]);
|
|
};
|
|
var unnamedEvents = function (handlers) {
|
|
return namedEvents(generate$1('unnamed-events'), handlers);
|
|
};
|
|
var SimpleBehaviours = {
|
|
namedEvents: namedEvents,
|
|
unnamedEvents: unnamedEvents
|
|
};
|
|
|
|
var TooltippingSchema = [
|
|
strict$1('lazySink'),
|
|
strict$1('tooltipDom'),
|
|
defaulted$1('exclusive', true),
|
|
defaulted$1('tooltipComponents', []),
|
|
defaulted$1('delay', 300),
|
|
defaultedStringEnum('mode', 'normal', [
|
|
'normal',
|
|
'follow-highlight'
|
|
]),
|
|
defaulted$1('anchor', function (comp) {
|
|
return {
|
|
anchor: 'hotspot',
|
|
hotspot: comp,
|
|
layouts: {
|
|
onLtr: constant([
|
|
south$1,
|
|
north$1,
|
|
southeast$1,
|
|
northeast$1,
|
|
southwest$1,
|
|
northwest$1
|
|
]),
|
|
onRtl: constant([
|
|
south$1,
|
|
north$1,
|
|
southeast$1,
|
|
northeast$1,
|
|
southwest$1,
|
|
northwest$1
|
|
])
|
|
}
|
|
};
|
|
}),
|
|
onHandler('onHide'),
|
|
onHandler('onShow')
|
|
];
|
|
|
|
var init$4 = function () {
|
|
var timer = Cell(Option.none());
|
|
var popup = Cell(Option.none());
|
|
var getTooltip = function () {
|
|
return popup.get();
|
|
};
|
|
var setTooltip = function (comp) {
|
|
popup.set(Option.some(comp));
|
|
};
|
|
var clearTooltip = function () {
|
|
popup.set(Option.none());
|
|
};
|
|
var clearTimer = function () {
|
|
timer.get().each(function (t) {
|
|
domGlobals.clearTimeout(t);
|
|
});
|
|
};
|
|
var resetTimer = function (f, delay) {
|
|
clearTimer();
|
|
timer.set(Option.some(domGlobals.setTimeout(function () {
|
|
f();
|
|
}, delay)));
|
|
};
|
|
var isShowing = function () {
|
|
return popup.get().isSome();
|
|
};
|
|
var readState = constant('not-implemented');
|
|
return nu$5({
|
|
getTooltip: getTooltip,
|
|
isShowing: isShowing,
|
|
setTooltip: setTooltip,
|
|
clearTooltip: clearTooltip,
|
|
clearTimer: clearTimer,
|
|
resetTimer: resetTimer,
|
|
readState: readState
|
|
});
|
|
};
|
|
|
|
var TooltippingState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
init: init$4
|
|
});
|
|
|
|
var ExclusivityChannel = generate$1('tooltip.exclusive');
|
|
var ShowTooltipEvent = generate$1('tooltip.show');
|
|
var HideTooltipEvent = generate$1('tooltip.hide');
|
|
|
|
var hideAllExclusive = function (component, _tConfig, _tState) {
|
|
component.getSystem().broadcastOn([ExclusivityChannel], {});
|
|
};
|
|
var setComponents = function (component, tConfig, tState, specs) {
|
|
tState.getTooltip().each(function (tooltip) {
|
|
if (tooltip.getSystem().isConnected()) {
|
|
Replacing.set(tooltip, specs);
|
|
}
|
|
});
|
|
};
|
|
|
|
var TooltippingApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
hideAllExclusive: hideAllExclusive,
|
|
setComponents: setComponents
|
|
});
|
|
|
|
var events$8 = function (tooltipConfig, state) {
|
|
var hide = function (comp) {
|
|
state.getTooltip().each(function (p) {
|
|
detach(p);
|
|
tooltipConfig.onHide(comp, p);
|
|
state.clearTooltip();
|
|
});
|
|
state.clearTimer();
|
|
};
|
|
var show = function (comp) {
|
|
if (!state.isShowing()) {
|
|
hideAllExclusive(comp);
|
|
var sink = tooltipConfig.lazySink(comp).getOrDie();
|
|
var popup = comp.getSystem().build({
|
|
dom: tooltipConfig.tooltipDom,
|
|
components: tooltipConfig.tooltipComponents,
|
|
events: derive(tooltipConfig.mode === 'normal' ? [
|
|
run(mouseover(), function (_) {
|
|
emit(comp, ShowTooltipEvent);
|
|
}),
|
|
run(mouseout(), function (_) {
|
|
emit(comp, HideTooltipEvent);
|
|
})
|
|
] : []),
|
|
behaviours: derive$1([Replacing.config({})])
|
|
});
|
|
state.setTooltip(popup);
|
|
attach$1(sink, popup);
|
|
tooltipConfig.onShow(comp, popup);
|
|
Positioning.position(sink, tooltipConfig.anchor(comp), popup);
|
|
}
|
|
};
|
|
return derive(flatten([
|
|
[
|
|
run(ShowTooltipEvent, function (comp) {
|
|
state.resetTimer(function () {
|
|
show(comp);
|
|
}, tooltipConfig.delay);
|
|
}),
|
|
run(HideTooltipEvent, function (comp) {
|
|
state.resetTimer(function () {
|
|
hide(comp);
|
|
}, tooltipConfig.delay);
|
|
}),
|
|
run(receive(), function (comp, message) {
|
|
var receivingData = message;
|
|
if (contains(receivingData.channels(), ExclusivityChannel)) {
|
|
hide(comp);
|
|
}
|
|
}),
|
|
runOnDetached(function (comp) {
|
|
hide(comp);
|
|
})
|
|
],
|
|
tooltipConfig.mode === 'normal' ? [
|
|
run(focusin(), function (comp) {
|
|
emit(comp, ShowTooltipEvent);
|
|
}),
|
|
run(postBlur(), function (comp) {
|
|
emit(comp, HideTooltipEvent);
|
|
}),
|
|
run(mouseover(), function (comp) {
|
|
emit(comp, ShowTooltipEvent);
|
|
}),
|
|
run(mouseout(), function (comp) {
|
|
emit(comp, HideTooltipEvent);
|
|
})
|
|
] : [
|
|
run(highlight(), function (comp, _se) {
|
|
emit(comp, ShowTooltipEvent);
|
|
}),
|
|
run(dehighlight(), function (comp) {
|
|
emit(comp, HideTooltipEvent);
|
|
})
|
|
]
|
|
]));
|
|
};
|
|
|
|
var ActiveTooltipping = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$8
|
|
});
|
|
|
|
var Tooltipping = create$1({
|
|
fields: TooltippingSchema,
|
|
name: 'tooltipping',
|
|
active: ActiveTooltipping,
|
|
state: TooltippingState,
|
|
apis: TooltippingApis
|
|
});
|
|
|
|
var global$5 = tinymce.util.Tools.resolve('tinymce.util.I18n');
|
|
|
|
var navClass = 'tox-menu-nav__js';
|
|
var selectableClass = 'tox-collection__item';
|
|
var colorClass = 'tox-swatch';
|
|
var presetClasses = {
|
|
normal: navClass,
|
|
color: colorClass
|
|
};
|
|
var tickedClass = 'tox-collection__item--enabled';
|
|
var groupHeadingClass = 'tox-collection__group-heading';
|
|
var iconClass = 'tox-collection__item-icon';
|
|
var textClass = 'tox-collection__item-label';
|
|
var accessoryClass = 'tox-collection__item-accessory';
|
|
var caretClass = 'tox-collection__item-caret';
|
|
var checkmarkClass = 'tox-collection__item-checkmark';
|
|
var activeClass = 'tox-collection__item--active';
|
|
var iconClassRtl = 'tox-collection__item-icon-rtl';
|
|
var classForPreset = function (presets) {
|
|
return get(presetClasses, presets).getOr(navClass);
|
|
};
|
|
|
|
var global$6 = tinymce.util.Tools.resolve('tinymce.Env');
|
|
|
|
var convertText = function (source) {
|
|
var mac = {
|
|
alt: '⌥',
|
|
ctrl: '⌃',
|
|
shift: '⇧',
|
|
meta: '⌘',
|
|
access: '⌃⌥'
|
|
};
|
|
var other = {
|
|
meta: 'Ctrl',
|
|
access: 'Shift+Alt'
|
|
};
|
|
var replace = global$6.mac ? mac : other;
|
|
var shortcut = source.split('+');
|
|
var updated = map(shortcut, function (segment) {
|
|
var search = segment.toLowerCase().trim();
|
|
return has(replace, search) ? replace[search] : segment;
|
|
});
|
|
return global$6.mac ? updated.join('') : updated.join('+');
|
|
};
|
|
|
|
var renderIcon = function (iconHtml) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [iconClass],
|
|
innerHtml: iconHtml
|
|
}
|
|
};
|
|
};
|
|
var renderText = function (text$1) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [textClass]
|
|
},
|
|
components: [text(global$5.translate(text$1))]
|
|
};
|
|
};
|
|
var renderHtml = function (html) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [textClass],
|
|
innerHtml: html
|
|
}
|
|
};
|
|
};
|
|
var renderStyledText = function (style, text$1) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [textClass]
|
|
},
|
|
components: [{
|
|
dom: {
|
|
tag: style.tag,
|
|
styles: style.styles
|
|
},
|
|
components: [text(global$5.translate(text$1))]
|
|
}]
|
|
};
|
|
};
|
|
var renderShortcut = function (shortcut) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [accessoryClass],
|
|
innerHtml: convertText(shortcut)
|
|
}
|
|
};
|
|
};
|
|
var renderCheckmark = function (icons) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [checkmarkClass],
|
|
innerHtml: get$d('checkmark', icons)
|
|
}
|
|
};
|
|
};
|
|
var renderSubmenuCaret = function (icons) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [caretClass],
|
|
innerHtml: get$d('chevron-right', icons)
|
|
}
|
|
};
|
|
};
|
|
var renderDownwardsCaret = function (icons) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [caretClass],
|
|
innerHtml: get$d('chevron-down', icons)
|
|
}
|
|
};
|
|
};
|
|
|
|
var renderColorStructure = function (itemText, itemValue, iconSvg, providerBackstage) {
|
|
var colorPickerCommand = 'custom';
|
|
var removeColorCommand = 'remove';
|
|
var getDom = function () {
|
|
var common = colorClass;
|
|
var icon = iconSvg.getOr('');
|
|
var attributes = itemText.map(function (text) {
|
|
return { title: providerBackstage.translate(text) };
|
|
}).getOr({});
|
|
var baseDom = {
|
|
tag: 'div',
|
|
attributes: attributes,
|
|
classes: [common]
|
|
};
|
|
if (itemValue === colorPickerCommand) {
|
|
return __assign(__assign({}, baseDom), {
|
|
tag: 'button',
|
|
classes: __spreadArrays(baseDom.classes, ['tox-swatches__picker-btn']),
|
|
innerHtml: icon
|
|
});
|
|
} else if (itemValue === removeColorCommand) {
|
|
return __assign(__assign({}, baseDom), {
|
|
classes: __spreadArrays(baseDom.classes, ['tox-swatch--remove']),
|
|
innerHtml: icon
|
|
});
|
|
} else {
|
|
return __assign(__assign({}, baseDom), {
|
|
attributes: __assign(__assign({}, baseDom.attributes), { 'data-mce-color': itemValue }),
|
|
styles: { 'background-color': itemValue }
|
|
});
|
|
}
|
|
};
|
|
return {
|
|
dom: getDom(),
|
|
optComponents: []
|
|
};
|
|
};
|
|
var renderNormalItemStructure = function (info, icon, renderIcons, textRender, rtlClass) {
|
|
var leftIcon = renderIcons ? icon.or(Option.some('')).map(renderIcon) : Option.none();
|
|
var checkmark = info.checkMark;
|
|
var domTitle = info.ariaLabel.map(function (label) {
|
|
return { attributes: { title: global$5.translate(label) } };
|
|
}).getOr({});
|
|
var dom = __assign({
|
|
tag: 'div',
|
|
classes: [
|
|
navClass,
|
|
selectableClass
|
|
].concat(rtlClass ? [iconClassRtl] : [])
|
|
}, domTitle);
|
|
var content = info.htmlContent.fold(function () {
|
|
return info.textContent.map(textRender);
|
|
}, function (html) {
|
|
return Option.some(renderHtml(html));
|
|
});
|
|
var menuItem = {
|
|
dom: dom,
|
|
optComponents: [
|
|
leftIcon,
|
|
content,
|
|
info.shortcutContent.map(renderShortcut),
|
|
checkmark,
|
|
info.caret
|
|
]
|
|
};
|
|
return menuItem;
|
|
};
|
|
var rtlIcon = [
|
|
'list-num-default',
|
|
'list-num-lower-alpha',
|
|
'list-num-lower-greek',
|
|
'list-num-lower-roman',
|
|
'list-num-upper-alpha',
|
|
'list-num-upper-roman'
|
|
];
|
|
var rtlTransform = [
|
|
'list-bull-circle',
|
|
'list-bull-default',
|
|
'list-bull-square'
|
|
];
|
|
var renderItemStructure = function (info, providersBackstage, renderIcons, fallbackIcon) {
|
|
if (fallbackIcon === void 0) {
|
|
fallbackIcon = Option.none();
|
|
}
|
|
var getIconName = function (iconName) {
|
|
return iconName.map(function (name) {
|
|
return global$5.isRtl() && contains(rtlIcon, name) ? name + '-rtl' : name;
|
|
});
|
|
};
|
|
var needRtlClass = global$5.isRtl() && info.iconContent.exists(function (name) {
|
|
return contains(rtlTransform, name);
|
|
});
|
|
var icon = getIconName(info.iconContent).map(function (iconName) {
|
|
return getOr(iconName, providersBackstage.icons, fallbackIcon);
|
|
});
|
|
var textRender = Option.from(info.meta).fold(function () {
|
|
return renderText;
|
|
}, function (meta) {
|
|
return has(meta, 'style') ? curry(renderStyledText, meta.style) : renderText;
|
|
});
|
|
if (info.presets === 'color') {
|
|
return renderColorStructure(info.ariaLabel, info.value, icon, providersBackstage);
|
|
} else {
|
|
return renderNormalItemStructure(info, icon, renderIcons, textRender, needRtlClass);
|
|
}
|
|
};
|
|
|
|
var nativeDisabled = [
|
|
'input',
|
|
'button',
|
|
'textarea',
|
|
'select'
|
|
];
|
|
var onLoad$5 = function (component, disableConfig, disableState) {
|
|
var f = disableConfig.disabled() ? disable : enable;
|
|
f(component, disableConfig, disableState);
|
|
};
|
|
var hasNative = function (component, config) {
|
|
return config.useNative === true && contains(nativeDisabled, name(component.element()));
|
|
};
|
|
var nativeIsDisabled = function (component) {
|
|
return has$1(component.element(), 'disabled');
|
|
};
|
|
var nativeDisable = function (component) {
|
|
set$1(component.element(), 'disabled', 'disabled');
|
|
};
|
|
var nativeEnable = function (component) {
|
|
remove$1(component.element(), 'disabled');
|
|
};
|
|
var ariaIsDisabled = function (component) {
|
|
return get$2(component.element(), 'aria-disabled') === 'true';
|
|
};
|
|
var ariaDisable = function (component) {
|
|
set$1(component.element(), 'aria-disabled', 'true');
|
|
};
|
|
var ariaEnable = function (component) {
|
|
set$1(component.element(), 'aria-disabled', 'false');
|
|
};
|
|
var disable = function (component, disableConfig, _disableState) {
|
|
disableConfig.disableClass.each(function (disableClass) {
|
|
add$2(component.element(), disableClass);
|
|
});
|
|
var f = hasNative(component, disableConfig) ? nativeDisable : ariaDisable;
|
|
f(component);
|
|
disableConfig.onDisabled(component);
|
|
};
|
|
var enable = function (component, disableConfig, _disableState) {
|
|
disableConfig.disableClass.each(function (disableClass) {
|
|
remove$4(component.element(), disableClass);
|
|
});
|
|
var f = hasNative(component, disableConfig) ? nativeEnable : ariaEnable;
|
|
f(component);
|
|
disableConfig.onEnabled(component);
|
|
};
|
|
var isDisabled = function (component, disableConfig) {
|
|
return hasNative(component, disableConfig) ? nativeIsDisabled(component) : ariaIsDisabled(component);
|
|
};
|
|
var set$7 = function (component, disableConfig, disableState, disabled) {
|
|
var f = disabled ? disable : enable;
|
|
f(component, disableConfig, disableState);
|
|
};
|
|
|
|
var DisableApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
enable: enable,
|
|
disable: disable,
|
|
isDisabled: isDisabled,
|
|
onLoad: onLoad$5,
|
|
set: set$7
|
|
});
|
|
|
|
var exhibit$3 = function (base, disableConfig) {
|
|
return nu$6({ classes: disableConfig.disabled ? disableConfig.disableClass.map(pure).getOr([]) : [] });
|
|
};
|
|
var events$9 = function (disableConfig, disableState) {
|
|
return derive([
|
|
abort(execute(), function (component, _simulatedEvent) {
|
|
return isDisabled(component, disableConfig);
|
|
}),
|
|
loadEvent(disableConfig, disableState, onLoad$5)
|
|
]);
|
|
};
|
|
|
|
var ActiveDisable = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit$3,
|
|
events: events$9
|
|
});
|
|
|
|
var DisableSchema = [
|
|
defaultedFunction('disabled', never),
|
|
defaulted$1('useNative', true),
|
|
option('disableClass'),
|
|
onHandler('onDisabled'),
|
|
onHandler('onEnabled')
|
|
];
|
|
|
|
var Disabling = create$1({
|
|
fields: DisableSchema,
|
|
name: 'disabling',
|
|
active: ActiveDisable,
|
|
apis: DisableApis
|
|
});
|
|
|
|
var global$7 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
|
|
|
|
var global$8 = tinymce.util.Tools.resolve('tinymce.EditorManager');
|
|
|
|
var getSkinUrl = function (editor) {
|
|
var settings = editor.settings;
|
|
var skin = settings.skin;
|
|
var skinUrl = settings.skin_url;
|
|
if (skin !== false) {
|
|
var skinName = skin ? skin : 'oxide';
|
|
if (skinUrl) {
|
|
skinUrl = editor.documentBaseURI.toAbsolute(skinUrl);
|
|
} else {
|
|
skinUrl = global$8.baseURL + '/skins/ui/' + skinName;
|
|
}
|
|
}
|
|
return skinUrl;
|
|
};
|
|
var isReadOnly = function (editor) {
|
|
return editor.getParam('readonly', false, 'boolean');
|
|
};
|
|
var isSkinDisabled = function (editor) {
|
|
return editor.getParam('skin') === false;
|
|
};
|
|
var getHeightSetting = function (editor) {
|
|
return editor.getParam('height', Math.max(editor.getElement().offsetHeight, 200));
|
|
};
|
|
var getWidthSetting = function (editor) {
|
|
return editor.getParam('width', global$7.DOM.getStyle(editor.getElement(), 'width'));
|
|
};
|
|
var getMinWidthSetting = function (editor) {
|
|
return Option.from(editor.settings.min_width).filter(isNumber);
|
|
};
|
|
var getMinHeightSetting = function (editor) {
|
|
return Option.from(editor.settings.min_height).filter(isNumber);
|
|
};
|
|
var getMaxWidthSetting = function (editor) {
|
|
return Option.from(editor.getParam('max_width')).filter(isNumber);
|
|
};
|
|
var getMaxHeightSetting = function (editor) {
|
|
return Option.from(editor.getParam('max_height')).filter(isNumber);
|
|
};
|
|
var getUserStyleFormats = function (editor) {
|
|
return Option.from(editor.getParam('style_formats')).filter(isArray);
|
|
};
|
|
var isMergeStyleFormats = function (editor) {
|
|
return editor.getParam('style_formats_merge', false, 'boolean');
|
|
};
|
|
var getRemovedMenuItems = function (editor) {
|
|
return editor.getParam('removed_menuitems', '');
|
|
};
|
|
var isMenubarEnabled = function (editor) {
|
|
return editor.getParam('menubar', true, 'boolean') !== false;
|
|
};
|
|
var isToolbarEnabled = function (editor) {
|
|
var toolbar = editor.getParam('toolbar', true);
|
|
var isToolbarTrue = toolbar === true;
|
|
var isToolbarString = isString(toolbar);
|
|
var isToolbarObjectArray = isArray(toolbar) && toolbar.length > 0;
|
|
return !isMultipleToolbars(editor) && (isToolbarObjectArray || isToolbarString || isToolbarTrue);
|
|
};
|
|
var getMultipleToolbarsSetting = function (editor) {
|
|
var keys$1 = keys(editor.settings);
|
|
var toolbarKeys = filter(keys$1, function (key) {
|
|
return /^toolbar([1-9])$/.test(key);
|
|
});
|
|
var toolbars = map(toolbarKeys, function (key) {
|
|
return editor.getParam(key, false, 'string');
|
|
});
|
|
var toolbarArray = filter(toolbars, function (toolbar) {
|
|
return typeof toolbar === 'string';
|
|
});
|
|
return toolbarArray.length > 0 ? Option.some(toolbarArray) : Option.none();
|
|
};
|
|
var isMultipleToolbars = function (editor) {
|
|
return getMultipleToolbarsSetting(editor).fold(function () {
|
|
var toolbar = editor.getParam('toolbar', [], 'string[]');
|
|
return toolbar.length > 0;
|
|
}, function () {
|
|
return true;
|
|
});
|
|
};
|
|
var ToolbarMode;
|
|
(function (ToolbarMode) {
|
|
ToolbarMode['default'] = 'wrap';
|
|
ToolbarMode['floating'] = 'floating';
|
|
ToolbarMode['sliding'] = 'sliding';
|
|
ToolbarMode['scrolling'] = 'scrolling';
|
|
}(ToolbarMode || (ToolbarMode = {})));
|
|
var getToolbarMode = function (editor) {
|
|
return editor.getParam('toolbar_mode', '', 'string');
|
|
};
|
|
var ToolbarLocation;
|
|
(function (ToolbarLocation) {
|
|
ToolbarLocation['auto'] = 'auto';
|
|
ToolbarLocation['top'] = 'top';
|
|
ToolbarLocation['bottom'] = 'bottom';
|
|
}(ToolbarLocation || (ToolbarLocation = {})));
|
|
var getToolbarGroups = function (editor) {
|
|
return editor.getParam('toolbar_groups', {}, 'object');
|
|
};
|
|
var getToolbarLocation = function (editor) {
|
|
return editor.getParam('toolbar_location', ToolbarLocation.auto, 'string');
|
|
};
|
|
var isToolbarLocationBottom = function (editor) {
|
|
return getToolbarLocation(editor) === ToolbarLocation.bottom;
|
|
};
|
|
var fixedContainerSelector = function (editor) {
|
|
return editor.getParam('fixed_toolbar_container', '', 'string');
|
|
};
|
|
var fixedContainerElement = function (editor) {
|
|
var selector = fixedContainerSelector(editor);
|
|
return selector.length > 0 && editor.inline ? descendant$1(body(), selector) : Option.none();
|
|
};
|
|
var useFixedContainer = function (editor) {
|
|
return editor.inline && fixedContainerElement(editor).isSome();
|
|
};
|
|
var getUiContainer = function (editor) {
|
|
var fixedContainer = fixedContainerElement(editor);
|
|
return fixedContainer.getOr(body());
|
|
};
|
|
var isDistractionFree = function (editor) {
|
|
return editor.inline && !isMenubarEnabled(editor) && !isToolbarEnabled(editor) && !isMultipleToolbars(editor);
|
|
};
|
|
var isStickyToolbar = function (editor) {
|
|
var isStickyToolbar = editor.getParam('toolbar_sticky', false, 'boolean');
|
|
return (isStickyToolbar || editor.inline) && !useFixedContainer(editor) && !isDistractionFree(editor);
|
|
};
|
|
var isDraggableModal = function (editor) {
|
|
return editor.getParam('draggable_modal', false, 'boolean');
|
|
};
|
|
|
|
var ReadOnlyChannel = 'silver.readonly';
|
|
var ReadOnlyDataSchema = objOf([strictBoolean('readonly')]);
|
|
var broadcastReadonly = function (uiComponents, readonly) {
|
|
var outerContainer = uiComponents.outerContainer;
|
|
var target = outerContainer.element();
|
|
if (readonly) {
|
|
uiComponents.mothership.broadcastOn([dismissPopups()], { target: target });
|
|
uiComponents.uiMothership.broadcastOn([dismissPopups()], { target: target });
|
|
}
|
|
uiComponents.mothership.broadcastOn([ReadOnlyChannel], { readonly: readonly });
|
|
uiComponents.uiMothership.broadcastOn([ReadOnlyChannel], { readonly: readonly });
|
|
};
|
|
var setupReadonlyModeSwitch = function (editor, uiComponents) {
|
|
editor.on('init', function () {
|
|
if (editor.mode.isReadOnly()) {
|
|
broadcastReadonly(uiComponents, true);
|
|
}
|
|
});
|
|
editor.on('SwitchMode', function () {
|
|
return broadcastReadonly(uiComponents, editor.mode.isReadOnly());
|
|
});
|
|
if (isReadOnly(editor)) {
|
|
editor.setMode('readonly');
|
|
}
|
|
};
|
|
var receivingConfig = function () {
|
|
var _a;
|
|
return Receiving.config({
|
|
channels: (_a = {}, _a[ReadOnlyChannel] = {
|
|
schema: ReadOnlyDataSchema,
|
|
onReceive: function (comp, data) {
|
|
Disabling.set(comp, data.readonly);
|
|
}
|
|
}, _a)
|
|
});
|
|
};
|
|
|
|
var item = function (disabled) {
|
|
return Disabling.config({
|
|
disabled: disabled,
|
|
disableClass: 'tox-collection__item--state-disabled'
|
|
});
|
|
};
|
|
var button = function (disabled) {
|
|
return Disabling.config({ disabled: disabled });
|
|
};
|
|
var splitButton = function (disabled) {
|
|
return Disabling.config({
|
|
disabled: disabled,
|
|
disableClass: 'tox-tbtn--disabled'
|
|
});
|
|
};
|
|
var toolbarButton = function (disabled) {
|
|
return Disabling.config({
|
|
disabled: disabled,
|
|
disableClass: 'tox-tbtn--disabled',
|
|
useNative: false
|
|
});
|
|
};
|
|
var DisablingConfigs = {
|
|
item: item,
|
|
button: button,
|
|
splitButton: splitButton,
|
|
toolbarButton: toolbarButton
|
|
};
|
|
|
|
var runWithApi = function (info, comp) {
|
|
var api = info.getApi(comp);
|
|
return function (f) {
|
|
f(api);
|
|
};
|
|
};
|
|
var onControlAttached = function (info, editorOffCell) {
|
|
return runOnAttached(function (comp) {
|
|
var run = runWithApi(info, comp);
|
|
run(function (api) {
|
|
var onDestroy = info.onSetup(api);
|
|
if (onDestroy !== null && onDestroy !== undefined) {
|
|
editorOffCell.set(onDestroy);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
var onControlDetached = function (getApi, editorOffCell) {
|
|
return runOnDetached(function (comp) {
|
|
return runWithApi(getApi, comp)(editorOffCell.get());
|
|
});
|
|
};
|
|
|
|
var ItemResponse;
|
|
(function (ItemResponse) {
|
|
ItemResponse[ItemResponse['CLOSE_ON_EXECUTE'] = 0] = 'CLOSE_ON_EXECUTE';
|
|
ItemResponse[ItemResponse['BUBBLE_TO_SANDBOX'] = 1] = 'BUBBLE_TO_SANDBOX';
|
|
}(ItemResponse || (ItemResponse = {})));
|
|
var ItemResponse$1 = ItemResponse;
|
|
|
|
var onMenuItemExecute = function (info, itemResponse) {
|
|
return runOnExecute(function (comp, simulatedEvent) {
|
|
runWithApi(info, comp)(info.onAction);
|
|
if (!info.triggersSubmenu && itemResponse === ItemResponse$1.CLOSE_ON_EXECUTE) {
|
|
emit(comp, sandboxClose());
|
|
simulatedEvent.stop();
|
|
}
|
|
});
|
|
};
|
|
var menuItemEventOrder = {
|
|
'alloy.execute': [
|
|
'disabling',
|
|
'alloy.base.behaviour',
|
|
'toggling',
|
|
'item-events'
|
|
]
|
|
};
|
|
|
|
var componentRenderPipeline = function (xs) {
|
|
return bind(xs, function (o) {
|
|
return o.toArray();
|
|
});
|
|
};
|
|
var renderCommonItem = function (spec, structure, itemResponse, providersbackstage) {
|
|
var editorOffCell = Cell(noop);
|
|
return {
|
|
type: 'item',
|
|
dom: structure.dom,
|
|
components: componentRenderPipeline(structure.optComponents),
|
|
data: spec.data,
|
|
eventOrder: menuItemEventOrder,
|
|
hasSubmenu: spec.triggersSubmenu,
|
|
itemBehaviours: derive$1([
|
|
config('item-events', [
|
|
onMenuItemExecute(spec, itemResponse),
|
|
onControlAttached(spec, editorOffCell),
|
|
onControlDetached(spec, editorOffCell)
|
|
]),
|
|
DisablingConfigs.item(function () {
|
|
return spec.disabled || providersbackstage.isReadOnly();
|
|
}),
|
|
receivingConfig(),
|
|
Replacing.config({})
|
|
].concat(spec.itemBehaviours))
|
|
};
|
|
};
|
|
var buildData = function (source) {
|
|
return {
|
|
value: source.value,
|
|
meta: __assign({ text: source.text.getOr('') }, source.meta)
|
|
};
|
|
};
|
|
|
|
var tooltipBehaviour = function (meta, sharedBackstage) {
|
|
return get(meta, 'tooltipWorker').map(function (tooltipWorker) {
|
|
return [Tooltipping.config({
|
|
lazySink: sharedBackstage.getSink,
|
|
tooltipDom: {
|
|
tag: 'div',
|
|
classes: ['tox-tooltip-worker-container']
|
|
},
|
|
tooltipComponents: [],
|
|
anchor: function (comp) {
|
|
return {
|
|
anchor: 'submenu',
|
|
item: comp,
|
|
overrides: { maxHeightFunction: expandable }
|
|
};
|
|
},
|
|
mode: 'follow-highlight',
|
|
onShow: function (component, _tooltip) {
|
|
tooltipWorker(function (elm) {
|
|
Tooltipping.setComponents(component, [external({ element: Element.fromDom(elm) })]);
|
|
});
|
|
}
|
|
})];
|
|
}).getOr([]);
|
|
};
|
|
var escapeRegExp = function (text) {
|
|
return text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
};
|
|
var encodeText = function (text) {
|
|
return global$7.DOM.encode(text);
|
|
};
|
|
var replaceText = function (text, matchText) {
|
|
var translated = global$5.translate(text);
|
|
var encoded = encodeText(translated);
|
|
if (matchText.length > 0) {
|
|
var escapedMatchRegex = new RegExp(escapeRegExp(matchText), 'gi');
|
|
return encoded.replace(escapedMatchRegex, function (match) {
|
|
return '<span class="tox-autocompleter-highlight">' + match + '</span>';
|
|
});
|
|
} else {
|
|
return encoded;
|
|
}
|
|
};
|
|
var renderAutocompleteItem = function (spec, matchText, useText, presets, onItemValueHandler, itemResponse, sharedBackstage, renderIcons) {
|
|
if (renderIcons === void 0) {
|
|
renderIcons = true;
|
|
}
|
|
var structure = renderItemStructure({
|
|
presets: presets,
|
|
textContent: Option.none(),
|
|
htmlContent: useText ? spec.text.map(function (text) {
|
|
return replaceText(text, matchText);
|
|
}) : Option.none(),
|
|
ariaLabel: spec.text,
|
|
iconContent: spec.icon,
|
|
shortcutContent: Option.none(),
|
|
checkMark: Option.none(),
|
|
caret: Option.none(),
|
|
value: spec.value
|
|
}, sharedBackstage.providers, renderIcons, spec.icon);
|
|
return renderCommonItem({
|
|
data: buildData(spec),
|
|
disabled: spec.disabled,
|
|
getApi: function () {
|
|
return {};
|
|
},
|
|
onAction: function (_api) {
|
|
return onItemValueHandler(spec.value, spec.meta);
|
|
},
|
|
onSetup: function () {
|
|
return function () {
|
|
};
|
|
},
|
|
triggersSubmenu: false,
|
|
itemBehaviours: tooltipBehaviour(spec.meta, sharedBackstage)
|
|
}, structure, itemResponse, sharedBackstage.providers);
|
|
};
|
|
|
|
var renderChoiceItem = function (spec, useText, presets, onItemValueHandler, isSelected, itemResponse, providersBackstage, renderIcons) {
|
|
if (renderIcons === void 0) {
|
|
renderIcons = true;
|
|
}
|
|
var getApi = function (component) {
|
|
return {
|
|
setActive: function (state) {
|
|
Toggling.set(component, state);
|
|
},
|
|
isActive: function () {
|
|
return Toggling.isOn(component);
|
|
},
|
|
isDisabled: function () {
|
|
return Disabling.isDisabled(component);
|
|
},
|
|
setDisabled: function (state) {
|
|
return Disabling.set(component, state);
|
|
}
|
|
};
|
|
};
|
|
var structure = renderItemStructure({
|
|
presets: presets,
|
|
textContent: useText ? spec.text : Option.none(),
|
|
htmlContent: Option.none(),
|
|
ariaLabel: spec.text,
|
|
iconContent: spec.icon,
|
|
shortcutContent: useText ? spec.shortcut : Option.none(),
|
|
checkMark: useText ? Option.some(renderCheckmark(providersBackstage.icons)) : Option.none(),
|
|
caret: Option.none(),
|
|
value: spec.value
|
|
}, providersBackstage, renderIcons);
|
|
return deepMerge(renderCommonItem({
|
|
data: buildData(spec),
|
|
disabled: spec.disabled,
|
|
getApi: getApi,
|
|
onAction: function (_api) {
|
|
return onItemValueHandler(spec.value);
|
|
},
|
|
onSetup: function (api) {
|
|
api.setActive(isSelected);
|
|
return function () {
|
|
};
|
|
},
|
|
triggersSubmenu: false,
|
|
itemBehaviours: []
|
|
}, structure, itemResponse, providersBackstage), {
|
|
toggling: {
|
|
toggleClass: tickedClass,
|
|
toggleOnExecute: false,
|
|
selected: spec.active
|
|
}
|
|
});
|
|
};
|
|
|
|
var parts$2 = constant(generate$4(owner$2(), parts()));
|
|
|
|
var cellOverEvent = generate$1('cell-over');
|
|
var cellExecuteEvent = generate$1('cell-execute');
|
|
var makeCell = function (row, col, labelId) {
|
|
var _a;
|
|
var emitCellOver = function (c) {
|
|
return emitWith(c, cellOverEvent, {
|
|
row: row,
|
|
col: col
|
|
});
|
|
};
|
|
var emitExecute = function (c) {
|
|
return emitWith(c, cellExecuteEvent, {
|
|
row: row,
|
|
col: col
|
|
});
|
|
};
|
|
var onClick = function (c, se) {
|
|
se.stop();
|
|
emitExecute(c);
|
|
};
|
|
return build$1({
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: (_a = { role: 'button' }, _a['aria-labelledby'] = labelId, _a)
|
|
},
|
|
behaviours: derive$1([
|
|
config('insert-table-picker-cell', [
|
|
run(mouseover(), Focusing.focus),
|
|
run(execute(), emitExecute),
|
|
run(click(), onClick),
|
|
run(tap(), onClick)
|
|
]),
|
|
Toggling.config({
|
|
toggleClass: 'tox-insert-table-picker__selected',
|
|
toggleOnExecute: false
|
|
}),
|
|
Focusing.config({ onFocus: emitCellOver })
|
|
])
|
|
});
|
|
};
|
|
var makeCells = function (labelId, numRows, numCols) {
|
|
var cells = [];
|
|
for (var i = 0; i < numRows; i++) {
|
|
var row = [];
|
|
for (var j = 0; j < numCols; j++) {
|
|
row.push(makeCell(i, j, labelId));
|
|
}
|
|
cells.push(row);
|
|
}
|
|
return cells;
|
|
};
|
|
var selectCells = function (cells, selectedRow, selectedColumn, numRows, numColumns) {
|
|
for (var i = 0; i < numRows; i++) {
|
|
for (var j = 0; j < numColumns; j++) {
|
|
Toggling.set(cells[i][j], i <= selectedRow && j <= selectedColumn);
|
|
}
|
|
}
|
|
};
|
|
var makeComponents = function (cells) {
|
|
return bind(cells, function (cellRow) {
|
|
return map(cellRow, premade$1);
|
|
});
|
|
};
|
|
var makeLabelText = function (row, col) {
|
|
return text(col + 1 + 'x' + (row + 1));
|
|
};
|
|
var renderInsertTableMenuItem = function (spec) {
|
|
var numRows = 10;
|
|
var numColumns = 10;
|
|
var sizeLabelId = generate$1('size-label');
|
|
var cells = makeCells(sizeLabelId, numRows, numColumns);
|
|
var memLabel = record({
|
|
dom: {
|
|
tag: 'span',
|
|
classes: ['tox-insert-table-picker__label'],
|
|
attributes: { id: sizeLabelId }
|
|
},
|
|
components: [text('0x0')],
|
|
behaviours: derive$1([Replacing.config({})])
|
|
});
|
|
return {
|
|
type: 'widget',
|
|
data: { value: generate$1('widget-id') },
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-fancymenuitem']
|
|
},
|
|
autofocus: true,
|
|
components: [parts$2().widget({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-insert-table-picker']
|
|
},
|
|
components: makeComponents(cells).concat(memLabel.asSpec()),
|
|
behaviours: derive$1([
|
|
config('insert-table-picker', [
|
|
runWithTarget(cellOverEvent, function (c, t, e) {
|
|
var row = e.event().row();
|
|
var col = e.event().col();
|
|
selectCells(cells, row, col, numRows, numColumns);
|
|
Replacing.set(memLabel.get(c), [makeLabelText(row, col)]);
|
|
}),
|
|
runWithTarget(cellExecuteEvent, function (c, _, e) {
|
|
spec.onAction({
|
|
numRows: e.event().row() + 1,
|
|
numColumns: e.event().col() + 1
|
|
});
|
|
emit(c, sandboxClose());
|
|
})
|
|
]),
|
|
Keying.config({
|
|
initSize: {
|
|
numRows: numRows,
|
|
numColumns: numColumns
|
|
},
|
|
mode: 'flatgrid',
|
|
selector: '[role="button"]'
|
|
})
|
|
])
|
|
})]
|
|
};
|
|
};
|
|
|
|
var hexColour = function (value) {
|
|
return { value: value };
|
|
};
|
|
var shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
|
var longformRegex = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i;
|
|
var isHexString = function (hex) {
|
|
return shorthandRegex.test(hex) || longformRegex.test(hex);
|
|
};
|
|
var getLongForm = function (hex) {
|
|
var hexString = hex.value.replace(shorthandRegex, function (m, r, g, b) {
|
|
return r + r + g + g + b + b;
|
|
});
|
|
return { value: hexString };
|
|
};
|
|
var extractValues = function (hex) {
|
|
var longForm = getLongForm(hex);
|
|
var splitForm = longformRegex.exec(longForm.value);
|
|
return splitForm === null ? [
|
|
'FFFFFF',
|
|
'FF',
|
|
'FF',
|
|
'FF'
|
|
] : splitForm;
|
|
};
|
|
var toHex = function (component) {
|
|
var hex = component.toString(16);
|
|
return hex.length === 1 ? '0' + hex : hex;
|
|
};
|
|
var fromRgba = function (rgbaColour) {
|
|
var value = toHex(rgbaColour.red) + toHex(rgbaColour.green) + toHex(rgbaColour.blue);
|
|
return hexColour(value);
|
|
};
|
|
|
|
var min = Math.min;
|
|
var max = Math.max;
|
|
var round = Math.round;
|
|
var rgbRegex = /^rgb\((\d+),\s*(\d+),\s*(\d+)\)/;
|
|
var rgbaRegex = /^rgba\((\d+),\s*(\d+),\s*(\d+),\s*(\d?(?:\.\d+)?)\)/;
|
|
var rgbaColour = function (red, green, blue, alpha) {
|
|
return {
|
|
red: red,
|
|
green: green,
|
|
blue: blue,
|
|
alpha: alpha
|
|
};
|
|
};
|
|
var isRgbaComponent = function (value) {
|
|
var num = parseInt(value, 10);
|
|
return num.toString() === value && num >= 0 && num <= 255;
|
|
};
|
|
var fromHsv = function (hsv) {
|
|
var r;
|
|
var g;
|
|
var b;
|
|
var hue = (hsv.hue || 0) % 360;
|
|
var saturation = hsv.saturation / 100;
|
|
var brightness = hsv.value / 100;
|
|
saturation = max(0, min(saturation, 1));
|
|
brightness = max(0, min(brightness, 1));
|
|
if (saturation === 0) {
|
|
r = g = b = round(255 * brightness);
|
|
return rgbaColour(r, g, b, 1);
|
|
}
|
|
var side = hue / 60;
|
|
var chroma = brightness * saturation;
|
|
var x = chroma * (1 - Math.abs(side % 2 - 1));
|
|
var match = brightness - chroma;
|
|
switch (Math.floor(side)) {
|
|
case 0:
|
|
r = chroma;
|
|
g = x;
|
|
b = 0;
|
|
break;
|
|
case 1:
|
|
r = x;
|
|
g = chroma;
|
|
b = 0;
|
|
break;
|
|
case 2:
|
|
r = 0;
|
|
g = chroma;
|
|
b = x;
|
|
break;
|
|
case 3:
|
|
r = 0;
|
|
g = x;
|
|
b = chroma;
|
|
break;
|
|
case 4:
|
|
r = x;
|
|
g = 0;
|
|
b = chroma;
|
|
break;
|
|
case 5:
|
|
r = chroma;
|
|
g = 0;
|
|
b = x;
|
|
break;
|
|
default:
|
|
r = g = b = 0;
|
|
}
|
|
r = round(255 * (r + match));
|
|
g = round(255 * (g + match));
|
|
b = round(255 * (b + match));
|
|
return rgbaColour(r, g, b, 1);
|
|
};
|
|
var fromHex = function (hexColour) {
|
|
var result = extractValues(hexColour);
|
|
var red = parseInt(result[1], 16);
|
|
var green = parseInt(result[2], 16);
|
|
var blue = parseInt(result[3], 16);
|
|
return rgbaColour(red, green, blue, 1);
|
|
};
|
|
var fromStringValues = function (red, green, blue, alpha) {
|
|
var r = parseInt(red, 10);
|
|
var g = parseInt(green, 10);
|
|
var b = parseInt(blue, 10);
|
|
var a = parseFloat(alpha);
|
|
return rgbaColour(r, g, b, a);
|
|
};
|
|
var fromString = function (rgbaString) {
|
|
if (rgbaString === 'transparent') {
|
|
return Option.some(rgbaColour(0, 0, 0, 0));
|
|
}
|
|
var rgbMatch = rgbRegex.exec(rgbaString);
|
|
if (rgbMatch !== null) {
|
|
return Option.some(fromStringValues(rgbMatch[1], rgbMatch[2], rgbMatch[3], '1'));
|
|
}
|
|
var rgbaMatch = rgbaRegex.exec(rgbaString);
|
|
if (rgbaMatch !== null) {
|
|
return Option.some(fromStringValues(rgbaMatch[1], rgbaMatch[2], rgbaMatch[3], rgbaMatch[4]));
|
|
}
|
|
return Option.none();
|
|
};
|
|
var toString = function (rgba) {
|
|
return 'rgba(' + rgba.red + ',' + rgba.green + ',' + rgba.blue + ',' + rgba.alpha + ')';
|
|
};
|
|
var red = rgbaColour(255, 0, 0, 1);
|
|
|
|
var global$9 = tinymce.util.Tools.resolve('tinymce.util.LocalStorage');
|
|
|
|
var storageName = 'tinymce-custom-colors';
|
|
function ColorCache (max) {
|
|
if (max === void 0) {
|
|
max = 10;
|
|
}
|
|
var storageString = global$9.getItem(storageName);
|
|
var localstorage = isString(storageString) ? JSON.parse(storageString) : [];
|
|
var prune = function (list) {
|
|
var diff = max - list.length;
|
|
return diff < 0 ? list.slice(0, max) : list;
|
|
};
|
|
var cache = prune(localstorage);
|
|
var add = function (key) {
|
|
indexOf(cache, key).each(remove);
|
|
cache.unshift(key);
|
|
if (cache.length > max) {
|
|
cache.pop();
|
|
}
|
|
global$9.setItem(storageName, JSON.stringify(cache));
|
|
};
|
|
var remove = function (idx) {
|
|
cache.splice(idx, 1);
|
|
};
|
|
var state = function () {
|
|
return cache.slice(0);
|
|
};
|
|
return {
|
|
add: add,
|
|
state: state
|
|
};
|
|
}
|
|
|
|
var choiceItem = 'choiceitem';
|
|
var defaultColors = [
|
|
{
|
|
type: choiceItem,
|
|
text: 'Light Green',
|
|
value: '#BFEDD2'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Light Yellow',
|
|
value: '#FBEEB8'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Light Red',
|
|
value: '#F8CAC6'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Light Purple',
|
|
value: '#ECCAFA'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Light Blue',
|
|
value: '#C2E0F4'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Green',
|
|
value: '#2DC26B'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Yellow',
|
|
value: '#F1C40F'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Red',
|
|
value: '#E03E2D'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Purple',
|
|
value: '#B96AD9'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Blue',
|
|
value: '#3598DB'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Dark Turquoise',
|
|
value: '#169179'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Orange',
|
|
value: '#E67E23'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Dark Red',
|
|
value: '#BA372A'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Dark Purple',
|
|
value: '#843FA1'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Dark Blue',
|
|
value: '#236FA1'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Light Gray',
|
|
value: '#ECF0F1'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Medium Gray',
|
|
value: '#CED4D9'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Gray',
|
|
value: '#95A5A6'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Dark Gray',
|
|
value: '#7E8C8D'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Navy Blue',
|
|
value: '#34495E'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'Black',
|
|
value: '#000000'
|
|
},
|
|
{
|
|
type: choiceItem,
|
|
text: 'White',
|
|
value: '#ffffff'
|
|
}
|
|
];
|
|
var colorCache = ColorCache(10);
|
|
var mapColors = function (colorMap) {
|
|
var colors = [];
|
|
var canvas = domGlobals.document.createElement('canvas');
|
|
canvas.height = 1;
|
|
canvas.width = 1;
|
|
var ctx = canvas.getContext('2d');
|
|
var byteAsHex = function (colorByte, alphaByte) {
|
|
var bg = 255;
|
|
var alpha = alphaByte / 255;
|
|
var colorByteWithWhiteBg = Math.round(colorByte * alpha + bg * (1 - alpha));
|
|
return ('0' + colorByteWithWhiteBg.toString(16)).slice(-2).toUpperCase();
|
|
};
|
|
var asHexColor = function (color) {
|
|
if (/^[0-9A-Fa-f]{6}$/.test(color)) {
|
|
return '#' + color.toUpperCase();
|
|
}
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
ctx.fillStyle = '#FFFFFF';
|
|
ctx.fillStyle = color;
|
|
ctx.fillRect(0, 0, 1, 1);
|
|
var rgba = ctx.getImageData(0, 0, 1, 1).data;
|
|
var r = rgba[0], g = rgba[1], b = rgba[2], a = rgba[3];
|
|
return '#' + byteAsHex(r, a) + byteAsHex(g, a) + byteAsHex(b, a);
|
|
};
|
|
for (var i = 0; i < colorMap.length; i += 2) {
|
|
colors.push({
|
|
text: colorMap[i + 1],
|
|
value: asHexColor(colorMap[i]),
|
|
type: 'choiceitem'
|
|
});
|
|
}
|
|
return colors;
|
|
};
|
|
var getColorCols = function (editor, defaultCols) {
|
|
return editor.getParam('color_cols', defaultCols, 'number');
|
|
};
|
|
var hasCustomColors = function (editor) {
|
|
return editor.getParam('custom_colors') !== false;
|
|
};
|
|
var getColorMap = function (editor) {
|
|
return editor.getParam('color_map');
|
|
};
|
|
var getColors = function (editor) {
|
|
var unmapped = getColorMap(editor);
|
|
return unmapped !== undefined ? mapColors(unmapped) : defaultColors;
|
|
};
|
|
var getCurrentColors = function () {
|
|
return map(colorCache.state(), function (color) {
|
|
return {
|
|
type: choiceItem,
|
|
text: color,
|
|
value: color
|
|
};
|
|
});
|
|
};
|
|
var addColor = function (color) {
|
|
colorCache.add(color);
|
|
};
|
|
|
|
var fireSkinLoaded = function (editor) {
|
|
return editor.fire('SkinLoaded');
|
|
};
|
|
var fireSkinLoadError = function (editor, error) {
|
|
return editor.fire('SkinLoadError', error);
|
|
};
|
|
var fireResizeEditor = function (editor) {
|
|
return editor.fire('ResizeEditor');
|
|
};
|
|
var fireResizeContent = function (editor, e) {
|
|
return editor.fire('ResizeContent', e);
|
|
};
|
|
var fireScrollContent = function (editor, e) {
|
|
return editor.fire('ScrollContent', e);
|
|
};
|
|
var fireTextColorChange = function (editor, data) {
|
|
return editor.fire('TextColorChange', data);
|
|
};
|
|
|
|
var getCurrentColor = function (editor, format) {
|
|
var color;
|
|
editor.dom.getParents(editor.selection.getStart(), function (elm) {
|
|
var value;
|
|
if (value = elm.style[format === 'forecolor' ? 'color' : 'background-color']) {
|
|
color = color ? color : value;
|
|
}
|
|
});
|
|
return color;
|
|
};
|
|
var applyFormat = function (editor, format, value) {
|
|
editor.undoManager.transact(function () {
|
|
editor.focus();
|
|
editor.formatter.apply(format, { value: value });
|
|
editor.nodeChanged();
|
|
});
|
|
};
|
|
var removeFormat = function (editor, format) {
|
|
editor.undoManager.transact(function () {
|
|
editor.focus();
|
|
editor.formatter.remove(format, { value: null }, null, true);
|
|
editor.nodeChanged();
|
|
});
|
|
};
|
|
var registerCommands = function (editor) {
|
|
editor.addCommand('mceApplyTextcolor', function (format, value) {
|
|
applyFormat(editor, format, value);
|
|
});
|
|
editor.addCommand('mceRemoveTextcolor', function (format) {
|
|
removeFormat(editor, format);
|
|
});
|
|
};
|
|
var calcCols = function (colors) {
|
|
return Math.max(5, Math.ceil(Math.sqrt(colors)));
|
|
};
|
|
var getColorCols$1 = function (editor) {
|
|
var colors = getColors(editor);
|
|
var defaultCols = calcCols(colors.length);
|
|
return getColorCols(editor, defaultCols);
|
|
};
|
|
var getAdditionalColors = function (hasCustom) {
|
|
var type = 'choiceitem';
|
|
var remove = {
|
|
type: type,
|
|
text: 'Remove color',
|
|
icon: 'color-swatch-remove-color',
|
|
value: 'remove'
|
|
};
|
|
var custom = {
|
|
type: type,
|
|
text: 'Custom color',
|
|
icon: 'color-picker',
|
|
value: 'custom'
|
|
};
|
|
return hasCustom ? [
|
|
remove,
|
|
custom
|
|
] : [remove];
|
|
};
|
|
var applyColor = function (editor, format, value, onChoice) {
|
|
if (value === 'custom') {
|
|
var dialog = colorPickerDialog(editor);
|
|
dialog(function (colorOpt) {
|
|
colorOpt.each(function (color) {
|
|
addColor(color);
|
|
editor.execCommand('mceApplyTextcolor', format, color);
|
|
onChoice(color);
|
|
});
|
|
}, '#000000');
|
|
} else if (value === 'remove') {
|
|
onChoice('');
|
|
editor.execCommand('mceRemoveTextcolor', format);
|
|
} else {
|
|
onChoice(value);
|
|
editor.execCommand('mceApplyTextcolor', format, value);
|
|
}
|
|
};
|
|
var getColors$1 = function (colors, hasCustom) {
|
|
return colors.concat(getCurrentColors().concat(getAdditionalColors(hasCustom)));
|
|
};
|
|
var getFetch = function (colors, hasCustom) {
|
|
return function (callback) {
|
|
callback(getColors$1(colors, hasCustom));
|
|
};
|
|
};
|
|
var setIconColor = function (splitButtonApi, name, newColor) {
|
|
var setIconFillAndStroke = function (pathId, color) {
|
|
splitButtonApi.setIconFill(pathId, color);
|
|
splitButtonApi.setIconStroke(pathId, color);
|
|
};
|
|
var id = name === 'forecolor' ? 'tox-icon-text-color__color' : 'tox-icon-highlight-bg-color__color';
|
|
setIconFillAndStroke(id, newColor);
|
|
};
|
|
var registerTextColorButton = function (editor, name, format, tooltip, lastColor) {
|
|
editor.ui.registry.addSplitButton(name, {
|
|
tooltip: tooltip,
|
|
presets: 'color',
|
|
icon: name === 'forecolor' ? 'text-color' : 'highlight-bg-color',
|
|
select: function (value) {
|
|
var optCurrentRgb = Option.from(getCurrentColor(editor, format));
|
|
return optCurrentRgb.bind(function (currentRgb) {
|
|
return fromString(currentRgb).map(function (rgba) {
|
|
var currentHex = fromRgba(rgba).value;
|
|
return contains$1(value.toLowerCase(), currentHex);
|
|
});
|
|
}).getOr(false);
|
|
},
|
|
columns: getColorCols$1(editor),
|
|
fetch: getFetch(getColors(editor), hasCustomColors(editor)),
|
|
onAction: function (_splitButtonApi) {
|
|
if (lastColor.get() !== null) {
|
|
applyColor(editor, format, lastColor.get(), function () {
|
|
});
|
|
}
|
|
},
|
|
onItemAction: function (_splitButtonApi, value) {
|
|
applyColor(editor, format, value, function (newColor) {
|
|
lastColor.set(newColor);
|
|
fireTextColorChange(editor, {
|
|
name: name,
|
|
color: newColor
|
|
});
|
|
});
|
|
},
|
|
onSetup: function (splitButtonApi) {
|
|
if (lastColor.get() !== null) {
|
|
setIconColor(splitButtonApi, name, lastColor.get());
|
|
}
|
|
var handler = function (e) {
|
|
if (e.name === name) {
|
|
setIconColor(splitButtonApi, e.name, e.color);
|
|
}
|
|
};
|
|
editor.on('TextColorChange', handler);
|
|
return function () {
|
|
editor.off('TextColorChange', handler);
|
|
};
|
|
}
|
|
});
|
|
};
|
|
var registerTextColorMenuItem = function (editor, name, format, text) {
|
|
editor.ui.registry.addNestedMenuItem(name, {
|
|
text: text,
|
|
icon: name === 'forecolor' ? 'text-color' : 'highlight-bg-color',
|
|
getSubmenuItems: function () {
|
|
return [{
|
|
type: 'fancymenuitem',
|
|
fancytype: 'colorswatch',
|
|
onAction: function (data) {
|
|
applyColor(editor, format, data.value, noop);
|
|
}
|
|
}];
|
|
}
|
|
});
|
|
};
|
|
var colorPickerDialog = function (editor) {
|
|
return function (callback, value) {
|
|
var getOnSubmit = function (callback) {
|
|
return function (api) {
|
|
var data = api.getData();
|
|
callback(Option.from(data.colorpicker));
|
|
api.close();
|
|
};
|
|
};
|
|
var onAction = function (api, details) {
|
|
if (details.name === 'hex-valid') {
|
|
if (details.value) {
|
|
api.enable('ok');
|
|
} else {
|
|
api.disable('ok');
|
|
}
|
|
}
|
|
};
|
|
var initialData = { colorpicker: value };
|
|
var submit = getOnSubmit(callback);
|
|
editor.windowManager.open({
|
|
title: 'Color Picker',
|
|
size: 'normal',
|
|
body: {
|
|
type: 'panel',
|
|
items: [{
|
|
type: 'colorpicker',
|
|
name: 'colorpicker',
|
|
label: 'Color'
|
|
}]
|
|
},
|
|
buttons: [
|
|
{
|
|
type: 'cancel',
|
|
name: 'cancel',
|
|
text: 'Cancel'
|
|
},
|
|
{
|
|
type: 'submit',
|
|
name: 'save',
|
|
text: 'Save',
|
|
primary: true
|
|
}
|
|
],
|
|
initialData: initialData,
|
|
onAction: onAction,
|
|
onSubmit: submit,
|
|
onClose: function () {
|
|
},
|
|
onCancel: function () {
|
|
callback(Option.none());
|
|
}
|
|
});
|
|
};
|
|
};
|
|
var register$1 = function (editor) {
|
|
registerCommands(editor);
|
|
var lastForeColor = Cell(null);
|
|
var lastBackColor = Cell(null);
|
|
registerTextColorButton(editor, 'forecolor', 'forecolor', 'Text color', lastForeColor);
|
|
registerTextColorButton(editor, 'backcolor', 'hilitecolor', 'Background color', lastBackColor);
|
|
registerTextColorMenuItem(editor, 'forecolor', 'forecolor', 'Text color');
|
|
registerTextColorMenuItem(editor, 'backcolor', 'hilitecolor', 'Background color');
|
|
};
|
|
|
|
var forMenu = function (presets) {
|
|
if (presets === 'color') {
|
|
return 'tox-swatches';
|
|
} else {
|
|
return 'tox-menu';
|
|
}
|
|
};
|
|
var classes = function (presets) {
|
|
return {
|
|
backgroundMenu: 'tox-background-menu',
|
|
selectedMenu: 'tox-selected-menu',
|
|
selectedItem: 'tox-collection__item--active',
|
|
hasIcons: 'tox-menu--has-icons',
|
|
menu: forMenu(presets),
|
|
tieredMenu: 'tox-tiered-menu'
|
|
};
|
|
};
|
|
|
|
var markers$1 = function (presets) {
|
|
var menuClasses = classes(presets);
|
|
return {
|
|
backgroundMenu: menuClasses.backgroundMenu,
|
|
selectedMenu: menuClasses.selectedMenu,
|
|
menu: menuClasses.menu,
|
|
selectedItem: menuClasses.selectedItem,
|
|
item: classForPreset(presets)
|
|
};
|
|
};
|
|
var dom$1 = function (hasIcons, columns, presets) {
|
|
var menuClasses = classes(presets);
|
|
return {
|
|
tag: 'div',
|
|
classes: flatten([
|
|
[
|
|
menuClasses.menu,
|
|
'tox-menu-' + columns + '-column'
|
|
],
|
|
hasIcons ? [menuClasses.hasIcons] : []
|
|
])
|
|
};
|
|
};
|
|
var components$1 = [Menu.parts().items({})];
|
|
var part = function (hasIcons, columns, presets) {
|
|
var menuClasses = classes(presets);
|
|
var d = {
|
|
tag: 'div',
|
|
classes: flatten([[menuClasses.tieredMenu]])
|
|
};
|
|
return {
|
|
dom: d,
|
|
markers: markers$1(presets)
|
|
};
|
|
};
|
|
|
|
var chunk$1 = function (rowDom, numColumns) {
|
|
return function (items) {
|
|
var chunks = chunk(items, numColumns);
|
|
return map(chunks, function (c) {
|
|
return {
|
|
dom: rowDom,
|
|
components: c
|
|
};
|
|
});
|
|
};
|
|
};
|
|
var forSwatch = function (columns) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-menu',
|
|
'tox-swatches-menu'
|
|
]
|
|
},
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-swatches']
|
|
},
|
|
components: [Menu.parts().items({
|
|
preprocess: columns !== 'auto' ? chunk$1({
|
|
tag: 'div',
|
|
classes: ['tox-swatches__row']
|
|
}, columns) : identity
|
|
})]
|
|
}]
|
|
};
|
|
};
|
|
var forToolbar = function (columns) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-menu',
|
|
'tox-collection',
|
|
'tox-collection--toolbar',
|
|
'tox-collection--toolbar-lg'
|
|
]
|
|
},
|
|
components: [Menu.parts().items({
|
|
preprocess: chunk$1({
|
|
tag: 'div',
|
|
classes: ['tox-collection__group']
|
|
}, columns)
|
|
})]
|
|
};
|
|
};
|
|
var preprocessCollection = function (items, isSeparator) {
|
|
var allSplits = [];
|
|
var currentSplit = [];
|
|
each(items, function (item, i) {
|
|
if (isSeparator(item, i)) {
|
|
if (currentSplit.length > 0) {
|
|
allSplits.push(currentSplit);
|
|
}
|
|
currentSplit = [];
|
|
if (has(item.dom, 'innerHtml')) {
|
|
currentSplit.push(item);
|
|
}
|
|
} else {
|
|
currentSplit.push(item);
|
|
}
|
|
});
|
|
if (currentSplit.length > 0) {
|
|
allSplits.push(currentSplit);
|
|
}
|
|
return map(allSplits, function (s) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-collection__group']
|
|
},
|
|
components: s
|
|
};
|
|
});
|
|
};
|
|
var forCollection = function (columns, initItems, _hasIcons) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-menu',
|
|
'tox-collection'
|
|
].concat(columns === 1 ? ['tox-collection--list'] : ['tox-collection--grid'])
|
|
},
|
|
components: [Menu.parts().items({
|
|
preprocess: function (items) {
|
|
if (columns !== 'auto' && columns > 1) {
|
|
return chunk$1({
|
|
tag: 'div',
|
|
classes: ['tox-collection__group']
|
|
}, columns)(items);
|
|
} else {
|
|
return preprocessCollection(items, function (_item, i) {
|
|
return initItems[i].type === 'separator';
|
|
});
|
|
}
|
|
}
|
|
})]
|
|
};
|
|
};
|
|
var forHorizontalCollection = function (initItems, _hasIcons) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-collection',
|
|
'tox-collection--horizontal'
|
|
]
|
|
},
|
|
components: [Menu.parts().items({
|
|
preprocess: function (items) {
|
|
return preprocessCollection(items, function (_item, i) {
|
|
return initItems[i].type === 'separator';
|
|
});
|
|
}
|
|
})]
|
|
};
|
|
};
|
|
|
|
var menuHasIcons = function (xs) {
|
|
return exists(xs, function (item) {
|
|
return 'icon' in item && item.icon !== undefined;
|
|
});
|
|
};
|
|
var handleError = function (error) {
|
|
domGlobals.console.error(formatError(error));
|
|
domGlobals.console.log(error);
|
|
return Option.none();
|
|
};
|
|
var createHorizontalPartialMenuWithAlloyItems = function (value, _hasIcons, items, _columns, _presets) {
|
|
var structure = forHorizontalCollection(items);
|
|
return {
|
|
value: value,
|
|
dom: structure.dom,
|
|
components: structure.components,
|
|
items: items
|
|
};
|
|
};
|
|
var createPartialMenuWithAlloyItems = function (value, hasIcons, items, columns, presets) {
|
|
if (presets === 'color') {
|
|
var structure = forSwatch(columns);
|
|
return {
|
|
value: value,
|
|
dom: structure.dom,
|
|
components: structure.components,
|
|
items: items
|
|
};
|
|
}
|
|
if (presets === 'normal' && columns === 'auto') {
|
|
var structure = forCollection(columns, items);
|
|
return {
|
|
value: value,
|
|
dom: structure.dom,
|
|
components: structure.components,
|
|
items: items
|
|
};
|
|
}
|
|
if (presets === 'normal' && columns === 1) {
|
|
var structure = forCollection(1, items);
|
|
return {
|
|
value: value,
|
|
dom: structure.dom,
|
|
components: structure.components,
|
|
items: items
|
|
};
|
|
}
|
|
if (presets === 'normal') {
|
|
var structure = forCollection(columns, items);
|
|
return {
|
|
value: value,
|
|
dom: structure.dom,
|
|
components: structure.components,
|
|
items: items
|
|
};
|
|
}
|
|
if (presets === 'listpreview' && columns !== 'auto') {
|
|
var structure = forToolbar(columns);
|
|
return {
|
|
value: value,
|
|
dom: structure.dom,
|
|
components: structure.components,
|
|
items: items
|
|
};
|
|
}
|
|
return {
|
|
value: value,
|
|
dom: dom$1(hasIcons, columns, presets),
|
|
components: components$1,
|
|
items: items
|
|
};
|
|
};
|
|
|
|
var createPartialChoiceMenu = function (value, items, onItemValueHandler, columns, presets, itemResponse, select, providersBackstage) {
|
|
var hasIcons = menuHasIcons(items);
|
|
var presetItemTypes = presets !== 'color' ? 'normal' : 'color';
|
|
var alloyItems = createChoiceItems(items, onItemValueHandler, columns, presetItemTypes, itemResponse, select, providersBackstage);
|
|
return createPartialMenuWithAlloyItems(value, hasIcons, alloyItems, columns, presets);
|
|
};
|
|
var createChoiceItems = function (items, onItemValueHandler, columns, itemPresets, itemResponse, select, providersBackstage) {
|
|
return cat(map(items, function (item) {
|
|
if (item.type === 'choiceitem') {
|
|
return createChoiceMenuItem(item).fold(handleError, function (d) {
|
|
return Option.some(renderChoiceItem(d, columns === 1, itemPresets, onItemValueHandler, select(item.value), itemResponse, providersBackstage, menuHasIcons(items)));
|
|
});
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
}));
|
|
};
|
|
|
|
var deriveMenuMovement = function (columns, presets) {
|
|
var menuMarkers = markers$1(presets);
|
|
if (columns === 1) {
|
|
return {
|
|
mode: 'menu',
|
|
moveOnTab: true
|
|
};
|
|
} else if (columns === 'auto') {
|
|
return {
|
|
mode: 'grid',
|
|
selector: '.' + menuMarkers.item,
|
|
initSize: {
|
|
numColumns: 1,
|
|
numRows: 1
|
|
}
|
|
};
|
|
} else {
|
|
var rowClass = presets === 'color' ? 'tox-swatches__row' : 'tox-collection__group';
|
|
return {
|
|
mode: 'matrix',
|
|
rowSelector: '.' + rowClass
|
|
};
|
|
}
|
|
};
|
|
var deriveCollectionMovement = function (columns, presets) {
|
|
if (columns === 1) {
|
|
return {
|
|
mode: 'menu',
|
|
moveOnTab: false,
|
|
selector: '.tox-collection__item'
|
|
};
|
|
} else if (columns === 'auto') {
|
|
return {
|
|
mode: 'flatgrid',
|
|
selector: '.' + 'tox-collection__item',
|
|
initSize: {
|
|
numColumns: 1,
|
|
numRows: 1
|
|
}
|
|
};
|
|
} else {
|
|
return {
|
|
mode: 'matrix',
|
|
selectors: {
|
|
row: presets === 'color' ? '.tox-swatches__row' : '.tox-collection__group',
|
|
cell: presets === 'color' ? '.' + colorClass : '.' + selectableClass
|
|
}
|
|
};
|
|
}
|
|
};
|
|
|
|
function renderColorSwatchItem(spec, backstage) {
|
|
var items = getColors$1(backstage.colorinput.getColors(), backstage.colorinput.hasCustomColors());
|
|
var columns = backstage.colorinput.getColorCols();
|
|
var presets = 'color';
|
|
var menuSpec = createPartialChoiceMenu(generate$1('menu-value'), items, function (value) {
|
|
spec.onAction({ value: value });
|
|
}, columns, presets, ItemResponse$1.CLOSE_ON_EXECUTE, function () {
|
|
return false;
|
|
}, backstage.shared.providers);
|
|
var widgetSpec = __assign(__assign({}, menuSpec), {
|
|
markers: markers$1(presets),
|
|
movement: deriveMenuMovement(columns, presets)
|
|
});
|
|
return {
|
|
type: 'widget',
|
|
data: { value: generate$1('widget-id') },
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-fancymenuitem']
|
|
},
|
|
autofocus: true,
|
|
components: [parts$2().widget(Menu.sketch(widgetSpec))]
|
|
};
|
|
}
|
|
|
|
var fancyMenuItems = {
|
|
inserttable: renderInsertTableMenuItem,
|
|
colorswatch: renderColorSwatchItem
|
|
};
|
|
var valueOpt = function (obj, key) {
|
|
return Object.prototype.hasOwnProperty.call(obj, key) ? Option.some(obj[key]) : Option.none();
|
|
};
|
|
var renderFancyMenuItem = function (spec, backstage) {
|
|
return valueOpt(fancyMenuItems, spec.fancytype).map(function (render) {
|
|
return render(spec, backstage);
|
|
});
|
|
};
|
|
|
|
var renderNormalItem = function (spec, itemResponse, providersBackstage, renderIcons) {
|
|
if (renderIcons === void 0) {
|
|
renderIcons = true;
|
|
}
|
|
var getApi = function (component) {
|
|
return {
|
|
isDisabled: function () {
|
|
return Disabling.isDisabled(component);
|
|
},
|
|
setDisabled: function (state) {
|
|
return Disabling.set(component, state);
|
|
}
|
|
};
|
|
};
|
|
var structure = renderItemStructure({
|
|
presets: 'normal',
|
|
iconContent: spec.icon,
|
|
textContent: spec.text,
|
|
htmlContent: Option.none(),
|
|
ariaLabel: spec.text,
|
|
caret: Option.none(),
|
|
checkMark: Option.none(),
|
|
shortcutContent: spec.shortcut
|
|
}, providersBackstage, renderIcons);
|
|
return renderCommonItem({
|
|
data: buildData(spec),
|
|
getApi: getApi,
|
|
disabled: spec.disabled,
|
|
onAction: spec.onAction,
|
|
onSetup: spec.onSetup,
|
|
triggersSubmenu: false,
|
|
itemBehaviours: []
|
|
}, structure, itemResponse, providersBackstage);
|
|
};
|
|
|
|
var renderNestedItem = function (spec, itemResponse, providersBackstage, renderIcons, downwardsCaret) {
|
|
if (renderIcons === void 0) {
|
|
renderIcons = true;
|
|
}
|
|
if (downwardsCaret === void 0) {
|
|
downwardsCaret = false;
|
|
}
|
|
var caret = downwardsCaret ? renderDownwardsCaret(providersBackstage.icons) : renderSubmenuCaret(providersBackstage.icons);
|
|
var getApi = function (component) {
|
|
return {
|
|
isDisabled: function () {
|
|
return Disabling.isDisabled(component);
|
|
},
|
|
setDisabled: function (state) {
|
|
return Disabling.set(component, state);
|
|
}
|
|
};
|
|
};
|
|
var structure = renderItemStructure({
|
|
presets: 'normal',
|
|
iconContent: spec.icon,
|
|
textContent: spec.text,
|
|
htmlContent: Option.none(),
|
|
ariaLabel: spec.text,
|
|
caret: Option.some(caret),
|
|
checkMark: Option.none(),
|
|
shortcutContent: spec.shortcut
|
|
}, providersBackstage, renderIcons);
|
|
return renderCommonItem({
|
|
data: buildData(spec),
|
|
getApi: getApi,
|
|
disabled: spec.disabled,
|
|
onAction: noop,
|
|
onSetup: spec.onSetup,
|
|
triggersSubmenu: true,
|
|
itemBehaviours: []
|
|
}, structure, itemResponse, providersBackstage);
|
|
};
|
|
|
|
var renderSeparatorItem = function (spec) {
|
|
var innerHtml = spec.text.fold(function () {
|
|
return {};
|
|
}, function (text) {
|
|
return { innerHtml: text };
|
|
});
|
|
return {
|
|
type: 'separator',
|
|
dom: __assign({
|
|
tag: 'div',
|
|
classes: [
|
|
selectableClass,
|
|
groupHeadingClass
|
|
]
|
|
}, innerHtml),
|
|
components: []
|
|
};
|
|
};
|
|
|
|
var renderToggleMenuItem = function (spec, itemResponse, providersBackstage, renderIcons) {
|
|
if (renderIcons === void 0) {
|
|
renderIcons = true;
|
|
}
|
|
var getApi = function (component) {
|
|
return {
|
|
setActive: function (state) {
|
|
Toggling.set(component, state);
|
|
},
|
|
isActive: function () {
|
|
return Toggling.isOn(component);
|
|
},
|
|
isDisabled: function () {
|
|
return Disabling.isDisabled(component);
|
|
},
|
|
setDisabled: function (state) {
|
|
return Disabling.set(component, state);
|
|
}
|
|
};
|
|
};
|
|
var structure = renderItemStructure({
|
|
iconContent: spec.icon,
|
|
textContent: spec.text,
|
|
htmlContent: Option.none(),
|
|
ariaLabel: spec.text,
|
|
checkMark: Option.some(renderCheckmark(providersBackstage.icons)),
|
|
caret: Option.none(),
|
|
shortcutContent: spec.shortcut,
|
|
presets: 'normal',
|
|
meta: spec.meta
|
|
}, providersBackstage, renderIcons);
|
|
return deepMerge(renderCommonItem({
|
|
data: buildData(spec),
|
|
disabled: spec.disabled,
|
|
getApi: getApi,
|
|
onAction: spec.onAction,
|
|
onSetup: spec.onSetup,
|
|
triggersSubmenu: false,
|
|
itemBehaviours: []
|
|
}, structure, itemResponse, providersBackstage), {
|
|
toggling: {
|
|
toggleClass: tickedClass,
|
|
toggleOnExecute: false,
|
|
selected: spec.active
|
|
}
|
|
});
|
|
};
|
|
|
|
var autocomplete = renderAutocompleteItem;
|
|
var separator = renderSeparatorItem;
|
|
var normal = renderNormalItem;
|
|
var nested = renderNestedItem;
|
|
var toggle$1 = renderToggleMenuItem;
|
|
var fancy = renderFancyMenuItem;
|
|
|
|
var FocusMode;
|
|
(function (FocusMode) {
|
|
FocusMode[FocusMode['ContentFocus'] = 0] = 'ContentFocus';
|
|
FocusMode[FocusMode['UiFocus'] = 1] = 'UiFocus';
|
|
}(FocusMode || (FocusMode = {})));
|
|
var createMenuItemFromBridge = function (item, itemResponse, backstage, menuHasIcons, isHorizontalMenu) {
|
|
var providersBackstage = backstage.shared.providers;
|
|
var parseForHorizontalMenu = function (menuitem) {
|
|
return !isHorizontalMenu ? menuitem : __assign(__assign({}, menuitem), {
|
|
shortcut: Option.none(),
|
|
icon: menuitem.text.isSome() ? Option.none() : menuitem.icon
|
|
});
|
|
};
|
|
switch (item.type) {
|
|
case 'menuitem':
|
|
return createMenuItem(item).fold(handleError, function (d) {
|
|
return Option.some(normal(parseForHorizontalMenu(d), itemResponse, providersBackstage, menuHasIcons));
|
|
});
|
|
case 'nestedmenuitem':
|
|
return createNestedMenuItem(item).fold(handleError, function (d) {
|
|
return Option.some(nested(parseForHorizontalMenu(d), itemResponse, providersBackstage, menuHasIcons, isHorizontalMenu));
|
|
});
|
|
case 'togglemenuitem':
|
|
return createToggleMenuItem(item).fold(handleError, function (d) {
|
|
return Option.some(toggle$1(parseForHorizontalMenu(d), itemResponse, providersBackstage, menuHasIcons));
|
|
});
|
|
case 'separator':
|
|
return createSeparatorMenuItem(item).fold(handleError, function (d) {
|
|
return Option.some(separator(d));
|
|
});
|
|
case 'fancymenuitem':
|
|
return createFancyMenuItem(item).fold(handleError, function (d) {
|
|
return fancy(parseForHorizontalMenu(d), backstage);
|
|
});
|
|
default: {
|
|
domGlobals.console.error('Unknown item in general menu', item);
|
|
return Option.none();
|
|
}
|
|
}
|
|
};
|
|
var createAutocompleteItems = function (items, matchText, onItemValueHandler, columns, itemResponse, sharedBackstage) {
|
|
var renderText = columns === 1;
|
|
var renderIcons = !renderText || menuHasIcons(items);
|
|
return cat(map(items, function (item) {
|
|
if (item.type === 'separator') {
|
|
return createSeparatorItem(item).fold(handleError, function (d) {
|
|
return Option.some(separator(d));
|
|
});
|
|
} else {
|
|
return createAutocompleterItem(item).fold(handleError, function (d) {
|
|
return Option.some(autocomplete(d, matchText, renderText, 'normal', onItemValueHandler, itemResponse, sharedBackstage, renderIcons));
|
|
});
|
|
}
|
|
}));
|
|
};
|
|
var createPartialMenu = function (value, items, itemResponse, backstage, isHorizontalMenu) {
|
|
var hasIcons = menuHasIcons(items);
|
|
var alloyItems = cat(map(items, function (item) {
|
|
var itemHasIcon = function (i) {
|
|
return isHorizontalMenu ? !i.hasOwnProperty('text') : hasIcons;
|
|
};
|
|
var createItem = function (i) {
|
|
return createMenuItemFromBridge(i, itemResponse, backstage, itemHasIcon(i), isHorizontalMenu);
|
|
};
|
|
if (item.type === 'nestedmenuitem' && item.getSubmenuItems().length <= 0) {
|
|
return createItem(__assign(__assign({}, item), { disabled: true }));
|
|
} else {
|
|
return createItem(item);
|
|
}
|
|
}));
|
|
var createPartial = isHorizontalMenu ? createHorizontalPartialMenuWithAlloyItems : createPartialMenuWithAlloyItems;
|
|
return createPartial(value, hasIcons, alloyItems, 1, 'normal');
|
|
};
|
|
var createTieredDataFrom = function (partialMenu) {
|
|
return tieredMenu.singleData(partialMenu.value, partialMenu);
|
|
};
|
|
var createMenuFrom = function (partialMenu, columns, focusMode, presets) {
|
|
var focusManager = focusMode === FocusMode.ContentFocus ? highlights() : dom();
|
|
var movement = deriveMenuMovement(columns, presets);
|
|
var menuMarkers = markers$1(presets);
|
|
return {
|
|
dom: partialMenu.dom,
|
|
components: partialMenu.components,
|
|
items: partialMenu.items,
|
|
value: partialMenu.value,
|
|
markers: {
|
|
selectedItem: menuMarkers.selectedItem,
|
|
item: menuMarkers.item
|
|
},
|
|
movement: movement,
|
|
fakeFocus: focusMode === FocusMode.ContentFocus,
|
|
focusManager: focusManager,
|
|
menuBehaviours: SimpleBehaviours.unnamedEvents(columns !== 'auto' ? [] : [runOnAttached(function (comp, _se) {
|
|
detectSize(comp, 4, menuMarkers.item).each(function (_a) {
|
|
var numColumns = _a.numColumns, numRows = _a.numRows;
|
|
Keying.setGridSize(comp, numRows, numColumns);
|
|
});
|
|
})])
|
|
};
|
|
};
|
|
|
|
var register$2 = function (editor, sharedBackstage) {
|
|
var activeAutocompleter = Cell(Option.none());
|
|
var processingAction = Cell(false);
|
|
var autocompleter = build$1(InlineView.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-autocompleter']
|
|
},
|
|
components: [],
|
|
fireDismissalEventInstead: {},
|
|
inlineBehaviours: derive$1([config('dismissAutocompleter', [run(dismissRequested(), function () {
|
|
return cancelIfNecessary();
|
|
})])]),
|
|
lazySink: sharedBackstage.getSink
|
|
}));
|
|
var isMenuOpen = function () {
|
|
return InlineView.isOpen(autocompleter);
|
|
};
|
|
var isActive = function () {
|
|
return activeAutocompleter.get().isSome();
|
|
};
|
|
var hideIfNecessary = function () {
|
|
if (isActive()) {
|
|
InlineView.hide(autocompleter);
|
|
}
|
|
};
|
|
var cancelIfNecessary = function () {
|
|
if (isActive()) {
|
|
var lastElement = activeAutocompleter.get().map(function (ac) {
|
|
return ac.element;
|
|
});
|
|
detect$4(lastElement.getOr(Element.fromDom(editor.selection.getNode()))).each(unwrap);
|
|
hideIfNecessary();
|
|
activeAutocompleter.set(Option.none());
|
|
processingAction.set(false);
|
|
}
|
|
};
|
|
var getAutocompleters = cached(function () {
|
|
return register(editor);
|
|
});
|
|
var getCombinedItems = function (triggerChar, matches) {
|
|
var columns = findMap(matches, function (m) {
|
|
return Option.from(m.columns);
|
|
}).getOr(1);
|
|
return bind(matches, function (match) {
|
|
var choices = match.items;
|
|
return createAutocompleteItems(choices, match.matchText, function (itemValue, itemMeta) {
|
|
var nr = editor.selection.getRng();
|
|
getContext(editor.dom, nr, triggerChar).fold(function () {
|
|
return domGlobals.console.error('Lost context. Cursor probably moved');
|
|
}, function (_a) {
|
|
var range = _a.range;
|
|
var autocompleterApi = {
|
|
hide: function () {
|
|
cancelIfNecessary();
|
|
},
|
|
reload: function (fetchOptions) {
|
|
hideIfNecessary();
|
|
load(fetchOptions);
|
|
}
|
|
};
|
|
processingAction.set(true);
|
|
match.onAction(autocompleterApi, range, itemValue, itemMeta);
|
|
processingAction.set(false);
|
|
});
|
|
}, columns, ItemResponse$1.BUBBLE_TO_SANDBOX, sharedBackstage);
|
|
});
|
|
};
|
|
var commenceIfNecessary = function (context) {
|
|
if (!isActive()) {
|
|
var wrapper = create$4(editor, context.range);
|
|
activeAutocompleter.set(Option.some({
|
|
triggerChar: context.triggerChar,
|
|
element: wrapper,
|
|
matchLength: context.text.length
|
|
}));
|
|
processingAction.set(false);
|
|
}
|
|
};
|
|
var display = function (ac, context, lookupData, items) {
|
|
ac.matchLength = context.text.length;
|
|
var columns = findMap(lookupData, function (ld) {
|
|
return Option.from(ld.columns);
|
|
}).getOr(1);
|
|
InlineView.showAt(autocompleter, {
|
|
anchor: 'node',
|
|
root: Element.fromDom(editor.getBody()),
|
|
node: Option.from(ac.element)
|
|
}, Menu.sketch(createMenuFrom(createPartialMenuWithAlloyItems('autocompleter-value', true, items, columns, 'normal'), columns, FocusMode.ContentFocus, 'normal')));
|
|
InlineView.getContent(autocompleter).each(Highlighting.highlightFirst);
|
|
};
|
|
var doLookup = function (fetchOptions) {
|
|
return activeAutocompleter.get().map(function (ac) {
|
|
return getContext(editor.dom, editor.selection.getRng(), ac.triggerChar).bind(function (newContext) {
|
|
return lookupWithContext(editor, getAutocompleters, newContext, fetchOptions);
|
|
});
|
|
}).getOrThunk(function () {
|
|
return lookup(editor, getAutocompleters);
|
|
});
|
|
};
|
|
var load = function (fetchOptions) {
|
|
doLookup(fetchOptions).fold(cancelIfNecessary, function (lookupInfo) {
|
|
commenceIfNecessary(lookupInfo.context);
|
|
lookupInfo.lookupData.then(function (lookupData) {
|
|
activeAutocompleter.get().map(function (ac) {
|
|
var context = lookupInfo.context;
|
|
if (ac.triggerChar === context.triggerChar) {
|
|
var combinedItems = getCombinedItems(context.triggerChar, lookupData);
|
|
if (combinedItems.length > 0) {
|
|
display(ac, context, lookupData, combinedItems);
|
|
} else if (context.text.length - ac.matchLength >= 10) {
|
|
cancelIfNecessary();
|
|
} else {
|
|
hideIfNecessary();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var onKeypress = last$2(function (e) {
|
|
if (e.which === 27) {
|
|
return;
|
|
}
|
|
load();
|
|
}, 50);
|
|
var autocompleterUiApi = {
|
|
onKeypress: onKeypress,
|
|
cancelIfNecessary: cancelIfNecessary,
|
|
isMenuOpen: isMenuOpen,
|
|
isActive: isActive,
|
|
isProcessingAction: processingAction.get,
|
|
getView: function () {
|
|
return InlineView.getContent(autocompleter);
|
|
}
|
|
};
|
|
AutocompleterEditorEvents.setup(autocompleterUiApi, editor);
|
|
};
|
|
var Autocompleter = { register: register$2 };
|
|
|
|
var filter$2 = constant(true);
|
|
var bind$3 = function (element, event, handler) {
|
|
return bind$2(element, event, filter$2, handler);
|
|
};
|
|
var capture$1 = function (element, event, handler) {
|
|
return capture(element, event, filter$2, handler);
|
|
};
|
|
var fromRawEvent$1 = fromRawEvent;
|
|
|
|
var closest$4 = function (scope, selector, isRoot) {
|
|
return closest$3(scope, selector, isRoot).isSome();
|
|
};
|
|
|
|
function DelayedFunction (fun, delay) {
|
|
var ref = null;
|
|
var schedule = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
ref = domGlobals.setTimeout(function () {
|
|
fun.apply(null, args);
|
|
ref = null;
|
|
}, delay);
|
|
};
|
|
var cancel = function () {
|
|
if (ref !== null) {
|
|
domGlobals.clearTimeout(ref);
|
|
ref = null;
|
|
}
|
|
};
|
|
return {
|
|
cancel: cancel,
|
|
schedule: schedule
|
|
};
|
|
}
|
|
|
|
var SIGNIFICANT_MOVE = 5;
|
|
var LONGPRESS_DELAY = 400;
|
|
var getTouch = function (event) {
|
|
var raw = event.raw();
|
|
if (raw.touches === undefined || raw.touches.length !== 1) {
|
|
return Option.none();
|
|
}
|
|
return Option.some(raw.touches[0]);
|
|
};
|
|
var isFarEnough = function (touch, data) {
|
|
var distX = Math.abs(touch.clientX - data.x);
|
|
var distY = Math.abs(touch.clientY - data.y);
|
|
return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE;
|
|
};
|
|
var monitor = function (settings) {
|
|
var startData = Cell(Option.none());
|
|
var longpressFired = Cell(false);
|
|
var longpress$1 = DelayedFunction(function (event) {
|
|
settings.triggerEvent(longpress(), event);
|
|
longpressFired.set(true);
|
|
}, LONGPRESS_DELAY);
|
|
var handleTouchstart = function (event) {
|
|
getTouch(event).each(function (touch) {
|
|
longpress$1.cancel();
|
|
var data = {
|
|
x: touch.clientX,
|
|
y: touch.clientY,
|
|
target: event.target()
|
|
};
|
|
longpress$1.schedule(event);
|
|
longpressFired.set(false);
|
|
startData.set(Option.some(data));
|
|
});
|
|
return Option.none();
|
|
};
|
|
var handleTouchmove = function (event) {
|
|
longpress$1.cancel();
|
|
getTouch(event).each(function (touch) {
|
|
startData.get().each(function (data) {
|
|
if (isFarEnough(touch, data)) {
|
|
startData.set(Option.none());
|
|
}
|
|
});
|
|
});
|
|
return Option.none();
|
|
};
|
|
var handleTouchend = function (event) {
|
|
longpress$1.cancel();
|
|
var isSame = function (data) {
|
|
return eq$1(data.target, event.target());
|
|
};
|
|
return startData.get().filter(isSame).map(function (_data) {
|
|
if (longpressFired.get()) {
|
|
event.prevent();
|
|
return false;
|
|
} else {
|
|
return settings.triggerEvent(tap(), event);
|
|
}
|
|
});
|
|
};
|
|
var handlers = wrapAll$1([
|
|
{
|
|
key: touchstart(),
|
|
value: handleTouchstart
|
|
},
|
|
{
|
|
key: touchmove(),
|
|
value: handleTouchmove
|
|
},
|
|
{
|
|
key: touchend(),
|
|
value: handleTouchend
|
|
}
|
|
]);
|
|
var fireIfReady = function (event, type) {
|
|
return get(handlers, type).bind(function (handler) {
|
|
return handler(event);
|
|
});
|
|
};
|
|
return { fireIfReady: fireIfReady };
|
|
};
|
|
|
|
var isDangerous = function (event) {
|
|
var keyEv = event.raw();
|
|
return keyEv.which === BACKSPACE()[0] && !contains([
|
|
'input',
|
|
'textarea'
|
|
], name(event.target())) && !closest$4(event.target(), '[contenteditable="true"]');
|
|
};
|
|
var isFirefox = function () {
|
|
return detect$3().browser.isFirefox();
|
|
};
|
|
var settingsSchema = objOfOnly([
|
|
strictFunction('triggerEvent'),
|
|
defaulted$1('stopBackspace', true)
|
|
]);
|
|
var bindFocus = function (container, handler) {
|
|
if (isFirefox()) {
|
|
return capture$1(container, 'focus', handler);
|
|
} else {
|
|
return bind$3(container, 'focusin', handler);
|
|
}
|
|
};
|
|
var bindBlur = function (container, handler) {
|
|
if (isFirefox()) {
|
|
return capture$1(container, 'blur', handler);
|
|
} else {
|
|
return bind$3(container, 'focusout', handler);
|
|
}
|
|
};
|
|
var setup$1 = function (container, rawSettings) {
|
|
var settings = asRawOrDie('Getting GUI events settings', settingsSchema, rawSettings);
|
|
var pointerEvents = [
|
|
'touchstart',
|
|
'touchmove',
|
|
'touchend',
|
|
'touchcancel',
|
|
'gesturestart',
|
|
'mousedown',
|
|
'mouseup',
|
|
'mouseover',
|
|
'mousemove',
|
|
'mouseout',
|
|
'click'
|
|
];
|
|
var tapEvent = monitor(settings);
|
|
var simpleEvents = map(pointerEvents.concat([
|
|
'selectstart',
|
|
'input',
|
|
'contextmenu',
|
|
'change',
|
|
'transitionend',
|
|
'drag',
|
|
'dragstart',
|
|
'dragend',
|
|
'dragenter',
|
|
'dragleave',
|
|
'dragover',
|
|
'drop',
|
|
'keyup'
|
|
]), function (type) {
|
|
return bind$3(container, type, function (event) {
|
|
tapEvent.fireIfReady(event, type).each(function (tapStopped) {
|
|
if (tapStopped) {
|
|
event.kill();
|
|
}
|
|
});
|
|
var stopped = settings.triggerEvent(type, event);
|
|
if (stopped) {
|
|
event.kill();
|
|
}
|
|
});
|
|
});
|
|
var pasteTimeout = Cell(Option.none());
|
|
var onPaste = bind$3(container, 'paste', function (event) {
|
|
tapEvent.fireIfReady(event, 'paste').each(function (tapStopped) {
|
|
if (tapStopped) {
|
|
event.kill();
|
|
}
|
|
});
|
|
var stopped = settings.triggerEvent('paste', event);
|
|
if (stopped) {
|
|
event.kill();
|
|
}
|
|
pasteTimeout.set(Option.some(domGlobals.setTimeout(function () {
|
|
settings.triggerEvent(postPaste(), event);
|
|
}, 0)));
|
|
});
|
|
var onKeydown = bind$3(container, 'keydown', function (event) {
|
|
var stopped = settings.triggerEvent('keydown', event);
|
|
if (stopped) {
|
|
event.kill();
|
|
} else if (settings.stopBackspace === true && isDangerous(event)) {
|
|
event.prevent();
|
|
}
|
|
});
|
|
var onFocusIn = bindFocus(container, function (event) {
|
|
var stopped = settings.triggerEvent('focusin', event);
|
|
if (stopped) {
|
|
event.kill();
|
|
}
|
|
});
|
|
var focusoutTimeout = Cell(Option.none());
|
|
var onFocusOut = bindBlur(container, function (event) {
|
|
var stopped = settings.triggerEvent('focusout', event);
|
|
if (stopped) {
|
|
event.kill();
|
|
}
|
|
focusoutTimeout.set(Option.some(domGlobals.setTimeout(function () {
|
|
settings.triggerEvent(postBlur(), event);
|
|
}, 0)));
|
|
});
|
|
var unbind = function () {
|
|
each(simpleEvents, function (e) {
|
|
e.unbind();
|
|
});
|
|
onKeydown.unbind();
|
|
onFocusIn.unbind();
|
|
onFocusOut.unbind();
|
|
onPaste.unbind();
|
|
pasteTimeout.get().each(domGlobals.clearTimeout);
|
|
focusoutTimeout.get().each(domGlobals.clearTimeout);
|
|
};
|
|
return { unbind: unbind };
|
|
};
|
|
|
|
var derive$2 = function (rawEvent, rawTarget) {
|
|
var source = get(rawEvent, 'target').map(function (getTarget) {
|
|
return getTarget();
|
|
}).getOr(rawTarget);
|
|
return Cell(source);
|
|
};
|
|
|
|
var fromSource = function (event, source) {
|
|
var stopper = Cell(false);
|
|
var cutter = Cell(false);
|
|
var stop = function () {
|
|
stopper.set(true);
|
|
};
|
|
var cut = function () {
|
|
cutter.set(true);
|
|
};
|
|
return {
|
|
stop: stop,
|
|
cut: cut,
|
|
isStopped: stopper.get,
|
|
isCut: cutter.get,
|
|
event: constant(event),
|
|
setSource: source.set,
|
|
getSource: source.get
|
|
};
|
|
};
|
|
var fromExternal = function (event) {
|
|
var stopper = Cell(false);
|
|
var stop = function () {
|
|
stopper.set(true);
|
|
};
|
|
return {
|
|
stop: stop,
|
|
cut: noop,
|
|
isStopped: stopper.get,
|
|
isCut: constant(false),
|
|
event: constant(event),
|
|
setSource: die('Cannot set source of a broadcasted event'),
|
|
getSource: die('Cannot get source of a broadcasted event')
|
|
};
|
|
};
|
|
|
|
var adt$b = Adt.generate([
|
|
{ stopped: [] },
|
|
{ resume: ['element'] },
|
|
{ complete: [] }
|
|
]);
|
|
var doTriggerHandler = function (lookup, eventType, rawEvent, target, source, logger) {
|
|
var handler = lookup(eventType, target);
|
|
var simulatedEvent = fromSource(rawEvent, source);
|
|
return handler.fold(function () {
|
|
logger.logEventNoHandlers(eventType, target);
|
|
return adt$b.complete();
|
|
}, function (handlerInfo) {
|
|
var descHandler = handlerInfo.descHandler;
|
|
var eventHandler = getCurried(descHandler);
|
|
eventHandler(simulatedEvent);
|
|
if (simulatedEvent.isStopped()) {
|
|
logger.logEventStopped(eventType, handlerInfo.element, descHandler.purpose());
|
|
return adt$b.stopped();
|
|
} else if (simulatedEvent.isCut()) {
|
|
logger.logEventCut(eventType, handlerInfo.element, descHandler.purpose());
|
|
return adt$b.complete();
|
|
} else {
|
|
return parent(handlerInfo.element).fold(function () {
|
|
logger.logNoParent(eventType, handlerInfo.element, descHandler.purpose());
|
|
return adt$b.complete();
|
|
}, function (parent) {
|
|
logger.logEventResponse(eventType, handlerInfo.element, descHandler.purpose());
|
|
return adt$b.resume(parent);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var doTriggerOnUntilStopped = function (lookup, eventType, rawEvent, rawTarget, source, logger) {
|
|
return doTriggerHandler(lookup, eventType, rawEvent, rawTarget, source, logger).fold(function () {
|
|
return true;
|
|
}, function (parent) {
|
|
return doTriggerOnUntilStopped(lookup, eventType, rawEvent, parent, source, logger);
|
|
}, function () {
|
|
return false;
|
|
});
|
|
};
|
|
var triggerHandler = function (lookup, eventType, rawEvent, target, logger) {
|
|
var source = derive$2(rawEvent, target);
|
|
return doTriggerHandler(lookup, eventType, rawEvent, target, source, logger);
|
|
};
|
|
var broadcast = function (listeners, rawEvent, _logger) {
|
|
var simulatedEvent = fromExternal(rawEvent);
|
|
each(listeners, function (listener) {
|
|
var descHandler = listener.descHandler();
|
|
var handler = getCurried(descHandler);
|
|
handler(simulatedEvent);
|
|
});
|
|
return simulatedEvent.isStopped();
|
|
};
|
|
var triggerUntilStopped = function (lookup, eventType, rawEvent, logger) {
|
|
var rawTarget = rawEvent.target();
|
|
return triggerOnUntilStopped(lookup, eventType, rawEvent, rawTarget, logger);
|
|
};
|
|
var triggerOnUntilStopped = function (lookup, eventType, rawEvent, rawTarget, logger) {
|
|
var source = derive$2(rawEvent, rawTarget);
|
|
return doTriggerOnUntilStopped(lookup, eventType, rawEvent, rawTarget, source, logger);
|
|
};
|
|
|
|
var eventHandler = function (element, descHandler) {
|
|
return {
|
|
element: element,
|
|
descHandler: descHandler
|
|
};
|
|
};
|
|
var broadcastHandler = function (id, handler) {
|
|
return {
|
|
id: constant(id),
|
|
descHandler: constant(handler)
|
|
};
|
|
};
|
|
function EventRegistry () {
|
|
var registry = {};
|
|
var registerId = function (extraArgs, id, events) {
|
|
each$1(events, function (v, k) {
|
|
var handlers = registry[k] !== undefined ? registry[k] : {};
|
|
handlers[id] = curryArgs(v, extraArgs);
|
|
registry[k] = handlers;
|
|
});
|
|
};
|
|
var findHandler = function (handlers, elem) {
|
|
return read$1(elem).fold(function () {
|
|
return Option.none();
|
|
}, function (id) {
|
|
return handlers.bind(function (h) {
|
|
return get(h, id);
|
|
}).map(function (descHandler) {
|
|
return eventHandler(elem, descHandler);
|
|
});
|
|
});
|
|
};
|
|
var filterByType = function (type) {
|
|
return get(registry, type).map(function (handlers) {
|
|
return mapToArray(handlers, function (f, id) {
|
|
return broadcastHandler(id, f);
|
|
});
|
|
}).getOr([]);
|
|
};
|
|
var find = function (isAboveRoot, type, target) {
|
|
var handlers = get(registry, type);
|
|
return closest(target, function (elem) {
|
|
return findHandler(handlers, elem);
|
|
}, isAboveRoot);
|
|
};
|
|
var unregisterId = function (id) {
|
|
each$1(registry, function (handlersById, _eventName) {
|
|
if (handlersById.hasOwnProperty(id)) {
|
|
delete handlersById[id];
|
|
}
|
|
});
|
|
};
|
|
return {
|
|
registerId: registerId,
|
|
unregisterId: unregisterId,
|
|
filterByType: filterByType,
|
|
find: find
|
|
};
|
|
}
|
|
|
|
function Registry () {
|
|
var events = EventRegistry();
|
|
var components = {};
|
|
var readOrTag = function (component) {
|
|
var elem = component.element();
|
|
return read$1(elem).fold(function () {
|
|
return write('uid-', component.element());
|
|
}, function (uid) {
|
|
return uid;
|
|
});
|
|
};
|
|
var failOnDuplicate = function (component, tagId) {
|
|
var conflict = components[tagId];
|
|
if (conflict === component) {
|
|
unregister(component);
|
|
} else {
|
|
throw new Error('The tagId "' + tagId + '" is already used by: ' + element(conflict.element()) + '\nCannot use it for: ' + element(component.element()) + '\n' + 'The conflicting element is' + (inBody(conflict.element()) ? ' ' : ' not ') + 'already in the DOM');
|
|
}
|
|
};
|
|
var register = function (component) {
|
|
var tagId = readOrTag(component);
|
|
if (hasNonNullableKey(components, tagId)) {
|
|
failOnDuplicate(component, tagId);
|
|
}
|
|
var extraArgs = [component];
|
|
events.registerId(extraArgs, tagId, component.events());
|
|
components[tagId] = component;
|
|
};
|
|
var unregister = function (component) {
|
|
read$1(component.element()).each(function (tagId) {
|
|
delete components[tagId];
|
|
events.unregisterId(tagId);
|
|
});
|
|
};
|
|
var filter = function (type) {
|
|
return events.filterByType(type);
|
|
};
|
|
var find = function (isAboveRoot, type, target) {
|
|
return events.find(isAboveRoot, type, target);
|
|
};
|
|
var getById = function (id) {
|
|
return get(components, id);
|
|
};
|
|
return {
|
|
find: find,
|
|
filter: filter,
|
|
register: register,
|
|
unregister: unregister,
|
|
getById: getById
|
|
};
|
|
}
|
|
|
|
var factory$3 = function (detail) {
|
|
var _a = detail.dom, attributes = _a.attributes, domWithoutAttributes = __rest(_a, ['attributes']);
|
|
return {
|
|
uid: detail.uid,
|
|
dom: __assign({
|
|
tag: 'div',
|
|
attributes: __assign({ role: 'presentation' }, attributes)
|
|
}, domWithoutAttributes),
|
|
components: detail.components,
|
|
behaviours: get$c(detail.containerBehaviours),
|
|
events: detail.events,
|
|
domModification: detail.domModification,
|
|
eventOrder: detail.eventOrder
|
|
};
|
|
};
|
|
var Container = single$2({
|
|
name: 'Container',
|
|
factory: factory$3,
|
|
configFields: [
|
|
defaulted$1('components', []),
|
|
field$1('containerBehaviours', []),
|
|
defaulted$1('events', {}),
|
|
defaulted$1('domModification', {}),
|
|
defaulted$1('eventOrder', {})
|
|
]
|
|
});
|
|
|
|
var takeover = function (root) {
|
|
var isAboveRoot = function (el) {
|
|
return parent(root.element()).fold(function () {
|
|
return true;
|
|
}, function (parent) {
|
|
return eq$1(el, parent);
|
|
});
|
|
};
|
|
var registry = Registry();
|
|
var lookup = function (eventName, target) {
|
|
return registry.find(isAboveRoot, eventName, target);
|
|
};
|
|
var domEvents = setup$1(root.element(), {
|
|
triggerEvent: function (eventName, event) {
|
|
return monitorEvent(eventName, event.target(), function (logger) {
|
|
return triggerUntilStopped(lookup, eventName, event, logger);
|
|
});
|
|
}
|
|
});
|
|
var systemApi = {
|
|
debugInfo: constant('real'),
|
|
triggerEvent: function (eventName, target, data) {
|
|
monitorEvent(eventName, target, function (logger) {
|
|
return triggerOnUntilStopped(lookup, eventName, data, target, logger);
|
|
});
|
|
},
|
|
triggerFocus: function (target, originator) {
|
|
read$1(target).fold(function () {
|
|
focus$1(target);
|
|
}, function (_alloyId) {
|
|
monitorEvent(focus(), target, function (logger) {
|
|
triggerHandler(lookup, focus(), {
|
|
originator: constant(originator),
|
|
kill: noop,
|
|
prevent: noop,
|
|
target: constant(target)
|
|
}, target, logger);
|
|
return false;
|
|
});
|
|
});
|
|
},
|
|
triggerEscape: function (comp, simulatedEvent) {
|
|
systemApi.triggerEvent('keydown', comp.element(), simulatedEvent.event());
|
|
},
|
|
getByUid: function (uid) {
|
|
return getByUid(uid);
|
|
},
|
|
getByDom: function (elem) {
|
|
return getByDom(elem);
|
|
},
|
|
build: build$1,
|
|
addToGui: function (c) {
|
|
add(c);
|
|
},
|
|
removeFromGui: function (c) {
|
|
remove$1(c);
|
|
},
|
|
addToWorld: function (c) {
|
|
addToWorld(c);
|
|
},
|
|
removeFromWorld: function (c) {
|
|
removeFromWorld(c);
|
|
},
|
|
broadcast: function (message) {
|
|
broadcast$1(message);
|
|
},
|
|
broadcastOn: function (channels, message) {
|
|
broadcastOn(channels, message);
|
|
},
|
|
broadcastEvent: function (eventName, event) {
|
|
broadcastEvent(eventName, event);
|
|
},
|
|
isConnected: constant(true)
|
|
};
|
|
var addToWorld = function (component) {
|
|
component.connect(systemApi);
|
|
if (!isText(component.element())) {
|
|
registry.register(component);
|
|
each(component.components(), addToWorld);
|
|
systemApi.triggerEvent(systemInit(), component.element(), { target: constant(component.element()) });
|
|
}
|
|
};
|
|
var removeFromWorld = function (component) {
|
|
if (!isText(component.element())) {
|
|
each(component.components(), removeFromWorld);
|
|
registry.unregister(component);
|
|
}
|
|
component.disconnect();
|
|
};
|
|
var add = function (component) {
|
|
attach$1(root, component);
|
|
};
|
|
var remove$1 = function (component) {
|
|
detach(component);
|
|
};
|
|
var destroy = function () {
|
|
domEvents.unbind();
|
|
remove(root.element());
|
|
};
|
|
var broadcastData = function (data) {
|
|
var receivers = registry.filter(receive());
|
|
each(receivers, function (receiver) {
|
|
var descHandler = receiver.descHandler();
|
|
var handler = getCurried(descHandler);
|
|
handler(data);
|
|
});
|
|
};
|
|
var broadcast$1 = function (message) {
|
|
broadcastData({
|
|
universal: constant(true),
|
|
data: constant(message)
|
|
});
|
|
};
|
|
var broadcastOn = function (channels, message) {
|
|
broadcastData({
|
|
universal: constant(false),
|
|
channels: constant(channels),
|
|
data: constant(message)
|
|
});
|
|
};
|
|
var broadcastEvent = function (eventName, event) {
|
|
var listeners = registry.filter(eventName);
|
|
return broadcast(listeners, event);
|
|
};
|
|
var getByUid = function (uid) {
|
|
return registry.getById(uid).fold(function () {
|
|
return Result.error(new Error('Could not find component with uid: "' + uid + '" in system.'));
|
|
}, Result.value);
|
|
};
|
|
var getByDom = function (elem) {
|
|
var uid = read$1(elem).getOr('not found');
|
|
return getByUid(uid);
|
|
};
|
|
addToWorld(root);
|
|
return {
|
|
root: constant(root),
|
|
element: root.element,
|
|
destroy: destroy,
|
|
add: add,
|
|
remove: remove$1,
|
|
getByUid: getByUid,
|
|
getByDom: getByDom,
|
|
addToWorld: addToWorld,
|
|
removeFromWorld: removeFromWorld,
|
|
broadcast: broadcast$1,
|
|
broadcastOn: broadcastOn,
|
|
broadcastEvent: broadcastEvent
|
|
};
|
|
};
|
|
|
|
var formChangeEvent = generate$1('form-component-change');
|
|
var formCloseEvent = generate$1('form-close');
|
|
var formCancelEvent = generate$1('form-cancel');
|
|
var formActionEvent = generate$1('form-action');
|
|
var formSubmitEvent = generate$1('form-submit');
|
|
var formBlockEvent = generate$1('form-block');
|
|
var formUnblockEvent = generate$1('form-unblock');
|
|
var formTabChangeEvent = generate$1('form-tabchange');
|
|
var formResizeEvent = generate$1('form-resize');
|
|
|
|
var renderAlertBanner = function (spec, providersBackstage) {
|
|
return Container.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { role: 'alert' },
|
|
classes: [
|
|
'tox-notification',
|
|
'tox-notification--in',
|
|
'tox-notification--' + spec.level
|
|
]
|
|
},
|
|
components: [
|
|
{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-notification__icon']
|
|
},
|
|
components: [Button.sketch({
|
|
dom: {
|
|
tag: 'button',
|
|
classes: [
|
|
'tox-button',
|
|
'tox-button--naked',
|
|
'tox-button--icon'
|
|
],
|
|
innerHtml: get$d(spec.icon, providersBackstage.icons),
|
|
attributes: { title: providersBackstage.translate(spec.iconTooltip) }
|
|
},
|
|
action: function (comp) {
|
|
emitWith(comp, formActionEvent, {
|
|
name: 'alert-banner',
|
|
value: spec.url
|
|
});
|
|
}
|
|
})]
|
|
},
|
|
{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-notification__body'],
|
|
innerHtml: providersBackstage.translate(spec.text)
|
|
}
|
|
}
|
|
]
|
|
});
|
|
};
|
|
|
|
var renderBar = function (spec, backstage) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-bar',
|
|
'tox-form__controls-h-stack'
|
|
]
|
|
},
|
|
components: map(spec.items, backstage.interpreter)
|
|
};
|
|
};
|
|
|
|
var schema$e = constant([
|
|
defaulted$1('prefix', 'form-field'),
|
|
field$1('fieldBehaviours', [
|
|
Composing,
|
|
Representing
|
|
])
|
|
]);
|
|
var parts$3 = constant([
|
|
optional({
|
|
schema: [strict$1('dom')],
|
|
name: 'label'
|
|
}),
|
|
optional({
|
|
factory: {
|
|
sketch: function (spec) {
|
|
return {
|
|
uid: spec.uid,
|
|
dom: {
|
|
tag: 'span',
|
|
styles: { display: 'none' },
|
|
attributes: { 'aria-hidden': 'true' },
|
|
innerHtml: spec.text
|
|
}
|
|
};
|
|
}
|
|
},
|
|
schema: [strict$1('text')],
|
|
name: 'aria-descriptor'
|
|
}),
|
|
required({
|
|
factory: {
|
|
sketch: function (spec) {
|
|
var excludeFactory = exclude$1(spec, ['factory']);
|
|
return spec.factory.sketch(excludeFactory);
|
|
}
|
|
},
|
|
schema: [strict$1('factory')],
|
|
name: 'field'
|
|
})
|
|
]);
|
|
|
|
var factory$4 = function (detail, components, _spec, _externals) {
|
|
var behaviours = augment(detail.fieldBehaviours, [
|
|
Composing.config({
|
|
find: function (container) {
|
|
return getPart(container, detail, 'field');
|
|
}
|
|
}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (field) {
|
|
return Composing.getCurrent(field).bind(Representing.getValue);
|
|
},
|
|
setValue: function (field, value) {
|
|
Composing.getCurrent(field).each(function (current) {
|
|
Representing.setValue(current, value);
|
|
});
|
|
}
|
|
}
|
|
})
|
|
]);
|
|
var events = derive([runOnAttached(function (component, _simulatedEvent) {
|
|
var ps = getParts(component, detail, [
|
|
'label',
|
|
'field',
|
|
'aria-descriptor'
|
|
]);
|
|
ps.field().each(function (field) {
|
|
var id = generate$1(detail.prefix);
|
|
ps.label().each(function (label) {
|
|
set$1(label.element(), 'for', id);
|
|
set$1(field.element(), 'id', id);
|
|
});
|
|
ps['aria-descriptor']().each(function (descriptor) {
|
|
var descriptorId = generate$1(detail.prefix);
|
|
set$1(descriptor.element(), 'id', descriptorId);
|
|
set$1(field.element(), 'aria-describedby', descriptorId);
|
|
});
|
|
});
|
|
})]);
|
|
var apis = {
|
|
getField: function (container) {
|
|
return getPart(container, detail, 'field');
|
|
},
|
|
getLabel: function (container) {
|
|
return getPart(container, detail, 'label');
|
|
}
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: behaviours,
|
|
events: events,
|
|
apis: apis
|
|
};
|
|
};
|
|
var FormField = composite$1({
|
|
name: 'FormField',
|
|
configFields: schema$e(),
|
|
partFields: parts$3(),
|
|
factory: factory$4,
|
|
apis: {
|
|
getField: function (apis, comp) {
|
|
return apis.getField(comp);
|
|
},
|
|
getLabel: function (apis, comp) {
|
|
return apis.getLabel(comp);
|
|
}
|
|
}
|
|
});
|
|
|
|
var schema$f = constant([
|
|
option('data'),
|
|
defaulted$1('inputAttributes', {}),
|
|
defaulted$1('inputStyles', {}),
|
|
defaulted$1('tag', 'input'),
|
|
defaulted$1('inputClasses', []),
|
|
onHandler('onSetValue'),
|
|
defaulted$1('styles', {}),
|
|
defaulted$1('eventOrder', {}),
|
|
field$1('inputBehaviours', [
|
|
Representing,
|
|
Focusing
|
|
]),
|
|
defaulted$1('selectOnFocus', true)
|
|
]);
|
|
var focusBehaviours = function (detail) {
|
|
return derive$1([Focusing.config({
|
|
onFocus: !detail.selectOnFocus ? noop : function (component) {
|
|
var input = component.element();
|
|
var value = get$5(input);
|
|
input.dom().setSelectionRange(0, value.length);
|
|
}
|
|
})]);
|
|
};
|
|
var behaviours = function (detail) {
|
|
return __assign(__assign({}, focusBehaviours(detail)), augment(detail.inputBehaviours, [Representing.config({
|
|
store: __assign(__assign({ mode: 'manual' }, detail.data.map(function (data) {
|
|
return { initialValue: data };
|
|
}).getOr({})), {
|
|
getValue: function (input) {
|
|
return get$5(input.element());
|
|
},
|
|
setValue: function (input, data) {
|
|
var current = get$5(input.element());
|
|
if (current !== data) {
|
|
set$3(input.element(), data);
|
|
}
|
|
}
|
|
}),
|
|
onSetValue: detail.onSetValue
|
|
})]));
|
|
};
|
|
var dom$2 = function (detail) {
|
|
return {
|
|
tag: detail.tag,
|
|
attributes: __assign({ type: 'text' }, detail.inputAttributes),
|
|
styles: detail.inputStyles,
|
|
classes: detail.inputClasses
|
|
};
|
|
};
|
|
|
|
var factory$5 = function (detail, _spec) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: dom$2(detail),
|
|
components: [],
|
|
behaviours: behaviours(detail),
|
|
eventOrder: detail.eventOrder
|
|
};
|
|
};
|
|
var Input = single$2({
|
|
name: 'Input',
|
|
configFields: schema$f(),
|
|
factory: factory$5
|
|
});
|
|
|
|
var exports$1 = {}, module = { exports: exports$1 };
|
|
(function (define, exports, module, require) {
|
|
(function (f) {
|
|
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
module.exports = f();
|
|
} else if (typeof define === 'function' && define.amd) {
|
|
define([], f);
|
|
} else {
|
|
var g;
|
|
if (typeof window !== 'undefined') {
|
|
g = window;
|
|
} else if (typeof global !== 'undefined') {
|
|
g = global;
|
|
} else if (typeof self !== 'undefined') {
|
|
g = self;
|
|
} else {
|
|
g = this;
|
|
}
|
|
g.EphoxContactWrapper = f();
|
|
}
|
|
}(function () {
|
|
return function () {
|
|
function r(e, n, t) {
|
|
function o(i, f) {
|
|
if (!n[i]) {
|
|
if (!e[i]) {
|
|
var c = 'function' == typeof require && require;
|
|
if (!f && c)
|
|
return c(i, !0);
|
|
if (u)
|
|
return u(i, !0);
|
|
var a = new Error('Cannot find module \'' + i + '\'');
|
|
throw a.code = 'MODULE_NOT_FOUND', a;
|
|
}
|
|
var p = n[i] = { exports: {} };
|
|
e[i][0].call(p.exports, function (r) {
|
|
var n = e[i][1][r];
|
|
return o(n || r);
|
|
}, p, p.exports, r, e, n, t);
|
|
}
|
|
return n[i].exports;
|
|
}
|
|
for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
|
|
o(t[i]);
|
|
return o;
|
|
}
|
|
return r;
|
|
}()({
|
|
1: [
|
|
function (require, module, exports) {
|
|
var process = module.exports = {};
|
|
var cachedSetTimeout;
|
|
var cachedClearTimeout;
|
|
function defaultSetTimout() {
|
|
throw new Error('setTimeout has not been defined');
|
|
}
|
|
function defaultClearTimeout() {
|
|
throw new Error('clearTimeout has not been defined');
|
|
}
|
|
(function () {
|
|
try {
|
|
if (typeof setTimeout === 'function') {
|
|
cachedSetTimeout = setTimeout;
|
|
} else {
|
|
cachedSetTimeout = defaultSetTimout;
|
|
}
|
|
} catch (e) {
|
|
cachedSetTimeout = defaultSetTimout;
|
|
}
|
|
try {
|
|
if (typeof clearTimeout === 'function') {
|
|
cachedClearTimeout = clearTimeout;
|
|
} else {
|
|
cachedClearTimeout = defaultClearTimeout;
|
|
}
|
|
} catch (e) {
|
|
cachedClearTimeout = defaultClearTimeout;
|
|
}
|
|
}());
|
|
function runTimeout(fun) {
|
|
if (cachedSetTimeout === setTimeout) {
|
|
return setTimeout(fun, 0);
|
|
}
|
|
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
|
cachedSetTimeout = setTimeout;
|
|
return setTimeout(fun, 0);
|
|
}
|
|
try {
|
|
return cachedSetTimeout(fun, 0);
|
|
} catch (e) {
|
|
try {
|
|
return cachedSetTimeout.call(null, fun, 0);
|
|
} catch (e) {
|
|
return cachedSetTimeout.call(this, fun, 0);
|
|
}
|
|
}
|
|
}
|
|
function runClearTimeout(marker) {
|
|
if (cachedClearTimeout === clearTimeout) {
|
|
return clearTimeout(marker);
|
|
}
|
|
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
|
cachedClearTimeout = clearTimeout;
|
|
return clearTimeout(marker);
|
|
}
|
|
try {
|
|
return cachedClearTimeout(marker);
|
|
} catch (e) {
|
|
try {
|
|
return cachedClearTimeout.call(null, marker);
|
|
} catch (e) {
|
|
return cachedClearTimeout.call(this, marker);
|
|
}
|
|
}
|
|
}
|
|
var queue = [];
|
|
var draining = false;
|
|
var currentQueue;
|
|
var queueIndex = -1;
|
|
function cleanUpNextTick() {
|
|
if (!draining || !currentQueue) {
|
|
return;
|
|
}
|
|
draining = false;
|
|
if (currentQueue.length) {
|
|
queue = currentQueue.concat(queue);
|
|
} else {
|
|
queueIndex = -1;
|
|
}
|
|
if (queue.length) {
|
|
drainQueue();
|
|
}
|
|
}
|
|
function drainQueue() {
|
|
if (draining) {
|
|
return;
|
|
}
|
|
var timeout = runTimeout(cleanUpNextTick);
|
|
draining = true;
|
|
var len = queue.length;
|
|
while (len) {
|
|
currentQueue = queue;
|
|
queue = [];
|
|
while (++queueIndex < len) {
|
|
if (currentQueue) {
|
|
currentQueue[queueIndex].run();
|
|
}
|
|
}
|
|
queueIndex = -1;
|
|
len = queue.length;
|
|
}
|
|
currentQueue = null;
|
|
draining = false;
|
|
runClearTimeout(timeout);
|
|
}
|
|
process.nextTick = function (fun) {
|
|
var args = new Array(arguments.length - 1);
|
|
if (arguments.length > 1) {
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
args[i - 1] = arguments[i];
|
|
}
|
|
}
|
|
queue.push(new Item(fun, args));
|
|
if (queue.length === 1 && !draining) {
|
|
runTimeout(drainQueue);
|
|
}
|
|
};
|
|
function Item(fun, array) {
|
|
this.fun = fun;
|
|
this.array = array;
|
|
}
|
|
Item.prototype.run = function () {
|
|
this.fun.apply(null, this.array);
|
|
};
|
|
process.title = 'browser';
|
|
process.browser = true;
|
|
process.env = {};
|
|
process.argv = [];
|
|
process.version = '';
|
|
process.versions = {};
|
|
function noop() {
|
|
}
|
|
process.on = noop;
|
|
process.addListener = noop;
|
|
process.once = noop;
|
|
process.off = noop;
|
|
process.removeListener = noop;
|
|
process.removeAllListeners = noop;
|
|
process.emit = noop;
|
|
process.prependListener = noop;
|
|
process.prependOnceListener = noop;
|
|
process.listeners = function (name) {
|
|
return [];
|
|
};
|
|
process.binding = function (name) {
|
|
throw new Error('process.binding is not supported');
|
|
};
|
|
process.cwd = function () {
|
|
return '/';
|
|
};
|
|
process.chdir = function (dir) {
|
|
throw new Error('process.chdir is not supported');
|
|
};
|
|
process.umask = function () {
|
|
return 0;
|
|
};
|
|
},
|
|
{}
|
|
],
|
|
2: [
|
|
function (require, module, exports) {
|
|
(function (setImmediate) {
|
|
(function (root) {
|
|
var setTimeoutFunc = setTimeout;
|
|
function noop() {
|
|
}
|
|
function bind(fn, thisArg) {
|
|
return function () {
|
|
fn.apply(thisArg, arguments);
|
|
};
|
|
}
|
|
function Promise(fn) {
|
|
if (typeof this !== 'object')
|
|
throw new TypeError('Promises must be constructed via new');
|
|
if (typeof fn !== 'function')
|
|
throw new TypeError('not a function');
|
|
this._state = 0;
|
|
this._handled = false;
|
|
this._value = undefined;
|
|
this._deferreds = [];
|
|
doResolve(fn, this);
|
|
}
|
|
function handle(self, deferred) {
|
|
while (self._state === 3) {
|
|
self = self._value;
|
|
}
|
|
if (self._state === 0) {
|
|
self._deferreds.push(deferred);
|
|
return;
|
|
}
|
|
self._handled = true;
|
|
Promise._immediateFn(function () {
|
|
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
|
|
if (cb === null) {
|
|
(self._state === 1 ? resolve : reject)(deferred.promise, self._value);
|
|
return;
|
|
}
|
|
var ret;
|
|
try {
|
|
ret = cb(self._value);
|
|
} catch (e) {
|
|
reject(deferred.promise, e);
|
|
return;
|
|
}
|
|
resolve(deferred.promise, ret);
|
|
});
|
|
}
|
|
function resolve(self, newValue) {
|
|
try {
|
|
if (newValue === self)
|
|
throw new TypeError('A promise cannot be resolved with itself.');
|
|
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
|
|
var then = newValue.then;
|
|
if (newValue instanceof Promise) {
|
|
self._state = 3;
|
|
self._value = newValue;
|
|
finale(self);
|
|
return;
|
|
} else if (typeof then === 'function') {
|
|
doResolve(bind(then, newValue), self);
|
|
return;
|
|
}
|
|
}
|
|
self._state = 1;
|
|
self._value = newValue;
|
|
finale(self);
|
|
} catch (e) {
|
|
reject(self, e);
|
|
}
|
|
}
|
|
function reject(self, newValue) {
|
|
self._state = 2;
|
|
self._value = newValue;
|
|
finale(self);
|
|
}
|
|
function finale(self) {
|
|
if (self._state === 2 && self._deferreds.length === 0) {
|
|
Promise._immediateFn(function () {
|
|
if (!self._handled) {
|
|
Promise._unhandledRejectionFn(self._value);
|
|
}
|
|
});
|
|
}
|
|
for (var i = 0, len = self._deferreds.length; i < len; i++) {
|
|
handle(self, self._deferreds[i]);
|
|
}
|
|
self._deferreds = null;
|
|
}
|
|
function Handler(onFulfilled, onRejected, promise) {
|
|
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
|
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
|
this.promise = promise;
|
|
}
|
|
function doResolve(fn, self) {
|
|
var done = false;
|
|
try {
|
|
fn(function (value) {
|
|
if (done)
|
|
return;
|
|
done = true;
|
|
resolve(self, value);
|
|
}, function (reason) {
|
|
if (done)
|
|
return;
|
|
done = true;
|
|
reject(self, reason);
|
|
});
|
|
} catch (ex) {
|
|
if (done)
|
|
return;
|
|
done = true;
|
|
reject(self, ex);
|
|
}
|
|
}
|
|
Promise.prototype['catch'] = function (onRejected) {
|
|
return this.then(null, onRejected);
|
|
};
|
|
Promise.prototype.then = function (onFulfilled, onRejected) {
|
|
var prom = new this.constructor(noop);
|
|
handle(this, new Handler(onFulfilled, onRejected, prom));
|
|
return prom;
|
|
};
|
|
Promise.all = function (arr) {
|
|
var args = Array.prototype.slice.call(arr);
|
|
return new Promise(function (resolve, reject) {
|
|
if (args.length === 0)
|
|
return resolve([]);
|
|
var remaining = args.length;
|
|
function res(i, val) {
|
|
try {
|
|
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
|
var then = val.then;
|
|
if (typeof then === 'function') {
|
|
then.call(val, function (val) {
|
|
res(i, val);
|
|
}, reject);
|
|
return;
|
|
}
|
|
}
|
|
args[i] = val;
|
|
if (--remaining === 0) {
|
|
resolve(args);
|
|
}
|
|
} catch (ex) {
|
|
reject(ex);
|
|
}
|
|
}
|
|
for (var i = 0; i < args.length; i++) {
|
|
res(i, args[i]);
|
|
}
|
|
});
|
|
};
|
|
Promise.resolve = function (value) {
|
|
if (value && typeof value === 'object' && value.constructor === Promise) {
|
|
return value;
|
|
}
|
|
return new Promise(function (resolve) {
|
|
resolve(value);
|
|
});
|
|
};
|
|
Promise.reject = function (value) {
|
|
return new Promise(function (resolve, reject) {
|
|
reject(value);
|
|
});
|
|
};
|
|
Promise.race = function (values) {
|
|
return new Promise(function (resolve, reject) {
|
|
for (var i = 0, len = values.length; i < len; i++) {
|
|
values[i].then(resolve, reject);
|
|
}
|
|
});
|
|
};
|
|
Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
|
|
setImmediate(fn);
|
|
} : function (fn) {
|
|
setTimeoutFunc(fn, 0);
|
|
};
|
|
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
|
|
if (typeof console !== 'undefined' && console) {
|
|
console.warn('Possible Unhandled Promise Rejection:', err);
|
|
}
|
|
};
|
|
Promise._setImmediateFn = function _setImmediateFn(fn) {
|
|
Promise._immediateFn = fn;
|
|
};
|
|
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
|
|
Promise._unhandledRejectionFn = fn;
|
|
};
|
|
if (typeof module !== 'undefined' && module.exports) {
|
|
module.exports = Promise;
|
|
} else if (!root.Promise) {
|
|
root.Promise = Promise;
|
|
}
|
|
}(this));
|
|
}.call(this, require('timers').setImmediate));
|
|
},
|
|
{ 'timers': 3 }
|
|
],
|
|
3: [
|
|
function (require, module, exports) {
|
|
(function (setImmediate, clearImmediate) {
|
|
var nextTick = require('process/browser.js').nextTick;
|
|
var apply = Function.prototype.apply;
|
|
var slice = Array.prototype.slice;
|
|
var immediateIds = {};
|
|
var nextImmediateId = 0;
|
|
exports.setTimeout = function () {
|
|
return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
|
|
};
|
|
exports.setInterval = function () {
|
|
return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
|
|
};
|
|
exports.clearTimeout = exports.clearInterval = function (timeout) {
|
|
timeout.close();
|
|
};
|
|
function Timeout(id, clearFn) {
|
|
this._id = id;
|
|
this._clearFn = clearFn;
|
|
}
|
|
Timeout.prototype.unref = Timeout.prototype.ref = function () {
|
|
};
|
|
Timeout.prototype.close = function () {
|
|
this._clearFn.call(window, this._id);
|
|
};
|
|
exports.enroll = function (item, msecs) {
|
|
clearTimeout(item._idleTimeoutId);
|
|
item._idleTimeout = msecs;
|
|
};
|
|
exports.unenroll = function (item) {
|
|
clearTimeout(item._idleTimeoutId);
|
|
item._idleTimeout = -1;
|
|
};
|
|
exports._unrefActive = exports.active = function (item) {
|
|
clearTimeout(item._idleTimeoutId);
|
|
var msecs = item._idleTimeout;
|
|
if (msecs >= 0) {
|
|
item._idleTimeoutId = setTimeout(function onTimeout() {
|
|
if (item._onTimeout)
|
|
item._onTimeout();
|
|
}, msecs);
|
|
}
|
|
};
|
|
exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
|
|
var id = nextImmediateId++;
|
|
var args = arguments.length < 2 ? false : slice.call(arguments, 1);
|
|
immediateIds[id] = true;
|
|
nextTick(function onNextTick() {
|
|
if (immediateIds[id]) {
|
|
if (args) {
|
|
fn.apply(null, args);
|
|
} else {
|
|
fn.call(null);
|
|
}
|
|
exports.clearImmediate(id);
|
|
}
|
|
});
|
|
return id;
|
|
};
|
|
exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
|
|
delete immediateIds[id];
|
|
};
|
|
}.call(this, require('timers').setImmediate, require('timers').clearImmediate));
|
|
},
|
|
{
|
|
'process/browser.js': 1,
|
|
'timers': 3
|
|
}
|
|
],
|
|
4: [
|
|
function (require, module, exports) {
|
|
var promisePolyfill = require('promise-polyfill');
|
|
var Global = function () {
|
|
if (typeof window !== 'undefined') {
|
|
return window;
|
|
} else {
|
|
return Function('return this;')();
|
|
}
|
|
}();
|
|
module.exports = { boltExport: Global.Promise || promisePolyfill };
|
|
},
|
|
{ 'promise-polyfill': 2 }
|
|
]
|
|
}, {}, [4])(4);
|
|
}));
|
|
}(undefined, exports$1, module, undefined));
|
|
var Promise = module.exports.boltExport;
|
|
|
|
var nu$a = function (baseFn) {
|
|
var data = Option.none();
|
|
var callbacks = [];
|
|
var map = function (f) {
|
|
return nu$a(function (nCallback) {
|
|
get(function (data) {
|
|
nCallback(f(data));
|
|
});
|
|
});
|
|
};
|
|
var get = function (nCallback) {
|
|
if (isReady()) {
|
|
call(nCallback);
|
|
} else {
|
|
callbacks.push(nCallback);
|
|
}
|
|
};
|
|
var set = function (x) {
|
|
data = Option.some(x);
|
|
run(callbacks);
|
|
callbacks = [];
|
|
};
|
|
var isReady = function () {
|
|
return data.isSome();
|
|
};
|
|
var run = function (cbs) {
|
|
each(cbs, call);
|
|
};
|
|
var call = function (cb) {
|
|
data.each(function (x) {
|
|
domGlobals.setTimeout(function () {
|
|
cb(x);
|
|
}, 0);
|
|
});
|
|
};
|
|
baseFn(set);
|
|
return {
|
|
get: get,
|
|
map: map,
|
|
isReady: isReady
|
|
};
|
|
};
|
|
var pure$1 = function (a) {
|
|
return nu$a(function (callback) {
|
|
callback(a);
|
|
});
|
|
};
|
|
var LazyValue = {
|
|
nu: nu$a,
|
|
pure: pure$1
|
|
};
|
|
|
|
var errorReporter = function (err) {
|
|
domGlobals.setTimeout(function () {
|
|
throw err;
|
|
}, 0);
|
|
};
|
|
var make$3 = function (run) {
|
|
var get = function (callback) {
|
|
run().then(callback, errorReporter);
|
|
};
|
|
var map = function (fab) {
|
|
return make$3(function () {
|
|
return run().then(fab);
|
|
});
|
|
};
|
|
var bind = function (aFutureB) {
|
|
return make$3(function () {
|
|
return run().then(function (v) {
|
|
return aFutureB(v).toPromise();
|
|
});
|
|
});
|
|
};
|
|
var anonBind = function (futureB) {
|
|
return make$3(function () {
|
|
return run().then(function () {
|
|
return futureB.toPromise();
|
|
});
|
|
});
|
|
};
|
|
var toLazy = function () {
|
|
return LazyValue.nu(get);
|
|
};
|
|
var toCached = function () {
|
|
var cache = null;
|
|
return make$3(function () {
|
|
if (cache === null) {
|
|
cache = run();
|
|
}
|
|
return cache;
|
|
});
|
|
};
|
|
var toPromise = run;
|
|
return {
|
|
map: map,
|
|
bind: bind,
|
|
anonBind: anonBind,
|
|
toLazy: toLazy,
|
|
toCached: toCached,
|
|
toPromise: toPromise,
|
|
get: get
|
|
};
|
|
};
|
|
var nu$b = function (baseFn) {
|
|
return make$3(function () {
|
|
return new Promise(baseFn);
|
|
});
|
|
};
|
|
var pure$2 = function (a) {
|
|
return make$3(function () {
|
|
return Promise.resolve(a);
|
|
});
|
|
};
|
|
var Future = {
|
|
nu: nu$b,
|
|
pure: pure$2
|
|
};
|
|
|
|
var ariaElements = [
|
|
'input',
|
|
'textarea'
|
|
];
|
|
var isAriaElement = function (elem) {
|
|
var name$1 = name(elem);
|
|
return contains(ariaElements, name$1);
|
|
};
|
|
var markValid = function (component, invalidConfig) {
|
|
var elem = invalidConfig.getRoot(component).getOr(component.element());
|
|
remove$4(elem, invalidConfig.invalidClass);
|
|
invalidConfig.notify.each(function (notifyInfo) {
|
|
if (isAriaElement(component.element())) {
|
|
set$1(component.element(), 'aria-invalid', false);
|
|
}
|
|
notifyInfo.getContainer(component).each(function (container) {
|
|
set(container, notifyInfo.validHtml);
|
|
});
|
|
notifyInfo.onValid(component);
|
|
});
|
|
};
|
|
var markInvalid = function (component, invalidConfig, invalidState, text) {
|
|
var elem = invalidConfig.getRoot(component).getOr(component.element());
|
|
add$2(elem, invalidConfig.invalidClass);
|
|
invalidConfig.notify.each(function (notifyInfo) {
|
|
if (isAriaElement(component.element())) {
|
|
set$1(component.element(), 'aria-invalid', true);
|
|
}
|
|
notifyInfo.getContainer(component).each(function (container) {
|
|
set(container, text);
|
|
});
|
|
notifyInfo.onInvalid(component, text);
|
|
});
|
|
};
|
|
var query = function (component, invalidConfig, _invalidState) {
|
|
return invalidConfig.validator.fold(function () {
|
|
return Future.pure(Result.value(true));
|
|
}, function (validatorInfo) {
|
|
return validatorInfo.validate(component);
|
|
});
|
|
};
|
|
var run$1 = function (component, invalidConfig, invalidState) {
|
|
invalidConfig.notify.each(function (notifyInfo) {
|
|
notifyInfo.onValidate(component);
|
|
});
|
|
return query(component, invalidConfig).map(function (valid) {
|
|
if (component.getSystem().isConnected()) {
|
|
return valid.fold(function (err) {
|
|
markInvalid(component, invalidConfig, invalidState, err);
|
|
return Result.error(err);
|
|
}, function (v) {
|
|
markValid(component, invalidConfig);
|
|
return Result.value(v);
|
|
});
|
|
} else {
|
|
return Result.error('No longer in system');
|
|
}
|
|
});
|
|
};
|
|
var isInvalid = function (component, invalidConfig) {
|
|
var elem = invalidConfig.getRoot(component).getOr(component.element());
|
|
return has$2(elem, invalidConfig.invalidClass);
|
|
};
|
|
|
|
var InvalidateApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
markValid: markValid,
|
|
markInvalid: markInvalid,
|
|
query: query,
|
|
run: run$1,
|
|
isInvalid: isInvalid
|
|
});
|
|
|
|
var events$a = function (invalidConfig, invalidState) {
|
|
return invalidConfig.validator.map(function (validatorInfo) {
|
|
return derive([run(validatorInfo.onEvent, function (component) {
|
|
run$1(component, invalidConfig, invalidState).get(identity);
|
|
})].concat(validatorInfo.validateOnLoad ? [runOnAttached(function (component) {
|
|
run$1(component, invalidConfig, invalidState).get(noop);
|
|
})] : []));
|
|
}).getOr({});
|
|
};
|
|
|
|
var ActiveInvalidate = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$a
|
|
});
|
|
|
|
var InvalidateSchema = [
|
|
strict$1('invalidClass'),
|
|
defaulted$1('getRoot', Option.none),
|
|
optionObjOf('notify', [
|
|
defaulted$1('aria', 'alert'),
|
|
defaulted$1('getContainer', Option.none),
|
|
defaulted$1('validHtml', ''),
|
|
onHandler('onValid'),
|
|
onHandler('onInvalid'),
|
|
onHandler('onValidate')
|
|
]),
|
|
optionObjOf('validator', [
|
|
strict$1('validate'),
|
|
defaulted$1('onEvent', 'input'),
|
|
defaulted$1('validateOnLoad', true)
|
|
])
|
|
];
|
|
|
|
var Invalidating = create$1({
|
|
fields: InvalidateSchema,
|
|
name: 'invalidating',
|
|
active: ActiveInvalidate,
|
|
apis: InvalidateApis,
|
|
extra: {
|
|
validation: function (validator) {
|
|
return function (component) {
|
|
var v = Representing.getValue(component);
|
|
return Future.pure(validator(v));
|
|
};
|
|
}
|
|
}
|
|
});
|
|
|
|
var exhibit$4 = function (base, tabConfig) {
|
|
return nu$6({
|
|
attributes: wrapAll$1([{
|
|
key: tabConfig.tabAttr,
|
|
value: 'true'
|
|
}])
|
|
});
|
|
};
|
|
|
|
var ActiveTabstopping = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit$4
|
|
});
|
|
|
|
var TabstopSchema = [defaulted$1('tabAttr', 'data-alloy-tabstop')];
|
|
|
|
var Tabstopping = create$1({
|
|
fields: TabstopSchema,
|
|
name: 'tabstopping',
|
|
active: ActiveTabstopping
|
|
});
|
|
|
|
var renderFormFieldWith = function (pLabel, pField, extraClasses, extraBehaviours) {
|
|
var spec = renderFormFieldSpecWith(pLabel, pField, extraClasses, extraBehaviours);
|
|
return FormField.sketch(spec);
|
|
};
|
|
var renderFormField = function (pLabel, pField) {
|
|
return renderFormFieldWith(pLabel, pField, [], []);
|
|
};
|
|
var renderFormFieldSpecWith = function (pLabel, pField, extraClasses, extraBehaviours) {
|
|
return {
|
|
dom: renderFormFieldDomWith(extraClasses),
|
|
components: pLabel.toArray().concat([pField]),
|
|
fieldBehaviours: derive$1(extraBehaviours)
|
|
};
|
|
};
|
|
var renderFormFieldDom = function () {
|
|
return renderFormFieldDomWith([]);
|
|
};
|
|
var renderFormFieldDomWith = function (extraClasses) {
|
|
return {
|
|
tag: 'div',
|
|
classes: ['tox-form__group'].concat(extraClasses)
|
|
};
|
|
};
|
|
var renderLabel = function (label, providersBackstage) {
|
|
return FormField.parts().label({
|
|
dom: {
|
|
tag: 'label',
|
|
classes: ['tox-label'],
|
|
innerHtml: providersBackstage.translate(label)
|
|
}
|
|
});
|
|
};
|
|
|
|
var getCoupled = function (component, coupleConfig, coupleState, name) {
|
|
return coupleState.getOrCreate(component, coupleConfig, name);
|
|
};
|
|
|
|
var CouplingApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
getCoupled: getCoupled
|
|
});
|
|
|
|
var CouplingSchema = [strictOf('others', setOf$1(Result.value, anyValue$1()))];
|
|
|
|
var init$5 = function () {
|
|
var coupled = {};
|
|
var getOrCreate = function (component, coupleConfig, name) {
|
|
var available = keys(coupleConfig.others);
|
|
if (!available) {
|
|
throw new Error('Cannot find coupled component: ' + name + '. Known coupled components: ' + JSON.stringify(available, null, 2));
|
|
} else {
|
|
return get(coupled, name).getOrThunk(function () {
|
|
var builder = get(coupleConfig.others, name).getOrDie('No information found for coupled component: ' + name);
|
|
var spec = builder(component);
|
|
var built = component.getSystem().build(spec);
|
|
coupled[name] = built;
|
|
return built;
|
|
});
|
|
}
|
|
};
|
|
var readState = constant({});
|
|
return nu$5({
|
|
readState: readState,
|
|
getOrCreate: getOrCreate
|
|
});
|
|
};
|
|
|
|
var CouplingState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
init: init$5
|
|
});
|
|
|
|
var Coupling = create$1({
|
|
fields: CouplingSchema,
|
|
name: 'coupling',
|
|
apis: CouplingApis,
|
|
state: CouplingState
|
|
});
|
|
|
|
var suffix = constant('sink');
|
|
var partType = constant(optional({
|
|
name: suffix(),
|
|
overrides: constant({
|
|
dom: { tag: 'div' },
|
|
behaviours: derive$1([Positioning.config({ useFixed: always })]),
|
|
events: derive([
|
|
cutter(keydown()),
|
|
cutter(mousedown()),
|
|
cutter(click())
|
|
])
|
|
})
|
|
}));
|
|
|
|
var HighlightOnOpen;
|
|
(function (HighlightOnOpen) {
|
|
HighlightOnOpen[HighlightOnOpen['HighlightFirst'] = 0] = 'HighlightFirst';
|
|
HighlightOnOpen[HighlightOnOpen['HighlightNone'] = 1] = 'HighlightNone';
|
|
}(HighlightOnOpen || (HighlightOnOpen = {})));
|
|
var getAnchor = function (detail, component) {
|
|
var hotspot = detail.getHotspot(component).getOr(component);
|
|
var anchor = 'hotspot';
|
|
var overrides = detail.getAnchorOverrides();
|
|
return detail.layouts.fold(function () {
|
|
return {
|
|
anchor: anchor,
|
|
hotspot: hotspot,
|
|
overrides: overrides
|
|
};
|
|
}, function (layouts) {
|
|
return {
|
|
anchor: anchor,
|
|
hotspot: hotspot,
|
|
overrides: overrides,
|
|
layouts: layouts
|
|
};
|
|
});
|
|
};
|
|
var fetch = function (detail, mapFetch, component) {
|
|
var fetcher = detail.fetch;
|
|
return fetcher(component).map(mapFetch);
|
|
};
|
|
var openF = function (detail, mapFetch, anchor, component, sandbox, externals, highlightOnOpen) {
|
|
var futureData = fetch(detail, mapFetch, component);
|
|
var getLazySink = getSink(component, detail);
|
|
return futureData.map(function (tdata) {
|
|
return tdata.bind(function (data) {
|
|
return Option.from(tieredMenu.sketch(__assign(__assign({}, externals.menu()), {
|
|
uid: generate$2(''),
|
|
data: data,
|
|
highlightImmediately: highlightOnOpen === HighlightOnOpen.HighlightFirst,
|
|
onOpenMenu: function (tmenu, menu) {
|
|
var sink = getLazySink().getOrDie();
|
|
Positioning.position(sink, anchor, menu);
|
|
Sandboxing.decloak(sandbox);
|
|
},
|
|
onOpenSubmenu: function (tmenu, item, submenu) {
|
|
var sink = getLazySink().getOrDie();
|
|
Positioning.position(sink, {
|
|
anchor: 'submenu',
|
|
item: item
|
|
}, submenu);
|
|
Sandboxing.decloak(sandbox);
|
|
},
|
|
onRepositionMenu: function (tmenu, primaryMenu, submenuTriggers) {
|
|
var sink = getLazySink().getOrDie();
|
|
Positioning.position(sink, anchor, primaryMenu);
|
|
each(submenuTriggers, function (st) {
|
|
Positioning.position(sink, {
|
|
anchor: 'submenu',
|
|
item: st.triggeringItem
|
|
}, st.triggeredMenu);
|
|
});
|
|
},
|
|
onEscape: function () {
|
|
Focusing.focus(component);
|
|
Sandboxing.close(sandbox);
|
|
return Option.some(true);
|
|
}
|
|
})));
|
|
});
|
|
});
|
|
};
|
|
var open$1 = function (detail, mapFetch, hotspot, sandbox, externals, onOpenSync, highlightOnOpen) {
|
|
var anchor = getAnchor(detail, hotspot);
|
|
var processed = openF(detail, mapFetch, anchor, hotspot, sandbox, externals, highlightOnOpen);
|
|
return processed.map(function (tdata) {
|
|
tdata.fold(function () {
|
|
if (Sandboxing.isOpen(sandbox)) {
|
|
Sandboxing.close(sandbox);
|
|
}
|
|
}, function (data) {
|
|
Sandboxing.cloak(sandbox);
|
|
Sandboxing.open(sandbox, data);
|
|
onOpenSync(sandbox);
|
|
});
|
|
return sandbox;
|
|
});
|
|
};
|
|
var close$1 = function (detail, mapFetch, component, sandbox, _externals, _onOpenSync, _highlightOnOpen) {
|
|
Sandboxing.close(sandbox);
|
|
return Future.pure(sandbox);
|
|
};
|
|
var togglePopup = function (detail, mapFetch, hotspot, externals, onOpenSync, highlightOnOpen) {
|
|
var sandbox = Coupling.getCoupled(hotspot, 'sandbox');
|
|
var showing = Sandboxing.isOpen(sandbox);
|
|
var action = showing ? close$1 : open$1;
|
|
return action(detail, mapFetch, hotspot, sandbox, externals, onOpenSync, highlightOnOpen);
|
|
};
|
|
var matchWidth = function (hotspot, container, useMinWidth) {
|
|
var menu = Composing.getCurrent(container).getOr(container);
|
|
var buttonWidth = get$7(hotspot.element());
|
|
if (useMinWidth) {
|
|
set$2(menu.element(), 'min-width', buttonWidth + 'px');
|
|
} else {
|
|
set$4(menu.element(), buttonWidth);
|
|
}
|
|
};
|
|
var getSink = function (anyInSystem, sinkDetail) {
|
|
return anyInSystem.getSystem().getByUid(sinkDetail.uid + '-' + suffix()).map(function (internalSink) {
|
|
return function () {
|
|
return Result.value(internalSink);
|
|
};
|
|
}).getOrThunk(function () {
|
|
return sinkDetail.lazySink.fold(function () {
|
|
return function () {
|
|
return Result.error(new Error('No internal sink is specified, nor could an external sink be found'));
|
|
};
|
|
}, function (lazySinkFn) {
|
|
return function () {
|
|
return lazySinkFn(anyInSystem);
|
|
};
|
|
});
|
|
});
|
|
};
|
|
var doRepositionMenus = function (sandbox) {
|
|
Sandboxing.getState(sandbox).each(function (tmenu) {
|
|
tieredMenu.repositionMenus(tmenu);
|
|
});
|
|
};
|
|
var makeSandbox = function (detail, hotspot, extras) {
|
|
var ariaOwner = manager();
|
|
var onOpen = function (component, menu) {
|
|
var anchor = getAnchor(detail, hotspot);
|
|
ariaOwner.link(hotspot.element());
|
|
if (detail.matchWidth) {
|
|
matchWidth(anchor.hotspot, menu, detail.useMinWidth);
|
|
}
|
|
detail.onOpen(anchor, component, menu);
|
|
if (extras !== undefined && extras.onOpen !== undefined) {
|
|
extras.onOpen(component, menu);
|
|
}
|
|
};
|
|
var onClose = function (component, menu) {
|
|
ariaOwner.unlink(hotspot.element());
|
|
if (extras !== undefined && extras.onClose !== undefined) {
|
|
extras.onClose(component, menu);
|
|
}
|
|
};
|
|
var lazySink = getSink(hotspot, detail);
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: detail.sandboxClasses,
|
|
attributes: {
|
|
id: ariaOwner.id,
|
|
role: 'listbox'
|
|
}
|
|
},
|
|
behaviours: SketchBehaviours.augment(detail.sandboxBehaviours, [
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: hotspot
|
|
}
|
|
}),
|
|
Sandboxing.config({
|
|
onOpen: onOpen,
|
|
onClose: onClose,
|
|
isPartOf: function (container, data, queryElem) {
|
|
return isPartOf(data, queryElem) || isPartOf(hotspot, queryElem);
|
|
},
|
|
getAttachPoint: function () {
|
|
return lazySink().getOrDie();
|
|
}
|
|
}),
|
|
Composing.config({
|
|
find: function (sandbox) {
|
|
return Sandboxing.getState(sandbox).bind(function (menu) {
|
|
return Composing.getCurrent(menu);
|
|
});
|
|
}
|
|
}),
|
|
Receiving.config({ channels: __assign(__assign({}, receivingChannel({ isExtraPart: never })), receivingChannel$1({ doReposition: doRepositionMenus })) })
|
|
])
|
|
};
|
|
};
|
|
var repositionMenus = function (comp) {
|
|
var sandbox = Coupling.getCoupled(comp, 'sandbox');
|
|
doRepositionMenus(sandbox);
|
|
};
|
|
|
|
var sandboxFields = function () {
|
|
return [
|
|
defaulted$1('sandboxClasses', []),
|
|
SketchBehaviours.field('sandboxBehaviours', [
|
|
Composing,
|
|
Receiving,
|
|
Sandboxing,
|
|
Representing
|
|
])
|
|
];
|
|
};
|
|
|
|
var schema$g = constant([
|
|
strict$1('dom'),
|
|
strict$1('fetch'),
|
|
onHandler('onOpen'),
|
|
onKeyboardHandler('onExecute'),
|
|
defaulted$1('getHotspot', Option.some),
|
|
defaulted$1('getAnchorOverrides', constant({})),
|
|
schema$1(),
|
|
field$1('dropdownBehaviours', [
|
|
Toggling,
|
|
Coupling,
|
|
Keying,
|
|
Focusing
|
|
]),
|
|
strict$1('toggleClass'),
|
|
defaulted$1('eventOrder', {}),
|
|
option('lazySink'),
|
|
defaulted$1('matchWidth', false),
|
|
defaulted$1('useMinWidth', false),
|
|
option('role')
|
|
].concat(sandboxFields()));
|
|
var parts$4 = constant([
|
|
external$1({
|
|
schema: [tieredMenuMarkers()],
|
|
name: 'menu',
|
|
defaults: function (detail) {
|
|
return { onExecute: detail.onExecute };
|
|
}
|
|
}),
|
|
partType()
|
|
]);
|
|
|
|
var factory$6 = function (detail, components, _spec, externals) {
|
|
var _a;
|
|
var lookupAttr = function (attr) {
|
|
return get(detail.dom, 'attributes').bind(function (attrs) {
|
|
return get(attrs, attr);
|
|
});
|
|
};
|
|
var switchToMenu = function (sandbox) {
|
|
Sandboxing.getState(sandbox).each(function (tmenu) {
|
|
tieredMenu.highlightPrimary(tmenu);
|
|
});
|
|
};
|
|
var action = function (component) {
|
|
var onOpenSync = switchToMenu;
|
|
togglePopup(detail, function (x) {
|
|
return x;
|
|
}, component, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
|
|
};
|
|
var apis = {
|
|
expand: function (comp) {
|
|
if (!Toggling.isOn(comp)) {
|
|
togglePopup(detail, function (x) {
|
|
return x;
|
|
}, comp, externals, noop, HighlightOnOpen.HighlightNone).get(noop);
|
|
}
|
|
},
|
|
open: function (comp) {
|
|
if (!Toggling.isOn(comp)) {
|
|
togglePopup(detail, function (x) {
|
|
return x;
|
|
}, comp, externals, noop, HighlightOnOpen.HighlightFirst).get(noop);
|
|
}
|
|
},
|
|
isOpen: Toggling.isOn,
|
|
close: function (comp) {
|
|
if (Toggling.isOn(comp)) {
|
|
togglePopup(detail, function (x) {
|
|
return x;
|
|
}, comp, externals, noop, HighlightOnOpen.HighlightFirst).get(noop);
|
|
}
|
|
},
|
|
repositionMenus: function (comp) {
|
|
if (Toggling.isOn(comp)) {
|
|
repositionMenus(comp);
|
|
}
|
|
}
|
|
};
|
|
var triggerExecute = function (comp, _se) {
|
|
emitExecute(comp);
|
|
return Option.some(true);
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: augment(detail.dropdownBehaviours, [
|
|
Toggling.config({
|
|
toggleClass: detail.toggleClass,
|
|
aria: { mode: 'expanded' }
|
|
}),
|
|
Coupling.config({
|
|
others: {
|
|
sandbox: function (hotspot) {
|
|
return makeSandbox(detail, hotspot, {
|
|
onOpen: function () {
|
|
Toggling.on(hotspot);
|
|
},
|
|
onClose: function () {
|
|
Toggling.off(hotspot);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}),
|
|
Keying.config({
|
|
mode: 'special',
|
|
onSpace: triggerExecute,
|
|
onEnter: triggerExecute,
|
|
onDown: function (comp, _se) {
|
|
if (Dropdown.isOpen(comp)) {
|
|
var sandbox = Coupling.getCoupled(comp, 'sandbox');
|
|
switchToMenu(sandbox);
|
|
} else {
|
|
Dropdown.open(comp);
|
|
}
|
|
return Option.some(true);
|
|
},
|
|
onEscape: function (comp, _se) {
|
|
if (Dropdown.isOpen(comp)) {
|
|
Dropdown.close(comp);
|
|
return Option.some(true);
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
}
|
|
}),
|
|
Focusing.config({})
|
|
]),
|
|
events: events$7(Option.some(action)),
|
|
eventOrder: __assign(__assign({}, detail.eventOrder), (_a = {}, _a[execute()] = [
|
|
'disabling',
|
|
'toggling',
|
|
'alloy.base.behaviour'
|
|
], _a)),
|
|
apis: apis,
|
|
domModification: {
|
|
attributes: __assign(__assign({ 'aria-haspopup': 'true' }, detail.role.fold(function () {
|
|
return {};
|
|
}, function (role) {
|
|
return { role: role };
|
|
})), detail.dom.tag === 'button' ? { type: lookupAttr('type').getOr('button') } : {})
|
|
}
|
|
};
|
|
};
|
|
var Dropdown = composite$1({
|
|
name: 'Dropdown',
|
|
configFields: schema$g(),
|
|
partFields: parts$4(),
|
|
factory: factory$6,
|
|
apis: {
|
|
open: function (apis, comp) {
|
|
return apis.open(comp);
|
|
},
|
|
expand: function (apis, comp) {
|
|
return apis.expand(comp);
|
|
},
|
|
close: function (apis, comp) {
|
|
return apis.close(comp);
|
|
},
|
|
isOpen: function (apis, comp) {
|
|
return apis.isOpen(comp);
|
|
},
|
|
repositionMenus: function (apis, comp) {
|
|
return apis.repositionMenus(comp);
|
|
}
|
|
}
|
|
});
|
|
|
|
var exhibit$5 = function () {
|
|
return nu$6({
|
|
styles: {
|
|
'-webkit-user-select': 'none',
|
|
'user-select': 'none',
|
|
'-ms-user-select': 'none',
|
|
'-moz-user-select': '-moz-none'
|
|
},
|
|
attributes: { unselectable: 'on' }
|
|
});
|
|
};
|
|
var events$b = function () {
|
|
return derive([abort(selectstart(), constant(true))]);
|
|
};
|
|
|
|
var ActiveUnselecting = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$b,
|
|
exhibit: exhibit$5
|
|
});
|
|
|
|
var Unselecting = create$1({
|
|
fields: [],
|
|
name: 'unselecting',
|
|
active: ActiveUnselecting
|
|
});
|
|
|
|
var renderPanelButton = function (spec, sharedBackstage) {
|
|
return Dropdown.sketch({
|
|
dom: spec.dom,
|
|
components: spec.components,
|
|
toggleClass: 'mce-active',
|
|
dropdownBehaviours: derive$1([
|
|
DisablingConfigs.button(sharedBackstage.providers.isReadOnly),
|
|
receivingConfig(),
|
|
Unselecting.config({}),
|
|
Tabstopping.config({})
|
|
]),
|
|
layouts: spec.layouts,
|
|
sandboxClasses: ['tox-dialog__popups'],
|
|
lazySink: sharedBackstage.getSink,
|
|
fetch: function (comp) {
|
|
return Future.nu(function (callback) {
|
|
return spec.fetch(callback);
|
|
}).map(function (items) {
|
|
return Option.from(createTieredDataFrom(deepMerge(createPartialChoiceMenu(generate$1('menu-value'), items, function (value) {
|
|
spec.onItemAction(comp, value);
|
|
}, spec.columns, spec.presets, ItemResponse$1.CLOSE_ON_EXECUTE, function () {
|
|
return false;
|
|
}, sharedBackstage.providers), { movement: deriveMenuMovement(spec.columns, spec.presets) })));
|
|
});
|
|
},
|
|
parts: { menu: part(false, 1, spec.presets) }
|
|
});
|
|
};
|
|
|
|
var colorInputChangeEvent = generate$1('color-input-change');
|
|
var colorSwatchChangeEvent = generate$1('color-swatch-change');
|
|
var colorPickerCancelEvent = generate$1('color-picker-cancel');
|
|
var renderColorInput = function (spec, sharedBackstage, colorInputBackstage) {
|
|
var pField = FormField.parts().field({
|
|
factory: Input,
|
|
inputClasses: ['tox-textfield'],
|
|
onSetValue: function (c) {
|
|
return Invalidating.run(c).get(function () {
|
|
});
|
|
},
|
|
inputBehaviours: derive$1([
|
|
Disabling.config({ disabled: sharedBackstage.providers.isReadOnly }),
|
|
receivingConfig(),
|
|
Tabstopping.config({}),
|
|
Invalidating.config({
|
|
invalidClass: 'tox-textbox-field-invalid',
|
|
getRoot: function (comp) {
|
|
return parent(comp.element());
|
|
},
|
|
notify: {
|
|
onValid: function (comp) {
|
|
var val = Representing.getValue(comp);
|
|
emitWith(comp, colorInputChangeEvent, { color: val });
|
|
}
|
|
},
|
|
validator: {
|
|
validateOnLoad: false,
|
|
validate: function (input) {
|
|
var inputValue = Representing.getValue(input);
|
|
if (inputValue.length === 0) {
|
|
return Future.pure(Result.value(true));
|
|
} else {
|
|
var span = Element.fromTag('span');
|
|
set$2(span, 'background-color', inputValue);
|
|
var res = getRaw(span, 'background-color').fold(function () {
|
|
return Result.error('blah');
|
|
}, function (_) {
|
|
return Result.value(inputValue);
|
|
});
|
|
return Future.pure(res);
|
|
}
|
|
}
|
|
}
|
|
})
|
|
]),
|
|
selectOnFocus: false
|
|
});
|
|
var pLabel = spec.label.map(function (label) {
|
|
return renderLabel(label, sharedBackstage.providers);
|
|
});
|
|
var emitSwatchChange = function (colorBit, value) {
|
|
emitWith(colorBit, colorSwatchChangeEvent, { value: value });
|
|
};
|
|
var onItemAction = function (comp, value) {
|
|
memColorButton.getOpt(comp).each(function (colorBit) {
|
|
if (value === 'custom') {
|
|
colorInputBackstage.colorPicker(function (valueOpt) {
|
|
valueOpt.fold(function () {
|
|
return emit(colorBit, colorPickerCancelEvent);
|
|
}, function (value) {
|
|
emitSwatchChange(colorBit, value);
|
|
addColor(value);
|
|
});
|
|
}, '#ffffff');
|
|
} else if (value === 'remove') {
|
|
emitSwatchChange(colorBit, '');
|
|
} else {
|
|
emitSwatchChange(colorBit, value);
|
|
}
|
|
});
|
|
};
|
|
var memColorButton = record(renderPanelButton({
|
|
dom: {
|
|
tag: 'span',
|
|
attributes: { 'aria-label': sharedBackstage.providers.translate('Color swatch') }
|
|
},
|
|
layouts: {
|
|
onRtl: function () {
|
|
return [
|
|
southwest$1,
|
|
southeast$1,
|
|
south$1
|
|
];
|
|
},
|
|
onLtr: function () {
|
|
return [
|
|
southeast$1,
|
|
southwest$1,
|
|
south$1
|
|
];
|
|
}
|
|
},
|
|
components: [],
|
|
fetch: getFetch(colorInputBackstage.getColors(), colorInputBackstage.hasCustomColors()),
|
|
columns: colorInputBackstage.getColorCols(),
|
|
presets: 'color',
|
|
onItemAction: onItemAction
|
|
}, sharedBackstage));
|
|
return FormField.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form__group']
|
|
},
|
|
components: pLabel.toArray().concat([{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-color-input']
|
|
},
|
|
components: [
|
|
pField,
|
|
memColorButton.asSpec()
|
|
]
|
|
}]),
|
|
fieldBehaviours: derive$1([config('form-field-events', [
|
|
run(colorInputChangeEvent, function (comp, se) {
|
|
memColorButton.getOpt(comp).each(function (colorButton) {
|
|
set$2(colorButton.element(), 'background-color', se.event().color());
|
|
});
|
|
emitWith(comp, formChangeEvent, { name: spec.name });
|
|
}),
|
|
run(colorSwatchChangeEvent, function (comp, se) {
|
|
FormField.getField(comp).each(function (field) {
|
|
Representing.setValue(field, se.event().value());
|
|
Composing.getCurrent(comp).each(Focusing.focus);
|
|
});
|
|
}),
|
|
run(colorPickerCancelEvent, function (comp, _se) {
|
|
FormField.getField(comp).each(function (_field) {
|
|
Composing.getCurrent(comp).each(Focusing.focus);
|
|
});
|
|
})
|
|
])])
|
|
});
|
|
};
|
|
|
|
var hsvColour = function (hue, saturation, value) {
|
|
return {
|
|
hue: hue,
|
|
saturation: saturation,
|
|
value: value
|
|
};
|
|
};
|
|
var fromRgb = function (rgbaColour) {
|
|
var h = 0;
|
|
var s = 0;
|
|
var v = 0;
|
|
var r = rgbaColour.red / 255;
|
|
var g = rgbaColour.green / 255;
|
|
var b = rgbaColour.blue / 255;
|
|
var minRGB = Math.min(r, Math.min(g, b));
|
|
var maxRGB = Math.max(r, Math.max(g, b));
|
|
if (minRGB === maxRGB) {
|
|
v = minRGB;
|
|
return hsvColour(0, 0, v * 100);
|
|
}
|
|
var d = r === minRGB ? g - b : b === minRGB ? r - g : b - r;
|
|
h = r === minRGB ? 3 : b === minRGB ? 1 : 5;
|
|
h = 60 * (h - d / (maxRGB - minRGB));
|
|
s = (maxRGB - minRGB) / maxRGB;
|
|
v = maxRGB;
|
|
return hsvColour(Math.round(h), Math.round(s * 100), Math.round(v * 100));
|
|
};
|
|
|
|
var calcHex = function (value) {
|
|
var hue = (100 - value) / 100 * 360;
|
|
var hsv = hsvColour(hue, 100, 100);
|
|
var rgb = fromHsv(hsv);
|
|
return fromRgba(rgb);
|
|
};
|
|
|
|
var fieldsUpdate = generate$1('rgb-hex-update');
|
|
var sliderUpdate = generate$1('slider-update');
|
|
var paletteUpdate = generate$1('palette-update');
|
|
|
|
var labelPart = optional({
|
|
schema: [strict$1('dom')],
|
|
name: 'label'
|
|
});
|
|
var edgePart = function (name) {
|
|
return optional({
|
|
name: '' + name + '-edge',
|
|
overrides: function (detail) {
|
|
var action = detail.model.manager.edgeActions[name];
|
|
return action.fold(function () {
|
|
return {};
|
|
}, function (a) {
|
|
return {
|
|
events: derive([
|
|
runActionExtra(touchstart(), function (comp, se, d) {
|
|
return a(comp, d);
|
|
}, [detail]),
|
|
runActionExtra(mousedown(), function (comp, se, d) {
|
|
return a(comp, d);
|
|
}, [detail]),
|
|
runActionExtra(mousemove(), function (comp, se, det) {
|
|
if (det.mouseIsDown.get()) {
|
|
a(comp, det);
|
|
}
|
|
}, [detail])
|
|
])
|
|
};
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var tlEdgePart = edgePart('top-left');
|
|
var tedgePart = edgePart('top');
|
|
var trEdgePart = edgePart('top-right');
|
|
var redgePart = edgePart('right');
|
|
var brEdgePart = edgePart('bottom-right');
|
|
var bedgePart = edgePart('bottom');
|
|
var blEdgePart = edgePart('bottom-left');
|
|
var ledgePart = edgePart('left');
|
|
var thumbPart = required({
|
|
name: 'thumb',
|
|
defaults: constant({ dom: { styles: { position: 'absolute' } } }),
|
|
overrides: function (detail) {
|
|
return {
|
|
events: derive([
|
|
redirectToPart(touchstart(), detail, 'spectrum'),
|
|
redirectToPart(touchmove(), detail, 'spectrum'),
|
|
redirectToPart(touchend(), detail, 'spectrum'),
|
|
redirectToPart(mousedown(), detail, 'spectrum'),
|
|
redirectToPart(mousemove(), detail, 'spectrum'),
|
|
redirectToPart(mouseup(), detail, 'spectrum')
|
|
])
|
|
};
|
|
}
|
|
});
|
|
var spectrumPart = required({
|
|
schema: [state$1('mouseIsDown', function () {
|
|
return Cell(false);
|
|
})],
|
|
name: 'spectrum',
|
|
overrides: function (detail) {
|
|
var modelDetail = detail.model;
|
|
var model = modelDetail.manager;
|
|
var setValueFrom = function (component, simulatedEvent) {
|
|
return model.getValueFromEvent(simulatedEvent).map(function (value) {
|
|
return model.setValueFrom(component, detail, value);
|
|
});
|
|
};
|
|
return {
|
|
behaviours: derive$1([
|
|
Keying.config({
|
|
mode: 'special',
|
|
onLeft: function (spectrum) {
|
|
return model.onLeft(spectrum, detail);
|
|
},
|
|
onRight: function (spectrum) {
|
|
return model.onRight(spectrum, detail);
|
|
},
|
|
onUp: function (spectrum) {
|
|
return model.onUp(spectrum, detail);
|
|
},
|
|
onDown: function (spectrum) {
|
|
return model.onDown(spectrum, detail);
|
|
}
|
|
}),
|
|
Focusing.config({})
|
|
]),
|
|
events: derive([
|
|
run(touchstart(), setValueFrom),
|
|
run(touchmove(), setValueFrom),
|
|
run(mousedown(), setValueFrom),
|
|
run(mousemove(), function (spectrum, se) {
|
|
if (detail.mouseIsDown.get()) {
|
|
setValueFrom(spectrum, se);
|
|
}
|
|
})
|
|
])
|
|
};
|
|
}
|
|
});
|
|
var SliderParts = [
|
|
labelPart,
|
|
ledgePart,
|
|
redgePart,
|
|
tedgePart,
|
|
bedgePart,
|
|
tlEdgePart,
|
|
trEdgePart,
|
|
blEdgePart,
|
|
brEdgePart,
|
|
thumbPart,
|
|
spectrumPart
|
|
];
|
|
|
|
var _sliderChangeEvent = 'slider.change.value';
|
|
var sliderChangeEvent = constant(_sliderChangeEvent);
|
|
var isTouchEvent = function (evt) {
|
|
return evt.type.indexOf('touch') !== -1;
|
|
};
|
|
var getEventSource = function (simulatedEvent) {
|
|
var evt = simulatedEvent.event().raw();
|
|
if (isTouchEvent(evt)) {
|
|
var touchEvent = evt;
|
|
return touchEvent.touches !== undefined && touchEvent.touches.length === 1 ? Option.some(touchEvent.touches[0]).map(function (t) {
|
|
return Position(t.clientX, t.clientY);
|
|
}) : Option.none();
|
|
} else {
|
|
var mouseEvent = evt;
|
|
return mouseEvent.clientX !== undefined ? Option.some(mouseEvent).map(function (me) {
|
|
return Position(me.clientX, me.clientY);
|
|
}) : Option.none();
|
|
}
|
|
};
|
|
|
|
var t = 'top', r$1 = 'right', b = 'bottom', l = 'left';
|
|
var minX = function (detail) {
|
|
return detail.model.minX;
|
|
};
|
|
var minY = function (detail) {
|
|
return detail.model.minY;
|
|
};
|
|
var min1X = function (detail) {
|
|
return detail.model.minX - 1;
|
|
};
|
|
var min1Y = function (detail) {
|
|
return detail.model.minY - 1;
|
|
};
|
|
var maxX = function (detail) {
|
|
return detail.model.maxX;
|
|
};
|
|
var maxY = function (detail) {
|
|
return detail.model.maxY;
|
|
};
|
|
var max1X = function (detail) {
|
|
return detail.model.maxX + 1;
|
|
};
|
|
var max1Y = function (detail) {
|
|
return detail.model.maxY + 1;
|
|
};
|
|
var range$2 = function (detail, max, min) {
|
|
return max(detail) - min(detail);
|
|
};
|
|
var xRange = function (detail) {
|
|
return range$2(detail, maxX, minX);
|
|
};
|
|
var yRange = function (detail) {
|
|
return range$2(detail, maxY, minY);
|
|
};
|
|
var halfX = function (detail) {
|
|
return xRange(detail) / 2;
|
|
};
|
|
var halfY = function (detail) {
|
|
return yRange(detail) / 2;
|
|
};
|
|
var step = function (detail) {
|
|
return detail.stepSize;
|
|
};
|
|
var snap = function (detail) {
|
|
return detail.snapToGrid;
|
|
};
|
|
var snapStart = function (detail) {
|
|
return detail.snapStart;
|
|
};
|
|
var rounded = function (detail) {
|
|
return detail.rounded;
|
|
};
|
|
var hasEdge = function (detail, edgeName) {
|
|
return detail[edgeName + '-edge'] !== undefined;
|
|
};
|
|
var hasLEdge = function (detail) {
|
|
return hasEdge(detail, l);
|
|
};
|
|
var hasREdge = function (detail) {
|
|
return hasEdge(detail, r$1);
|
|
};
|
|
var hasTEdge = function (detail) {
|
|
return hasEdge(detail, t);
|
|
};
|
|
var hasBEdge = function (detail) {
|
|
return hasEdge(detail, b);
|
|
};
|
|
var currentValue = function (detail) {
|
|
return detail.model.value.get();
|
|
};
|
|
|
|
var xValue = function (x) {
|
|
return { x: constant(x) };
|
|
};
|
|
var yValue = function (y) {
|
|
return { y: constant(y) };
|
|
};
|
|
var xyValue = function (x, y) {
|
|
return {
|
|
x: constant(x),
|
|
y: constant(y)
|
|
};
|
|
};
|
|
var fireSliderChange = function (component, value) {
|
|
emitWith(component, sliderChangeEvent(), { value: value });
|
|
};
|
|
var setToTLEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(min1X(detail), min1Y(detail)));
|
|
};
|
|
var setToTEdge = function (edge, detail) {
|
|
fireSliderChange(edge, yValue(min1Y(detail)));
|
|
};
|
|
var setToTEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(halfX(detail), min1Y(detail)));
|
|
};
|
|
var setToTREdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(max1X(detail), min1Y(detail)));
|
|
};
|
|
var setToREdge = function (edge, detail) {
|
|
fireSliderChange(edge, xValue(max1X(detail)));
|
|
};
|
|
var setToREdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(max1X(detail), halfY(detail)));
|
|
};
|
|
var setToBREdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(max1X(detail), max1Y(detail)));
|
|
};
|
|
var setToBEdge = function (edge, detail) {
|
|
fireSliderChange(edge, yValue(max1Y(detail)));
|
|
};
|
|
var setToBEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(halfX(detail), max1Y(detail)));
|
|
};
|
|
var setToBLEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(min1X(detail), max1Y(detail)));
|
|
};
|
|
var setToLEdge = function (edge, detail) {
|
|
fireSliderChange(edge, xValue(min1X(detail)));
|
|
};
|
|
var setToLEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(min1X(detail), halfY(detail)));
|
|
};
|
|
|
|
var reduceBy = function (value, min, max, step) {
|
|
if (value < min) {
|
|
return value;
|
|
} else if (value > max) {
|
|
return max;
|
|
} else if (value === min) {
|
|
return min - 1;
|
|
} else {
|
|
return Math.max(min, value - step);
|
|
}
|
|
};
|
|
var increaseBy = function (value, min, max, step) {
|
|
if (value > max) {
|
|
return value;
|
|
} else if (value < min) {
|
|
return min;
|
|
} else if (value === max) {
|
|
return max + 1;
|
|
} else {
|
|
return Math.min(max, value + step);
|
|
}
|
|
};
|
|
var capValue = function (value, min, max) {
|
|
return Math.max(min, Math.min(max, value));
|
|
};
|
|
var snapValueOf = function (value, min, max, step, snapStart) {
|
|
return snapStart.fold(function () {
|
|
var initValue = value - min;
|
|
var extraValue = Math.round(initValue / step) * step;
|
|
return capValue(min + extraValue, min - 1, max + 1);
|
|
}, function (start) {
|
|
var remainder = (value - start) % step;
|
|
var adjustment = Math.round(remainder / step);
|
|
var rawSteps = Math.floor((value - start) / step);
|
|
var maxSteps = Math.floor((max - start) / step);
|
|
var numSteps = Math.min(maxSteps, rawSteps + adjustment);
|
|
var r = start + numSteps * step;
|
|
return Math.max(start, r);
|
|
});
|
|
};
|
|
var findOffsetOf = function (value, min, max) {
|
|
return Math.min(max, Math.max(value, min)) - min;
|
|
};
|
|
var findValueOf = function (args) {
|
|
var min = args.min, max = args.max, range = args.range, value = args.value, step = args.step, snap = args.snap, snapStart = args.snapStart, rounded = args.rounded, hasMinEdge = args.hasMinEdge, hasMaxEdge = args.hasMaxEdge, minBound = args.minBound, maxBound = args.maxBound, screenRange = args.screenRange;
|
|
var capMin = hasMinEdge ? min - 1 : min;
|
|
var capMax = hasMaxEdge ? max + 1 : max;
|
|
if (value < minBound) {
|
|
return capMin;
|
|
} else if (value > maxBound) {
|
|
return capMax;
|
|
} else {
|
|
var offset = findOffsetOf(value, minBound, maxBound);
|
|
var newValue = capValue(offset / screenRange * range + min, capMin, capMax);
|
|
if (snap && newValue >= min && newValue <= max) {
|
|
return snapValueOf(newValue, min, max, step, snapStart);
|
|
} else if (rounded) {
|
|
return Math.round(newValue);
|
|
} else {
|
|
return newValue;
|
|
}
|
|
}
|
|
};
|
|
var findOffsetOfValue = function (args) {
|
|
var min = args.min, max = args.max, range = args.range, value = args.value, hasMinEdge = args.hasMinEdge, hasMaxEdge = args.hasMaxEdge, maxBound = args.maxBound, maxOffset = args.maxOffset, centerMinEdge = args.centerMinEdge, centerMaxEdge = args.centerMaxEdge;
|
|
if (value < min) {
|
|
return hasMinEdge ? 0 : centerMinEdge;
|
|
} else if (value > max) {
|
|
return hasMaxEdge ? maxBound : centerMaxEdge;
|
|
} else {
|
|
return (value - min) / range * maxOffset;
|
|
}
|
|
};
|
|
|
|
var top = 'top', right = 'right', bottom = 'bottom', left = 'left', width = 'width', height = 'height';
|
|
var getBounds$1 = function (component) {
|
|
return component.element().dom().getBoundingClientRect();
|
|
};
|
|
var getBoundsProperty = function (bounds, property) {
|
|
return bounds[property];
|
|
};
|
|
var getMinXBounds = function (component) {
|
|
var bounds = getBounds$1(component);
|
|
return getBoundsProperty(bounds, left);
|
|
};
|
|
var getMaxXBounds = function (component) {
|
|
var bounds = getBounds$1(component);
|
|
return getBoundsProperty(bounds, right);
|
|
};
|
|
var getMinYBounds = function (component) {
|
|
var bounds = getBounds$1(component);
|
|
return getBoundsProperty(bounds, top);
|
|
};
|
|
var getMaxYBounds = function (component) {
|
|
var bounds = getBounds$1(component);
|
|
return getBoundsProperty(bounds, bottom);
|
|
};
|
|
var getXScreenRange = function (component) {
|
|
var bounds = getBounds$1(component);
|
|
return getBoundsProperty(bounds, width);
|
|
};
|
|
var getYScreenRange = function (component) {
|
|
var bounds = getBounds$1(component);
|
|
return getBoundsProperty(bounds, height);
|
|
};
|
|
var getCenterOffsetOf = function (componentMinEdge, componentMaxEdge, spectrumMinEdge) {
|
|
return (componentMinEdge + componentMaxEdge) / 2 - spectrumMinEdge;
|
|
};
|
|
var getXCenterOffSetOf = function (component, spectrum) {
|
|
var componentBounds = getBounds$1(component);
|
|
var spectrumBounds = getBounds$1(spectrum);
|
|
var componentMinEdge = getBoundsProperty(componentBounds, left);
|
|
var componentMaxEdge = getBoundsProperty(componentBounds, right);
|
|
var spectrumMinEdge = getBoundsProperty(spectrumBounds, left);
|
|
return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
|
|
};
|
|
var getYCenterOffSetOf = function (component, spectrum) {
|
|
var componentBounds = getBounds$1(component);
|
|
var spectrumBounds = getBounds$1(spectrum);
|
|
var componentMinEdge = getBoundsProperty(componentBounds, top);
|
|
var componentMaxEdge = getBoundsProperty(componentBounds, bottom);
|
|
var spectrumMinEdge = getBoundsProperty(spectrumBounds, top);
|
|
return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
|
|
};
|
|
|
|
var fireSliderChange$1 = function (spectrum, value) {
|
|
emitWith(spectrum, sliderChangeEvent(), { value: value });
|
|
};
|
|
var sliderValue = function (x) {
|
|
return { x: constant(x) };
|
|
};
|
|
var findValueOfOffset = function (spectrum, detail, left) {
|
|
var args = {
|
|
min: minX(detail),
|
|
max: maxX(detail),
|
|
range: xRange(detail),
|
|
value: left,
|
|
step: step(detail),
|
|
snap: snap(detail),
|
|
snapStart: snapStart(detail),
|
|
rounded: rounded(detail),
|
|
hasMinEdge: hasLEdge(detail),
|
|
hasMaxEdge: hasREdge(detail),
|
|
minBound: getMinXBounds(spectrum),
|
|
maxBound: getMaxXBounds(spectrum),
|
|
screenRange: getXScreenRange(spectrum)
|
|
};
|
|
return findValueOf(args);
|
|
};
|
|
var setValueFrom = function (spectrum, detail, value) {
|
|
var xValue = findValueOfOffset(spectrum, detail, value);
|
|
var sliderVal = sliderValue(xValue);
|
|
fireSliderChange$1(spectrum, sliderVal);
|
|
return xValue;
|
|
};
|
|
var setToMin = function (spectrum, detail) {
|
|
var min = minX(detail);
|
|
fireSliderChange$1(spectrum, sliderValue(min));
|
|
};
|
|
var setToMax = function (spectrum, detail) {
|
|
var max = maxX(detail);
|
|
fireSliderChange$1(spectrum, sliderValue(max));
|
|
};
|
|
var moveBy = function (direction, spectrum, detail) {
|
|
var f = direction > 0 ? increaseBy : reduceBy;
|
|
var xValue = f(currentValue(detail).x(), minX(detail), maxX(detail), step(detail));
|
|
fireSliderChange$1(spectrum, sliderValue(xValue));
|
|
return Option.some(xValue);
|
|
};
|
|
var handleMovement = function (direction) {
|
|
return function (spectrum, detail) {
|
|
return moveBy(direction, spectrum, detail).map(function () {
|
|
return true;
|
|
});
|
|
};
|
|
};
|
|
var getValueFromEvent = function (simulatedEvent) {
|
|
var pos = getEventSource(simulatedEvent);
|
|
return pos.map(function (p) {
|
|
return p.left();
|
|
});
|
|
};
|
|
var findOffsetOfValue$1 = function (spectrum, detail, value, minEdge, maxEdge) {
|
|
var minOffset = 0;
|
|
var maxOffset = getXScreenRange(spectrum);
|
|
var centerMinEdge = minEdge.bind(function (edge) {
|
|
return Option.some(getXCenterOffSetOf(edge, spectrum));
|
|
}).getOr(minOffset);
|
|
var centerMaxEdge = maxEdge.bind(function (edge) {
|
|
return Option.some(getXCenterOffSetOf(edge, spectrum));
|
|
}).getOr(maxOffset);
|
|
var args = {
|
|
min: minX(detail),
|
|
max: maxX(detail),
|
|
range: xRange(detail),
|
|
value: value,
|
|
hasMinEdge: hasLEdge(detail),
|
|
hasMaxEdge: hasREdge(detail),
|
|
minBound: getMinXBounds(spectrum),
|
|
minOffset: minOffset,
|
|
maxBound: getMaxXBounds(spectrum),
|
|
maxOffset: maxOffset,
|
|
centerMinEdge: centerMinEdge,
|
|
centerMaxEdge: centerMaxEdge
|
|
};
|
|
return findOffsetOfValue(args);
|
|
};
|
|
var findPositionOfValue = function (slider, spectrum, value, minEdge, maxEdge, detail) {
|
|
var offset = findOffsetOfValue$1(spectrum, detail, value, minEdge, maxEdge);
|
|
return getMinXBounds(spectrum) - getMinXBounds(slider) + offset;
|
|
};
|
|
var setPositionFromValue = function (slider, thumb, detail, edges) {
|
|
var value = currentValue(detail);
|
|
var pos = findPositionOfValue(slider, edges.getSpectrum(slider), value.x(), edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
|
|
var thumbRadius = get$7(thumb.element()) / 2;
|
|
set$2(thumb.element(), 'left', pos - thumbRadius + 'px');
|
|
};
|
|
var onLeft = handleMovement(-1);
|
|
var onRight = handleMovement(1);
|
|
var onUp = Option.none;
|
|
var onDown = Option.none;
|
|
var edgeActions = {
|
|
'top-left': Option.none(),
|
|
'top': Option.none(),
|
|
'top-right': Option.none(),
|
|
'right': Option.some(setToREdge),
|
|
'bottom-right': Option.none(),
|
|
'bottom': Option.none(),
|
|
'bottom-left': Option.none(),
|
|
'left': Option.some(setToLEdge)
|
|
};
|
|
|
|
var HorizontalModel = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
setValueFrom: setValueFrom,
|
|
setToMin: setToMin,
|
|
setToMax: setToMax,
|
|
findValueOfOffset: findValueOfOffset,
|
|
getValueFromEvent: getValueFromEvent,
|
|
findPositionOfValue: findPositionOfValue,
|
|
setPositionFromValue: setPositionFromValue,
|
|
onLeft: onLeft,
|
|
onRight: onRight,
|
|
onUp: onUp,
|
|
onDown: onDown,
|
|
edgeActions: edgeActions
|
|
});
|
|
|
|
var fireSliderChange$2 = function (spectrum, value) {
|
|
emitWith(spectrum, sliderChangeEvent(), { value: value });
|
|
};
|
|
var sliderValue$1 = function (y) {
|
|
return { y: constant(y) };
|
|
};
|
|
var findValueOfOffset$1 = function (spectrum, detail, top) {
|
|
var args = {
|
|
min: minY(detail),
|
|
max: maxY(detail),
|
|
range: yRange(detail),
|
|
value: top,
|
|
step: step(detail),
|
|
snap: snap(detail),
|
|
snapStart: snapStart(detail),
|
|
rounded: rounded(detail),
|
|
hasMinEdge: hasTEdge(detail),
|
|
hasMaxEdge: hasBEdge(detail),
|
|
minBound: getMinYBounds(spectrum),
|
|
maxBound: getMaxYBounds(spectrum),
|
|
screenRange: getYScreenRange(spectrum)
|
|
};
|
|
return findValueOf(args);
|
|
};
|
|
var setValueFrom$1 = function (spectrum, detail, value) {
|
|
var yValue = findValueOfOffset$1(spectrum, detail, value);
|
|
var sliderVal = sliderValue$1(yValue);
|
|
fireSliderChange$2(spectrum, sliderVal);
|
|
return yValue;
|
|
};
|
|
var setToMin$1 = function (spectrum, detail) {
|
|
var min = minY(detail);
|
|
fireSliderChange$2(spectrum, sliderValue$1(min));
|
|
};
|
|
var setToMax$1 = function (spectrum, detail) {
|
|
var max = maxY(detail);
|
|
fireSliderChange$2(spectrum, sliderValue$1(max));
|
|
};
|
|
var moveBy$1 = function (direction, spectrum, detail) {
|
|
var f = direction > 0 ? increaseBy : reduceBy;
|
|
var yValue = f(currentValue(detail).y(), minY(detail), maxY(detail), step(detail));
|
|
fireSliderChange$2(spectrum, sliderValue$1(yValue));
|
|
return Option.some(yValue);
|
|
};
|
|
var handleMovement$1 = function (direction) {
|
|
return function (spectrum, detail) {
|
|
return moveBy$1(direction, spectrum, detail).map(function () {
|
|
return true;
|
|
});
|
|
};
|
|
};
|
|
var getValueFromEvent$1 = function (simulatedEvent) {
|
|
var pos = getEventSource(simulatedEvent);
|
|
return pos.map(function (p) {
|
|
return p.top();
|
|
});
|
|
};
|
|
var findOffsetOfValue$2 = function (spectrum, detail, value, minEdge, maxEdge) {
|
|
var minOffset = 0;
|
|
var maxOffset = getYScreenRange(spectrum);
|
|
var centerMinEdge = minEdge.bind(function (edge) {
|
|
return Option.some(getYCenterOffSetOf(edge, spectrum));
|
|
}).getOr(minOffset);
|
|
var centerMaxEdge = maxEdge.bind(function (edge) {
|
|
return Option.some(getYCenterOffSetOf(edge, spectrum));
|
|
}).getOr(maxOffset);
|
|
var args = {
|
|
min: minY(detail),
|
|
max: maxY(detail),
|
|
range: yRange(detail),
|
|
value: value,
|
|
hasMinEdge: hasTEdge(detail),
|
|
hasMaxEdge: hasBEdge(detail),
|
|
minBound: getMinYBounds(spectrum),
|
|
minOffset: minOffset,
|
|
maxBound: getMaxYBounds(spectrum),
|
|
maxOffset: maxOffset,
|
|
centerMinEdge: centerMinEdge,
|
|
centerMaxEdge: centerMaxEdge
|
|
};
|
|
return findOffsetOfValue(args);
|
|
};
|
|
var findPositionOfValue$1 = function (slider, spectrum, value, minEdge, maxEdge, detail) {
|
|
var offset = findOffsetOfValue$2(spectrum, detail, value, minEdge, maxEdge);
|
|
return getMinYBounds(spectrum) - getMinYBounds(slider) + offset;
|
|
};
|
|
var setPositionFromValue$1 = function (slider, thumb, detail, edges) {
|
|
var value = currentValue(detail);
|
|
var pos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value.y(), edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
|
|
var thumbRadius = get$6(thumb.element()) / 2;
|
|
set$2(thumb.element(), 'top', pos - thumbRadius + 'px');
|
|
};
|
|
var onLeft$1 = Option.none;
|
|
var onRight$1 = Option.none;
|
|
var onUp$1 = handleMovement$1(-1);
|
|
var onDown$1 = handleMovement$1(1);
|
|
var edgeActions$1 = {
|
|
'top-left': Option.none(),
|
|
'top': Option.some(setToTEdge),
|
|
'top-right': Option.none(),
|
|
'right': Option.none(),
|
|
'bottom-right': Option.none(),
|
|
'bottom': Option.some(setToBEdge),
|
|
'bottom-left': Option.none(),
|
|
'left': Option.none()
|
|
};
|
|
|
|
var VerticalModel = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
setValueFrom: setValueFrom$1,
|
|
setToMin: setToMin$1,
|
|
setToMax: setToMax$1,
|
|
findValueOfOffset: findValueOfOffset$1,
|
|
getValueFromEvent: getValueFromEvent$1,
|
|
findPositionOfValue: findPositionOfValue$1,
|
|
setPositionFromValue: setPositionFromValue$1,
|
|
onLeft: onLeft$1,
|
|
onRight: onRight$1,
|
|
onUp: onUp$1,
|
|
onDown: onDown$1,
|
|
edgeActions: edgeActions$1
|
|
});
|
|
|
|
var fireSliderChange$3 = function (spectrum, value) {
|
|
emitWith(spectrum, sliderChangeEvent(), { value: value });
|
|
};
|
|
var sliderValue$2 = function (x, y) {
|
|
return {
|
|
x: constant(x),
|
|
y: constant(y)
|
|
};
|
|
};
|
|
var setValueFrom$2 = function (spectrum, detail, value) {
|
|
var xValue = findValueOfOffset(spectrum, detail, value.left());
|
|
var yValue = findValueOfOffset$1(spectrum, detail, value.top());
|
|
var val = sliderValue$2(xValue, yValue);
|
|
fireSliderChange$3(spectrum, val);
|
|
return val;
|
|
};
|
|
var moveBy$2 = function (direction, isVerticalMovement, spectrum, detail) {
|
|
var f = direction > 0 ? increaseBy : reduceBy;
|
|
var xValue = isVerticalMovement ? currentValue(detail).x() : f(currentValue(detail).x(), minX(detail), maxX(detail), step(detail));
|
|
var yValue = !isVerticalMovement ? currentValue(detail).y() : f(currentValue(detail).y(), minY(detail), maxY(detail), step(detail));
|
|
fireSliderChange$3(spectrum, sliderValue$2(xValue, yValue));
|
|
return Option.some(xValue);
|
|
};
|
|
var handleMovement$2 = function (direction, isVerticalMovement) {
|
|
return function (spectrum, detail) {
|
|
return moveBy$2(direction, isVerticalMovement, spectrum, detail).map(function () {
|
|
return true;
|
|
});
|
|
};
|
|
};
|
|
var setToMin$2 = function (spectrum, detail) {
|
|
var mX = minX(detail);
|
|
var mY = minY(detail);
|
|
fireSliderChange$3(spectrum, sliderValue$2(mX, mY));
|
|
};
|
|
var setToMax$2 = function (spectrum, detail) {
|
|
var mX = maxX(detail);
|
|
var mY = maxY(detail);
|
|
fireSliderChange$3(spectrum, sliderValue$2(mX, mY));
|
|
};
|
|
var getValueFromEvent$2 = function (simulatedEvent) {
|
|
return getEventSource(simulatedEvent);
|
|
};
|
|
var setPositionFromValue$2 = function (slider, thumb, detail, edges) {
|
|
var value = currentValue(detail);
|
|
var xPos = findPositionOfValue(slider, edges.getSpectrum(slider), value.x(), edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
|
|
var yPos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value.y(), edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
|
|
var thumbXRadius = get$7(thumb.element()) / 2;
|
|
var thumbYRadius = get$6(thumb.element()) / 2;
|
|
set$2(thumb.element(), 'left', xPos - thumbXRadius + 'px');
|
|
set$2(thumb.element(), 'top', yPos - thumbYRadius + 'px');
|
|
};
|
|
var onLeft$2 = handleMovement$2(-1, false);
|
|
var onRight$2 = handleMovement$2(1, false);
|
|
var onUp$2 = handleMovement$2(-1, true);
|
|
var onDown$2 = handleMovement$2(1, true);
|
|
var edgeActions$2 = {
|
|
'top-left': Option.some(setToTLEdgeXY),
|
|
'top': Option.some(setToTEdgeXY),
|
|
'top-right': Option.some(setToTREdgeXY),
|
|
'right': Option.some(setToREdgeXY),
|
|
'bottom-right': Option.some(setToBREdgeXY),
|
|
'bottom': Option.some(setToBEdgeXY),
|
|
'bottom-left': Option.some(setToBLEdgeXY),
|
|
'left': Option.some(setToLEdgeXY)
|
|
};
|
|
|
|
var TwoDModel = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
setValueFrom: setValueFrom$2,
|
|
setToMin: setToMin$2,
|
|
setToMax: setToMax$2,
|
|
getValueFromEvent: getValueFromEvent$2,
|
|
setPositionFromValue: setPositionFromValue$2,
|
|
onLeft: onLeft$2,
|
|
onRight: onRight$2,
|
|
onUp: onUp$2,
|
|
onDown: onDown$2,
|
|
edgeActions: edgeActions$2
|
|
});
|
|
|
|
var SliderSchema = [
|
|
defaulted$1('stepSize', 1),
|
|
defaulted$1('onChange', noop),
|
|
defaulted$1('onChoose', noop),
|
|
defaulted$1('onInit', noop),
|
|
defaulted$1('onDragStart', noop),
|
|
defaulted$1('onDragEnd', noop),
|
|
defaulted$1('snapToGrid', false),
|
|
defaulted$1('rounded', true),
|
|
option('snapStart'),
|
|
strictOf('model', choose$1('mode', {
|
|
x: [
|
|
defaulted$1('minX', 0),
|
|
defaulted$1('maxX', 100),
|
|
state$1('value', function (spec) {
|
|
return Cell(spec.mode.minX);
|
|
}),
|
|
strict$1('getInitialValue'),
|
|
output('manager', HorizontalModel)
|
|
],
|
|
y: [
|
|
defaulted$1('minY', 0),
|
|
defaulted$1('maxY', 100),
|
|
state$1('value', function (spec) {
|
|
return Cell(spec.mode.minY);
|
|
}),
|
|
strict$1('getInitialValue'),
|
|
output('manager', VerticalModel)
|
|
],
|
|
xy: [
|
|
defaulted$1('minX', 0),
|
|
defaulted$1('maxX', 100),
|
|
defaulted$1('minY', 0),
|
|
defaulted$1('maxY', 100),
|
|
state$1('value', function (spec) {
|
|
return Cell({
|
|
x: constant(spec.mode.minX),
|
|
y: constant(spec.mode.minY)
|
|
});
|
|
}),
|
|
strict$1('getInitialValue'),
|
|
output('manager', TwoDModel)
|
|
]
|
|
})),
|
|
field$1('sliderBehaviours', [
|
|
Keying,
|
|
Representing
|
|
]),
|
|
state$1('mouseIsDown', function () {
|
|
return Cell(false);
|
|
})
|
|
];
|
|
|
|
var sketch = function (detail, components, _spec, _externals) {
|
|
var _a;
|
|
var getThumb = function (component) {
|
|
return getPartOrDie(component, detail, 'thumb');
|
|
};
|
|
var getSpectrum = function (component) {
|
|
return getPartOrDie(component, detail, 'spectrum');
|
|
};
|
|
var getLeftEdge = function (component) {
|
|
return getPart(component, detail, 'left-edge');
|
|
};
|
|
var getRightEdge = function (component) {
|
|
return getPart(component, detail, 'right-edge');
|
|
};
|
|
var getTopEdge = function (component) {
|
|
return getPart(component, detail, 'top-edge');
|
|
};
|
|
var getBottomEdge = function (component) {
|
|
return getPart(component, detail, 'bottom-edge');
|
|
};
|
|
var modelDetail = detail.model;
|
|
var model = modelDetail.manager;
|
|
var refresh = function (slider, thumb) {
|
|
model.setPositionFromValue(slider, thumb, detail, {
|
|
getLeftEdge: getLeftEdge,
|
|
getRightEdge: getRightEdge,
|
|
getTopEdge: getTopEdge,
|
|
getBottomEdge: getBottomEdge,
|
|
getSpectrum: getSpectrum
|
|
});
|
|
};
|
|
var changeValue = function (slider, newValue) {
|
|
modelDetail.value.set(newValue);
|
|
var thumb = getThumb(slider);
|
|
refresh(slider, thumb);
|
|
detail.onChange(slider, thumb, newValue);
|
|
return Option.some(true);
|
|
};
|
|
var resetToMin = function (slider) {
|
|
model.setToMin(slider, detail);
|
|
};
|
|
var resetToMax = function (slider) {
|
|
model.setToMax(slider, detail);
|
|
};
|
|
var choose = function (slider) {
|
|
var fireOnChoose = function () {
|
|
getPart(slider, detail, 'thumb').each(function (thumb) {
|
|
var value = modelDetail.value.get();
|
|
detail.onChoose(slider, thumb, value);
|
|
});
|
|
};
|
|
var wasDown = detail.mouseIsDown.get();
|
|
detail.mouseIsDown.set(false);
|
|
if (wasDown) {
|
|
fireOnChoose();
|
|
}
|
|
};
|
|
var onDragStart = function (slider, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
detail.mouseIsDown.set(true);
|
|
detail.onDragStart(slider, getThumb(slider));
|
|
};
|
|
var onDragEnd = function (slider, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
detail.onDragEnd(slider, getThumb(slider));
|
|
choose(slider);
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: augment(detail.sliderBehaviours, [
|
|
Keying.config({
|
|
mode: 'special',
|
|
focusIn: function (slider) {
|
|
return getPart(slider, detail, 'spectrum').map(Keying.focusIn).map(constant(true));
|
|
}
|
|
}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (_) {
|
|
return modelDetail.value.get();
|
|
}
|
|
}
|
|
}),
|
|
Receiving.config({ channels: (_a = {}, _a[mouseReleased()] = { onReceive: choose }, _a) })
|
|
]),
|
|
events: derive([
|
|
run(sliderChangeEvent(), function (slider, simulatedEvent) {
|
|
changeValue(slider, simulatedEvent.event().value());
|
|
}),
|
|
runOnAttached(function (slider, _simulatedEvent) {
|
|
var getInitial = modelDetail.getInitialValue();
|
|
modelDetail.value.set(getInitial);
|
|
var thumb = getThumb(slider);
|
|
refresh(slider, thumb);
|
|
var spectrum = getSpectrum(slider);
|
|
detail.onInit(slider, thumb, spectrum, modelDetail.value.get());
|
|
}),
|
|
run(touchstart(), onDragStart),
|
|
run(touchend(), onDragEnd),
|
|
run(mousedown(), onDragStart),
|
|
run(mouseup(), onDragEnd)
|
|
]),
|
|
apis: {
|
|
resetToMin: resetToMin,
|
|
resetToMax: resetToMax,
|
|
changeValue: changeValue,
|
|
refresh: refresh
|
|
},
|
|
domModification: { styles: { position: 'relative' } }
|
|
};
|
|
};
|
|
|
|
var Slider = composite$1({
|
|
name: 'Slider',
|
|
configFields: SliderSchema,
|
|
partFields: SliderParts,
|
|
factory: sketch,
|
|
apis: {
|
|
resetToMin: function (apis, slider) {
|
|
apis.resetToMin(slider);
|
|
},
|
|
resetToMax: function (apis, slider) {
|
|
apis.resetToMax(slider);
|
|
},
|
|
refresh: function (apis, slider) {
|
|
apis.refresh(slider);
|
|
}
|
|
}
|
|
});
|
|
|
|
var sliderFactory = function (translate, getClass) {
|
|
var spectrum = Slider.parts().spectrum({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [getClass('hue-slider-spectrum')],
|
|
attributes: { role: 'presentation' }
|
|
}
|
|
});
|
|
var thumb = Slider.parts().thumb({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [getClass('hue-slider-thumb')],
|
|
attributes: { role: 'presentation' }
|
|
}
|
|
});
|
|
return Slider.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [getClass('hue-slider')],
|
|
attributes: { role: 'presentation' }
|
|
},
|
|
rounded: false,
|
|
model: {
|
|
mode: 'y',
|
|
getInitialValue: constant({ y: constant(0) })
|
|
},
|
|
components: [
|
|
spectrum,
|
|
thumb
|
|
],
|
|
sliderBehaviours: derive$1([Focusing.config({})]),
|
|
onChange: function (slider, _thumb, value) {
|
|
emitWith(slider, sliderUpdate, { value: value });
|
|
}
|
|
});
|
|
};
|
|
|
|
var owner$3 = 'form';
|
|
var schema$h = [field$1('formBehaviours', [Representing])];
|
|
var getPartName = function (name) {
|
|
return '<alloy.field.' + name + '>';
|
|
};
|
|
var sketch$1 = function (fSpec) {
|
|
var parts = function () {
|
|
var record = [];
|
|
var field = function (name, config) {
|
|
record.push(name);
|
|
return generateOne(owner$3, getPartName(name), config);
|
|
};
|
|
return {
|
|
field: field,
|
|
record: function () {
|
|
return record;
|
|
}
|
|
};
|
|
}();
|
|
var spec = fSpec(parts);
|
|
var partNames = parts.record();
|
|
var fieldParts = map(partNames, function (n) {
|
|
return required({
|
|
name: n,
|
|
pname: getPartName(n)
|
|
});
|
|
});
|
|
return composite(owner$3, schema$h, fieldParts, make$4, spec);
|
|
};
|
|
var toResult$1 = function (o, e) {
|
|
return o.fold(function () {
|
|
return Result.error(e);
|
|
}, Result.value);
|
|
};
|
|
var make$4 = function (detail, components) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: augment(detail.formBehaviours, [Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (form) {
|
|
var resPs = getAllParts(form, detail);
|
|
return map$1(resPs, function (resPThunk, pName) {
|
|
return resPThunk().bind(function (v) {
|
|
var opt = Composing.getCurrent(v);
|
|
return toResult$1(opt, new Error('Cannot find a current component to extract the value from for form part \'' + pName + '\': ' + element(v.element())));
|
|
}).map(Representing.getValue);
|
|
});
|
|
},
|
|
setValue: function (form, values) {
|
|
each$1(values, function (newValue, key) {
|
|
getPart(form, detail, key).each(function (wrapper) {
|
|
Composing.getCurrent(wrapper).each(function (field) {
|
|
Representing.setValue(field, newValue);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
})]),
|
|
apis: {
|
|
getField: function (form, key) {
|
|
return getPart(form, detail, key).bind(Composing.getCurrent);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
var Form = {
|
|
getField: makeApi(function (apis, component, key) {
|
|
return apis.getField(component, key);
|
|
}),
|
|
sketch: sketch$1
|
|
};
|
|
|
|
var validInput = generate$1('valid-input');
|
|
var invalidInput = generate$1('invalid-input');
|
|
var validatingInput = generate$1('validating-input');
|
|
var translatePrefix = 'colorcustom.rgb.';
|
|
var rgbFormFactory = function (translate, getClass, onValidHexx, onInvalidHexx) {
|
|
var invalidation = function (label, isValid) {
|
|
return Invalidating.config({
|
|
invalidClass: getClass('invalid'),
|
|
notify: {
|
|
onValidate: function (comp) {
|
|
emitWith(comp, validatingInput, { type: label });
|
|
},
|
|
onValid: function (comp) {
|
|
emitWith(comp, validInput, {
|
|
type: label,
|
|
value: Representing.getValue(comp)
|
|
});
|
|
},
|
|
onInvalid: function (comp) {
|
|
emitWith(comp, invalidInput, {
|
|
type: label,
|
|
value: Representing.getValue(comp)
|
|
});
|
|
}
|
|
},
|
|
validator: {
|
|
validate: function (comp) {
|
|
var value = Representing.getValue(comp);
|
|
var res = isValid(value) ? Result.value(true) : Result.error(translate('aria.input.invalid'));
|
|
return Future.pure(res);
|
|
},
|
|
validateOnLoad: false
|
|
}
|
|
});
|
|
};
|
|
var renderTextField = function (isValid, name, label, description, data) {
|
|
var helptext = translate(translatePrefix + 'range');
|
|
var pLabel = FormField.parts().label({
|
|
dom: {
|
|
tag: 'label',
|
|
innerHtml: label,
|
|
attributes: { 'aria-label': description }
|
|
}
|
|
});
|
|
var pField = FormField.parts().field({
|
|
data: data,
|
|
factory: Input,
|
|
inputAttributes: __assign({ type: 'text' }, name === 'hex' ? { 'aria-live': 'polite' } : {}),
|
|
inputClasses: [getClass('textfield')],
|
|
inputBehaviours: derive$1([
|
|
invalidation(name, isValid),
|
|
Tabstopping.config({})
|
|
]),
|
|
onSetValue: function (input) {
|
|
if (Invalidating.isInvalid(input)) {
|
|
var run = Invalidating.run(input);
|
|
run.get(noop);
|
|
}
|
|
}
|
|
});
|
|
var comps = [
|
|
pLabel,
|
|
pField
|
|
];
|
|
var concats = name !== 'hex' ? [FormField.parts()['aria-descriptor']({ text: helptext })] : [];
|
|
var components = comps.concat(concats);
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { role: 'presentation' }
|
|
},
|
|
components: components
|
|
};
|
|
};
|
|
var copyRgbToHex = function (form, rgba) {
|
|
var hex = fromRgba(rgba);
|
|
Form.getField(form, 'hex').each(function (hexField) {
|
|
if (!Focusing.isFocused(hexField)) {
|
|
Representing.setValue(form, { hex: hex.value });
|
|
}
|
|
});
|
|
return hex;
|
|
};
|
|
var copyRgbToForm = function (form, rgb) {
|
|
var red = rgb.red;
|
|
var green = rgb.green;
|
|
var blue = rgb.blue;
|
|
Representing.setValue(form, {
|
|
red: red,
|
|
green: green,
|
|
blue: blue
|
|
});
|
|
};
|
|
var memPreview = record({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [getClass('rgba-preview')],
|
|
styles: { 'background-color': 'white' },
|
|
attributes: { role: 'presentation' }
|
|
}
|
|
});
|
|
var updatePreview = function (anyInSystem, hex) {
|
|
memPreview.getOpt(anyInSystem).each(function (preview) {
|
|
set$2(preview.element(), 'background-color', '#' + hex.value);
|
|
});
|
|
};
|
|
var factory = function () {
|
|
var state = {
|
|
red: Cell(Option.some(255)),
|
|
green: Cell(Option.some(255)),
|
|
blue: Cell(Option.some(255)),
|
|
hex: Cell(Option.some('ffffff'))
|
|
};
|
|
var copyHexToRgb = function (form, hex) {
|
|
var rgb = fromHex(hex);
|
|
copyRgbToForm(form, rgb);
|
|
setValueRgb(rgb);
|
|
};
|
|
var get = function (prop) {
|
|
return state[prop].get();
|
|
};
|
|
var set = function (prop, value) {
|
|
state[prop].set(value);
|
|
};
|
|
var getValueRgb = function () {
|
|
return get('red').bind(function (red) {
|
|
return get('green').bind(function (green) {
|
|
return get('blue').map(function (blue) {
|
|
return rgbaColour(red, green, blue, 1);
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var setValueRgb = function (rgb) {
|
|
var red = rgb.red;
|
|
var green = rgb.green;
|
|
var blue = rgb.blue;
|
|
set('red', Option.some(red));
|
|
set('green', Option.some(green));
|
|
set('blue', Option.some(blue));
|
|
};
|
|
var onInvalidInput = function (form, simulatedEvent) {
|
|
var data = simulatedEvent.event();
|
|
if (data.type() !== 'hex') {
|
|
set(data.type(), Option.none());
|
|
} else {
|
|
onInvalidHexx(form);
|
|
}
|
|
};
|
|
var onValidHex = function (form, value) {
|
|
onValidHexx(form);
|
|
var hex = hexColour(value);
|
|
set('hex', Option.some(value));
|
|
var rgb = fromHex(hex);
|
|
copyRgbToForm(form, rgb);
|
|
setValueRgb(rgb);
|
|
emitWith(form, fieldsUpdate, { hex: hex });
|
|
updatePreview(form, hex);
|
|
};
|
|
var onValidRgb = function (form, prop, value) {
|
|
var val = parseInt(value, 10);
|
|
set(prop, Option.some(val));
|
|
getValueRgb().each(function (rgb) {
|
|
var hex = copyRgbToHex(form, rgb);
|
|
updatePreview(form, hex);
|
|
});
|
|
};
|
|
var isHexInputEvent = function (data) {
|
|
return data.type() === 'hex';
|
|
};
|
|
var onValidInput = function (form, simulatedEvent) {
|
|
var data = simulatedEvent.event();
|
|
if (isHexInputEvent(data)) {
|
|
onValidHex(form, data.value());
|
|
} else {
|
|
onValidRgb(form, data.type(), data.value());
|
|
}
|
|
};
|
|
var formPartStrings = function (key) {
|
|
return {
|
|
label: translate(translatePrefix + key + '.label'),
|
|
description: translate(translatePrefix + key + '.description')
|
|
};
|
|
};
|
|
var redStrings = formPartStrings('red');
|
|
var greenStrings = formPartStrings('green');
|
|
var blueStrings = formPartStrings('blue');
|
|
var hexStrings = formPartStrings('hex');
|
|
return deepMerge(Form.sketch(function (parts) {
|
|
return {
|
|
dom: {
|
|
tag: 'form',
|
|
classes: [getClass('rgb-form')],
|
|
attributes: { 'aria-label': translate('aria.color.picker') }
|
|
},
|
|
components: [
|
|
parts.field('red', FormField.sketch(renderTextField(isRgbaComponent, 'red', redStrings.label, redStrings.description, 255))),
|
|
parts.field('green', FormField.sketch(renderTextField(isRgbaComponent, 'green', greenStrings.label, greenStrings.description, 255))),
|
|
parts.field('blue', FormField.sketch(renderTextField(isRgbaComponent, 'blue', blueStrings.label, blueStrings.description, 255))),
|
|
parts.field('hex', FormField.sketch(renderTextField(isHexString, 'hex', hexStrings.label, hexStrings.description, 'ffffff'))),
|
|
memPreview.asSpec()
|
|
],
|
|
formBehaviours: derive$1([
|
|
Invalidating.config({ invalidClass: getClass('form-invalid') }),
|
|
config('rgb-form-events', [
|
|
run(validInput, onValidInput),
|
|
run(invalidInput, onInvalidInput),
|
|
run(validatingInput, onInvalidInput)
|
|
])
|
|
])
|
|
};
|
|
}), {
|
|
apis: {
|
|
updateHex: function (form, hex) {
|
|
Representing.setValue(form, { hex: hex.value });
|
|
copyHexToRgb(form, hex);
|
|
updatePreview(form, hex);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
var rgbFormSketcher = single$2({
|
|
factory: factory,
|
|
name: 'RgbForm',
|
|
configFields: [],
|
|
apis: {
|
|
updateHex: function (apis, form, hex) {
|
|
apis.updateHex(form, hex);
|
|
}
|
|
},
|
|
extraApis: {}
|
|
});
|
|
return rgbFormSketcher;
|
|
};
|
|
|
|
var paletteFactory = function (_translate, getClass) {
|
|
var spectrumPart = Slider.parts().spectrum({
|
|
dom: {
|
|
tag: 'canvas',
|
|
attributes: { role: 'presentation' },
|
|
classes: [getClass('sv-palette-spectrum')]
|
|
}
|
|
});
|
|
var thumbPart = Slider.parts().thumb({
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { role: 'presentation' },
|
|
classes: [getClass('sv-palette-thumb')],
|
|
innerHtml: '<div class=' + getClass('sv-palette-inner-thumb') + ' role="presentation"></div>'
|
|
}
|
|
});
|
|
var setColour = function (canvas, rgba) {
|
|
var width = canvas.width, height = canvas.height;
|
|
var ctx = canvas.getContext('2d');
|
|
if (ctx === null) {
|
|
return;
|
|
}
|
|
ctx.fillStyle = rgba;
|
|
ctx.fillRect(0, 0, width, height);
|
|
var grdWhite = ctx.createLinearGradient(0, 0, width, 0);
|
|
grdWhite.addColorStop(0, 'rgba(255,255,255,1)');
|
|
grdWhite.addColorStop(1, 'rgba(255,255,255,0)');
|
|
ctx.fillStyle = grdWhite;
|
|
ctx.fillRect(0, 0, width, height);
|
|
var grdBlack = ctx.createLinearGradient(0, 0, 0, height);
|
|
grdBlack.addColorStop(0, 'rgba(0,0,0,0)');
|
|
grdBlack.addColorStop(1, 'rgba(0,0,0,1)');
|
|
ctx.fillStyle = grdBlack;
|
|
ctx.fillRect(0, 0, width, height);
|
|
};
|
|
var setSliderColour = function (slider, rgba) {
|
|
var canvas = slider.components()[0].element().dom();
|
|
setColour(canvas, toString(rgba));
|
|
};
|
|
var factory = function (_detail) {
|
|
var getInitialValue = constant({
|
|
x: constant(0),
|
|
y: constant(0)
|
|
});
|
|
var onChange = function (slider, _thumb, value) {
|
|
emitWith(slider, paletteUpdate, { value: value });
|
|
};
|
|
var onInit = function (_slider, _thumb, spectrum, _value) {
|
|
setColour(spectrum.element().dom(), toString(red));
|
|
};
|
|
var sliderBehaviours = derive$1([
|
|
Composing.config({ find: Option.some }),
|
|
Focusing.config({})
|
|
]);
|
|
return Slider.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { role: 'presentation' },
|
|
classes: [getClass('sv-palette')]
|
|
},
|
|
model: {
|
|
mode: 'xy',
|
|
getInitialValue: getInitialValue
|
|
},
|
|
rounded: false,
|
|
components: [
|
|
spectrumPart,
|
|
thumbPart
|
|
],
|
|
onChange: onChange,
|
|
onInit: onInit,
|
|
sliderBehaviours: sliderBehaviours
|
|
});
|
|
};
|
|
var saturationBrightnessPaletteSketcher = single$2({
|
|
factory: factory,
|
|
name: 'SaturationBrightnessPalette',
|
|
configFields: [],
|
|
apis: {
|
|
setRgba: function (_apis, slider, rgba) {
|
|
setSliderColour(slider, rgba);
|
|
}
|
|
},
|
|
extraApis: {}
|
|
});
|
|
return saturationBrightnessPaletteSketcher;
|
|
};
|
|
|
|
var makeFactory = function (translate, getClass) {
|
|
var factory = function (detail) {
|
|
var rgbForm = rgbFormFactory(translate, getClass, detail.onValidHex, detail.onInvalidHex);
|
|
var sbPalette = paletteFactory(translate, getClass);
|
|
var state = { paletteRgba: Cell(red) };
|
|
var memPalette = record(sbPalette.sketch({}));
|
|
var memRgb = record(rgbForm.sketch({}));
|
|
var updatePalette = function (anyInSystem, hex) {
|
|
memPalette.getOpt(anyInSystem).each(function (palette) {
|
|
var rgba = fromHex(hex);
|
|
state.paletteRgba.set(rgba);
|
|
sbPalette.setRgba(palette, rgba);
|
|
});
|
|
};
|
|
var updateFields = function (anyInSystem, hex) {
|
|
memRgb.getOpt(anyInSystem).each(function (form) {
|
|
rgbForm.updateHex(form, hex);
|
|
});
|
|
};
|
|
var runUpdates = function (anyInSystem, hex, updates) {
|
|
each(updates, function (update) {
|
|
update(anyInSystem, hex);
|
|
});
|
|
};
|
|
var paletteUpdates = function () {
|
|
var updates = [updateFields];
|
|
return function (form, simulatedEvent) {
|
|
var value = simulatedEvent.event().value();
|
|
var oldRgb = state.paletteRgba.get();
|
|
var hsvColour$1 = fromRgb(oldRgb);
|
|
var newHsvColour = hsvColour(hsvColour$1.hue, value.x(), 100 - value.y());
|
|
var rgb = fromHsv(newHsvColour);
|
|
var nuHex = fromRgba(rgb);
|
|
runUpdates(form, nuHex, updates);
|
|
};
|
|
};
|
|
var sliderUpdates = function () {
|
|
var updates = [
|
|
updatePalette,
|
|
updateFields
|
|
];
|
|
return function (form, simulatedEvent) {
|
|
var value = simulatedEvent.event().value();
|
|
var hex = calcHex(value.y());
|
|
runUpdates(form, hex, updates);
|
|
};
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: [
|
|
memPalette.asSpec(),
|
|
sliderFactory(translate, getClass),
|
|
memRgb.asSpec()
|
|
],
|
|
behaviours: derive$1([
|
|
config('colour-picker-events', [
|
|
run(paletteUpdate, paletteUpdates()),
|
|
run(sliderUpdate, sliderUpdates())
|
|
]),
|
|
Composing.config({
|
|
find: function (comp) {
|
|
return memRgb.getOpt(comp);
|
|
}
|
|
}),
|
|
Keying.config({ mode: 'acyclic' })
|
|
])
|
|
};
|
|
};
|
|
var colourPickerSketcher = single$2({
|
|
name: 'ColourPicker',
|
|
configFields: [
|
|
strict$1('dom'),
|
|
defaulted$1('onValidHex', noop),
|
|
defaulted$1('onInvalidHex', noop)
|
|
],
|
|
factory: factory
|
|
});
|
|
return colourPickerSketcher;
|
|
};
|
|
|
|
var self$1 = function () {
|
|
return Composing.config({ find: Option.some });
|
|
};
|
|
var memento = function (mem) {
|
|
return Composing.config({ find: mem.getOpt });
|
|
};
|
|
var childAt = function (index) {
|
|
return Composing.config({
|
|
find: function (comp) {
|
|
return child(comp.element(), index).bind(function (element) {
|
|
return comp.getSystem().getByDom(element).toOption();
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var ComposingConfigs = {
|
|
self: self$1,
|
|
memento: memento,
|
|
childAt: childAt
|
|
};
|
|
|
|
var english = {
|
|
'colorcustom.rgb.red.label': 'R',
|
|
'colorcustom.rgb.red.description': 'Red component',
|
|
'colorcustom.rgb.green.label': 'G',
|
|
'colorcustom.rgb.green.description': 'Green component',
|
|
'colorcustom.rgb.blue.label': 'B',
|
|
'colorcustom.rgb.blue.description': 'Blue component',
|
|
'colorcustom.rgb.hex.label': '#',
|
|
'colorcustom.rgb.hex.description': 'Hex color code',
|
|
'colorcustom.rgb.range': 'Range 0 to 255',
|
|
'colorcustom.sb.saturation': 'Saturation',
|
|
'colorcustom.sb.brightness': 'Brightness',
|
|
'colorcustom.sb.picker': 'Saturation and Brightness Picker',
|
|
'colorcustom.sb.palette': 'Saturation and Brightness Palette',
|
|
'colorcustom.sb.instructions': 'Use arrow keys to select saturation and brightness, on x and y axes',
|
|
'colorcustom.hue.hue': 'Hue',
|
|
'colorcustom.hue.slider': 'Hue Slider',
|
|
'colorcustom.hue.palette': 'Hue Palette',
|
|
'colorcustom.hue.instructions': 'Use arrow keys to select a hue',
|
|
'aria.color.picker': 'Color Picker',
|
|
'aria.input.invalid': 'Invalid input'
|
|
};
|
|
var getEnglishText = function (key) {
|
|
return english[key];
|
|
};
|
|
var translate$1 = function (key) {
|
|
return getEnglishText(key);
|
|
};
|
|
var renderColorPicker = function (_spec) {
|
|
var getClass = function (key) {
|
|
return 'tox-' + key;
|
|
};
|
|
var colourPickerFactory = makeFactory(translate$1, getClass);
|
|
var onValidHex = function (form) {
|
|
emitWith(form, formActionEvent, {
|
|
name: 'hex-valid',
|
|
value: true
|
|
});
|
|
};
|
|
var onInvalidHex = function (form) {
|
|
emitWith(form, formActionEvent, {
|
|
name: 'hex-valid',
|
|
value: false
|
|
});
|
|
};
|
|
var memPicker = record(colourPickerFactory.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [getClass('color-picker-container')],
|
|
attributes: { role: 'presentation' }
|
|
},
|
|
onValidHex: onValidHex,
|
|
onInvalidHex: onInvalidHex
|
|
}));
|
|
return {
|
|
dom: { tag: 'div' },
|
|
components: [memPicker.asSpec()],
|
|
behaviours: derive$1([
|
|
Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (comp) {
|
|
var picker = memPicker.get(comp);
|
|
var optRgbForm = Composing.getCurrent(picker);
|
|
var optHex = optRgbForm.bind(function (rgbForm) {
|
|
var formValues = Representing.getValue(rgbForm);
|
|
return formValues.hex;
|
|
});
|
|
return optHex.map(function (hex) {
|
|
return '#' + hex;
|
|
}).getOr('');
|
|
},
|
|
setValue: function (comp, newValue) {
|
|
var pattern = /^#([a-fA-F0-9]{3}(?:[a-fA-F0-9]{3})?)/;
|
|
var m = pattern.exec(newValue);
|
|
var picker = memPicker.get(comp);
|
|
var optRgbForm = Composing.getCurrent(picker);
|
|
optRgbForm.fold(function () {
|
|
domGlobals.console.log('Can not find form');
|
|
}, function (rgbForm) {
|
|
Representing.setValue(rgbForm, { hex: Option.from(m[1]).getOr('') });
|
|
Form.getField(rgbForm, 'hex').each(function (hexField) {
|
|
emit(hexField, input());
|
|
});
|
|
});
|
|
}
|
|
}
|
|
}),
|
|
ComposingConfigs.self()
|
|
])
|
|
};
|
|
};
|
|
|
|
var global$a = tinymce.util.Tools.resolve('tinymce.Resource');
|
|
|
|
var isOldCustomEditor = function (spec) {
|
|
return Object.prototype.hasOwnProperty.call(spec, 'init');
|
|
};
|
|
var renderCustomEditor = function (spec) {
|
|
var editorApi = Cell(Option.none());
|
|
var memReplaced = record({ dom: { tag: spec.tag } });
|
|
var initialValue = Cell(Option.none());
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-custom-editor']
|
|
},
|
|
behaviours: derive$1([
|
|
config('editor-foo-events', [runOnAttached(function (component) {
|
|
memReplaced.getOpt(component).each(function (ta) {
|
|
(isOldCustomEditor(spec) ? spec.init(ta.element().dom()) : global$a.load(spec.scriptId, spec.scriptUrl).then(function (init) {
|
|
return init(ta.element().dom(), spec.settings);
|
|
})).then(function (ea) {
|
|
initialValue.get().each(function (cvalue) {
|
|
ea.setValue(cvalue);
|
|
});
|
|
initialValue.set(Option.none());
|
|
editorApi.set(Option.some(ea));
|
|
});
|
|
});
|
|
})]),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function () {
|
|
return editorApi.get().fold(function () {
|
|
return initialValue.get().getOr('');
|
|
}, function (ed) {
|
|
return ed.getValue();
|
|
});
|
|
},
|
|
setValue: function (component, value) {
|
|
editorApi.get().fold(function () {
|
|
initialValue.set(Option.some(value));
|
|
}, function (ed) {
|
|
return ed.setValue(value);
|
|
});
|
|
}
|
|
}
|
|
}),
|
|
ComposingConfigs.self()
|
|
]),
|
|
components: [memReplaced.asSpec()]
|
|
};
|
|
};
|
|
|
|
var processors = objOf([
|
|
defaulted$1('preprocess', identity),
|
|
defaulted$1('postprocess', identity)
|
|
]);
|
|
var memento$1 = function (mem, rawProcessors) {
|
|
var ps = asRawOrDie('RepresentingConfigs.memento processors', processors, rawProcessors);
|
|
return Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (comp) {
|
|
var other = mem.get(comp);
|
|
var rawValue = Representing.getValue(other);
|
|
return ps.postprocess(rawValue);
|
|
},
|
|
setValue: function (comp, rawValue) {
|
|
var newValue = ps.preprocess(rawValue);
|
|
var other = mem.get(comp);
|
|
Representing.setValue(other, newValue);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
var withComp = function (optInitialValue, getter, setter) {
|
|
return Representing.config(deepMerge({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: getter,
|
|
setValue: setter
|
|
}
|
|
}, optInitialValue.map(function (initialValue) {
|
|
return { store: { initialValue: initialValue } };
|
|
}).getOr({})));
|
|
};
|
|
var withElement = function (initialValue, getter, setter) {
|
|
return withComp(initialValue, function (c) {
|
|
return getter(c.element());
|
|
}, function (c, v) {
|
|
return setter(c.element(), v);
|
|
});
|
|
};
|
|
var domValue = function (optInitialValue) {
|
|
return withElement(optInitialValue, get$5, set$3);
|
|
};
|
|
var domHtml = function (optInitialValue) {
|
|
return withElement(optInitialValue, get$1, set);
|
|
};
|
|
var memory$1 = function (initialValue) {
|
|
return Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: initialValue
|
|
}
|
|
});
|
|
};
|
|
var RepresentingConfigs = {
|
|
memento: memento$1,
|
|
withElement: withElement,
|
|
withComp: withComp,
|
|
domValue: domValue,
|
|
domHtml: domHtml,
|
|
memory: memory$1
|
|
};
|
|
|
|
var extensionsAccepted = '.jpg,.jpeg,.png,.gif';
|
|
var filterByExtension = function (files) {
|
|
var re = new RegExp('(' + extensionsAccepted.split(/\s*,\s*/).join('|') + ')$', 'i');
|
|
return filter(from$1(files), function (file) {
|
|
return re.test(file.name);
|
|
});
|
|
};
|
|
var renderDropZone = function (spec, providersBackstage) {
|
|
var stopper = function (_, se) {
|
|
se.stop();
|
|
};
|
|
var sequence = function (actions) {
|
|
return function (comp, se) {
|
|
each(actions, function (a) {
|
|
a(comp, se);
|
|
});
|
|
};
|
|
};
|
|
var onDrop = function (comp, se) {
|
|
if (!Disabling.isDisabled(comp)) {
|
|
var transferEvent = se.event().raw();
|
|
handleFiles(comp, transferEvent.dataTransfer.files);
|
|
}
|
|
};
|
|
var onSelect = function (component, simulatedEvent) {
|
|
var files = simulatedEvent.event().raw().target.files;
|
|
handleFiles(component, files);
|
|
};
|
|
var handleFiles = function (component, files) {
|
|
Representing.setValue(component, filterByExtension(files));
|
|
emitWith(component, formChangeEvent, { name: spec.name });
|
|
};
|
|
var memInput = record({
|
|
dom: {
|
|
tag: 'input',
|
|
attributes: {
|
|
type: 'file',
|
|
accept: 'image/*'
|
|
},
|
|
styles: { display: 'none' }
|
|
},
|
|
behaviours: derive$1([config('input-file-events', [
|
|
cutter(click()),
|
|
cutter(tap())
|
|
])])
|
|
});
|
|
var renderField = function (s) {
|
|
return {
|
|
uid: s.uid,
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dropzone-container']
|
|
},
|
|
behaviours: derive$1([
|
|
RepresentingConfigs.memory([]),
|
|
ComposingConfigs.self(),
|
|
Disabling.config({}),
|
|
Toggling.config({
|
|
toggleClass: 'dragenter',
|
|
toggleOnExecute: false
|
|
}),
|
|
config('dropzone-events', [
|
|
run('dragenter', sequence([
|
|
stopper,
|
|
Toggling.toggle
|
|
])),
|
|
run('dragleave', sequence([
|
|
stopper,
|
|
Toggling.toggle
|
|
])),
|
|
run('dragover', stopper),
|
|
run('drop', sequence([
|
|
stopper,
|
|
onDrop
|
|
])),
|
|
run(change(), onSelect)
|
|
])
|
|
]),
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dropzone'],
|
|
styles: {}
|
|
},
|
|
components: [
|
|
{
|
|
dom: {
|
|
tag: 'p',
|
|
innerHtml: providersBackstage.translate('Drop an image here')
|
|
}
|
|
},
|
|
Button.sketch({
|
|
dom: {
|
|
tag: 'button',
|
|
innerHtml: providersBackstage.translate('Browse for an image'),
|
|
styles: { position: 'relative' },
|
|
classes: [
|
|
'tox-button',
|
|
'tox-button--secondary'
|
|
]
|
|
},
|
|
components: [memInput.asSpec()],
|
|
action: function (comp) {
|
|
var inputComp = memInput.get(comp);
|
|
inputComp.element().dom().click();
|
|
},
|
|
buttonBehaviours: derive$1([
|
|
Tabstopping.config({}),
|
|
DisablingConfigs.button(providersBackstage.isReadOnly),
|
|
receivingConfig()
|
|
])
|
|
})
|
|
]
|
|
}]
|
|
};
|
|
};
|
|
var pLabel = spec.label.map(function (label) {
|
|
return renderLabel(label, providersBackstage);
|
|
});
|
|
var pField = FormField.parts().field({ factory: { sketch: renderField } });
|
|
return renderFormFieldWith(pLabel, pField, ['tox-form__group--stretched'], []);
|
|
};
|
|
|
|
var renderGrid = function (spec, backstage) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-form__grid',
|
|
'tox-form__grid--' + spec.columns + 'col'
|
|
]
|
|
},
|
|
components: map(spec.items, backstage.interpreter)
|
|
};
|
|
};
|
|
|
|
var beforeObject = generate$1('alloy-fake-before-tabstop');
|
|
var afterObject = generate$1('alloy-fake-after-tabstop');
|
|
var craftWithClasses = function (classes) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
styles: {
|
|
width: '1px',
|
|
height: '1px',
|
|
outline: 'none'
|
|
},
|
|
attributes: { tabindex: '0' },
|
|
classes: classes
|
|
},
|
|
behaviours: derive$1([
|
|
Focusing.config({ ignore: true }),
|
|
Tabstopping.config({})
|
|
])
|
|
};
|
|
};
|
|
var craft = function (spec) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-navobj']
|
|
},
|
|
components: [
|
|
craftWithClasses([beforeObject]),
|
|
spec,
|
|
craftWithClasses([afterObject])
|
|
],
|
|
behaviours: derive$1([ComposingConfigs.childAt(1)])
|
|
};
|
|
};
|
|
var triggerTab = function (placeholder, shiftKey) {
|
|
emitWith(placeholder, keydown(), {
|
|
raw: {
|
|
which: 9,
|
|
shiftKey: shiftKey
|
|
}
|
|
});
|
|
};
|
|
var onFocus$1 = function (container, targetComp) {
|
|
var target = targetComp.element();
|
|
if (has$2(target, beforeObject)) {
|
|
triggerTab(container, true);
|
|
} else if (has$2(target, afterObject)) {
|
|
triggerTab(container, false);
|
|
}
|
|
};
|
|
var isPseudoStop = function (element) {
|
|
return closest$4(element, [
|
|
'.' + beforeObject,
|
|
'.' + afterObject
|
|
].join(','), constant(false));
|
|
};
|
|
|
|
var platformNeedsSandboxing = !(detect$3().browser.isIE() || detect$3().browser.isEdge());
|
|
var getDynamicSource = function (isSandbox) {
|
|
var cachedValue = Cell('');
|
|
return {
|
|
getValue: function (_frameComponent) {
|
|
return cachedValue.get();
|
|
},
|
|
setValue: function (frameComponent, html) {
|
|
if (!isSandbox) {
|
|
set$1(frameComponent.element(), 'src', 'javascript:\'\'');
|
|
var doc = frameComponent.element().dom().contentWindow.document;
|
|
doc.open();
|
|
doc.write(html);
|
|
doc.close();
|
|
} else {
|
|
set$1(frameComponent.element(), 'srcdoc', html);
|
|
}
|
|
cachedValue.set(html);
|
|
}
|
|
};
|
|
};
|
|
var renderIFrame = function (spec, providersBackstage) {
|
|
var isSandbox = platformNeedsSandboxing && spec.sandboxed;
|
|
var attributes = __assign(__assign({}, spec.label.map(function (title) {
|
|
return { title: title };
|
|
}).getOr({})), isSandbox ? { sandbox: 'allow-scripts allow-same-origin' } : {});
|
|
var sourcing = getDynamicSource(isSandbox);
|
|
var pLabel = spec.label.map(function (label) {
|
|
return renderLabel(label, providersBackstage);
|
|
});
|
|
var factory = function (newSpec) {
|
|
return craft({
|
|
uid: newSpec.uid,
|
|
dom: {
|
|
tag: 'iframe',
|
|
attributes: attributes
|
|
},
|
|
behaviours: derive$1([
|
|
Tabstopping.config({}),
|
|
Focusing.config({}),
|
|
RepresentingConfigs.withComp(Option.none(), sourcing.getValue, sourcing.setValue)
|
|
])
|
|
});
|
|
};
|
|
var pField = FormField.parts().field({ factory: { sketch: factory } });
|
|
return renderFormFieldWith(pLabel, pField, ['tox-form__group--stretched'], []);
|
|
};
|
|
|
|
function create$5(width, height) {
|
|
return resize(domGlobals.document.createElement('canvas'), width, height);
|
|
}
|
|
function clone$1(canvas) {
|
|
var tCanvas = create$5(canvas.width, canvas.height);
|
|
var ctx = get2dContext(tCanvas);
|
|
ctx.drawImage(canvas, 0, 0);
|
|
return tCanvas;
|
|
}
|
|
function get2dContext(canvas) {
|
|
return canvas.getContext('2d');
|
|
}
|
|
function resize(canvas, width, height) {
|
|
canvas.width = width;
|
|
canvas.height = height;
|
|
return canvas;
|
|
}
|
|
|
|
function getWidth(image) {
|
|
return image.naturalWidth || image.width;
|
|
}
|
|
function getHeight(image) {
|
|
return image.naturalHeight || image.height;
|
|
}
|
|
|
|
var promise = function () {
|
|
var Promise = function (fn) {
|
|
if (typeof this !== 'object') {
|
|
throw new TypeError('Promises must be constructed via new');
|
|
}
|
|
if (typeof fn !== 'function') {
|
|
throw new TypeError('not a function');
|
|
}
|
|
this._state = null;
|
|
this._value = null;
|
|
this._deferreds = [];
|
|
doResolve(fn, bind(resolve, this), bind(reject, this));
|
|
};
|
|
var asap = Promise.immediateFn || typeof window.setImmediate === 'function' && window.setImmediate || function (fn) {
|
|
domGlobals.setTimeout(fn, 1);
|
|
};
|
|
function bind(fn, thisArg) {
|
|
return function () {
|
|
return fn.apply(thisArg, arguments);
|
|
};
|
|
}
|
|
var isArray = Array.isArray || function (value) {
|
|
return Object.prototype.toString.call(value) === '[object Array]';
|
|
};
|
|
function handle(deferred) {
|
|
var me = this;
|
|
if (this._state === null) {
|
|
this._deferreds.push(deferred);
|
|
return;
|
|
}
|
|
asap(function () {
|
|
var cb = me._state ? deferred.onFulfilled : deferred.onRejected;
|
|
if (cb === null) {
|
|
(me._state ? deferred.resolve : deferred.reject)(me._value);
|
|
return;
|
|
}
|
|
var ret;
|
|
try {
|
|
ret = cb(me._value);
|
|
} catch (e) {
|
|
deferred.reject(e);
|
|
return;
|
|
}
|
|
deferred.resolve(ret);
|
|
});
|
|
}
|
|
function resolve(newValue) {
|
|
try {
|
|
if (newValue === this) {
|
|
throw new TypeError('A promise cannot be resolved with itself.');
|
|
}
|
|
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
|
|
var then = newValue.then;
|
|
if (typeof then === 'function') {
|
|
doResolve(bind(then, newValue), bind(resolve, this), bind(reject, this));
|
|
return;
|
|
}
|
|
}
|
|
this._state = true;
|
|
this._value = newValue;
|
|
finale.call(this);
|
|
} catch (e) {
|
|
reject.call(this, e);
|
|
}
|
|
}
|
|
function reject(newValue) {
|
|
this._state = false;
|
|
this._value = newValue;
|
|
finale.call(this);
|
|
}
|
|
function finale() {
|
|
for (var _i = 0, _a = this._deferreds; _i < _a.length; _i++) {
|
|
var deferred = _a[_i];
|
|
handle.call(this, deferred);
|
|
}
|
|
this._deferreds = [];
|
|
}
|
|
function Handler(onFulfilled, onRejected, resolve, reject) {
|
|
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
|
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
|
this.resolve = resolve;
|
|
this.reject = reject;
|
|
}
|
|
function doResolve(fn, onFulfilled, onRejected) {
|
|
var done = false;
|
|
try {
|
|
fn(function (value) {
|
|
if (done) {
|
|
return;
|
|
}
|
|
done = true;
|
|
onFulfilled(value);
|
|
}, function (reason) {
|
|
if (done) {
|
|
return;
|
|
}
|
|
done = true;
|
|
onRejected(reason);
|
|
});
|
|
} catch (ex) {
|
|
if (done) {
|
|
return;
|
|
}
|
|
done = true;
|
|
onRejected(ex);
|
|
}
|
|
}
|
|
Promise.prototype.catch = function (onRejected) {
|
|
return this.then(null, onRejected);
|
|
};
|
|
Promise.prototype.then = function (onFulfilled, onRejected) {
|
|
var me = this;
|
|
return new Promise(function (resolve, reject) {
|
|
handle.call(me, new Handler(onFulfilled, onRejected, resolve, reject));
|
|
});
|
|
};
|
|
Promise.all = function () {
|
|
var values = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
values[_i] = arguments[_i];
|
|
}
|
|
var args = Array.prototype.slice.call(values.length === 1 && isArray(values[0]) ? values[0] : values);
|
|
return new Promise(function (resolve, reject) {
|
|
if (args.length === 0) {
|
|
return resolve([]);
|
|
}
|
|
var remaining = args.length;
|
|
function res(i, val) {
|
|
try {
|
|
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
|
var then = val.then;
|
|
if (typeof then === 'function') {
|
|
then.call(val, function (val) {
|
|
res(i, val);
|
|
}, reject);
|
|
return;
|
|
}
|
|
}
|
|
args[i] = val;
|
|
if (--remaining === 0) {
|
|
resolve(args);
|
|
}
|
|
} catch (ex) {
|
|
reject(ex);
|
|
}
|
|
}
|
|
for (var i = 0; i < args.length; i++) {
|
|
res(i, args[i]);
|
|
}
|
|
});
|
|
};
|
|
Promise.resolve = function (value) {
|
|
if (value && typeof value === 'object' && value.constructor === Promise) {
|
|
return value;
|
|
}
|
|
return new Promise(function (resolve) {
|
|
resolve(value);
|
|
});
|
|
};
|
|
Promise.reject = function (reason) {
|
|
return new Promise(function (resolve, reject) {
|
|
reject(reason);
|
|
});
|
|
};
|
|
Promise.race = function (values) {
|
|
return new Promise(function (resolve, reject) {
|
|
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
var value = values_1[_i];
|
|
value.then(resolve, reject);
|
|
}
|
|
});
|
|
};
|
|
return Promise;
|
|
};
|
|
var Promise$1 = window.Promise ? window.Promise : promise();
|
|
|
|
function blobToImage(blob) {
|
|
return new Promise$1(function (resolve, reject) {
|
|
var blobUrl = domGlobals.URL.createObjectURL(blob);
|
|
var image = new domGlobals.Image();
|
|
var removeListeners = function () {
|
|
image.removeEventListener('load', loaded);
|
|
image.removeEventListener('error', error);
|
|
};
|
|
function loaded() {
|
|
removeListeners();
|
|
resolve(image);
|
|
}
|
|
function error() {
|
|
removeListeners();
|
|
reject('Unable to load data of type ' + blob.type + ': ' + blobUrl);
|
|
}
|
|
image.addEventListener('load', loaded);
|
|
image.addEventListener('error', error);
|
|
image.src = blobUrl;
|
|
if (image.complete) {
|
|
loaded();
|
|
}
|
|
});
|
|
}
|
|
function dataUriToBlobSync(uri) {
|
|
var data = uri.split(',');
|
|
var matches = /data:([^;]+)/.exec(data[0]);
|
|
if (!matches) {
|
|
return Option.none();
|
|
}
|
|
var mimetype = matches[1];
|
|
var base64 = data[1];
|
|
var sliceSize = 1024;
|
|
var byteCharacters = domGlobals.atob(base64);
|
|
var bytesLength = byteCharacters.length;
|
|
var slicesCount = Math.ceil(bytesLength / sliceSize);
|
|
var byteArrays = new Array(slicesCount);
|
|
for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
|
|
var begin = sliceIndex * sliceSize;
|
|
var end = Math.min(begin + sliceSize, bytesLength);
|
|
var bytes = new Array(end - begin);
|
|
for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
|
|
bytes[i] = byteCharacters[offset].charCodeAt(0);
|
|
}
|
|
byteArrays[sliceIndex] = new Uint8Array(bytes);
|
|
}
|
|
return Option.some(new domGlobals.Blob(byteArrays, { type: mimetype }));
|
|
}
|
|
function dataUriToBlob(uri) {
|
|
return new Promise$1(function (resolve, reject) {
|
|
dataUriToBlobSync(uri).fold(function () {
|
|
reject('uri is not base64: ' + uri);
|
|
}, resolve);
|
|
});
|
|
}
|
|
function canvasToBlob(canvas, type, quality) {
|
|
type = type || 'image/png';
|
|
if (domGlobals.HTMLCanvasElement.prototype.toBlob) {
|
|
return new Promise$1(function (resolve, reject) {
|
|
canvas.toBlob(function (blob) {
|
|
if (blob) {
|
|
resolve(blob);
|
|
} else {
|
|
reject();
|
|
}
|
|
}, type, quality);
|
|
});
|
|
} else {
|
|
return dataUriToBlob(canvas.toDataURL(type, quality));
|
|
}
|
|
}
|
|
function canvasToDataURL(canvas, type, quality) {
|
|
type = type || 'image/png';
|
|
return canvas.toDataURL(type, quality);
|
|
}
|
|
function blobToCanvas(blob) {
|
|
return blobToImage(blob).then(function (image) {
|
|
revokeImageUrl(image);
|
|
var canvas = create$5(getWidth(image), getHeight(image));
|
|
var context = get2dContext(canvas);
|
|
context.drawImage(image, 0, 0);
|
|
return canvas;
|
|
});
|
|
}
|
|
function blobToDataUri(blob) {
|
|
return new Promise$1(function (resolve) {
|
|
var reader = new domGlobals.FileReader();
|
|
reader.onloadend = function () {
|
|
resolve(reader.result);
|
|
};
|
|
reader.readAsDataURL(blob);
|
|
});
|
|
}
|
|
function revokeImageUrl(image) {
|
|
domGlobals.URL.revokeObjectURL(image.src);
|
|
}
|
|
|
|
function create$6(getCanvas, blob, uri) {
|
|
var initialType = blob.type;
|
|
var getType = constant(initialType);
|
|
function toBlob() {
|
|
return Promise$1.resolve(blob);
|
|
}
|
|
var toDataURL = constant(uri);
|
|
function toBase64() {
|
|
return uri.split(',')[1];
|
|
}
|
|
function toAdjustedBlob(type, quality) {
|
|
return getCanvas.then(function (canvas) {
|
|
return canvasToBlob(canvas, type, quality);
|
|
});
|
|
}
|
|
function toAdjustedDataURL(type, quality) {
|
|
return getCanvas.then(function (canvas) {
|
|
return canvasToDataURL(canvas, type, quality);
|
|
});
|
|
}
|
|
function toAdjustedBase64(type, quality) {
|
|
return toAdjustedDataURL(type, quality).then(function (dataurl) {
|
|
return dataurl.split(',')[1];
|
|
});
|
|
}
|
|
function toCanvas() {
|
|
return getCanvas.then(clone$1);
|
|
}
|
|
return {
|
|
getType: getType,
|
|
toBlob: toBlob,
|
|
toDataURL: toDataURL,
|
|
toBase64: toBase64,
|
|
toAdjustedBlob: toAdjustedBlob,
|
|
toAdjustedDataURL: toAdjustedDataURL,
|
|
toAdjustedBase64: toAdjustedBase64,
|
|
toCanvas: toCanvas
|
|
};
|
|
}
|
|
function fromBlob(blob) {
|
|
return blobToDataUri(blob).then(function (uri) {
|
|
return create$6(blobToCanvas(blob), blob, uri);
|
|
});
|
|
}
|
|
function fromCanvas(canvas, type) {
|
|
return canvasToBlob(canvas, type).then(function (blob) {
|
|
return create$6(Promise$1.resolve(canvas), blob, canvas.toDataURL());
|
|
});
|
|
}
|
|
|
|
var blobToImageResult = function (blob) {
|
|
return fromBlob(blob);
|
|
};
|
|
|
|
function clamp$1(value, min, max) {
|
|
var parsedValue = typeof value === 'string' ? parseFloat(value) : value;
|
|
if (parsedValue > max) {
|
|
parsedValue = max;
|
|
} else if (parsedValue < min) {
|
|
parsedValue = min;
|
|
}
|
|
return parsedValue;
|
|
}
|
|
function identity$1() {
|
|
return [
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
];
|
|
}
|
|
var DELTA_INDEX = [
|
|
0,
|
|
0.01,
|
|
0.02,
|
|
0.04,
|
|
0.05,
|
|
0.06,
|
|
0.07,
|
|
0.08,
|
|
0.1,
|
|
0.11,
|
|
0.12,
|
|
0.14,
|
|
0.15,
|
|
0.16,
|
|
0.17,
|
|
0.18,
|
|
0.2,
|
|
0.21,
|
|
0.22,
|
|
0.24,
|
|
0.25,
|
|
0.27,
|
|
0.28,
|
|
0.3,
|
|
0.32,
|
|
0.34,
|
|
0.36,
|
|
0.38,
|
|
0.4,
|
|
0.42,
|
|
0.44,
|
|
0.46,
|
|
0.48,
|
|
0.5,
|
|
0.53,
|
|
0.56,
|
|
0.59,
|
|
0.62,
|
|
0.65,
|
|
0.68,
|
|
0.71,
|
|
0.74,
|
|
0.77,
|
|
0.8,
|
|
0.83,
|
|
0.86,
|
|
0.89,
|
|
0.92,
|
|
0.95,
|
|
0.98,
|
|
1,
|
|
1.06,
|
|
1.12,
|
|
1.18,
|
|
1.24,
|
|
1.3,
|
|
1.36,
|
|
1.42,
|
|
1.48,
|
|
1.54,
|
|
1.6,
|
|
1.66,
|
|
1.72,
|
|
1.78,
|
|
1.84,
|
|
1.9,
|
|
1.96,
|
|
2,
|
|
2.12,
|
|
2.25,
|
|
2.37,
|
|
2.5,
|
|
2.62,
|
|
2.75,
|
|
2.87,
|
|
3,
|
|
3.2,
|
|
3.4,
|
|
3.6,
|
|
3.8,
|
|
4,
|
|
4.3,
|
|
4.7,
|
|
4.9,
|
|
5,
|
|
5.5,
|
|
6,
|
|
6.5,
|
|
6.8,
|
|
7,
|
|
7.3,
|
|
7.5,
|
|
7.8,
|
|
8,
|
|
8.4,
|
|
8.7,
|
|
9,
|
|
9.4,
|
|
9.6,
|
|
9.8,
|
|
10
|
|
];
|
|
function multiply(matrix1, matrix2) {
|
|
var col = [];
|
|
var out = new Array(25);
|
|
var val;
|
|
for (var i = 0; i < 5; i++) {
|
|
for (var j = 0; j < 5; j++) {
|
|
col[j] = matrix2[j + i * 5];
|
|
}
|
|
for (var j = 0; j < 5; j++) {
|
|
val = 0;
|
|
for (var k = 0; k < 5; k++) {
|
|
val += matrix1[j + k * 5] * col[k];
|
|
}
|
|
out[j + i * 5] = val;
|
|
}
|
|
}
|
|
return out;
|
|
}
|
|
function adjustContrast(matrix, value) {
|
|
var x;
|
|
value = clamp$1(value, -1, 1);
|
|
value *= 100;
|
|
if (value < 0) {
|
|
x = 127 + value / 100 * 127;
|
|
} else {
|
|
x = value % 1;
|
|
if (x === 0) {
|
|
x = DELTA_INDEX[value];
|
|
} else {
|
|
x = DELTA_INDEX[Math.floor(value)] * (1 - x) + DELTA_INDEX[Math.floor(value) + 1] * x;
|
|
}
|
|
x = x * 127 + 127;
|
|
}
|
|
return multiply(matrix, [
|
|
x / 127,
|
|
0,
|
|
0,
|
|
0,
|
|
0.5 * (127 - x),
|
|
0,
|
|
x / 127,
|
|
0,
|
|
0,
|
|
0.5 * (127 - x),
|
|
0,
|
|
0,
|
|
x / 127,
|
|
0,
|
|
0.5 * (127 - x),
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
]);
|
|
}
|
|
function adjustBrightness(matrix, value) {
|
|
value = clamp$1(255 * value, -255, 255);
|
|
return multiply(matrix, [
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
value,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
value,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
value,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
]);
|
|
}
|
|
function adjustColors(matrix, adjustR, adjustG, adjustB) {
|
|
adjustR = clamp$1(adjustR, 0, 2);
|
|
adjustG = clamp$1(adjustG, 0, 2);
|
|
adjustB = clamp$1(adjustB, 0, 2);
|
|
return multiply(matrix, [
|
|
adjustR,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
adjustG,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
adjustB,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
]);
|
|
}
|
|
|
|
function colorFilter(ir, matrix) {
|
|
return ir.toCanvas().then(function (canvas) {
|
|
return applyColorFilter(canvas, ir.getType(), matrix);
|
|
});
|
|
}
|
|
function applyColorFilter(canvas, type, matrix) {
|
|
var context = get2dContext(canvas);
|
|
function applyMatrix(pixelsData, m) {
|
|
var r, g, b, a;
|
|
var data = pixelsData.data, m0 = m[0], m1 = m[1], m2 = m[2], m3 = m[3], m4 = m[4], m5 = m[5], m6 = m[6], m7 = m[7], m8 = m[8], m9 = m[9], m10 = m[10], m11 = m[11], m12 = m[12], m13 = m[13], m14 = m[14], m15 = m[15], m16 = m[16], m17 = m[17], m18 = m[18], m19 = m[19];
|
|
for (var i = 0; i < data.length; i += 4) {
|
|
r = data[i];
|
|
g = data[i + 1];
|
|
b = data[i + 2];
|
|
a = data[i + 3];
|
|
data[i] = r * m0 + g * m1 + b * m2 + a * m3 + m4;
|
|
data[i + 1] = r * m5 + g * m6 + b * m7 + a * m8 + m9;
|
|
data[i + 2] = r * m10 + g * m11 + b * m12 + a * m13 + m14;
|
|
data[i + 3] = r * m15 + g * m16 + b * m17 + a * m18 + m19;
|
|
}
|
|
return pixelsData;
|
|
}
|
|
var pixels = applyMatrix(context.getImageData(0, 0, canvas.width, canvas.height), matrix);
|
|
context.putImageData(pixels, 0, 0);
|
|
return fromCanvas(canvas, type);
|
|
}
|
|
function convoluteFilter(ir, matrix) {
|
|
return ir.toCanvas().then(function (canvas) {
|
|
return applyConvoluteFilter(canvas, ir.getType(), matrix);
|
|
});
|
|
}
|
|
function applyConvoluteFilter(canvas, type, matrix) {
|
|
var context = get2dContext(canvas);
|
|
function applyMatrix(pIn, pOut, aMatrix) {
|
|
function clamp(value, min, max) {
|
|
if (value > max) {
|
|
value = max;
|
|
} else if (value < min) {
|
|
value = min;
|
|
}
|
|
return value;
|
|
}
|
|
var side = Math.round(Math.sqrt(aMatrix.length));
|
|
var halfSide = Math.floor(side / 2);
|
|
var rgba = pIn.data;
|
|
var drgba = pOut.data;
|
|
var w = pIn.width;
|
|
var h = pIn.height;
|
|
for (var y = 0; y < h; y++) {
|
|
for (var x = 0; x < w; x++) {
|
|
var r = 0;
|
|
var g = 0;
|
|
var b = 0;
|
|
for (var cy = 0; cy < side; cy++) {
|
|
for (var cx = 0; cx < side; cx++) {
|
|
var scx = clamp(x + cx - halfSide, 0, w - 1);
|
|
var scy = clamp(y + cy - halfSide, 0, h - 1);
|
|
var innerOffset = (scy * w + scx) * 4;
|
|
var wt = aMatrix[cy * side + cx];
|
|
r += rgba[innerOffset] * wt;
|
|
g += rgba[innerOffset + 1] * wt;
|
|
b += rgba[innerOffset + 2] * wt;
|
|
}
|
|
}
|
|
var offset = (y * w + x) * 4;
|
|
drgba[offset] = clamp(r, 0, 255);
|
|
drgba[offset + 1] = clamp(g, 0, 255);
|
|
drgba[offset + 2] = clamp(b, 0, 255);
|
|
}
|
|
}
|
|
return pOut;
|
|
}
|
|
var pixelsIn = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
var pixelsOut = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
pixelsOut = applyMatrix(pixelsIn, pixelsOut, matrix);
|
|
context.putImageData(pixelsOut, 0, 0);
|
|
return fromCanvas(canvas, type);
|
|
}
|
|
function functionColorFilter(colorFn) {
|
|
var filterImpl = function (canvas, type, value) {
|
|
var context = get2dContext(canvas);
|
|
var lookup = new Array(256);
|
|
function applyLookup(pixelsData, lookupData) {
|
|
var data = pixelsData.data;
|
|
for (var i = 0; i < data.length; i += 4) {
|
|
data[i] = lookupData[data[i]];
|
|
data[i + 1] = lookupData[data[i + 1]];
|
|
data[i + 2] = lookupData[data[i + 2]];
|
|
}
|
|
return pixelsData;
|
|
}
|
|
for (var i = 0; i < lookup.length; i++) {
|
|
lookup[i] = colorFn(i, value);
|
|
}
|
|
var pixels = applyLookup(context.getImageData(0, 0, canvas.width, canvas.height), lookup);
|
|
context.putImageData(pixels, 0, 0);
|
|
return fromCanvas(canvas, type);
|
|
};
|
|
return function (ir, value) {
|
|
return ir.toCanvas().then(function (canvas) {
|
|
return filterImpl(canvas, ir.getType(), value);
|
|
});
|
|
};
|
|
}
|
|
function complexAdjustableColorFilter(matrixAdjustFn) {
|
|
return function (ir, adjust) {
|
|
return colorFilter(ir, matrixAdjustFn(identity$1(), adjust));
|
|
};
|
|
}
|
|
function basicColorFilter(matrix) {
|
|
return function (ir) {
|
|
return colorFilter(ir, matrix);
|
|
};
|
|
}
|
|
function basicConvolutionFilter(kernel) {
|
|
return function (ir) {
|
|
return convoluteFilter(ir, kernel);
|
|
};
|
|
}
|
|
var invert = basicColorFilter([
|
|
-1,
|
|
0,
|
|
0,
|
|
0,
|
|
255,
|
|
0,
|
|
-1,
|
|
0,
|
|
0,
|
|
255,
|
|
0,
|
|
0,
|
|
-1,
|
|
0,
|
|
255,
|
|
0,
|
|
0,
|
|
0,
|
|
1,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
1
|
|
]);
|
|
var brightness = complexAdjustableColorFilter(adjustBrightness);
|
|
var contrast = complexAdjustableColorFilter(adjustContrast);
|
|
var colorize = function (ir, adjustR, adjustG, adjustB) {
|
|
return colorFilter(ir, adjustColors(identity$1(), adjustR, adjustG, adjustB));
|
|
};
|
|
var sharpen = basicConvolutionFilter([
|
|
0,
|
|
-1,
|
|
0,
|
|
-1,
|
|
5,
|
|
-1,
|
|
0,
|
|
-1,
|
|
0
|
|
]);
|
|
var gamma = functionColorFilter(function (color, value) {
|
|
return Math.pow(color / 255, 1 - value) * 255;
|
|
});
|
|
|
|
function scale(image, dW, dH) {
|
|
var sW = getWidth(image);
|
|
var sH = getHeight(image);
|
|
var wRatio = dW / sW;
|
|
var hRatio = dH / sH;
|
|
var scaleCapped = false;
|
|
if (wRatio < 0.5 || wRatio > 2) {
|
|
wRatio = wRatio < 0.5 ? 0.5 : 2;
|
|
scaleCapped = true;
|
|
}
|
|
if (hRatio < 0.5 || hRatio > 2) {
|
|
hRatio = hRatio < 0.5 ? 0.5 : 2;
|
|
scaleCapped = true;
|
|
}
|
|
var scaled = _scale(image, wRatio, hRatio);
|
|
return !scaleCapped ? scaled : scaled.then(function (tCanvas) {
|
|
return scale(tCanvas, dW, dH);
|
|
});
|
|
}
|
|
function _scale(image, wRatio, hRatio) {
|
|
return new Promise$1(function (resolve) {
|
|
var sW = getWidth(image);
|
|
var sH = getHeight(image);
|
|
var dW = Math.floor(sW * wRatio);
|
|
var dH = Math.floor(sH * hRatio);
|
|
var canvas = create$5(dW, dH);
|
|
var context = get2dContext(canvas);
|
|
context.drawImage(image, 0, 0, sW, sH, 0, 0, dW, dH);
|
|
resolve(canvas);
|
|
});
|
|
}
|
|
|
|
function rotate(ir, angle) {
|
|
return ir.toCanvas().then(function (canvas) {
|
|
return applyRotate(canvas, ir.getType(), angle);
|
|
});
|
|
}
|
|
function applyRotate(image, type, angle) {
|
|
var canvas = create$5(image.width, image.height);
|
|
var context = get2dContext(canvas);
|
|
var translateX = 0;
|
|
var translateY = 0;
|
|
angle = angle < 0 ? 360 + angle : angle;
|
|
if (angle === 90 || angle === 270) {
|
|
resize(canvas, canvas.height, canvas.width);
|
|
}
|
|
if (angle === 90 || angle === 180) {
|
|
translateX = canvas.width;
|
|
}
|
|
if (angle === 270 || angle === 180) {
|
|
translateY = canvas.height;
|
|
}
|
|
context.translate(translateX, translateY);
|
|
context.rotate(angle * Math.PI / 180);
|
|
context.drawImage(image, 0, 0);
|
|
return fromCanvas(canvas, type);
|
|
}
|
|
function flip(ir, axis) {
|
|
return ir.toCanvas().then(function (canvas) {
|
|
return applyFlip(canvas, ir.getType(), axis);
|
|
});
|
|
}
|
|
function applyFlip(image, type, axis) {
|
|
var canvas = create$5(image.width, image.height);
|
|
var context = get2dContext(canvas);
|
|
if (axis === 'v') {
|
|
context.scale(1, -1);
|
|
context.drawImage(image, 0, -canvas.height);
|
|
} else {
|
|
context.scale(-1, 1);
|
|
context.drawImage(image, -canvas.width, 0);
|
|
}
|
|
return fromCanvas(canvas, type);
|
|
}
|
|
function crop(ir, x, y, w, h) {
|
|
return ir.toCanvas().then(function (canvas) {
|
|
return applyCrop(canvas, ir.getType(), x, y, w, h);
|
|
});
|
|
}
|
|
function applyCrop(image, type, x, y, w, h) {
|
|
var canvas = create$5(w, h);
|
|
var context = get2dContext(canvas);
|
|
context.drawImage(image, -x, -y);
|
|
return fromCanvas(canvas, type);
|
|
}
|
|
function resize$1(ir, w, h) {
|
|
return ir.toCanvas().then(function (canvas) {
|
|
return scale(canvas, w, h).then(function (newCanvas) {
|
|
return fromCanvas(newCanvas, ir.getType());
|
|
});
|
|
});
|
|
}
|
|
|
|
var invert$1 = function (ir) {
|
|
return invert(ir);
|
|
};
|
|
var sharpen$1 = function (ir) {
|
|
return sharpen(ir);
|
|
};
|
|
var gamma$1 = function (ir, value) {
|
|
return gamma(ir, value);
|
|
};
|
|
var colorize$1 = function (ir, adjustR, adjustG, adjustB) {
|
|
return colorize(ir, adjustR, adjustG, adjustB);
|
|
};
|
|
var brightness$1 = function (ir, adjust) {
|
|
return brightness(ir, adjust);
|
|
};
|
|
var contrast$1 = function (ir, adjust) {
|
|
return contrast(ir, adjust);
|
|
};
|
|
var flip$1 = function (ir, axis) {
|
|
return flip(ir, axis);
|
|
};
|
|
var crop$1 = function (ir, x, y, w, h) {
|
|
return crop(ir, x, y, w, h);
|
|
};
|
|
var resize$2 = function (ir, w, h) {
|
|
return resize$1(ir, w, h);
|
|
};
|
|
var rotate$1 = function (ir, angle) {
|
|
return rotate(ir, angle);
|
|
};
|
|
|
|
var renderIcon$1 = function (iconHtml, behaviours) {
|
|
return __assign({
|
|
dom: {
|
|
tag: 'span',
|
|
innerHtml: iconHtml,
|
|
classes: [
|
|
'tox-icon',
|
|
'tox-tbtn__icon-wrap'
|
|
]
|
|
}
|
|
}, behaviours);
|
|
};
|
|
var renderIconFromPack = function (iconName, iconsProvider) {
|
|
return renderIcon$1(get$d(iconName, iconsProvider), {});
|
|
};
|
|
var renderReplacableIconFromPack = function (iconName, iconsProvider) {
|
|
return renderIcon$1(get$d(iconName, iconsProvider), { behaviours: derive$1([Replacing.config({})]) });
|
|
};
|
|
var renderLabel$1 = function (text, prefix, providersBackstage) {
|
|
return {
|
|
dom: {
|
|
tag: 'span',
|
|
innerHtml: providersBackstage.translate(text),
|
|
classes: [prefix + '__select-label']
|
|
},
|
|
behaviours: derive$1([Replacing.config({})])
|
|
};
|
|
};
|
|
|
|
var internalToolbarButtonExecute = generate$1('toolbar.button.execute');
|
|
var onToolbarButtonExecute = function (info) {
|
|
return runOnExecute(function (comp, _simulatedEvent) {
|
|
runWithApi(info, comp)(function (itemApi) {
|
|
emitWith(comp, internalToolbarButtonExecute, { buttonApi: itemApi });
|
|
info.onAction(itemApi);
|
|
});
|
|
});
|
|
};
|
|
var toolbarButtonEventOrder = {
|
|
'alloy.execute': [
|
|
'disabling',
|
|
'alloy.base.behaviour',
|
|
'toggling',
|
|
'toolbar-button-events'
|
|
]
|
|
};
|
|
|
|
var updateMenuText = generate$1('update-menu-text');
|
|
var updateMenuIcon = generate$1('update-menu-icon');
|
|
var renderCommonDropdown = function (spec, prefix, sharedBackstage) {
|
|
var editorOffCell = Cell(noop);
|
|
var optMemDisplayText = spec.text.map(function (text) {
|
|
return record(renderLabel$1(text, prefix, sharedBackstage.providers));
|
|
});
|
|
var optMemDisplayIcon = spec.icon.map(function (iconName) {
|
|
return record(renderReplacableIconFromPack(iconName, sharedBackstage.providers.icons));
|
|
});
|
|
var onLeftOrRightInMenu = function (comp, se) {
|
|
var dropdown = Representing.getValue(comp);
|
|
Focusing.focus(dropdown);
|
|
emitWith(dropdown, 'keydown', { raw: se.event().raw() });
|
|
Dropdown.close(dropdown);
|
|
return Option.some(true);
|
|
};
|
|
var role = spec.role.fold(function () {
|
|
return {};
|
|
}, function (role) {
|
|
return { role: role };
|
|
});
|
|
var tooltipAttributes = spec.tooltip.fold(function () {
|
|
return {};
|
|
}, function (tooltip) {
|
|
var translatedTooltip = sharedBackstage.providers.translate(tooltip);
|
|
return {
|
|
'title': translatedTooltip,
|
|
'aria-label': translatedTooltip
|
|
};
|
|
});
|
|
var memDropdown = record(Dropdown.sketch(__assign(__assign({}, role), {
|
|
dom: {
|
|
tag: 'button',
|
|
classes: [
|
|
prefix,
|
|
prefix + '--select'
|
|
].concat(map(spec.classes, function (c) {
|
|
return prefix + '--' + c;
|
|
})),
|
|
attributes: __assign({}, tooltipAttributes)
|
|
},
|
|
components: componentRenderPipeline([
|
|
optMemDisplayIcon.map(function (mem) {
|
|
return mem.asSpec();
|
|
}),
|
|
optMemDisplayText.map(function (mem) {
|
|
return mem.asSpec();
|
|
}),
|
|
Option.some({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [prefix + '__select-chevron'],
|
|
innerHtml: get$d('chevron-down', sharedBackstage.providers.icons)
|
|
}
|
|
})
|
|
]),
|
|
matchWidth: true,
|
|
useMinWidth: true,
|
|
dropdownBehaviours: derive$1(__spreadArrays(spec.dropdownBehaviours, [
|
|
DisablingConfigs.button(function () {
|
|
return spec.disabled || sharedBackstage.providers.isReadOnly();
|
|
}),
|
|
receivingConfig(),
|
|
Unselecting.config({}),
|
|
Replacing.config({}),
|
|
config('dropdown-events', [
|
|
onControlAttached(spec, editorOffCell),
|
|
onControlDetached(spec, editorOffCell)
|
|
]),
|
|
config('menubutton-update-display-text', [
|
|
run(updateMenuText, function (comp, se) {
|
|
optMemDisplayText.bind(function (mem) {
|
|
return mem.getOpt(comp);
|
|
}).each(function (displayText) {
|
|
Replacing.set(displayText, [text(sharedBackstage.providers.translate(se.event().text()))]);
|
|
});
|
|
}),
|
|
run(updateMenuIcon, function (comp, se) {
|
|
optMemDisplayIcon.bind(function (mem) {
|
|
return mem.getOpt(comp);
|
|
}).each(function (displayIcon) {
|
|
Replacing.set(displayIcon, [renderReplacableIconFromPack(se.event().icon(), sharedBackstage.providers.icons)]);
|
|
});
|
|
})
|
|
])
|
|
])),
|
|
eventOrder: deepMerge(toolbarButtonEventOrder, {
|
|
mousedown: [
|
|
'focusing',
|
|
'alloy.base.behaviour',
|
|
'item-type-events',
|
|
'normal-dropdown-events'
|
|
]
|
|
}),
|
|
sandboxBehaviours: derive$1([Keying.config({
|
|
mode: 'special',
|
|
onLeft: onLeftOrRightInMenu,
|
|
onRight: onLeftOrRightInMenu
|
|
})]),
|
|
lazySink: sharedBackstage.getSink,
|
|
toggleClass: prefix + '--active',
|
|
parts: { menu: part(false, spec.columns, spec.presets) },
|
|
fetch: function () {
|
|
return Future.nu(spec.fetch);
|
|
}
|
|
})));
|
|
return memDropdown.asSpec();
|
|
};
|
|
|
|
var isMenuItemReference = function (item) {
|
|
return isString(item);
|
|
};
|
|
var isSeparator = function (item) {
|
|
return item.type === 'separator';
|
|
};
|
|
var isExpandingMenuItem = function (item) {
|
|
return has(item, 'getSubmenuItems');
|
|
};
|
|
var separator$1 = { type: 'separator' };
|
|
var unwrapReferences = function (items, menuItems) {
|
|
var realItems = foldl(items, function (acc, item) {
|
|
if (isMenuItemReference(item)) {
|
|
if (item === '') {
|
|
return acc;
|
|
} else if (item === '|') {
|
|
return acc.length > 0 && !isSeparator(acc[acc.length - 1]) ? acc.concat([separator$1]) : acc;
|
|
} else if (has(menuItems, item.toLowerCase())) {
|
|
return acc.concat([menuItems[item.toLowerCase()]]);
|
|
} else {
|
|
return acc;
|
|
}
|
|
} else {
|
|
return acc.concat([item]);
|
|
}
|
|
}, []);
|
|
if (realItems.length > 0 && isSeparator(realItems[realItems.length - 1])) {
|
|
realItems.pop();
|
|
}
|
|
return realItems;
|
|
};
|
|
var getFromExpandingItem = function (item, menuItems) {
|
|
var submenuItems = item.getSubmenuItems();
|
|
var rest = expand(submenuItems, menuItems);
|
|
var newMenus = deepMerge(rest.menus, wrap$1(item.value, rest.items));
|
|
var newExpansions = deepMerge(rest.expansions, wrap$1(item.value, item.value));
|
|
return {
|
|
item: item,
|
|
menus: newMenus,
|
|
expansions: newExpansions
|
|
};
|
|
};
|
|
var getFromItem = function (item, menuItems) {
|
|
return isExpandingMenuItem(item) ? getFromExpandingItem(item, menuItems) : {
|
|
item: item,
|
|
menus: {},
|
|
expansions: {}
|
|
};
|
|
};
|
|
var generateValueIfRequired = function (item) {
|
|
if (isSeparator(item)) {
|
|
return item;
|
|
} else {
|
|
var itemValue = get(item, 'value').getOrThunk(function () {
|
|
return generate$1('generated-menu-item');
|
|
});
|
|
return deepMerge({ value: itemValue }, item);
|
|
}
|
|
};
|
|
var expand = function (items, menuItems) {
|
|
var realItems = unwrapReferences(isString(items) ? items.split(' ') : items, menuItems);
|
|
return foldr(realItems, function (acc, item) {
|
|
var itemWithValue = generateValueIfRequired(item);
|
|
var newData = getFromItem(itemWithValue, menuItems);
|
|
return {
|
|
menus: deepMerge(acc.menus, newData.menus),
|
|
items: [newData.item].concat(acc.items),
|
|
expansions: deepMerge(acc.expansions, newData.expansions)
|
|
};
|
|
}, {
|
|
menus: {},
|
|
expansions: {},
|
|
items: []
|
|
});
|
|
};
|
|
|
|
var build$2 = function (items, itemResponse, backstage, isHorizontalMenu) {
|
|
var primary = generate$1('primary-menu');
|
|
var data = expand(items, backstage.shared.providers.menuItems());
|
|
if (data.items.length === 0) {
|
|
return Option.none();
|
|
}
|
|
var mainMenu = createPartialMenu(primary, data.items, itemResponse, backstage, isHorizontalMenu);
|
|
var submenus = map$1(data.menus, function (menuItems, menuName) {
|
|
return createPartialMenu(menuName, menuItems, itemResponse, backstage, false);
|
|
});
|
|
var menus = deepMerge(submenus, wrap$1(primary, mainMenu));
|
|
return Option.from(tieredMenu.tieredData(primary, menus, data.expansions));
|
|
};
|
|
|
|
var getMenuButtonApi = function (component) {
|
|
return {
|
|
isDisabled: function () {
|
|
return Disabling.isDisabled(component);
|
|
},
|
|
setDisabled: function (state) {
|
|
return Disabling.set(component, state);
|
|
},
|
|
setActive: function (state) {
|
|
var elm = component.element();
|
|
if (state) {
|
|
add$2(elm, 'tox-tbtn--enabled');
|
|
set$1(elm, 'aria-pressed', true);
|
|
} else {
|
|
remove$4(elm, 'tox-tbtn--enabled');
|
|
remove$1(elm, 'aria-pressed');
|
|
}
|
|
},
|
|
isActive: function () {
|
|
return has$2(component.element(), 'tox-tbtn--enabled');
|
|
}
|
|
};
|
|
};
|
|
var renderMenuButton = function (spec, prefix, backstage, role) {
|
|
return renderCommonDropdown({
|
|
text: spec.text,
|
|
icon: spec.icon,
|
|
tooltip: spec.tooltip,
|
|
role: role,
|
|
fetch: function (callback) {
|
|
spec.fetch(function (items) {
|
|
callback(build$2(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, false));
|
|
});
|
|
},
|
|
onSetup: spec.onSetup,
|
|
getApi: getMenuButtonApi,
|
|
columns: 1,
|
|
presets: 'normal',
|
|
classes: [],
|
|
dropdownBehaviours: [Tabstopping.config({})]
|
|
}, prefix, backstage.shared);
|
|
};
|
|
var getFetch$1 = function (items, getButton, backstage) {
|
|
var getMenuItemAction = function (item) {
|
|
return function (api) {
|
|
var newValue = !api.isActive();
|
|
api.setActive(newValue);
|
|
item.storage.set(newValue);
|
|
backstage.shared.getSink().each(function (sink) {
|
|
getButton().getOpt(sink).each(function (orig) {
|
|
focus$1(orig.element());
|
|
emitWith(orig, formActionEvent, {
|
|
name: item.name,
|
|
value: item.storage.get()
|
|
});
|
|
});
|
|
});
|
|
};
|
|
};
|
|
var getMenuItemSetup = function (item) {
|
|
return function (api) {
|
|
api.setActive(item.storage.get());
|
|
};
|
|
};
|
|
return function (success) {
|
|
success(map(items, function (item) {
|
|
var text = item.text.fold(function () {
|
|
return {};
|
|
}, function (text) {
|
|
return { text: text };
|
|
});
|
|
return __assign(__assign({
|
|
type: item.type,
|
|
active: false
|
|
}, text), {
|
|
onAction: getMenuItemAction(item),
|
|
onSetup: getMenuItemSetup(item)
|
|
});
|
|
}));
|
|
};
|
|
};
|
|
|
|
var renderCommonSpec = function (spec, actionOpt, extraBehaviours, dom, components, providersBackstage) {
|
|
if (extraBehaviours === void 0) {
|
|
extraBehaviours = [];
|
|
}
|
|
var action = actionOpt.fold(function () {
|
|
return {};
|
|
}, function (action) {
|
|
return { action: action };
|
|
});
|
|
var common = __assign({
|
|
buttonBehaviours: derive$1([
|
|
DisablingConfigs.button(function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
}),
|
|
receivingConfig(),
|
|
Tabstopping.config({}),
|
|
config('button press', [
|
|
preventDefault('click'),
|
|
preventDefault('mousedown')
|
|
])
|
|
].concat(extraBehaviours)),
|
|
eventOrder: {
|
|
click: [
|
|
'button press',
|
|
'alloy.base.behaviour'
|
|
],
|
|
mousedown: [
|
|
'button press',
|
|
'alloy.base.behaviour'
|
|
]
|
|
}
|
|
}, action);
|
|
var domFinal = deepMerge(common, { dom: dom });
|
|
return deepMerge(domFinal, { components: components });
|
|
};
|
|
var renderIconButtonSpec = function (spec, action, providersBackstage, extraBehaviours) {
|
|
if (extraBehaviours === void 0) {
|
|
extraBehaviours = [];
|
|
}
|
|
var tooltipAttributes = spec.tooltip.map(function (tooltip) {
|
|
return {
|
|
'aria-label': providersBackstage.translate(tooltip),
|
|
'title': providersBackstage.translate(tooltip)
|
|
};
|
|
}).getOr({});
|
|
var dom = {
|
|
tag: 'button',
|
|
classes: ['tox-tbtn'],
|
|
attributes: tooltipAttributes
|
|
};
|
|
var icon = spec.icon.map(function (iconName) {
|
|
return renderIconFromPack(iconName, providersBackstage.icons);
|
|
});
|
|
var components = componentRenderPipeline([icon]);
|
|
return renderCommonSpec(spec, action, extraBehaviours, dom, components, providersBackstage);
|
|
};
|
|
var renderIconButton = function (spec, action, providersBackstage, extraBehaviours) {
|
|
if (extraBehaviours === void 0) {
|
|
extraBehaviours = [];
|
|
}
|
|
var iconButtonSpec = renderIconButtonSpec(spec, Option.some(action), providersBackstage, extraBehaviours);
|
|
return Button.sketch(iconButtonSpec);
|
|
};
|
|
var renderButtonSpec = function (spec, action, providersBackstage, extraBehaviours, extraClasses) {
|
|
if (extraBehaviours === void 0) {
|
|
extraBehaviours = [];
|
|
}
|
|
if (extraClasses === void 0) {
|
|
extraClasses = [];
|
|
}
|
|
var translatedText = providersBackstage.translate(spec.text);
|
|
var icon = spec.icon ? spec.icon.map(function (iconName) {
|
|
return renderIconFromPack(iconName, providersBackstage.icons);
|
|
}) : Option.none();
|
|
var components = icon.isSome() ? componentRenderPipeline([icon]) : [];
|
|
var innerHtml = icon.isSome() ? {} : { innerHtml: translatedText };
|
|
var classes = __spreadArrays(!spec.primary && !spec.borderless ? [
|
|
'tox-button',
|
|
'tox-button--secondary'
|
|
] : ['tox-button'], icon.isSome() ? ['tox-button--icon'] : [], spec.borderless ? ['tox-button--naked'] : [], extraClasses);
|
|
var dom = __assign(__assign({
|
|
tag: 'button',
|
|
classes: classes
|
|
}, innerHtml), { attributes: { title: translatedText } });
|
|
return renderCommonSpec(spec, action, extraBehaviours, dom, components, providersBackstage);
|
|
};
|
|
var renderButton = function (spec, action, providersBackstage, extraBehaviours, extraClasses) {
|
|
if (extraBehaviours === void 0) {
|
|
extraBehaviours = [];
|
|
}
|
|
if (extraClasses === void 0) {
|
|
extraClasses = [];
|
|
}
|
|
var buttonSpec = renderButtonSpec(spec, Option.some(action), providersBackstage, extraBehaviours, extraClasses);
|
|
return Button.sketch(buttonSpec);
|
|
};
|
|
var getAction = function (name, buttonType) {
|
|
return function (comp) {
|
|
if (buttonType === 'custom') {
|
|
emitWith(comp, formActionEvent, {
|
|
name: name,
|
|
value: {}
|
|
});
|
|
} else if (buttonType === 'submit') {
|
|
emit(comp, formSubmitEvent);
|
|
} else if (buttonType === 'cancel') {
|
|
emit(comp, formCancelEvent);
|
|
} else {
|
|
domGlobals.console.error('Unknown button type: ', buttonType);
|
|
}
|
|
};
|
|
};
|
|
var isMenuFooterButtonSpec = function (spec, buttonType) {
|
|
return buttonType === 'menu';
|
|
};
|
|
var isNormalFooterButtonSpec = function (spec, buttonType) {
|
|
return buttonType === 'custom' || buttonType === 'cancel' || buttonType === 'submit';
|
|
};
|
|
var renderFooterButton = function (spec, buttonType, backstage) {
|
|
if (isMenuFooterButtonSpec(spec, buttonType)) {
|
|
var getButton = function () {
|
|
return memButton_1;
|
|
};
|
|
var menuButtonSpec = spec;
|
|
var fixedSpec = __assign(__assign({}, spec), {
|
|
onSetup: function (api) {
|
|
api.setDisabled(spec.disabled);
|
|
return noop;
|
|
},
|
|
fetch: getFetch$1(menuButtonSpec.items, getButton, backstage)
|
|
});
|
|
var memButton_1 = record(renderMenuButton(fixedSpec, 'tox-tbtn', backstage, Option.none()));
|
|
return memButton_1.asSpec();
|
|
} else if (isNormalFooterButtonSpec(spec, buttonType)) {
|
|
var action = getAction(spec.name, buttonType);
|
|
var buttonSpec = __assign(__assign({}, spec), { borderless: false });
|
|
return renderButton(buttonSpec, action, backstage.shared.providers, []);
|
|
} else {
|
|
domGlobals.console.error('Unknown footer button type: ', buttonType);
|
|
}
|
|
};
|
|
var renderDialogButton = function (spec, providersBackstage) {
|
|
var action = getAction(spec.name, 'custom');
|
|
return renderFormField(Option.none(), FormField.parts().field(__assign({ factory: Button }, renderButtonSpec(spec, Option.some(action), providersBackstage, [
|
|
RepresentingConfigs.memory(''),
|
|
ComposingConfigs.self()
|
|
]))));
|
|
};
|
|
|
|
var schema$i = constant([
|
|
defaulted$1('field1Name', 'field1'),
|
|
defaulted$1('field2Name', 'field2'),
|
|
onStrictHandler('onLockedChange'),
|
|
markers(['lockClass']),
|
|
defaulted$1('locked', false),
|
|
SketchBehaviours.field('coupledFieldBehaviours', [
|
|
Composing,
|
|
Representing
|
|
])
|
|
]);
|
|
var getField = function (comp, detail, partName) {
|
|
return getPart(comp, detail, partName).bind(Composing.getCurrent);
|
|
};
|
|
var coupledPart = function (selfName, otherName) {
|
|
return required({
|
|
factory: FormField,
|
|
name: selfName,
|
|
overrides: function (detail) {
|
|
return {
|
|
fieldBehaviours: derive$1([config('coupled-input-behaviour', [run(input(), function (me) {
|
|
getField(me, detail, otherName).each(function (other) {
|
|
getPart(me, detail, 'lock').each(function (lock) {
|
|
if (Toggling.isOn(lock)) {
|
|
detail.onLockedChange(me, other, lock);
|
|
}
|
|
});
|
|
});
|
|
})])])
|
|
};
|
|
}
|
|
});
|
|
};
|
|
var parts$5 = constant([
|
|
coupledPart('field1', 'field2'),
|
|
coupledPart('field2', 'field1'),
|
|
required({
|
|
factory: Button,
|
|
schema: [strict$1('dom')],
|
|
name: 'lock',
|
|
overrides: function (detail) {
|
|
return {
|
|
buttonBehaviours: derive$1([Toggling.config({
|
|
selected: detail.locked,
|
|
toggleClass: detail.markers.lockClass,
|
|
aria: { mode: 'pressed' }
|
|
})])
|
|
};
|
|
}
|
|
})
|
|
]);
|
|
|
|
var factory$7 = function (detail, components, _spec, _externals) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: SketchBehaviours.augment(detail.coupledFieldBehaviours, [
|
|
Composing.config({ find: Option.some }),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (comp) {
|
|
var _a;
|
|
var parts = getPartsOrDie(comp, detail, [
|
|
'field1',
|
|
'field2'
|
|
]);
|
|
return _a = {}, _a[detail.field1Name] = Representing.getValue(parts.field1()), _a[detail.field2Name] = Representing.getValue(parts.field2()), _a;
|
|
},
|
|
setValue: function (comp, value) {
|
|
var parts = getPartsOrDie(comp, detail, [
|
|
'field1',
|
|
'field2'
|
|
]);
|
|
if (hasNonNullableKey(value, detail.field1Name)) {
|
|
Representing.setValue(parts.field1(), value[detail.field1Name]);
|
|
}
|
|
if (hasNonNullableKey(value, detail.field2Name)) {
|
|
Representing.setValue(parts.field2(), value[detail.field2Name]);
|
|
}
|
|
}
|
|
}
|
|
})
|
|
]),
|
|
apis: {
|
|
getField1: function (component) {
|
|
return getPart(component, detail, 'field1');
|
|
},
|
|
getField2: function (component) {
|
|
return getPart(component, detail, 'field2');
|
|
},
|
|
getLock: function (component) {
|
|
return getPart(component, detail, 'lock');
|
|
}
|
|
}
|
|
};
|
|
};
|
|
var FormCoupledInputs = composite$1({
|
|
name: 'FormCoupledInputs',
|
|
configFields: schema$i(),
|
|
partFields: parts$5(),
|
|
factory: factory$7,
|
|
apis: {
|
|
getField1: function (apis, component) {
|
|
return apis.getField1(component);
|
|
},
|
|
getField2: function (apis, component) {
|
|
return apis.getField2(component);
|
|
},
|
|
getLock: function (apis, component) {
|
|
return apis.getLock(component);
|
|
}
|
|
}
|
|
});
|
|
|
|
var formatSize = function (size) {
|
|
var unitDec = {
|
|
'': 0,
|
|
'px': 0,
|
|
'pt': 1,
|
|
'mm': 1,
|
|
'pc': 2,
|
|
'ex': 2,
|
|
'em': 2,
|
|
'ch': 2,
|
|
'rem': 2,
|
|
'cm': 3,
|
|
'in': 4,
|
|
'%': 4
|
|
};
|
|
var maxDecimal = function (unit) {
|
|
return unit in unitDec ? unitDec[unit] : 1;
|
|
};
|
|
var numText = size.value.toFixed(maxDecimal(size.unit));
|
|
if (numText.indexOf('.') !== -1) {
|
|
numText = numText.replace(/\.?0*$/, '');
|
|
}
|
|
return numText + size.unit;
|
|
};
|
|
var parseSize = function (sizeText) {
|
|
var numPattern = /^\s*(\d+(?:\.\d+)?)\s*(|cm|mm|in|px|pt|pc|em|ex|ch|rem|vw|vh|vmin|vmax|%)\s*$/;
|
|
var match = numPattern.exec(sizeText);
|
|
if (match !== null) {
|
|
var value = parseFloat(match[1]);
|
|
var unit = match[2];
|
|
return Result.value({
|
|
value: value,
|
|
unit: unit
|
|
});
|
|
} else {
|
|
return Result.error(sizeText);
|
|
}
|
|
};
|
|
var convertUnit = function (size, unit) {
|
|
var inInch = {
|
|
'': 96,
|
|
'px': 96,
|
|
'pt': 72,
|
|
'cm': 2.54,
|
|
'pc': 12,
|
|
'mm': 25.4,
|
|
'in': 1
|
|
};
|
|
var supported = function (u) {
|
|
return Object.prototype.hasOwnProperty.call(inInch, u);
|
|
};
|
|
if (size.unit === unit) {
|
|
return Option.some(size.value);
|
|
} else if (supported(size.unit) && supported(unit)) {
|
|
if (inInch[size.unit] === inInch[unit]) {
|
|
return Option.some(size.value);
|
|
} else {
|
|
return Option.some(size.value / inInch[size.unit] * inInch[unit]);
|
|
}
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
};
|
|
var noSizeConversion = function (_input) {
|
|
return Option.none();
|
|
};
|
|
var ratioSizeConversion = function (scale, unit) {
|
|
return function (size) {
|
|
return convertUnit(size, unit).map(function (value) {
|
|
return {
|
|
value: value * scale,
|
|
unit: unit
|
|
};
|
|
});
|
|
};
|
|
};
|
|
var makeRatioConverter = function (currentFieldText, otherFieldText) {
|
|
var cValue = parseSize(currentFieldText).toOption();
|
|
var oValue = parseSize(otherFieldText).toOption();
|
|
return lift2(cValue, oValue, function (cSize, oSize) {
|
|
return convertUnit(cSize, oSize.unit).map(function (val) {
|
|
return oSize.value / val;
|
|
}).map(function (r) {
|
|
return ratioSizeConversion(r, oSize.unit);
|
|
}).getOr(noSizeConversion);
|
|
}).getOr(noSizeConversion);
|
|
};
|
|
|
|
var renderSizeInput = function (spec, providersBackstage) {
|
|
var converter = noSizeConversion;
|
|
var ratioEvent = generate$1('ratio-event');
|
|
var pLock = FormCoupledInputs.parts().lock({
|
|
dom: {
|
|
tag: 'button',
|
|
classes: [
|
|
'tox-lock',
|
|
'tox-button',
|
|
'tox-button--naked',
|
|
'tox-button--icon'
|
|
],
|
|
attributes: { title: providersBackstage.translate(spec.label.getOr('Constrain proportions')) }
|
|
},
|
|
components: [
|
|
{
|
|
dom: {
|
|
tag: 'span',
|
|
classes: [
|
|
'tox-icon',
|
|
'tox-lock-icon__lock'
|
|
],
|
|
innerHtml: get$d('lock', providersBackstage.icons)
|
|
}
|
|
},
|
|
{
|
|
dom: {
|
|
tag: 'span',
|
|
classes: [
|
|
'tox-icon',
|
|
'tox-lock-icon__unlock'
|
|
],
|
|
innerHtml: get$d('unlock', providersBackstage.icons)
|
|
}
|
|
}
|
|
],
|
|
buttonBehaviours: derive$1([
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
}
|
|
}),
|
|
receivingConfig(),
|
|
Tabstopping.config({})
|
|
])
|
|
});
|
|
var formGroup = function (components) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form__group']
|
|
},
|
|
components: components
|
|
};
|
|
};
|
|
var getFieldPart = function (isField1) {
|
|
return FormField.parts().field({
|
|
factory: Input,
|
|
inputClasses: ['tox-textfield'],
|
|
inputBehaviours: derive$1([
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
}
|
|
}),
|
|
receivingConfig(),
|
|
Tabstopping.config({}),
|
|
config('size-input-events', [
|
|
run(focusin(), function (component, _simulatedEvent) {
|
|
emitWith(component, ratioEvent, { isField1: isField1 });
|
|
}),
|
|
run(change(), function (component, _simulatedEvent) {
|
|
emitWith(component, formChangeEvent, { name: spec.name });
|
|
})
|
|
])
|
|
]),
|
|
selectOnFocus: false
|
|
});
|
|
};
|
|
var getLabel = function (label) {
|
|
return {
|
|
dom: {
|
|
tag: 'label',
|
|
classes: ['tox-label'],
|
|
innerHtml: providersBackstage.translate(label)
|
|
}
|
|
};
|
|
};
|
|
var widthField = FormCoupledInputs.parts().field1(formGroup([
|
|
FormField.parts().label(getLabel('Width')),
|
|
getFieldPart(true)
|
|
]));
|
|
var heightField = FormCoupledInputs.parts().field2(formGroup([
|
|
FormField.parts().label(getLabel('Height')),
|
|
getFieldPart(false)
|
|
]));
|
|
return FormCoupledInputs.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form__group']
|
|
},
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form__controls-h-stack']
|
|
},
|
|
components: [
|
|
widthField,
|
|
heightField,
|
|
formGroup([
|
|
getLabel(' '),
|
|
pLock
|
|
])
|
|
]
|
|
}],
|
|
field1Name: 'width',
|
|
field2Name: 'height',
|
|
locked: true,
|
|
markers: { lockClass: 'tox-locked' },
|
|
onLockedChange: function (current, other, _lock) {
|
|
parseSize(Representing.getValue(current)).each(function (size) {
|
|
converter(size).each(function (newSize) {
|
|
Representing.setValue(other, formatSize(newSize));
|
|
});
|
|
});
|
|
},
|
|
coupledFieldBehaviours: derive$1([
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
},
|
|
onDisabled: function (comp) {
|
|
FormCoupledInputs.getField1(comp).bind(FormField.getField).each(Disabling.disable);
|
|
FormCoupledInputs.getField2(comp).bind(FormField.getField).each(Disabling.disable);
|
|
FormCoupledInputs.getLock(comp).each(Disabling.disable);
|
|
},
|
|
onEnabled: function (comp) {
|
|
FormCoupledInputs.getField1(comp).bind(FormField.getField).each(Disabling.enable);
|
|
FormCoupledInputs.getField2(comp).bind(FormField.getField).each(Disabling.enable);
|
|
FormCoupledInputs.getLock(comp).each(Disabling.enable);
|
|
}
|
|
}),
|
|
receivingConfig(),
|
|
config('size-input-events2', [run(ratioEvent, function (component, simulatedEvent) {
|
|
var isField1 = simulatedEvent.event().isField1();
|
|
var optCurrent = isField1 ? FormCoupledInputs.getField1(component) : FormCoupledInputs.getField2(component);
|
|
var optOther = isField1 ? FormCoupledInputs.getField2(component) : FormCoupledInputs.getField1(component);
|
|
var value1 = optCurrent.map(Representing.getValue).getOr('');
|
|
var value2 = optOther.map(Representing.getValue).getOr('');
|
|
converter = makeRatioConverter(value1, value2);
|
|
})])
|
|
])
|
|
});
|
|
};
|
|
|
|
var undo = constant(generate$1('undo'));
|
|
var redo = constant(generate$1('redo'));
|
|
var zoom = constant(generate$1('zoom'));
|
|
var back = constant(generate$1('back'));
|
|
var apply = constant(generate$1('apply'));
|
|
var swap = constant(generate$1('swap'));
|
|
var transform = constant(generate$1('transform'));
|
|
var tempTransform = constant(generate$1('temp-transform'));
|
|
var transformApply = constant(generate$1('transform-apply'));
|
|
var internal = {
|
|
undo: undo,
|
|
redo: redo,
|
|
zoom: zoom,
|
|
back: back,
|
|
apply: apply,
|
|
swap: swap,
|
|
transform: transform,
|
|
tempTransform: tempTransform,
|
|
transformApply: transformApply
|
|
};
|
|
var saveState = constant('save-state');
|
|
var disable$1 = constant('disable');
|
|
var enable$1 = constant('enable');
|
|
var external$2 = {
|
|
formActionEvent: formActionEvent,
|
|
saveState: saveState,
|
|
disable: disable$1,
|
|
enable: enable$1
|
|
};
|
|
|
|
var renderEditPanel = function (imagePanel, providersBackstage) {
|
|
var createButton = function (text, action, disabled, primary) {
|
|
return record(renderButton({
|
|
name: text,
|
|
text: text,
|
|
disabled: disabled,
|
|
primary: primary,
|
|
icon: Option.none(),
|
|
borderless: false
|
|
}, action, providersBackstage));
|
|
};
|
|
var createIconButton = function (icon, tooltip, action, disabled) {
|
|
return record(renderIconButton({
|
|
name: icon,
|
|
icon: Option.some(icon),
|
|
tooltip: Option.some(tooltip),
|
|
disabled: disabled,
|
|
primary: false,
|
|
borderless: false
|
|
}, action, providersBackstage));
|
|
};
|
|
var disableAllComponents = function (comps, eventcomp) {
|
|
comps.map(function (mem) {
|
|
var component = mem.get(eventcomp);
|
|
if (component.hasConfigured(Disabling)) {
|
|
Disabling.disable(component);
|
|
}
|
|
});
|
|
};
|
|
var enableAllComponents = function (comps, eventcomp) {
|
|
comps.map(function (mem) {
|
|
var component = mem.get(eventcomp);
|
|
if (component.hasConfigured(Disabling)) {
|
|
Disabling.enable(component);
|
|
}
|
|
});
|
|
};
|
|
var panelDom = {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-image-tools__toolbar',
|
|
'tox-image-tools-edit-panel'
|
|
]
|
|
};
|
|
var noop$1 = noop;
|
|
var emit$1 = function (comp, event, data) {
|
|
emitWith(comp, event, data);
|
|
};
|
|
var emitDisable = function (component) {
|
|
return emit(component, external$2.disable());
|
|
};
|
|
var emitEnable = function (component) {
|
|
return emit(component, external$2.enable());
|
|
};
|
|
var emitTransform = function (comp, transform) {
|
|
emitDisable(comp);
|
|
emit$1(comp, internal.transform(), { transform: transform });
|
|
emitEnable(comp);
|
|
};
|
|
var emitTempTransform = function (comp, transform) {
|
|
emitDisable(comp);
|
|
emit$1(comp, internal.tempTransform(), { transform: transform });
|
|
emitEnable(comp);
|
|
};
|
|
var getBackSwap = function (anyInSystem) {
|
|
return function () {
|
|
memContainer.getOpt(anyInSystem).each(function (container) {
|
|
Replacing.set(container, [ButtonPanel]);
|
|
});
|
|
};
|
|
};
|
|
var emitTransformApply = function (comp, transform) {
|
|
emitDisable(comp);
|
|
emit$1(comp, internal.transformApply(), {
|
|
transform: transform,
|
|
swap: getBackSwap(comp)
|
|
});
|
|
emitEnable(comp);
|
|
};
|
|
var createBackButton = function () {
|
|
return createButton('Back', function (button) {
|
|
return emit$1(button, internal.back(), { swap: getBackSwap(button) });
|
|
}, false, false);
|
|
};
|
|
var createSpacer = function () {
|
|
return record({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-spacer']
|
|
},
|
|
behaviours: derive$1([Disabling.config({})])
|
|
});
|
|
};
|
|
var createApplyButton = function () {
|
|
return createButton('Apply', function (button) {
|
|
return emit$1(button, internal.apply(), { swap: getBackSwap(button) });
|
|
}, true, true);
|
|
};
|
|
var makeCropTransform = function () {
|
|
return function (ir) {
|
|
var rect = imagePanel.getRect();
|
|
return crop$1(ir, rect.x, rect.y, rect.w, rect.h);
|
|
};
|
|
};
|
|
var cropPanelComponents = [
|
|
createBackButton(),
|
|
createSpacer(),
|
|
createButton('Apply', function (button) {
|
|
var transform = makeCropTransform();
|
|
emitTransformApply(button, transform);
|
|
imagePanel.hideCrop();
|
|
}, false, true)
|
|
];
|
|
var CropPanel = Container.sketch({
|
|
dom: panelDom,
|
|
components: cropPanelComponents.map(function (mem) {
|
|
return mem.asSpec();
|
|
}),
|
|
containerBehaviours: derive$1([config('image-tools-crop-buttons-events', [
|
|
run(external$2.disable(), function (comp, _se) {
|
|
disableAllComponents(cropPanelComponents, comp);
|
|
}),
|
|
run(external$2.enable(), function (comp, _se) {
|
|
enableAllComponents(cropPanelComponents, comp);
|
|
})
|
|
])])
|
|
});
|
|
var memSize = record(renderSizeInput({
|
|
name: 'size',
|
|
label: Option.none(),
|
|
constrain: true,
|
|
disabled: false
|
|
}, providersBackstage));
|
|
var makeResizeTransform = function (width, height) {
|
|
return function (ir) {
|
|
return resize$2(ir, width, height);
|
|
};
|
|
};
|
|
var resizePanelComponents = [
|
|
createBackButton(),
|
|
createSpacer(),
|
|
memSize,
|
|
createSpacer(),
|
|
createButton('Apply', function (button) {
|
|
memSize.getOpt(button).each(function (sizeInput) {
|
|
var value = Representing.getValue(sizeInput);
|
|
var width = parseInt(value.width, 10);
|
|
var height = parseInt(value.height, 10);
|
|
var transform = makeResizeTransform(width, height);
|
|
emitTransformApply(button, transform);
|
|
});
|
|
}, false, true)
|
|
];
|
|
var ResizePanel = Container.sketch({
|
|
dom: panelDom,
|
|
components: resizePanelComponents.map(function (mem) {
|
|
return mem.asSpec();
|
|
}),
|
|
containerBehaviours: derive$1([config('image-tools-resize-buttons-events', [
|
|
run(external$2.disable(), function (comp, _se) {
|
|
disableAllComponents(resizePanelComponents, comp);
|
|
}),
|
|
run(external$2.enable(), function (comp, _se) {
|
|
enableAllComponents(resizePanelComponents, comp);
|
|
})
|
|
])])
|
|
});
|
|
var makeValueTransform = function (transform, value) {
|
|
return function (ir) {
|
|
return transform(ir, value);
|
|
};
|
|
};
|
|
var horizontalFlip = makeValueTransform(flip$1, 'h');
|
|
var verticalFlip = makeValueTransform(flip$1, 'v');
|
|
var counterclockwiseRotate = makeValueTransform(rotate$1, -90);
|
|
var clockwiseRotate = makeValueTransform(rotate$1, 90);
|
|
var flipRotateOnAction = function (comp, operation) {
|
|
emitTempTransform(comp, operation);
|
|
};
|
|
var flipRotateComponents = [
|
|
createBackButton(),
|
|
createSpacer(),
|
|
createIconButton('flip-horizontally', 'Flip horizontally', function (button) {
|
|
flipRotateOnAction(button, horizontalFlip);
|
|
}, false),
|
|
createIconButton('flip-vertically', 'Flip vertically', function (button) {
|
|
flipRotateOnAction(button, verticalFlip);
|
|
}, false),
|
|
createIconButton('rotate-left', 'Rotate counterclockwise', function (button) {
|
|
flipRotateOnAction(button, counterclockwiseRotate);
|
|
}, false),
|
|
createIconButton('rotate-right', 'Rotate clockwise', function (button) {
|
|
flipRotateOnAction(button, clockwiseRotate);
|
|
}, false),
|
|
createSpacer(),
|
|
createApplyButton()
|
|
];
|
|
var FlipRotatePanel = Container.sketch({
|
|
dom: panelDom,
|
|
components: flipRotateComponents.map(function (mem) {
|
|
return mem.asSpec();
|
|
}),
|
|
containerBehaviours: derive$1([config('image-tools-fliprotate-buttons-events', [
|
|
run(external$2.disable(), function (comp, _se) {
|
|
disableAllComponents(flipRotateComponents, comp);
|
|
}),
|
|
run(external$2.enable(), function (comp, _se) {
|
|
enableAllComponents(flipRotateComponents, comp);
|
|
})
|
|
])])
|
|
});
|
|
var makeSlider = function (label, onChoose, min, value, max) {
|
|
var labelPart = Slider.parts().label({
|
|
dom: {
|
|
tag: 'label',
|
|
classes: ['tox-label'],
|
|
innerHtml: providersBackstage.translate(label)
|
|
}
|
|
});
|
|
var spectrum = Slider.parts().spectrum({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-slider__rail'],
|
|
attributes: { role: 'presentation' }
|
|
}
|
|
});
|
|
var thumb = Slider.parts().thumb({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-slider__handle'],
|
|
attributes: { role: 'presentation' }
|
|
}
|
|
});
|
|
return record(Slider.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-slider'],
|
|
attributes: { role: 'presentation' }
|
|
},
|
|
model: {
|
|
mode: 'x',
|
|
minX: min,
|
|
maxX: max,
|
|
getInitialValue: constant({ x: constant(value) })
|
|
},
|
|
components: [
|
|
labelPart,
|
|
spectrum,
|
|
thumb
|
|
],
|
|
sliderBehaviours: derive$1([Focusing.config({})]),
|
|
onChoose: onChoose
|
|
}));
|
|
};
|
|
var makeVariableSlider = function (label, transform, min, value, max) {
|
|
var onChoose = function (slider, _thumb, value) {
|
|
var valTransform = makeValueTransform(transform, value.x() / 100);
|
|
emitTransform(slider, valTransform);
|
|
};
|
|
return makeSlider(label, onChoose, min, value, max);
|
|
};
|
|
var variableFilterPanelComponents = function (label, transform, min, value, max) {
|
|
return [
|
|
createBackButton(),
|
|
makeVariableSlider(label, transform, min, value, max),
|
|
createApplyButton()
|
|
];
|
|
};
|
|
var createVariableFilterPanel = function (label, transform, min, value, max) {
|
|
var filterPanelComponents = variableFilterPanelComponents(label, transform, min, value, max);
|
|
return Container.sketch({
|
|
dom: panelDom,
|
|
components: filterPanelComponents.map(function (mem) {
|
|
return mem.asSpec();
|
|
}),
|
|
containerBehaviours: derive$1([config('image-tools-filter-panel-buttons-events', [
|
|
run(external$2.disable(), function (comp, _se) {
|
|
disableAllComponents(filterPanelComponents, comp);
|
|
}),
|
|
run(external$2.enable(), function (comp, _se) {
|
|
enableAllComponents(filterPanelComponents, comp);
|
|
})
|
|
])])
|
|
});
|
|
};
|
|
var filterPanelComponents = [
|
|
createBackButton(),
|
|
createSpacer(),
|
|
createApplyButton()
|
|
];
|
|
var FilterPanel = Container.sketch({
|
|
dom: panelDom,
|
|
components: filterPanelComponents.map(function (mem) {
|
|
return mem.asSpec();
|
|
})
|
|
});
|
|
var BrightnessPanel = createVariableFilterPanel('Brightness', brightness$1, -100, 0, 100);
|
|
var ContrastPanel = createVariableFilterPanel('Contrast', contrast$1, -100, 0, 100);
|
|
var GammaPanel = createVariableFilterPanel('Gamma', gamma$1, -100, 0, 100);
|
|
var makeColorTransform = function (red, green, blue) {
|
|
return function (ir) {
|
|
return colorize$1(ir, red, green, blue);
|
|
};
|
|
};
|
|
var makeColorSlider = function (label) {
|
|
var onChoose = function (slider, _thumb, _value) {
|
|
var redOpt = memRed.getOpt(slider);
|
|
var blueOpt = memBlue.getOpt(slider);
|
|
var greenOpt = memGreen.getOpt(slider);
|
|
redOpt.each(function (red) {
|
|
blueOpt.each(function (blue) {
|
|
greenOpt.each(function (green) {
|
|
var r = Representing.getValue(red).x() / 100;
|
|
var g = Representing.getValue(green).x() / 100;
|
|
var b = Representing.getValue(blue).x() / 100;
|
|
var transform = makeColorTransform(r, g, b);
|
|
emitTransform(slider, transform);
|
|
});
|
|
});
|
|
});
|
|
};
|
|
return makeSlider(label, onChoose, 0, 100, 200);
|
|
};
|
|
var memRed = makeColorSlider('R');
|
|
var memGreen = makeColorSlider('G');
|
|
var memBlue = makeColorSlider('B');
|
|
var colorizePanelComponents = [
|
|
createBackButton(),
|
|
memRed,
|
|
memGreen,
|
|
memBlue,
|
|
createApplyButton()
|
|
];
|
|
var ColorizePanel = Container.sketch({
|
|
dom: panelDom,
|
|
components: colorizePanelComponents.map(function (mem) {
|
|
return mem.asSpec();
|
|
})
|
|
});
|
|
var getTransformPanelEvent = function (panel, transform, update) {
|
|
return function (button) {
|
|
var swap = function () {
|
|
memContainer.getOpt(button).each(function (container) {
|
|
Replacing.set(container, [panel]);
|
|
update(container);
|
|
});
|
|
};
|
|
emit$1(button, internal.swap(), {
|
|
transform: transform,
|
|
swap: swap
|
|
});
|
|
};
|
|
};
|
|
var cropPanelUpdate = function (_anyInSystem) {
|
|
imagePanel.showCrop();
|
|
};
|
|
var resizePanelUpdate = function (anyInSystem) {
|
|
memSize.getOpt(anyInSystem).each(function (sizeInput) {
|
|
var measurements = imagePanel.getMeasurements();
|
|
var width = measurements.width;
|
|
var height = measurements.height;
|
|
Representing.setValue(sizeInput, {
|
|
width: width,
|
|
height: height
|
|
});
|
|
});
|
|
};
|
|
var sharpenTransform = Option.some(sharpen$1);
|
|
var invertTransform = Option.some(invert$1);
|
|
var buttonPanelComponents = [
|
|
createIconButton('crop', 'Crop', getTransformPanelEvent(CropPanel, Option.none(), cropPanelUpdate), false),
|
|
createIconButton('resize', 'Resize', getTransformPanelEvent(ResizePanel, Option.none(), resizePanelUpdate), false),
|
|
createIconButton('orientation', 'Orientation', getTransformPanelEvent(FlipRotatePanel, Option.none(), noop$1), false),
|
|
createIconButton('brightness', 'Brightness', getTransformPanelEvent(BrightnessPanel, Option.none(), noop$1), false),
|
|
createIconButton('sharpen', 'Sharpen', getTransformPanelEvent(FilterPanel, sharpenTransform, noop$1), false),
|
|
createIconButton('contrast', 'Contrast', getTransformPanelEvent(ContrastPanel, Option.none(), noop$1), false),
|
|
createIconButton('color-levels', 'Color levels', getTransformPanelEvent(ColorizePanel, Option.none(), noop$1), false),
|
|
createIconButton('gamma', 'Gamma', getTransformPanelEvent(GammaPanel, Option.none(), noop$1), false),
|
|
createIconButton('invert', 'Invert', getTransformPanelEvent(FilterPanel, invertTransform, noop$1), false)
|
|
];
|
|
var ButtonPanel = Container.sketch({
|
|
dom: panelDom,
|
|
components: buttonPanelComponents.map(function (mem) {
|
|
return mem.asSpec();
|
|
})
|
|
});
|
|
var container = Container.sketch({
|
|
dom: { tag: 'div' },
|
|
components: [ButtonPanel],
|
|
containerBehaviours: derive$1([Replacing.config({})])
|
|
});
|
|
var memContainer = record(container);
|
|
var getApplyButton = function (anyInSystem) {
|
|
return memContainer.getOpt(anyInSystem).map(function (container) {
|
|
var panel = container.components()[0];
|
|
return panel.components()[panel.components().length - 1];
|
|
});
|
|
};
|
|
return {
|
|
memContainer: memContainer,
|
|
getApplyButton: getApplyButton
|
|
};
|
|
};
|
|
|
|
var global$b = tinymce.util.Tools.resolve('tinymce.dom.DomQuery');
|
|
|
|
var global$c = tinymce.util.Tools.resolve('tinymce.geom.Rect');
|
|
|
|
var global$d = tinymce.util.Tools.resolve('tinymce.util.Observable');
|
|
|
|
var global$e = tinymce.util.Tools.resolve('tinymce.util.Tools');
|
|
|
|
var global$f = tinymce.util.Tools.resolve('tinymce.util.VK');
|
|
|
|
function getDocumentSize(doc) {
|
|
var documentElement, body, scrollWidth, clientWidth;
|
|
var offsetWidth, scrollHeight, clientHeight, offsetHeight;
|
|
var max = Math.max;
|
|
documentElement = doc.documentElement;
|
|
body = doc.body;
|
|
scrollWidth = max(documentElement.scrollWidth, body.scrollWidth);
|
|
clientWidth = max(documentElement.clientWidth, body.clientWidth);
|
|
offsetWidth = max(documentElement.offsetWidth, body.offsetWidth);
|
|
scrollHeight = max(documentElement.scrollHeight, body.scrollHeight);
|
|
clientHeight = max(documentElement.clientHeight, body.clientHeight);
|
|
offsetHeight = max(documentElement.offsetHeight, body.offsetHeight);
|
|
return {
|
|
width: scrollWidth < offsetWidth ? clientWidth : scrollWidth,
|
|
height: scrollHeight < offsetHeight ? clientHeight : scrollHeight
|
|
};
|
|
}
|
|
function updateWithTouchData(e) {
|
|
var keys, i;
|
|
if (e.changedTouches) {
|
|
keys = 'screenX screenY pageX pageY clientX clientY'.split(' ');
|
|
for (i = 0; i < keys.length; i++) {
|
|
e[keys[i]] = e.changedTouches[0][keys[i]];
|
|
}
|
|
}
|
|
}
|
|
function DragHelper (id, settings) {
|
|
var $eventOverlay;
|
|
var doc = settings.document || domGlobals.document;
|
|
var downButton;
|
|
var start, stop, drag, startX, startY;
|
|
settings = settings || {};
|
|
var handleElement = doc.getElementById(settings.handle || id);
|
|
start = function (e) {
|
|
var docSize = getDocumentSize(doc);
|
|
var handleElm, cursor;
|
|
updateWithTouchData(e);
|
|
e.preventDefault();
|
|
downButton = e.button;
|
|
handleElm = handleElement;
|
|
startX = e.screenX;
|
|
startY = e.screenY;
|
|
if (domGlobals.window.getComputedStyle) {
|
|
cursor = domGlobals.window.getComputedStyle(handleElm, null).getPropertyValue('cursor');
|
|
} else {
|
|
cursor = handleElm.runtimeStyle.cursor;
|
|
}
|
|
$eventOverlay = global$b('<div></div>').css({
|
|
position: 'absolute',
|
|
top: 0,
|
|
left: 0,
|
|
width: docSize.width,
|
|
height: docSize.height,
|
|
zIndex: 2147483647,
|
|
opacity: 0.0001,
|
|
cursor: cursor
|
|
}).appendTo(doc.body);
|
|
global$b(doc).on('mousemove touchmove', drag).on('mouseup touchend', stop);
|
|
settings.start(e);
|
|
};
|
|
drag = function (e) {
|
|
updateWithTouchData(e);
|
|
if (e.button !== downButton) {
|
|
return stop(e);
|
|
}
|
|
e.deltaX = e.screenX - startX;
|
|
e.deltaY = e.screenY - startY;
|
|
e.preventDefault();
|
|
settings.drag(e);
|
|
};
|
|
stop = function (e) {
|
|
updateWithTouchData(e);
|
|
global$b(doc).off('mousemove touchmove', drag).off('mouseup touchend', stop);
|
|
$eventOverlay.remove();
|
|
if (settings.stop) {
|
|
settings.stop(e);
|
|
}
|
|
};
|
|
this.destroy = function () {
|
|
global$b(handleElement).off();
|
|
};
|
|
global$b(handleElement).on('mousedown touchstart', start);
|
|
}
|
|
|
|
var count = 0;
|
|
var create$7 = function (currentRect, viewPortRect, clampRect, containerElm, action) {
|
|
var instance;
|
|
var dragHelpers;
|
|
var blockers;
|
|
var prefix = 'tox-';
|
|
var id = prefix + 'crid-' + count++;
|
|
var handles = [
|
|
{
|
|
name: 'move',
|
|
xMul: 0,
|
|
yMul: 0,
|
|
deltaX: 1,
|
|
deltaY: 1,
|
|
deltaW: 0,
|
|
deltaH: 0,
|
|
label: 'Crop Mask'
|
|
},
|
|
{
|
|
name: 'nw',
|
|
xMul: 0,
|
|
yMul: 0,
|
|
deltaX: 1,
|
|
deltaY: 1,
|
|
deltaW: -1,
|
|
deltaH: -1,
|
|
label: 'Top Left Crop Handle'
|
|
},
|
|
{
|
|
name: 'ne',
|
|
xMul: 1,
|
|
yMul: 0,
|
|
deltaX: 0,
|
|
deltaY: 1,
|
|
deltaW: 1,
|
|
deltaH: -1,
|
|
label: 'Top Right Crop Handle'
|
|
},
|
|
{
|
|
name: 'sw',
|
|
xMul: 0,
|
|
yMul: 1,
|
|
deltaX: 1,
|
|
deltaY: 0,
|
|
deltaW: -1,
|
|
deltaH: 1,
|
|
label: 'Bottom Left Crop Handle'
|
|
},
|
|
{
|
|
name: 'se',
|
|
xMul: 1,
|
|
yMul: 1,
|
|
deltaX: 0,
|
|
deltaY: 0,
|
|
deltaW: 1,
|
|
deltaH: 1,
|
|
label: 'Bottom Right Crop Handle'
|
|
}
|
|
];
|
|
blockers = [
|
|
'top',
|
|
'right',
|
|
'bottom',
|
|
'left'
|
|
];
|
|
var getAbsoluteRect = function (outerRect, relativeRect) {
|
|
return {
|
|
x: relativeRect.x + outerRect.x,
|
|
y: relativeRect.y + outerRect.y,
|
|
w: relativeRect.w,
|
|
h: relativeRect.h
|
|
};
|
|
};
|
|
var getRelativeRect = function (outerRect, innerRect) {
|
|
return {
|
|
x: innerRect.x - outerRect.x,
|
|
y: innerRect.y - outerRect.y,
|
|
w: innerRect.w,
|
|
h: innerRect.h
|
|
};
|
|
};
|
|
var getInnerRect = function () {
|
|
return getRelativeRect(clampRect, currentRect);
|
|
};
|
|
function moveRect(handle, startRect, deltaX, deltaY) {
|
|
var x, y, w, h, rect;
|
|
x = startRect.x;
|
|
y = startRect.y;
|
|
w = startRect.w;
|
|
h = startRect.h;
|
|
x += deltaX * handle.deltaX;
|
|
y += deltaY * handle.deltaY;
|
|
w += deltaX * handle.deltaW;
|
|
h += deltaY * handle.deltaH;
|
|
if (w < 20) {
|
|
w = 20;
|
|
}
|
|
if (h < 20) {
|
|
h = 20;
|
|
}
|
|
rect = currentRect = global$c.clamp({
|
|
x: x,
|
|
y: y,
|
|
w: w,
|
|
h: h
|
|
}, clampRect, handle.name === 'move');
|
|
rect = getRelativeRect(clampRect, rect);
|
|
instance.fire('updateRect', { rect: rect });
|
|
setInnerRect(rect);
|
|
}
|
|
function render() {
|
|
function createDragHelper(handle) {
|
|
var startRect;
|
|
return new DragHelper(id, {
|
|
document: containerElm.ownerDocument,
|
|
handle: id + '-' + handle.name,
|
|
start: function () {
|
|
startRect = currentRect;
|
|
},
|
|
drag: function (e) {
|
|
moveRect(handle, startRect, e.deltaX, e.deltaY);
|
|
}
|
|
});
|
|
}
|
|
global$b('<div id="' + id + '" class="' + prefix + 'croprect-container"' + ' role="grid" aria-dropeffect="execute">').appendTo(containerElm);
|
|
global$e.each(blockers, function (blocker) {
|
|
global$b('#' + id, containerElm).append('<div id="' + id + '-' + blocker + '"class="' + prefix + 'croprect-block" style="display: none" data-mce-bogus="all">');
|
|
});
|
|
global$e.each(handles, function (handle) {
|
|
global$b('#' + id, containerElm).append('<div id="' + id + '-' + handle.name + '" class="' + prefix + 'croprect-handle ' + prefix + 'croprect-handle-' + handle.name + '"' + 'style="display: none" data-mce-bogus="all" role="gridcell" tabindex="-1"' + ' aria-label="' + handle.label + '" aria-grabbed="false" title="' + handle.label + '">');
|
|
});
|
|
dragHelpers = global$e.map(handles, createDragHelper);
|
|
repaint(currentRect);
|
|
global$b(containerElm).on('focusin focusout', function (e) {
|
|
global$b(e.target).attr('aria-grabbed', e.type === 'focus' ? 'true' : 'false');
|
|
});
|
|
global$b(containerElm).on('keydown', function (e) {
|
|
var activeHandle;
|
|
global$e.each(handles, function (handle) {
|
|
if (e.target.id === id + '-' + handle.name) {
|
|
activeHandle = handle;
|
|
return false;
|
|
}
|
|
});
|
|
function moveAndBlock(evt, handle, startRect, deltaX, deltaY) {
|
|
evt.stopPropagation();
|
|
evt.preventDefault();
|
|
moveRect(activeHandle, startRect, deltaX, deltaY);
|
|
}
|
|
switch (e.keyCode) {
|
|
case global$f.LEFT:
|
|
moveAndBlock(e, activeHandle, currentRect, -10, 0);
|
|
break;
|
|
case global$f.RIGHT:
|
|
moveAndBlock(e, activeHandle, currentRect, 10, 0);
|
|
break;
|
|
case global$f.UP:
|
|
moveAndBlock(e, activeHandle, currentRect, 0, -10);
|
|
break;
|
|
case global$f.DOWN:
|
|
moveAndBlock(e, activeHandle, currentRect, 0, 10);
|
|
break;
|
|
case global$f.ENTER:
|
|
case global$f.SPACEBAR:
|
|
e.preventDefault();
|
|
action();
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
function toggleVisibility(state) {
|
|
var selectors;
|
|
selectors = global$e.map(handles, function (handle) {
|
|
return '#' + id + '-' + handle.name;
|
|
}).concat(global$e.map(blockers, function (blocker) {
|
|
return '#' + id + '-' + blocker;
|
|
})).join(',');
|
|
if (state) {
|
|
global$b(selectors, containerElm).show();
|
|
} else {
|
|
global$b(selectors, containerElm).hide();
|
|
}
|
|
}
|
|
function repaint(rect) {
|
|
function updateElementRect(name, rect) {
|
|
if (rect.h < 0) {
|
|
rect.h = 0;
|
|
}
|
|
if (rect.w < 0) {
|
|
rect.w = 0;
|
|
}
|
|
global$b('#' + id + '-' + name, containerElm).css({
|
|
left: rect.x,
|
|
top: rect.y,
|
|
width: rect.w,
|
|
height: rect.h
|
|
});
|
|
}
|
|
global$e.each(handles, function (handle) {
|
|
global$b('#' + id + '-' + handle.name, containerElm).css({
|
|
left: rect.w * handle.xMul + rect.x,
|
|
top: rect.h * handle.yMul + rect.y
|
|
});
|
|
});
|
|
updateElementRect('top', {
|
|
x: viewPortRect.x,
|
|
y: viewPortRect.y,
|
|
w: viewPortRect.w,
|
|
h: rect.y - viewPortRect.y
|
|
});
|
|
updateElementRect('right', {
|
|
x: rect.x + rect.w,
|
|
y: rect.y,
|
|
w: viewPortRect.w - rect.x - rect.w + viewPortRect.x,
|
|
h: rect.h
|
|
});
|
|
updateElementRect('bottom', {
|
|
x: viewPortRect.x,
|
|
y: rect.y + rect.h,
|
|
w: viewPortRect.w,
|
|
h: viewPortRect.h - rect.y - rect.h + viewPortRect.y
|
|
});
|
|
updateElementRect('left', {
|
|
x: viewPortRect.x,
|
|
y: rect.y,
|
|
w: rect.x - viewPortRect.x,
|
|
h: rect.h
|
|
});
|
|
updateElementRect('move', rect);
|
|
}
|
|
function setRect(rect) {
|
|
currentRect = rect;
|
|
repaint(currentRect);
|
|
}
|
|
function setViewPortRect(rect) {
|
|
viewPortRect = rect;
|
|
repaint(currentRect);
|
|
}
|
|
function setInnerRect(rect) {
|
|
setRect(getAbsoluteRect(clampRect, rect));
|
|
}
|
|
function setClampRect(rect) {
|
|
clampRect = rect;
|
|
repaint(currentRect);
|
|
}
|
|
function destroy() {
|
|
global$e.each(dragHelpers, function (helper) {
|
|
helper.destroy();
|
|
});
|
|
dragHelpers = [];
|
|
}
|
|
render();
|
|
instance = global$e.extend({
|
|
toggleVisibility: toggleVisibility,
|
|
setClampRect: setClampRect,
|
|
setRect: setRect,
|
|
getInnerRect: getInnerRect,
|
|
setInnerRect: setInnerRect,
|
|
setViewPortRect: setViewPortRect,
|
|
destroy: destroy
|
|
}, global$d);
|
|
return instance;
|
|
};
|
|
var CropRect = { create: create$7 };
|
|
|
|
var loadImage = function (image) {
|
|
return new global$4(function (resolve) {
|
|
var loaded = function () {
|
|
image.removeEventListener('load', loaded);
|
|
resolve(image);
|
|
};
|
|
if (image.complete) {
|
|
resolve(image);
|
|
} else {
|
|
image.addEventListener('load', loaded);
|
|
}
|
|
});
|
|
};
|
|
var renderImagePanel = function (initialUrl) {
|
|
var memBg = record({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-image-tools__image-bg'],
|
|
attributes: { role: 'presentation' }
|
|
}
|
|
});
|
|
var zoomState = Cell(1);
|
|
var cropRect = Cell(Option.none());
|
|
var rectState = Cell({
|
|
x: 0,
|
|
y: 0,
|
|
w: 1,
|
|
h: 1
|
|
});
|
|
var viewRectState = Cell({
|
|
x: 0,
|
|
y: 0,
|
|
w: 1,
|
|
h: 1
|
|
});
|
|
var repaintImg = function (anyInSystem, img) {
|
|
memContainer.getOpt(anyInSystem).each(function (panel) {
|
|
var zoom = zoomState.get();
|
|
var panelW = get$7(panel.element());
|
|
var panelH = get$6(panel.element());
|
|
var width = img.dom().naturalWidth * zoom;
|
|
var height = img.dom().naturalHeight * zoom;
|
|
var left = Math.max(0, panelW / 2 - width / 2);
|
|
var top = Math.max(0, panelH / 2 - height / 2);
|
|
var css = {
|
|
left: left.toString() + 'px',
|
|
top: top.toString() + 'px',
|
|
width: width.toString() + 'px',
|
|
height: height.toString() + 'px',
|
|
position: 'absolute'
|
|
};
|
|
setAll$1(img, css);
|
|
memBg.getOpt(panel).each(function (bg) {
|
|
setAll$1(bg.element(), css);
|
|
});
|
|
cropRect.get().each(function (cRect) {
|
|
var rect = rectState.get();
|
|
cRect.setRect({
|
|
x: rect.x * zoom + left,
|
|
y: rect.y * zoom + top,
|
|
w: rect.w * zoom,
|
|
h: rect.h * zoom
|
|
});
|
|
cRect.setClampRect({
|
|
x: left,
|
|
y: top,
|
|
w: width,
|
|
h: height
|
|
});
|
|
cRect.setViewPortRect({
|
|
x: 0,
|
|
y: 0,
|
|
w: panelW,
|
|
h: panelH
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var zoomFit = function (anyInSystem, img) {
|
|
memContainer.getOpt(anyInSystem).each(function (panel) {
|
|
var panelW = get$7(panel.element());
|
|
var panelH = get$6(panel.element());
|
|
var width = img.dom().naturalWidth;
|
|
var height = img.dom().naturalHeight;
|
|
var zoom = Math.min(panelW / width, panelH / height);
|
|
if (zoom >= 1) {
|
|
zoomState.set(1);
|
|
} else {
|
|
zoomState.set(zoom);
|
|
}
|
|
});
|
|
};
|
|
var updateSrc = function (anyInSystem, url) {
|
|
var img = Element.fromTag('img');
|
|
set$1(img, 'src', url);
|
|
return loadImage(img.dom()).then(function () {
|
|
return memContainer.getOpt(anyInSystem).map(function (panel) {
|
|
var aImg = external({ element: img });
|
|
Replacing.replaceAt(panel, 1, Option.some(aImg));
|
|
var lastViewRect = viewRectState.get();
|
|
var viewRect = {
|
|
x: 0,
|
|
y: 0,
|
|
w: img.dom().naturalWidth,
|
|
h: img.dom().naturalHeight
|
|
};
|
|
viewRectState.set(viewRect);
|
|
var rect = global$c.inflate(viewRect, -20, -20);
|
|
rectState.set(rect);
|
|
if (lastViewRect.w !== viewRect.w || lastViewRect.h !== viewRect.h) {
|
|
zoomFit(panel, img);
|
|
}
|
|
repaintImg(panel, img);
|
|
return img;
|
|
});
|
|
});
|
|
};
|
|
var zoom = function (anyInSystem, direction) {
|
|
var currentZoom = zoomState.get();
|
|
var newZoom = direction > 0 ? Math.min(2, currentZoom + 0.1) : Math.max(0.1, currentZoom - 0.1);
|
|
zoomState.set(newZoom);
|
|
memContainer.getOpt(anyInSystem).each(function (panel) {
|
|
var img = panel.components()[1].element();
|
|
repaintImg(panel, img);
|
|
});
|
|
};
|
|
var showCrop = function () {
|
|
cropRect.get().each(function (cRect) {
|
|
cRect.toggleVisibility(true);
|
|
});
|
|
};
|
|
var hideCrop = function () {
|
|
cropRect.get().each(function (cRect) {
|
|
cRect.toggleVisibility(false);
|
|
});
|
|
};
|
|
var getRect = function () {
|
|
return rectState.get();
|
|
};
|
|
var container = Container.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-image-tools__image']
|
|
},
|
|
components: [
|
|
memBg.asSpec(),
|
|
{
|
|
dom: {
|
|
tag: 'img',
|
|
attributes: { src: initialUrl }
|
|
}
|
|
},
|
|
{
|
|
dom: { tag: 'div' },
|
|
behaviours: derive$1([config('image-panel-crop-events', [runOnAttached(function (comp) {
|
|
memContainer.getOpt(comp).each(function (container) {
|
|
var el = container.element().dom();
|
|
var cRect = CropRect.create({
|
|
x: 10,
|
|
y: 10,
|
|
w: 100,
|
|
h: 100
|
|
}, {
|
|
x: 0,
|
|
y: 0,
|
|
w: 200,
|
|
h: 200
|
|
}, {
|
|
x: 0,
|
|
y: 0,
|
|
w: 200,
|
|
h: 200
|
|
}, el, function () {
|
|
});
|
|
cRect.toggleVisibility(false);
|
|
cRect.on('updateRect', function (e) {
|
|
var rect = e.rect;
|
|
var zoom = zoomState.get();
|
|
var newRect = {
|
|
x: Math.round(rect.x / zoom),
|
|
y: Math.round(rect.y / zoom),
|
|
w: Math.round(rect.w / zoom),
|
|
h: Math.round(rect.h / zoom)
|
|
};
|
|
rectState.set(newRect);
|
|
});
|
|
cropRect.set(Option.some(cRect));
|
|
});
|
|
})])])
|
|
}
|
|
],
|
|
containerBehaviours: derive$1([
|
|
Replacing.config({}),
|
|
config('image-panel-events', [runOnAttached(function (comp) {
|
|
updateSrc(comp, initialUrl);
|
|
})])
|
|
])
|
|
});
|
|
var memContainer = record(container);
|
|
var getMeasurements = function () {
|
|
var viewRect = viewRectState.get();
|
|
return {
|
|
width: viewRect.w,
|
|
height: viewRect.h
|
|
};
|
|
};
|
|
return {
|
|
memContainer: memContainer,
|
|
updateSrc: updateSrc,
|
|
zoom: zoom,
|
|
showCrop: showCrop,
|
|
hideCrop: hideCrop,
|
|
getRect: getRect,
|
|
getMeasurements: getMeasurements
|
|
};
|
|
};
|
|
|
|
var createButton = function (innerHtml, icon, disabled, action, providersBackstage) {
|
|
return renderIconButton({
|
|
name: innerHtml,
|
|
icon: Option.some(icon),
|
|
disabled: disabled,
|
|
tooltip: Option.some(innerHtml),
|
|
primary: false,
|
|
borderless: false
|
|
}, action, providersBackstage);
|
|
};
|
|
var setButtonEnabled = function (button, enabled) {
|
|
if (enabled) {
|
|
Disabling.enable(button);
|
|
} else {
|
|
Disabling.disable(button);
|
|
}
|
|
};
|
|
var renderSideBar = function (providersBackstage) {
|
|
var updateButtonUndoStates = function (anyInSystem, undoEnabled, redoEnabled) {
|
|
memUndo.getOpt(anyInSystem).each(function (undo) {
|
|
setButtonEnabled(undo, undoEnabled);
|
|
});
|
|
memRedo.getOpt(anyInSystem).each(function (redo) {
|
|
setButtonEnabled(redo, redoEnabled);
|
|
});
|
|
};
|
|
var memUndo = record(createButton('Undo', 'undo', true, function (button) {
|
|
emitWith(button, internal.undo(), { direction: 1 });
|
|
}, providersBackstage));
|
|
var memRedo = record(createButton('Redo', 'redo', true, function (button) {
|
|
emitWith(button, internal.redo(), { direction: 1 });
|
|
}, providersBackstage));
|
|
var container = Container.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-image-tools__toolbar',
|
|
'tox-image-tools__sidebar'
|
|
]
|
|
},
|
|
components: [
|
|
memUndo.asSpec(),
|
|
memRedo.asSpec(),
|
|
createButton('Zoom in', 'zoom-in', false, function (button) {
|
|
emitWith(button, internal.zoom(), { direction: 1 });
|
|
}, providersBackstage),
|
|
createButton('Zoom out', 'zoom-out', false, function (button) {
|
|
emitWith(button, internal.zoom(), { direction: -1 });
|
|
}, providersBackstage)
|
|
]
|
|
});
|
|
return {
|
|
container: container,
|
|
updateButtonUndoStates: updateButtonUndoStates
|
|
};
|
|
};
|
|
|
|
function UndoStack () {
|
|
var data = [];
|
|
var index = -1;
|
|
function add(state) {
|
|
var removed;
|
|
removed = data.splice(++index);
|
|
data.push(state);
|
|
return {
|
|
state: state,
|
|
removed: removed
|
|
};
|
|
}
|
|
function undo() {
|
|
if (canUndo()) {
|
|
return data[--index];
|
|
}
|
|
}
|
|
function redo() {
|
|
if (canRedo()) {
|
|
return data[++index];
|
|
}
|
|
}
|
|
function canUndo() {
|
|
return index > 0;
|
|
}
|
|
function canRedo() {
|
|
return index !== -1 && index < data.length - 1;
|
|
}
|
|
return {
|
|
data: data,
|
|
add: add,
|
|
undo: undo,
|
|
redo: redo,
|
|
canUndo: canUndo,
|
|
canRedo: canRedo
|
|
};
|
|
}
|
|
|
|
var makeState = function (initialState) {
|
|
var blobState = Cell(initialState);
|
|
var tempState = Cell(Option.none());
|
|
var undoStack = UndoStack();
|
|
undoStack.add(initialState);
|
|
var getBlobState = function () {
|
|
return blobState.get();
|
|
};
|
|
var setBlobState = function (state) {
|
|
blobState.set(state);
|
|
};
|
|
var getTempState = function () {
|
|
return tempState.get().fold(function () {
|
|
return blobState.get();
|
|
}, function (temp) {
|
|
return temp;
|
|
});
|
|
};
|
|
var updateTempState = function (blob) {
|
|
var newTempState = createState(blob);
|
|
destroyTempState();
|
|
tempState.set(Option.some(newTempState));
|
|
return newTempState.url;
|
|
};
|
|
var createState = function (blob) {
|
|
return {
|
|
blob: blob,
|
|
url: domGlobals.URL.createObjectURL(blob)
|
|
};
|
|
};
|
|
var destroyState = function (state) {
|
|
domGlobals.URL.revokeObjectURL(state.url);
|
|
};
|
|
var destroyStates = function (states) {
|
|
global$e.each(states, destroyState);
|
|
};
|
|
var destroyTempState = function () {
|
|
tempState.get().each(destroyState);
|
|
tempState.set(Option.none());
|
|
};
|
|
var addBlobState = function (blob) {
|
|
var newState = createState(blob);
|
|
setBlobState(newState);
|
|
var removed = undoStack.add(newState).removed;
|
|
destroyStates(removed);
|
|
return newState.url;
|
|
};
|
|
var addTempState = function (blob) {
|
|
var newState = createState(blob);
|
|
tempState.set(Option.some(newState));
|
|
return newState.url;
|
|
};
|
|
var applyTempState = function (postApply) {
|
|
return tempState.get().fold(function () {
|
|
}, function (temp) {
|
|
addBlobState(temp.blob);
|
|
postApply();
|
|
});
|
|
};
|
|
var undo = function () {
|
|
var currentState = undoStack.undo();
|
|
setBlobState(currentState);
|
|
return currentState.url;
|
|
};
|
|
var redo = function () {
|
|
var currentState = undoStack.redo();
|
|
setBlobState(currentState);
|
|
return currentState.url;
|
|
};
|
|
var getHistoryStates = function () {
|
|
var undoEnabled = undoStack.canUndo();
|
|
var redoEnabled = undoStack.canRedo();
|
|
return {
|
|
undoEnabled: undoEnabled,
|
|
redoEnabled: redoEnabled
|
|
};
|
|
};
|
|
return {
|
|
getBlobState: getBlobState,
|
|
setBlobState: setBlobState,
|
|
addBlobState: addBlobState,
|
|
getTempState: getTempState,
|
|
updateTempState: updateTempState,
|
|
addTempState: addTempState,
|
|
applyTempState: applyTempState,
|
|
destroyTempState: destroyTempState,
|
|
undo: undo,
|
|
redo: redo,
|
|
getHistoryStates: getHistoryStates
|
|
};
|
|
};
|
|
|
|
var renderImageTools = function (detail, providersBackstage) {
|
|
var state = makeState(detail.currentState);
|
|
var zoom = function (anyInSystem, simulatedEvent) {
|
|
var direction = simulatedEvent.event().direction();
|
|
imagePanel.zoom(anyInSystem, direction);
|
|
};
|
|
var updateButtonUndoStates = function (anyInSystem) {
|
|
var historyStates = state.getHistoryStates();
|
|
sideBar.updateButtonUndoStates(anyInSystem, historyStates.undoEnabled, historyStates.redoEnabled);
|
|
emitWith(anyInSystem, external$2.formActionEvent, {
|
|
name: external$2.saveState(),
|
|
value: historyStates.undoEnabled
|
|
});
|
|
};
|
|
var disableUndoRedo = function (anyInSystem) {
|
|
sideBar.updateButtonUndoStates(anyInSystem, false, false);
|
|
};
|
|
var undo = function (anyInSystem, _simulatedEvent) {
|
|
var url = state.undo();
|
|
updateSrc(anyInSystem, url).then(function (_oImg) {
|
|
unblock(anyInSystem);
|
|
updateButtonUndoStates(anyInSystem);
|
|
});
|
|
};
|
|
var redo = function (anyInSystem, _simulatedEvent) {
|
|
var url = state.redo();
|
|
updateSrc(anyInSystem, url).then(function (_oImg) {
|
|
unblock(anyInSystem);
|
|
updateButtonUndoStates(anyInSystem);
|
|
});
|
|
};
|
|
var imageResultToBlob = function (ir) {
|
|
return ir.toBlob();
|
|
};
|
|
var block = function (anyInSystem) {
|
|
emitWith(anyInSystem, external$2.formActionEvent, {
|
|
name: external$2.disable(),
|
|
value: {}
|
|
});
|
|
};
|
|
var unblock = function (anyInSystem) {
|
|
editPanel.getApplyButton(anyInSystem).each(function (applyButton) {
|
|
Disabling.enable(applyButton);
|
|
});
|
|
emitWith(anyInSystem, external$2.formActionEvent, {
|
|
name: external$2.enable(),
|
|
value: {}
|
|
});
|
|
};
|
|
var updateSrc = function (anyInSystem, src) {
|
|
block(anyInSystem);
|
|
return imagePanel.updateSrc(anyInSystem, src);
|
|
};
|
|
var blobManipulate = function (anyInSystem, blob, filter, action, swap) {
|
|
block(anyInSystem);
|
|
return blobToImageResult(blob).then(filter).then(imageResultToBlob).then(action).then(function (url) {
|
|
return updateSrc(anyInSystem, url).then(function (oImg) {
|
|
updateButtonUndoStates(anyInSystem);
|
|
swap();
|
|
unblock(anyInSystem);
|
|
return oImg;
|
|
});
|
|
}).catch(function (err) {
|
|
domGlobals.console.log(err);
|
|
unblock(anyInSystem);
|
|
return err;
|
|
});
|
|
};
|
|
var manipulate = function (anyInSystem, filter, swap) {
|
|
var blob = state.getBlobState().blob;
|
|
var action = function (blob) {
|
|
return state.updateTempState(blob);
|
|
};
|
|
blobManipulate(anyInSystem, blob, filter, action, swap);
|
|
};
|
|
var tempManipulate = function (anyInSystem, filter) {
|
|
var blob = state.getTempState().blob;
|
|
var action = function (blob) {
|
|
return state.addTempState(blob);
|
|
};
|
|
blobManipulate(anyInSystem, blob, filter, action, noop);
|
|
};
|
|
var manipulateApply = function (anyInSystem, filter, swap) {
|
|
var blob = state.getBlobState().blob;
|
|
var action = function (blob) {
|
|
var url = state.addBlobState(blob);
|
|
destroyTempState(anyInSystem);
|
|
return url;
|
|
};
|
|
blobManipulate(anyInSystem, blob, filter, action, swap);
|
|
};
|
|
var apply = function (anyInSystem, simulatedEvent) {
|
|
var postApply = function () {
|
|
destroyTempState(anyInSystem);
|
|
var swap = simulatedEvent.event().swap();
|
|
swap();
|
|
};
|
|
state.applyTempState(postApply);
|
|
};
|
|
var destroyTempState = function (anyInSystem) {
|
|
var currentUrl = state.getBlobState().url;
|
|
state.destroyTempState();
|
|
updateButtonUndoStates(anyInSystem);
|
|
return currentUrl;
|
|
};
|
|
var cancel = function (anyInSystem) {
|
|
var currentUrl = destroyTempState(anyInSystem);
|
|
updateSrc(anyInSystem, currentUrl).then(function (_oImg) {
|
|
unblock(anyInSystem);
|
|
});
|
|
};
|
|
var back = function (anyInSystem, simulatedEvent) {
|
|
cancel(anyInSystem);
|
|
var swap = simulatedEvent.event().swap();
|
|
swap();
|
|
imagePanel.hideCrop();
|
|
};
|
|
var transform = function (anyInSystem, simulatedEvent) {
|
|
return manipulate(anyInSystem, simulatedEvent.event().transform(), noop);
|
|
};
|
|
var tempTransform = function (anyInSystem, simulatedEvent) {
|
|
return tempManipulate(anyInSystem, simulatedEvent.event().transform());
|
|
};
|
|
var transformApply = function (anyInSystem, simulatedEvent) {
|
|
return manipulateApply(anyInSystem, simulatedEvent.event().transform(), simulatedEvent.event().swap());
|
|
};
|
|
var imagePanel = renderImagePanel(detail.currentState.url);
|
|
var sideBar = renderSideBar(providersBackstage);
|
|
var editPanel = renderEditPanel(imagePanel, providersBackstage);
|
|
var swap = function (anyInSystem, simulatedEvent) {
|
|
disableUndoRedo(anyInSystem);
|
|
var transform = simulatedEvent.event().transform();
|
|
var swap = simulatedEvent.event().swap();
|
|
transform.fold(function () {
|
|
swap();
|
|
}, function (transform) {
|
|
manipulate(anyInSystem, transform, swap);
|
|
});
|
|
};
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { role: 'presentation' }
|
|
},
|
|
components: [
|
|
editPanel.memContainer.asSpec(),
|
|
imagePanel.memContainer.asSpec(),
|
|
sideBar.container
|
|
],
|
|
behaviours: derive$1([
|
|
Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function () {
|
|
return state.getBlobState();
|
|
}
|
|
}
|
|
}),
|
|
config('image-tools-events', [
|
|
run(internal.undo(), undo),
|
|
run(internal.redo(), redo),
|
|
run(internal.zoom(), zoom),
|
|
run(internal.back(), back),
|
|
run(internal.apply(), apply),
|
|
run(internal.transform(), transform),
|
|
run(internal.tempTransform(), tempTransform),
|
|
run(internal.transformApply(), transformApply),
|
|
run(internal.swap(), swap)
|
|
]),
|
|
ComposingConfigs.self()
|
|
])
|
|
};
|
|
};
|
|
|
|
var factory$8 = function (detail, _spec) {
|
|
var options = map(detail.options, function (option) {
|
|
return {
|
|
dom: {
|
|
tag: 'option',
|
|
value: option.value,
|
|
innerHtml: option.text
|
|
}
|
|
};
|
|
});
|
|
var initialValues = detail.data.map(function (v) {
|
|
return wrap$1('initialValue', v);
|
|
}).getOr({});
|
|
return {
|
|
uid: detail.uid,
|
|
dom: {
|
|
tag: 'select',
|
|
classes: detail.selectClasses,
|
|
attributes: detail.selectAttributes
|
|
},
|
|
components: options,
|
|
behaviours: augment(detail.selectBehaviours, [
|
|
Focusing.config({}),
|
|
Representing.config({
|
|
store: __assign({
|
|
mode: 'manual',
|
|
getValue: function (select) {
|
|
return get$5(select.element());
|
|
},
|
|
setValue: function (select, newValue) {
|
|
var found = find(detail.options, function (opt) {
|
|
return opt.value === newValue;
|
|
});
|
|
if (found.isSome()) {
|
|
set$3(select.element(), newValue);
|
|
}
|
|
}
|
|
}, initialValues)
|
|
})
|
|
])
|
|
};
|
|
};
|
|
var HtmlSelect = single$2({
|
|
name: 'HtmlSelect',
|
|
configFields: [
|
|
strict$1('options'),
|
|
field$1('selectBehaviours', [
|
|
Focusing,
|
|
Representing
|
|
]),
|
|
defaulted$1('selectClasses', []),
|
|
defaulted$1('selectAttributes', {}),
|
|
option('data')
|
|
],
|
|
factory: factory$8
|
|
});
|
|
|
|
var renderSelectBox = function (spec, providersBackstage) {
|
|
var translatedOptions = map(spec.items, function (item) {
|
|
return {
|
|
text: providersBackstage.translate(item.text),
|
|
value: item.value
|
|
};
|
|
});
|
|
var pLabel = spec.label.map(function (label) {
|
|
return renderLabel(label, providersBackstage);
|
|
});
|
|
var pField = FormField.parts().field({
|
|
dom: {},
|
|
selectAttributes: { size: spec.size },
|
|
options: translatedOptions,
|
|
factory: HtmlSelect,
|
|
selectBehaviours: derive$1([
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
}
|
|
}),
|
|
Tabstopping.config({}),
|
|
config('selectbox-change', [run(change(), function (component, _) {
|
|
emitWith(component, formChangeEvent, { name: spec.name });
|
|
})])
|
|
])
|
|
});
|
|
var chevron = spec.size > 1 ? Option.none() : Option.some({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-selectfield__icon-js'],
|
|
innerHtml: get$d('chevron-down', providersBackstage.icons)
|
|
}
|
|
});
|
|
var selectWrap = {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-selectfield']
|
|
},
|
|
components: flatten([
|
|
[pField],
|
|
chevron.toArray()
|
|
])
|
|
};
|
|
return FormField.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form__group']
|
|
},
|
|
components: flatten([
|
|
pLabel.toArray(),
|
|
[selectWrap]
|
|
]),
|
|
fieldBehaviours: derive$1([
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
},
|
|
onDisabled: function (comp) {
|
|
FormField.getField(comp).each(Disabling.disable);
|
|
},
|
|
onEnabled: function (comp) {
|
|
FormField.getField(comp).each(Disabling.enable);
|
|
}
|
|
}),
|
|
receivingConfig()
|
|
])
|
|
});
|
|
};
|
|
|
|
var renderTextField = function (spec, providersBackstage) {
|
|
var pLabel = spec.label.map(function (label) {
|
|
return renderLabel(label, providersBackstage);
|
|
});
|
|
var baseInputBehaviours = [
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
}
|
|
}),
|
|
receivingConfig(),
|
|
Keying.config({
|
|
mode: 'execution',
|
|
useEnter: spec.multiline !== true,
|
|
useControlEnter: spec.multiline === true,
|
|
execute: function (comp) {
|
|
emit(comp, formSubmitEvent);
|
|
return Option.some(true);
|
|
}
|
|
}),
|
|
config('textfield-change', [
|
|
run(input(), function (component, _) {
|
|
emitWith(component, formChangeEvent, { name: spec.name });
|
|
}),
|
|
run(postPaste(), function (component, _) {
|
|
emitWith(component, formChangeEvent, { name: spec.name });
|
|
})
|
|
]),
|
|
Tabstopping.config({})
|
|
];
|
|
var validatingBehaviours = spec.validation.map(function (vl) {
|
|
return Invalidating.config({
|
|
getRoot: function (input) {
|
|
return parent(input.element());
|
|
},
|
|
invalidClass: 'tox-invalid',
|
|
validator: {
|
|
validate: function (input) {
|
|
var v = Representing.getValue(input);
|
|
var result = vl.validator(v);
|
|
return Future.pure(result === true ? Result.value(v) : Result.error(result));
|
|
},
|
|
validateOnLoad: vl.validateOnLoad
|
|
}
|
|
});
|
|
}).toArray();
|
|
var placeholder = spec.placeholder.fold(constant({}), function (p) {
|
|
return { placeholder: providersBackstage.translate(p) };
|
|
});
|
|
var inputMode = spec.inputMode.fold(constant({}), function (mode) {
|
|
return { inputmode: mode };
|
|
});
|
|
var inputAttributes = __assign(__assign({}, placeholder), inputMode);
|
|
var pField = FormField.parts().field({
|
|
tag: spec.multiline === true ? 'textarea' : 'input',
|
|
inputAttributes: inputAttributes,
|
|
inputClasses: [spec.classname],
|
|
inputBehaviours: derive$1(flatten([
|
|
baseInputBehaviours,
|
|
validatingBehaviours
|
|
])),
|
|
selectOnFocus: false,
|
|
factory: Input
|
|
});
|
|
var extraClasses = spec.flex ? ['tox-form__group--stretched'] : [];
|
|
var extraClasses2 = extraClasses.concat(spec.maximized ? ['tox-form-group--maximize'] : []);
|
|
var extraBehaviours = [
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
},
|
|
onDisabled: function (comp) {
|
|
FormField.getField(comp).each(Disabling.disable);
|
|
},
|
|
onEnabled: function (comp) {
|
|
FormField.getField(comp).each(Disabling.enable);
|
|
}
|
|
}),
|
|
receivingConfig()
|
|
];
|
|
return renderFormFieldWith(pLabel, pField, extraClasses2, extraBehaviours);
|
|
};
|
|
var renderInput = function (spec, providersBackstage) {
|
|
return renderTextField({
|
|
name: spec.name,
|
|
multiline: false,
|
|
label: spec.label,
|
|
inputMode: spec.inputMode,
|
|
placeholder: spec.placeholder,
|
|
flex: false,
|
|
disabled: spec.disabled,
|
|
classname: 'tox-textfield',
|
|
validation: Option.none(),
|
|
maximized: spec.maximized
|
|
}, providersBackstage);
|
|
};
|
|
var renderTextarea = function (spec, providersBackstage) {
|
|
return renderTextField({
|
|
name: spec.name,
|
|
multiline: true,
|
|
label: spec.label,
|
|
inputMode: Option.none(),
|
|
placeholder: spec.placeholder,
|
|
flex: true,
|
|
disabled: spec.disabled,
|
|
classname: 'tox-textarea',
|
|
validation: Option.none(),
|
|
maximized: spec.maximized
|
|
}, providersBackstage);
|
|
};
|
|
|
|
var events$c = function (streamConfig, streamState) {
|
|
var streams = streamConfig.stream.streams;
|
|
var processor = streams.setup(streamConfig, streamState);
|
|
return derive([
|
|
run(streamConfig.event, processor),
|
|
runOnDetached(function () {
|
|
return streamState.cancel();
|
|
})
|
|
].concat(streamConfig.cancelEvent.map(function (e) {
|
|
return [run(e, function () {
|
|
return streamState.cancel();
|
|
})];
|
|
}).getOr([])));
|
|
};
|
|
|
|
var ActiveStreaming = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$c
|
|
});
|
|
|
|
var throttle = function (_config) {
|
|
var state = Cell(null);
|
|
var readState = function () {
|
|
return { timer: state.get() !== null ? 'set' : 'unset' };
|
|
};
|
|
var setTimer = function (t) {
|
|
state.set(t);
|
|
};
|
|
var cancel = function () {
|
|
var t = state.get();
|
|
if (t !== null) {
|
|
t.cancel();
|
|
}
|
|
};
|
|
return nu$5({
|
|
readState: readState,
|
|
setTimer: setTimer,
|
|
cancel: cancel
|
|
});
|
|
};
|
|
var init$6 = function (spec) {
|
|
return spec.stream.streams.state(spec);
|
|
};
|
|
|
|
var StreamingState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
throttle: throttle,
|
|
init: init$6
|
|
});
|
|
|
|
var setup$2 = function (streamInfo, streamState) {
|
|
var sInfo = streamInfo.stream;
|
|
var throttler = last$2(streamInfo.onStream, sInfo.delay);
|
|
streamState.setTimer(throttler);
|
|
return function (component, simulatedEvent) {
|
|
throttler.throttle(component, simulatedEvent);
|
|
if (sInfo.stopEvent) {
|
|
simulatedEvent.stop();
|
|
}
|
|
};
|
|
};
|
|
var StreamingSchema = [
|
|
strictOf('stream', choose$1('mode', {
|
|
throttle: [
|
|
strict$1('delay'),
|
|
defaulted$1('stopEvent', true),
|
|
output('streams', {
|
|
setup: setup$2,
|
|
state: throttle
|
|
})
|
|
]
|
|
})),
|
|
defaulted$1('event', 'input'),
|
|
option('cancelEvent'),
|
|
onStrictHandler('onStream')
|
|
];
|
|
|
|
var Streaming = create$1({
|
|
fields: StreamingSchema,
|
|
name: 'streaming',
|
|
active: ActiveStreaming,
|
|
state: StreamingState
|
|
});
|
|
|
|
var setValueFromItem = function (model, input, item) {
|
|
var itemData = Representing.getValue(item);
|
|
Representing.setValue(input, itemData);
|
|
setCursorAtEnd(input);
|
|
};
|
|
var setSelectionOn = function (input, f) {
|
|
var el = input.element();
|
|
var value = get$5(el);
|
|
var node = el.dom();
|
|
if (get$2(el, 'type') !== 'number') {
|
|
f(node, value);
|
|
}
|
|
};
|
|
var setCursorAtEnd = function (input) {
|
|
setSelectionOn(input, function (node, value) {
|
|
return node.setSelectionRange(value.length, value.length);
|
|
});
|
|
};
|
|
var setSelectionToEnd = function (input, startOffset) {
|
|
setSelectionOn(input, function (node, value) {
|
|
return node.setSelectionRange(startOffset, value.length);
|
|
});
|
|
};
|
|
var attemptSelectOver = function (model, input, item) {
|
|
if (!model.selectsOver) {
|
|
return Option.none();
|
|
} else {
|
|
var currentValue = Representing.getValue(input);
|
|
var inputDisplay_1 = model.getDisplayText(currentValue);
|
|
var itemValue = Representing.getValue(item);
|
|
var itemDisplay = model.getDisplayText(itemValue);
|
|
return itemDisplay.indexOf(inputDisplay_1) === 0 ? Option.some(function () {
|
|
setValueFromItem(model, input, item);
|
|
setSelectionToEnd(input, inputDisplay_1.length);
|
|
}) : Option.none();
|
|
}
|
|
};
|
|
|
|
var itemExecute = constant('alloy.typeahead.itemexecute');
|
|
|
|
var make$5 = function (detail, components, spec, externals) {
|
|
var navigateList = function (comp, simulatedEvent, highlighter) {
|
|
detail.previewing.set(false);
|
|
var sandbox = Coupling.getCoupled(comp, 'sandbox');
|
|
if (Sandboxing.isOpen(sandbox)) {
|
|
Composing.getCurrent(sandbox).each(function (menu) {
|
|
Highlighting.getHighlighted(menu).fold(function () {
|
|
highlighter(menu);
|
|
}, function () {
|
|
dispatchEvent(sandbox, menu.element(), 'keydown', simulatedEvent);
|
|
});
|
|
});
|
|
} else {
|
|
var onOpenSync = function (sandbox) {
|
|
Composing.getCurrent(sandbox).each(highlighter);
|
|
};
|
|
open$1(detail, mapFetch(comp), comp, sandbox, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
|
|
}
|
|
};
|
|
var focusBehaviours$1 = focusBehaviours(detail);
|
|
var mapFetch = function (comp) {
|
|
return function (tdata) {
|
|
return tdata.map(function (data) {
|
|
var menus = values(data.menus);
|
|
var items = bind(menus, function (menu) {
|
|
return filter(menu.items, function (item) {
|
|
return item.type === 'item';
|
|
});
|
|
});
|
|
var repState = Representing.getState(comp);
|
|
repState.update(map(items, function (item) {
|
|
return item.data;
|
|
}));
|
|
return data;
|
|
});
|
|
};
|
|
};
|
|
var behaviours = [
|
|
Focusing.config({}),
|
|
Representing.config({
|
|
onSetValue: detail.onSetValue,
|
|
store: __assign({
|
|
mode: 'dataset',
|
|
getDataKey: function (comp) {
|
|
return get$5(comp.element());
|
|
},
|
|
getFallbackEntry: function (itemString) {
|
|
return {
|
|
value: itemString,
|
|
meta: {}
|
|
};
|
|
},
|
|
setValue: function (comp, data) {
|
|
set$3(comp.element(), detail.model.getDisplayText(data));
|
|
}
|
|
}, detail.initialData.map(function (d) {
|
|
return wrap$1('initialValue', d);
|
|
}).getOr({}))
|
|
}),
|
|
Streaming.config({
|
|
stream: {
|
|
mode: 'throttle',
|
|
delay: detail.responseTime,
|
|
stopEvent: false
|
|
},
|
|
onStream: function (component, _simulatedEvent) {
|
|
var sandbox = Coupling.getCoupled(component, 'sandbox');
|
|
var focusInInput = Focusing.isFocused(component);
|
|
if (focusInInput) {
|
|
if (get$5(component.element()).length >= detail.minChars) {
|
|
var previousValue_1 = Composing.getCurrent(sandbox).bind(function (menu) {
|
|
return Highlighting.getHighlighted(menu).map(Representing.getValue);
|
|
});
|
|
detail.previewing.set(true);
|
|
var onOpenSync = function (_sandbox) {
|
|
Composing.getCurrent(sandbox).each(function (menu) {
|
|
previousValue_1.fold(function () {
|
|
if (detail.model.selectsOver) {
|
|
Highlighting.highlightFirst(menu);
|
|
}
|
|
}, function (pv) {
|
|
Highlighting.highlightBy(menu, function (item) {
|
|
var itemData = Representing.getValue(item);
|
|
return itemData.value === pv.value;
|
|
});
|
|
Highlighting.getHighlighted(menu).orThunk(function () {
|
|
Highlighting.highlightFirst(menu);
|
|
return Option.none();
|
|
});
|
|
});
|
|
});
|
|
};
|
|
open$1(detail, mapFetch(component), component, sandbox, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
|
|
}
|
|
}
|
|
},
|
|
cancelEvent: typeaheadCancel()
|
|
}),
|
|
Keying.config({
|
|
mode: 'special',
|
|
onDown: function (comp, simulatedEvent) {
|
|
navigateList(comp, simulatedEvent, Highlighting.highlightFirst);
|
|
return Option.some(true);
|
|
},
|
|
onEscape: function (comp) {
|
|
var sandbox = Coupling.getCoupled(comp, 'sandbox');
|
|
if (Sandboxing.isOpen(sandbox)) {
|
|
Sandboxing.close(sandbox);
|
|
return Option.some(true);
|
|
}
|
|
return Option.none();
|
|
},
|
|
onUp: function (comp, simulatedEvent) {
|
|
navigateList(comp, simulatedEvent, Highlighting.highlightLast);
|
|
return Option.some(true);
|
|
},
|
|
onEnter: function (comp) {
|
|
var sandbox = Coupling.getCoupled(comp, 'sandbox');
|
|
var sandboxIsOpen = Sandboxing.isOpen(sandbox);
|
|
if (sandboxIsOpen && !detail.previewing.get()) {
|
|
return Composing.getCurrent(sandbox).bind(function (menu) {
|
|
return Highlighting.getHighlighted(menu);
|
|
}).map(function (item) {
|
|
emitWith(comp, itemExecute(), { item: item });
|
|
return true;
|
|
});
|
|
} else {
|
|
var currentValue = Representing.getValue(comp);
|
|
emit(comp, typeaheadCancel());
|
|
detail.onExecute(sandbox, comp, currentValue);
|
|
if (sandboxIsOpen) {
|
|
Sandboxing.close(sandbox);
|
|
}
|
|
return Option.some(true);
|
|
}
|
|
}
|
|
}),
|
|
Toggling.config({
|
|
toggleClass: detail.markers.openClass,
|
|
aria: { mode: 'expanded' }
|
|
}),
|
|
Coupling.config({
|
|
others: {
|
|
sandbox: function (hotspot) {
|
|
return makeSandbox(detail, hotspot, {
|
|
onOpen: function () {
|
|
return Toggling.on(hotspot);
|
|
},
|
|
onClose: function () {
|
|
return Toggling.off(hotspot);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
}),
|
|
config('typeaheadevents', [
|
|
runOnExecute(function (comp) {
|
|
var onOpenSync = noop;
|
|
togglePopup(detail, mapFetch(comp), comp, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
|
|
}),
|
|
run(itemExecute(), function (comp, se) {
|
|
var sandbox = Coupling.getCoupled(comp, 'sandbox');
|
|
setValueFromItem(detail.model, comp, se.event().item());
|
|
emit(comp, typeaheadCancel());
|
|
detail.onItemExecute(comp, sandbox, se.event().item(), Representing.getValue(comp));
|
|
Sandboxing.close(sandbox);
|
|
setCursorAtEnd(comp);
|
|
})
|
|
].concat(detail.dismissOnBlur ? [run(postBlur(), function (typeahead) {
|
|
var sandbox = Coupling.getCoupled(typeahead, 'sandbox');
|
|
if (search(sandbox.element()).isNone()) {
|
|
Sandboxing.close(sandbox);
|
|
}
|
|
})] : []))
|
|
];
|
|
return {
|
|
uid: detail.uid,
|
|
dom: dom$2(deepMerge(detail, {
|
|
inputAttributes: {
|
|
'role': 'combobox',
|
|
'aria-autocomplete': 'list',
|
|
'aria-haspopup': 'true'
|
|
}
|
|
})),
|
|
behaviours: __assign(__assign({}, focusBehaviours$1), augment(detail.typeaheadBehaviours, behaviours)),
|
|
eventOrder: detail.eventOrder
|
|
};
|
|
};
|
|
|
|
var schema$j = constant([
|
|
option('lazySink'),
|
|
strict$1('fetch'),
|
|
defaulted$1('minChars', 5),
|
|
defaulted$1('responseTime', 1000),
|
|
onHandler('onOpen'),
|
|
defaulted$1('getHotspot', Option.some),
|
|
defaulted$1('getAnchorOverrides', constant({})),
|
|
defaulted$1('layouts', Option.none()),
|
|
defaulted$1('eventOrder', {}),
|
|
defaultedObjOf('model', {}, [
|
|
defaulted$1('getDisplayText', function (itemData) {
|
|
return itemData.meta !== undefined && itemData.meta.text !== undefined ? itemData.meta.text : itemData.value;
|
|
}),
|
|
defaulted$1('selectsOver', true),
|
|
defaulted$1('populateFromBrowse', true)
|
|
]),
|
|
onHandler('onSetValue'),
|
|
onKeyboardHandler('onExecute'),
|
|
onHandler('onItemExecute'),
|
|
defaulted$1('inputClasses', []),
|
|
defaulted$1('inputAttributes', {}),
|
|
defaulted$1('inputStyles', {}),
|
|
defaulted$1('matchWidth', true),
|
|
defaulted$1('useMinWidth', false),
|
|
defaulted$1('dismissOnBlur', true),
|
|
markers(['openClass']),
|
|
option('initialData'),
|
|
field$1('typeaheadBehaviours', [
|
|
Focusing,
|
|
Representing,
|
|
Streaming,
|
|
Keying,
|
|
Toggling,
|
|
Coupling
|
|
]),
|
|
state$1('previewing', function () {
|
|
return Cell(true);
|
|
})
|
|
].concat(schema$f()).concat(sandboxFields()));
|
|
var parts$6 = constant([external$1({
|
|
schema: [tieredMenuMarkers()],
|
|
name: 'menu',
|
|
overrides: function (detail) {
|
|
return {
|
|
fakeFocus: true,
|
|
onHighlight: function (menu, item) {
|
|
if (!detail.previewing.get()) {
|
|
menu.getSystem().getByUid(detail.uid).each(function (input) {
|
|
if (detail.model.populateFromBrowse) {
|
|
setValueFromItem(detail.model, input, item);
|
|
}
|
|
});
|
|
} else {
|
|
menu.getSystem().getByUid(detail.uid).each(function (input) {
|
|
attemptSelectOver(detail.model, input, item).fold(function () {
|
|
return Highlighting.dehighlight(menu, item);
|
|
}, function (fn) {
|
|
return fn();
|
|
});
|
|
});
|
|
}
|
|
detail.previewing.set(false);
|
|
},
|
|
onExecute: function (menu, item) {
|
|
return menu.getSystem().getByUid(detail.uid).toOption().map(function (typeahead) {
|
|
emitWith(typeahead, itemExecute(), { item: item });
|
|
return true;
|
|
});
|
|
},
|
|
onHover: function (menu, item) {
|
|
detail.previewing.set(false);
|
|
menu.getSystem().getByUid(detail.uid).each(function (input) {
|
|
if (detail.model.populateFromBrowse) {
|
|
setValueFromItem(detail.model, input, item);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}
|
|
})]);
|
|
|
|
var Typeahead = composite$1({
|
|
name: 'Typeahead',
|
|
configFields: schema$j(),
|
|
partFields: parts$6(),
|
|
factory: make$5
|
|
});
|
|
|
|
var wrap$2 = function (delegate) {
|
|
var toCached = function () {
|
|
return wrap$2(delegate.toCached());
|
|
};
|
|
var bindFuture = function (f) {
|
|
return wrap$2(delegate.bind(function (resA) {
|
|
return resA.fold(function (err) {
|
|
return Future.pure(Result.error(err));
|
|
}, function (a) {
|
|
return f(a);
|
|
});
|
|
}));
|
|
};
|
|
var bindResult = function (f) {
|
|
return wrap$2(delegate.map(function (resA) {
|
|
return resA.bind(f);
|
|
}));
|
|
};
|
|
var mapResult = function (f) {
|
|
return wrap$2(delegate.map(function (resA) {
|
|
return resA.map(f);
|
|
}));
|
|
};
|
|
var mapError = function (f) {
|
|
return wrap$2(delegate.map(function (resA) {
|
|
return resA.mapError(f);
|
|
}));
|
|
};
|
|
var foldResult = function (whenError, whenValue) {
|
|
return delegate.map(function (res) {
|
|
return res.fold(whenError, whenValue);
|
|
});
|
|
};
|
|
var withTimeout = function (timeout, errorThunk) {
|
|
return wrap$2(Future.nu(function (callback) {
|
|
var timedOut = false;
|
|
var timer = domGlobals.setTimeout(function () {
|
|
timedOut = true;
|
|
callback(Result.error(errorThunk()));
|
|
}, timeout);
|
|
delegate.get(function (result) {
|
|
if (!timedOut) {
|
|
domGlobals.clearTimeout(timer);
|
|
callback(result);
|
|
}
|
|
});
|
|
}));
|
|
};
|
|
return __assign(__assign({}, delegate), {
|
|
toCached: toCached,
|
|
bindFuture: bindFuture,
|
|
bindResult: bindResult,
|
|
mapResult: mapResult,
|
|
mapError: mapError,
|
|
foldResult: foldResult,
|
|
withTimeout: withTimeout
|
|
});
|
|
};
|
|
var nu$c = function (worker) {
|
|
return wrap$2(Future.nu(worker));
|
|
};
|
|
var value$2 = function (value) {
|
|
return wrap$2(Future.pure(Result.value(value)));
|
|
};
|
|
var error$1 = function (error) {
|
|
return wrap$2(Future.pure(Result.error(error)));
|
|
};
|
|
var fromResult$1 = function (result) {
|
|
return wrap$2(Future.pure(result));
|
|
};
|
|
var fromFuture = function (future) {
|
|
return wrap$2(future.map(Result.value));
|
|
};
|
|
var fromPromise = function (promise) {
|
|
return nu$c(function (completer) {
|
|
promise.then(function (value) {
|
|
completer(Result.value(value));
|
|
}, function (error) {
|
|
completer(Result.error(error));
|
|
});
|
|
});
|
|
};
|
|
var FutureResult = {
|
|
nu: nu$c,
|
|
wrap: wrap$2,
|
|
pure: value$2,
|
|
value: value$2,
|
|
error: error$1,
|
|
fromResult: fromResult$1,
|
|
fromFuture: fromFuture,
|
|
fromPromise: fromPromise
|
|
};
|
|
|
|
var separator$2 = { type: 'separator' };
|
|
var toMenuItem = function (target) {
|
|
return {
|
|
type: 'menuitem',
|
|
value: target.url,
|
|
text: target.title,
|
|
meta: { attach: target.attach },
|
|
onAction: function () {
|
|
}
|
|
};
|
|
};
|
|
var staticMenuItem = function (title, url) {
|
|
return {
|
|
type: 'menuitem',
|
|
value: url,
|
|
text: title,
|
|
meta: { attach: undefined },
|
|
onAction: function () {
|
|
}
|
|
};
|
|
};
|
|
var toMenuItems = function (targets) {
|
|
return map(targets, toMenuItem);
|
|
};
|
|
var filterLinkTargets = function (type, targets) {
|
|
return filter(targets, function (target) {
|
|
return target.type === type;
|
|
});
|
|
};
|
|
var filteredTargets = function (type, targets) {
|
|
return toMenuItems(filterLinkTargets(type, targets));
|
|
};
|
|
var headerTargets = function (linkInfo) {
|
|
return filteredTargets('header', linkInfo.targets);
|
|
};
|
|
var anchorTargets = function (linkInfo) {
|
|
return filteredTargets('anchor', linkInfo.targets);
|
|
};
|
|
var anchorTargetTop = function (linkInfo) {
|
|
return Option.from(linkInfo.anchorTop).map(function (url) {
|
|
return staticMenuItem('<top>', url);
|
|
}).toArray();
|
|
};
|
|
var anchorTargetBottom = function (linkInfo) {
|
|
return Option.from(linkInfo.anchorBottom).map(function (url) {
|
|
return staticMenuItem('<bottom>', url);
|
|
}).toArray();
|
|
};
|
|
var historyTargets = function (history) {
|
|
return map(history, function (url) {
|
|
return staticMenuItem(url, url);
|
|
});
|
|
};
|
|
var joinMenuLists = function (items) {
|
|
return foldl(items, function (a, b) {
|
|
var bothEmpty = a.length === 0 || b.length === 0;
|
|
return bothEmpty ? a.concat(b) : a.concat(separator$2, b);
|
|
}, []);
|
|
};
|
|
var filterByQuery = function (term, menuItems) {
|
|
var lowerCaseTerm = term.toLowerCase();
|
|
return filter(menuItems, function (item) {
|
|
var text = item.meta !== undefined && item.meta.text !== undefined ? item.meta.text : item.text;
|
|
return contains$1(text.toLowerCase(), lowerCaseTerm) || contains$1(item.value.toLowerCase(), lowerCaseTerm);
|
|
});
|
|
};
|
|
|
|
var getItems = function (fileType, input, urlBackstage) {
|
|
var urlInputValue = Representing.getValue(input);
|
|
var term = urlInputValue.meta.text !== undefined ? urlInputValue.meta.text : urlInputValue.value;
|
|
var info = urlBackstage.getLinkInformation();
|
|
return info.fold(function () {
|
|
return [];
|
|
}, function (linkInfo) {
|
|
var history = filterByQuery(term, historyTargets(urlBackstage.getHistory(fileType)));
|
|
return fileType === 'file' ? joinMenuLists([
|
|
history,
|
|
filterByQuery(term, headerTargets(linkInfo)),
|
|
filterByQuery(term, flatten([
|
|
anchorTargetTop(linkInfo),
|
|
anchorTargets(linkInfo),
|
|
anchorTargetBottom(linkInfo)
|
|
]))
|
|
]) : history;
|
|
});
|
|
};
|
|
var errorId = generate$1('aria-invalid');
|
|
var renderUrlInput = function (spec, backstage, urlBackstage) {
|
|
var _a;
|
|
var providersBackstage = backstage.shared.providers;
|
|
var updateHistory = function (component) {
|
|
var urlEntry = Representing.getValue(component);
|
|
urlBackstage.addToHistory(urlEntry.value, spec.filetype);
|
|
};
|
|
var pField = FormField.parts().field({
|
|
factory: Typeahead,
|
|
dismissOnBlur: true,
|
|
inputClasses: ['tox-textfield'],
|
|
sandboxClasses: ['tox-dialog__popups'],
|
|
inputAttributes: {
|
|
'aria-errormessage': errorId,
|
|
'type': 'url'
|
|
},
|
|
minChars: 0,
|
|
responseTime: 0,
|
|
fetch: function (input) {
|
|
var items = getItems(spec.filetype, input, urlBackstage);
|
|
var tdata = build$2(items, ItemResponse$1.BUBBLE_TO_SANDBOX, backstage, false);
|
|
return Future.pure(tdata);
|
|
},
|
|
getHotspot: function (comp) {
|
|
return memUrlBox.getOpt(comp);
|
|
},
|
|
onSetValue: function (comp, _newValue) {
|
|
if (comp.hasConfigured(Invalidating)) {
|
|
Invalidating.run(comp).get(noop);
|
|
}
|
|
},
|
|
typeaheadBehaviours: derive$1(flatten([
|
|
urlBackstage.getValidationHandler().map(function (handler) {
|
|
return Invalidating.config({
|
|
getRoot: function (comp) {
|
|
return parent(comp.element());
|
|
},
|
|
invalidClass: 'tox-control-wrap--status-invalid',
|
|
notify: {
|
|
onInvalid: function (comp, err) {
|
|
memInvalidIcon.getOpt(comp).each(function (invalidComp) {
|
|
set$1(invalidComp.element(), 'title', providersBackstage.translate(err));
|
|
});
|
|
}
|
|
},
|
|
validator: {
|
|
validate: function (input) {
|
|
var urlEntry = Representing.getValue(input);
|
|
return FutureResult.nu(function (completer) {
|
|
handler({
|
|
type: spec.filetype,
|
|
url: urlEntry.value
|
|
}, function (validation) {
|
|
if (validation.status === 'invalid') {
|
|
var err = Result.error(validation.message);
|
|
completer(err);
|
|
} else {
|
|
var val = Result.value(validation.message);
|
|
completer(val);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
validateOnLoad: false
|
|
}
|
|
});
|
|
}).toArray(),
|
|
[
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
}
|
|
}),
|
|
Tabstopping.config({}),
|
|
config('urlinput-events', flatten([
|
|
spec.filetype === 'file' ? [run(input(), function (comp) {
|
|
emitWith(comp, formChangeEvent, { name: spec.name });
|
|
})] : [],
|
|
[
|
|
run(change(), function (comp) {
|
|
emitWith(comp, formChangeEvent, { name: spec.name });
|
|
updateHistory(comp);
|
|
}),
|
|
run(postPaste(), function (comp) {
|
|
emitWith(comp, formChangeEvent, { name: spec.name });
|
|
updateHistory(comp);
|
|
})
|
|
]
|
|
]))
|
|
]
|
|
])),
|
|
eventOrder: (_a = {}, _a[input()] = [
|
|
'streaming',
|
|
'urlinput-events',
|
|
'invalidating'
|
|
], _a),
|
|
model: {
|
|
getDisplayText: function (itemData) {
|
|
return itemData.value;
|
|
},
|
|
selectsOver: false,
|
|
populateFromBrowse: false
|
|
},
|
|
markers: { openClass: 'tox-textfield--popup-open' },
|
|
lazySink: backstage.shared.getSink,
|
|
parts: { menu: part(false, 1, 'normal') },
|
|
onExecute: function (_menu, component, _entry) {
|
|
emitWith(component, formSubmitEvent, {});
|
|
},
|
|
onItemExecute: function (typeahead, _sandbox, _item, _value) {
|
|
updateHistory(typeahead);
|
|
emitWith(typeahead, formChangeEvent, { name: spec.name });
|
|
}
|
|
});
|
|
var pLabel = spec.label.map(function (label) {
|
|
return renderLabel(label, providersBackstage);
|
|
});
|
|
var makeIcon = function (name, errId, icon, label) {
|
|
if (icon === void 0) {
|
|
icon = name;
|
|
}
|
|
if (label === void 0) {
|
|
label = name;
|
|
}
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-icon',
|
|
'tox-control-wrap__status-icon-' + name
|
|
],
|
|
innerHtml: get$d(icon, providersBackstage.icons),
|
|
attributes: __assign({
|
|
'title': providersBackstage.translate(label),
|
|
'aria-live': 'polite'
|
|
}, errId.fold(function () {
|
|
return {};
|
|
}, function (id) {
|
|
return { id: id };
|
|
}))
|
|
}
|
|
};
|
|
};
|
|
var memInvalidIcon = record(makeIcon('invalid', Option.some(errorId), 'warning'));
|
|
var memStatus = record({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-control-wrap__status-icon-wrap']
|
|
},
|
|
components: [memInvalidIcon.asSpec()]
|
|
});
|
|
var optUrlPicker = urlBackstage.getUrlPicker(spec.filetype);
|
|
var browseUrlEvent = generate$1('browser.url.event');
|
|
var memUrlBox = record({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-control-wrap']
|
|
},
|
|
components: [
|
|
pField,
|
|
memStatus.asSpec()
|
|
],
|
|
behaviours: derive$1([Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
}
|
|
})])
|
|
});
|
|
var memUrlPickerButton = record(renderButton({
|
|
name: spec.name,
|
|
icon: Option.some('browse'),
|
|
text: spec.label.getOr(''),
|
|
disabled: spec.disabled,
|
|
primary: false,
|
|
borderless: true
|
|
}, function (component) {
|
|
return emit(component, browseUrlEvent);
|
|
}, providersBackstage, [], ['tox-browse-url']));
|
|
var controlHWrapper = function () {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form__controls-h-stack']
|
|
},
|
|
components: flatten([
|
|
[memUrlBox.asSpec()],
|
|
optUrlPicker.map(function () {
|
|
return memUrlPickerButton.asSpec();
|
|
}).toArray()
|
|
])
|
|
};
|
|
};
|
|
var openUrlPicker = function (comp) {
|
|
Composing.getCurrent(comp).each(function (field) {
|
|
var componentData = Representing.getValue(field);
|
|
var urlData = __assign({ fieldname: spec.name }, componentData);
|
|
optUrlPicker.each(function (picker) {
|
|
picker(urlData).get(function (chosenData) {
|
|
Representing.setValue(field, chosenData);
|
|
emitWith(comp, formChangeEvent, { name: spec.name });
|
|
});
|
|
});
|
|
});
|
|
};
|
|
return FormField.sketch({
|
|
dom: renderFormFieldDom(),
|
|
components: pLabel.toArray().concat([controlHWrapper()]),
|
|
fieldBehaviours: derive$1([
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
},
|
|
onDisabled: function (comp) {
|
|
FormField.getField(comp).each(Disabling.disable);
|
|
memUrlPickerButton.getOpt(comp).each(Disabling.disable);
|
|
},
|
|
onEnabled: function (comp) {
|
|
FormField.getField(comp).each(Disabling.enable);
|
|
memUrlPickerButton.getOpt(comp).each(Disabling.enable);
|
|
}
|
|
}),
|
|
receivingConfig(),
|
|
config('url-input-events', [run(browseUrlEvent, openUrlPicker)])
|
|
])
|
|
});
|
|
};
|
|
|
|
var renderCheckbox = function (spec, providerBackstage) {
|
|
var repBehaviour = Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (comp) {
|
|
var el = comp.element().dom();
|
|
return el.checked;
|
|
},
|
|
setValue: function (comp, value) {
|
|
var el = comp.element().dom();
|
|
el.checked = value;
|
|
}
|
|
}
|
|
});
|
|
var toggleCheckboxHandler = function (comp) {
|
|
comp.element().dom().click();
|
|
return Option.some(true);
|
|
};
|
|
var pField = FormField.parts().field({
|
|
factory: { sketch: identity },
|
|
dom: {
|
|
tag: 'input',
|
|
classes: ['tox-checkbox__input'],
|
|
attributes: { type: 'checkbox' }
|
|
},
|
|
behaviours: derive$1([
|
|
ComposingConfigs.self(),
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providerBackstage.isReadOnly();
|
|
}
|
|
}),
|
|
Tabstopping.config({}),
|
|
Focusing.config({}),
|
|
repBehaviour,
|
|
Keying.config({
|
|
mode: 'special',
|
|
onEnter: toggleCheckboxHandler,
|
|
onSpace: toggleCheckboxHandler,
|
|
stopSpaceKeyup: true
|
|
}),
|
|
config('checkbox-events', [run(change(), function (component, _) {
|
|
emitWith(component, formChangeEvent, { name: spec.name });
|
|
})])
|
|
])
|
|
});
|
|
var pLabel = FormField.parts().label({
|
|
dom: {
|
|
tag: 'span',
|
|
classes: ['tox-checkbox__label'],
|
|
innerHtml: providerBackstage.translate(spec.label)
|
|
},
|
|
behaviours: derive$1([Unselecting.config({})])
|
|
});
|
|
var makeIcon = function (className) {
|
|
var iconName = className === 'checked' ? 'selected' : 'unselected';
|
|
return {
|
|
dom: {
|
|
tag: 'span',
|
|
classes: [
|
|
'tox-icon',
|
|
'tox-checkbox-icon__' + className
|
|
],
|
|
innerHtml: get$d(iconName, providerBackstage.icons)
|
|
}
|
|
};
|
|
};
|
|
var memIcons = record({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-checkbox__icons']
|
|
},
|
|
components: [
|
|
makeIcon('checked'),
|
|
makeIcon('unchecked')
|
|
]
|
|
});
|
|
return FormField.sketch({
|
|
dom: {
|
|
tag: 'label',
|
|
classes: ['tox-checkbox']
|
|
},
|
|
components: [
|
|
pField,
|
|
memIcons.asSpec(),
|
|
pLabel
|
|
],
|
|
fieldBehaviours: derive$1([
|
|
Disabling.config({
|
|
disabled: function () {
|
|
return spec.disabled || providerBackstage.isReadOnly();
|
|
},
|
|
disableClass: 'tox-checkbox--disabled',
|
|
onDisabled: function (comp) {
|
|
FormField.getField(comp).each(Disabling.disable);
|
|
},
|
|
onEnabled: function (comp) {
|
|
FormField.getField(comp).each(Disabling.enable);
|
|
}
|
|
}),
|
|
receivingConfig()
|
|
])
|
|
});
|
|
};
|
|
|
|
var renderHtmlPanel = function (spec) {
|
|
if (spec.presets === 'presentation') {
|
|
return Container.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form__group'],
|
|
innerHtml: spec.html
|
|
}
|
|
});
|
|
} else {
|
|
return Container.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form__group'],
|
|
innerHtml: spec.html,
|
|
attributes: { role: 'document' }
|
|
},
|
|
containerBehaviours: derive$1([
|
|
Tabstopping.config({}),
|
|
Focusing.config({})
|
|
])
|
|
});
|
|
}
|
|
};
|
|
|
|
var renderLabel$2 = function (spec, backstageShared) {
|
|
var label = {
|
|
dom: {
|
|
tag: 'label',
|
|
innerHtml: backstageShared.providers.translate(spec.label),
|
|
classes: ['tox-label']
|
|
}
|
|
};
|
|
var comps = map(spec.items, backstageShared.interpreter);
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form__group']
|
|
},
|
|
components: [label].concat(comps),
|
|
behaviours: derive$1([
|
|
ComposingConfigs.self(),
|
|
Replacing.config({}),
|
|
RepresentingConfigs.domHtml(Option.none()),
|
|
Keying.config({ mode: 'acyclic' })
|
|
])
|
|
};
|
|
};
|
|
|
|
var renderCollection = function (spec, providersBackstage) {
|
|
var pLabel = spec.label.map(function (label) {
|
|
return renderLabel(label, providersBackstage);
|
|
});
|
|
var runOnItem = function (f) {
|
|
return function (comp, se) {
|
|
closest$3(se.event().target(), '[data-collection-item-value]').each(function (target) {
|
|
f(comp, se, target, get$2(target, 'data-collection-item-value'));
|
|
});
|
|
};
|
|
};
|
|
var escapeAttribute = function (ch) {
|
|
if (ch === '"') {
|
|
return '"';
|
|
}
|
|
return ch;
|
|
};
|
|
var setContents = function (comp, items) {
|
|
var htmlLines = map(items, function (item) {
|
|
var itemText = global$5.translate(item.text);
|
|
var textContent = spec.columns === 1 ? '<div class="tox-collection__item-label">' + itemText + '</div>' : '';
|
|
var iconContent = '<div class="tox-collection__item-icon">' + item.icon + '</div>';
|
|
var mapItemName = {
|
|
'_': ' ',
|
|
' - ': ' ',
|
|
'-': ' '
|
|
};
|
|
var ariaLabel = itemText.replace(/\_| \- |\-/g, function (match) {
|
|
return mapItemName[match];
|
|
});
|
|
var readonlyClass = providersBackstage.isReadOnly() ? ' tox-collection__item--state-disabled' : '';
|
|
return '<div class="tox-collection__item' + readonlyClass + '" tabindex="-1" data-collection-item-value="' + escapeAttribute(item.value) + '" title="' + ariaLabel + '" aria-label="' + ariaLabel + '">' + iconContent + textContent + '</div>';
|
|
});
|
|
var chunks = spec.columns > 1 && spec.columns !== 'auto' ? chunk(htmlLines, spec.columns) : [htmlLines];
|
|
var html = map(chunks, function (ch) {
|
|
return '<div class="tox-collection__group">' + ch.join('') + '</div>';
|
|
});
|
|
set(comp.element(), html.join(''));
|
|
};
|
|
var onClick = runOnItem(function (comp, se, tgt, itemValue) {
|
|
se.stop();
|
|
if (!providersBackstage.isReadOnly()) {
|
|
emitWith(comp, formActionEvent, {
|
|
name: spec.name,
|
|
value: itemValue
|
|
});
|
|
}
|
|
});
|
|
var collectionEvents = [
|
|
run(mouseover(), runOnItem(function (comp, se, tgt) {
|
|
focus$1(tgt);
|
|
})),
|
|
run(click(), onClick),
|
|
run(tap(), onClick),
|
|
run(focusin(), runOnItem(function (comp, se, tgt) {
|
|
descendant$1(comp.element(), '.' + activeClass).each(function (currentActive) {
|
|
remove$4(currentActive, activeClass);
|
|
});
|
|
add$2(tgt, activeClass);
|
|
})),
|
|
run(focusout(), runOnItem(function (comp) {
|
|
descendant$1(comp.element(), '.' + activeClass).each(function (currentActive) {
|
|
remove$4(currentActive, activeClass);
|
|
});
|
|
})),
|
|
runOnExecute(runOnItem(function (comp, se, tgt, itemValue) {
|
|
emitWith(comp, formActionEvent, {
|
|
name: spec.name,
|
|
value: itemValue
|
|
});
|
|
}))
|
|
];
|
|
var iterCollectionItems = function (comp, applyAttributes) {
|
|
return map(descendants(comp.element(), '.tox-collection__item'), applyAttributes);
|
|
};
|
|
var pField = FormField.parts().field({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-collection'].concat(spec.columns !== 1 ? ['tox-collection--grid'] : ['tox-collection--list'])
|
|
},
|
|
components: [],
|
|
factory: { sketch: identity },
|
|
behaviours: derive$1([
|
|
Disabling.config({
|
|
disabled: providersBackstage.isReadOnly,
|
|
onDisabled: function (comp) {
|
|
iterCollectionItems(comp, function (childElm) {
|
|
add$2(childElm, 'tox-collection__item--state-disabled');
|
|
set$1(childElm, 'aria-disabled', true);
|
|
});
|
|
},
|
|
onEnabled: function (comp) {
|
|
iterCollectionItems(comp, function (childElm) {
|
|
remove$4(childElm, 'tox-collection__item--state-disabled');
|
|
remove$1(childElm, 'aria-disabled');
|
|
});
|
|
}
|
|
}),
|
|
receivingConfig(),
|
|
Replacing.config({}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: []
|
|
},
|
|
onSetValue: function (comp, items) {
|
|
setContents(comp, items);
|
|
if (spec.columns === 'auto') {
|
|
detectSize(comp, 5, 'tox-collection__item').each(function (_a) {
|
|
var numRows = _a.numRows, numColumns = _a.numColumns;
|
|
Keying.setGridSize(comp, numRows, numColumns);
|
|
});
|
|
}
|
|
emit(comp, formResizeEvent);
|
|
}
|
|
}),
|
|
Tabstopping.config({}),
|
|
Keying.config(deriveCollectionMovement(spec.columns, 'normal')),
|
|
config('collection-events', collectionEvents)
|
|
]),
|
|
eventOrder: {
|
|
'alloy.execute': [
|
|
'disabling',
|
|
'alloy.base.behaviour',
|
|
'collection-events'
|
|
]
|
|
}
|
|
});
|
|
var extraClasses = ['tox-form__group--collection'];
|
|
return renderFormFieldWith(pLabel, pField, extraClasses, []);
|
|
};
|
|
|
|
var renderTable = function (spec, providersBackstage) {
|
|
var renderTh = function (text) {
|
|
return {
|
|
dom: {
|
|
tag: 'th',
|
|
innerHtml: providersBackstage.translate(text)
|
|
}
|
|
};
|
|
};
|
|
var renderHeader = function (header) {
|
|
return {
|
|
dom: { tag: 'thead' },
|
|
components: [{
|
|
dom: { tag: 'tr' },
|
|
components: map(header, renderTh)
|
|
}]
|
|
};
|
|
};
|
|
var renderTd = function (text) {
|
|
return {
|
|
dom: {
|
|
tag: 'td',
|
|
innerHtml: providersBackstage.translate(text)
|
|
}
|
|
};
|
|
};
|
|
var renderTr = function (row) {
|
|
return {
|
|
dom: { tag: 'tr' },
|
|
components: map(row, renderTd)
|
|
};
|
|
};
|
|
var renderRows = function (rows) {
|
|
return {
|
|
dom: { tag: 'tbody' },
|
|
components: map(rows, renderTr)
|
|
};
|
|
};
|
|
return {
|
|
dom: {
|
|
tag: 'table',
|
|
classes: ['tox-dialog__table']
|
|
},
|
|
components: [
|
|
renderHeader(spec.header),
|
|
renderRows(spec.cells)
|
|
],
|
|
behaviours: derive$1([
|
|
Tabstopping.config({}),
|
|
Focusing.config({})
|
|
])
|
|
};
|
|
};
|
|
|
|
var renderPanel = function (spec, backstage) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: spec.classes
|
|
},
|
|
components: map(spec.items, backstage.shared.interpreter)
|
|
};
|
|
};
|
|
|
|
var make$6 = function (render) {
|
|
return function (parts, spec, backstage) {
|
|
return get(spec, 'name').fold(function () {
|
|
return render(spec, backstage);
|
|
}, function (fieldName) {
|
|
return parts.field(fieldName, render(spec, backstage));
|
|
});
|
|
};
|
|
};
|
|
var makeIframe = function (render) {
|
|
return function (parts, spec, backstage) {
|
|
var iframeSpec = deepMerge(spec, { source: 'dynamic' });
|
|
return make$6(render)(parts, iframeSpec, backstage);
|
|
};
|
|
};
|
|
var factories = {
|
|
bar: make$6(function (spec, backstage) {
|
|
return renderBar(spec, backstage.shared);
|
|
}),
|
|
collection: make$6(function (spec, backstage) {
|
|
return renderCollection(spec, backstage.shared.providers);
|
|
}),
|
|
alertbanner: make$6(function (spec, backstage) {
|
|
return renderAlertBanner(spec, backstage.shared.providers);
|
|
}),
|
|
input: make$6(function (spec, backstage) {
|
|
return renderInput(spec, backstage.shared.providers);
|
|
}),
|
|
textarea: make$6(function (spec, backstage) {
|
|
return renderTextarea(spec, backstage.shared.providers);
|
|
}),
|
|
label: make$6(function (spec, backstage) {
|
|
return renderLabel$2(spec, backstage.shared);
|
|
}),
|
|
iframe: makeIframe(function (spec, backstage) {
|
|
return renderIFrame(spec, backstage.shared.providers);
|
|
}),
|
|
button: make$6(function (spec, backstage) {
|
|
return renderDialogButton(spec, backstage.shared.providers);
|
|
}),
|
|
checkbox: make$6(function (spec, backstage) {
|
|
return renderCheckbox(spec, backstage.shared.providers);
|
|
}),
|
|
colorinput: make$6(function (spec, backstage) {
|
|
return renderColorInput(spec, backstage.shared, backstage.colorinput);
|
|
}),
|
|
colorpicker: make$6(renderColorPicker),
|
|
dropzone: make$6(function (spec, backstage) {
|
|
return renderDropZone(spec, backstage.shared.providers);
|
|
}),
|
|
grid: make$6(function (spec, backstage) {
|
|
return renderGrid(spec, backstage.shared);
|
|
}),
|
|
selectbox: make$6(function (spec, backstage) {
|
|
return renderSelectBox(spec, backstage.shared.providers);
|
|
}),
|
|
sizeinput: make$6(function (spec, backstage) {
|
|
return renderSizeInput(spec, backstage.shared.providers);
|
|
}),
|
|
urlinput: make$6(function (spec, backstage) {
|
|
return renderUrlInput(spec, backstage, backstage.urlinput);
|
|
}),
|
|
customeditor: make$6(renderCustomEditor),
|
|
htmlpanel: make$6(renderHtmlPanel),
|
|
imagetools: make$6(function (spec, backstage) {
|
|
return renderImageTools(spec, backstage.shared.providers);
|
|
}),
|
|
table: make$6(function (spec, backstage) {
|
|
return renderTable(spec, backstage.shared.providers);
|
|
}),
|
|
panel: make$6(function (spec, backstage) {
|
|
return renderPanel(spec, backstage);
|
|
})
|
|
};
|
|
var noFormParts = {
|
|
field: function (_name, spec) {
|
|
return spec;
|
|
}
|
|
};
|
|
var interpretInForm = function (parts, spec, oldBackstage) {
|
|
var newBackstage = deepMerge(oldBackstage, {
|
|
shared: {
|
|
interpreter: function (childSpec) {
|
|
return interpretParts(parts, childSpec, newBackstage);
|
|
}
|
|
}
|
|
});
|
|
return interpretParts(parts, spec, newBackstage);
|
|
};
|
|
var interpretParts = function (parts, spec, backstage) {
|
|
return get(factories, spec.type).fold(function () {
|
|
domGlobals.console.error('Unknown factory type "' + spec.type + '", defaulting to container: ', spec);
|
|
return spec;
|
|
}, function (factory) {
|
|
return factory(parts, spec, backstage);
|
|
});
|
|
};
|
|
var interpretWithoutForm = function (spec, backstage) {
|
|
var parts = noFormParts;
|
|
return interpretParts(parts, spec, backstage);
|
|
};
|
|
|
|
var bubbleAlignments = {
|
|
valignCentre: [],
|
|
alignCentre: [],
|
|
alignLeft: [],
|
|
alignRight: [],
|
|
right: [],
|
|
left: [],
|
|
bottom: [],
|
|
top: []
|
|
};
|
|
var getInlineDialogAnchor = function (contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor) {
|
|
var bubble = nu$8(-12, 12, bubbleAlignments);
|
|
var overrides = { maxHeightFunction: expandable() };
|
|
var editableAreaAnchor = function () {
|
|
return {
|
|
anchor: 'node',
|
|
root: getBody(owner(contentAreaElement())),
|
|
node: Option.from(contentAreaElement()),
|
|
bubble: bubble,
|
|
layouts: {
|
|
onRtl: function () {
|
|
return [northwest$3];
|
|
},
|
|
onLtr: function () {
|
|
return [northeast$3];
|
|
}
|
|
},
|
|
overrides: overrides
|
|
};
|
|
};
|
|
var standardAnchor = function () {
|
|
return {
|
|
anchor: 'hotspot',
|
|
hotspot: lazyAnchorbar(),
|
|
bubble: bubble,
|
|
layouts: {
|
|
onRtl: function () {
|
|
return [southeast$1];
|
|
},
|
|
onLtr: function () {
|
|
return [southwest$1];
|
|
}
|
|
},
|
|
overrides: overrides
|
|
};
|
|
};
|
|
return function () {
|
|
return lazyUseEditableAreaAnchor() ? editableAreaAnchor() : standardAnchor();
|
|
};
|
|
};
|
|
var getBannerAnchor = function (contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor) {
|
|
var editableAreaAnchor = function () {
|
|
return {
|
|
anchor: 'node',
|
|
root: getBody(owner(contentAreaElement())),
|
|
node: Option.from(contentAreaElement()),
|
|
layouts: {
|
|
onRtl: function () {
|
|
return [north$3];
|
|
},
|
|
onLtr: function () {
|
|
return [north$3];
|
|
}
|
|
}
|
|
};
|
|
};
|
|
var standardAnchor = function () {
|
|
return {
|
|
anchor: 'hotspot',
|
|
hotspot: lazyAnchorbar(),
|
|
layouts: {
|
|
onRtl: function () {
|
|
return [south$1];
|
|
},
|
|
onLtr: function () {
|
|
return [south$1];
|
|
}
|
|
}
|
|
};
|
|
};
|
|
return function () {
|
|
return lazyUseEditableAreaAnchor() ? editableAreaAnchor() : standardAnchor();
|
|
};
|
|
};
|
|
var getCursorAnchor = function (editor, bodyElement) {
|
|
return function () {
|
|
return {
|
|
anchor: 'selection',
|
|
root: bodyElement(),
|
|
getSelection: function () {
|
|
var rng = editor.selection.getRng();
|
|
return Option.some(Selection.range(Element.fromDom(rng.startContainer), rng.startOffset, Element.fromDom(rng.endContainer), rng.endOffset));
|
|
}
|
|
};
|
|
};
|
|
};
|
|
var getNodeAnchor = function (bodyElement) {
|
|
return function (element) {
|
|
return {
|
|
anchor: 'node',
|
|
root: bodyElement(),
|
|
node: element
|
|
};
|
|
};
|
|
};
|
|
var getAnchors = function (editor, lazyAnchorbar, isToolbarTop) {
|
|
var useFixedToolbarContainer = useFixedContainer(editor);
|
|
var bodyElement = function () {
|
|
return Element.fromDom(editor.getBody());
|
|
};
|
|
var contentAreaElement = function () {
|
|
return Element.fromDom(editor.getContentAreaContainer());
|
|
};
|
|
var lazyUseEditableAreaAnchor = function () {
|
|
return useFixedToolbarContainer || !isToolbarTop();
|
|
};
|
|
return {
|
|
inlineDialog: getInlineDialogAnchor(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor),
|
|
banner: getBannerAnchor(contentAreaElement, lazyAnchorbar, lazyUseEditableAreaAnchor),
|
|
cursor: getCursorAnchor(editor, bodyElement),
|
|
node: getNodeAnchor(bodyElement)
|
|
};
|
|
};
|
|
|
|
var colorPicker = function (editor) {
|
|
return function (callback, value) {
|
|
var dialog = colorPickerDialog(editor);
|
|
dialog(callback, value);
|
|
};
|
|
};
|
|
var hasCustomColors$1 = function (editor) {
|
|
return function () {
|
|
return hasCustomColors(editor);
|
|
};
|
|
};
|
|
var getColors$2 = function (editor) {
|
|
return function () {
|
|
return getColors(editor);
|
|
};
|
|
};
|
|
var getColorCols$2 = function (editor) {
|
|
return function () {
|
|
return getColorCols$1(editor);
|
|
};
|
|
};
|
|
var ColorInputBackstage = function (editor) {
|
|
return {
|
|
colorPicker: colorPicker(editor),
|
|
hasCustomColors: hasCustomColors$1(editor),
|
|
getColors: getColors$2(editor),
|
|
getColorCols: getColorCols$2(editor)
|
|
};
|
|
};
|
|
|
|
var isDraggableModal$1 = function (editor) {
|
|
return function () {
|
|
return isDraggableModal(editor);
|
|
};
|
|
};
|
|
var DialogBackstage = function (editor) {
|
|
return { isDraggableModal: isDraggableModal$1(editor) };
|
|
};
|
|
|
|
var HeaderBackstage = function (editor) {
|
|
var mode = Cell(isToolbarLocationBottom(editor) ? 'bottom' : 'top');
|
|
return {
|
|
isPositionedAtTop: function () {
|
|
return mode.get() === 'top';
|
|
},
|
|
getDockingMode: mode.get,
|
|
setDockingMode: mode.set
|
|
};
|
|
};
|
|
|
|
var defaultStyleFormats = [
|
|
{
|
|
title: 'Headings',
|
|
items: [
|
|
{
|
|
title: 'Heading 1',
|
|
format: 'h1'
|
|
},
|
|
{
|
|
title: 'Heading 2',
|
|
format: 'h2'
|
|
},
|
|
{
|
|
title: 'Heading 3',
|
|
format: 'h3'
|
|
},
|
|
{
|
|
title: 'Heading 4',
|
|
format: 'h4'
|
|
},
|
|
{
|
|
title: 'Heading 5',
|
|
format: 'h5'
|
|
},
|
|
{
|
|
title: 'Heading 6',
|
|
format: 'h6'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
title: 'Inline',
|
|
items: [
|
|
{
|
|
title: 'Bold',
|
|
format: 'bold'
|
|
},
|
|
{
|
|
title: 'Italic',
|
|
format: 'italic'
|
|
},
|
|
{
|
|
title: 'Underline',
|
|
format: 'underline'
|
|
},
|
|
{
|
|
title: 'Strikethrough',
|
|
format: 'strikethrough'
|
|
},
|
|
{
|
|
title: 'Superscript',
|
|
format: 'superscript'
|
|
},
|
|
{
|
|
title: 'Subscript',
|
|
format: 'subscript'
|
|
},
|
|
{
|
|
title: 'Code',
|
|
format: 'code'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
title: 'Blocks',
|
|
items: [
|
|
{
|
|
title: 'Paragraph',
|
|
format: 'p'
|
|
},
|
|
{
|
|
title: 'Blockquote',
|
|
format: 'blockquote'
|
|
},
|
|
{
|
|
title: 'Div',
|
|
format: 'div'
|
|
},
|
|
{
|
|
title: 'Pre',
|
|
format: 'pre'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
title: 'Align',
|
|
items: [
|
|
{
|
|
title: 'Left',
|
|
format: 'alignleft'
|
|
},
|
|
{
|
|
title: 'Center',
|
|
format: 'aligncenter'
|
|
},
|
|
{
|
|
title: 'Right',
|
|
format: 'alignright'
|
|
},
|
|
{
|
|
title: 'Justify',
|
|
format: 'alignjustify'
|
|
}
|
|
]
|
|
}
|
|
];
|
|
var isNestedFormat = function (format) {
|
|
return has(format, 'items');
|
|
};
|
|
var isBlockFormat = function (format) {
|
|
return has(format, 'block');
|
|
};
|
|
var isInlineFormat = function (format) {
|
|
return has(format, 'inline');
|
|
};
|
|
var isSelectorFormat = function (format) {
|
|
return has(format, 'selector');
|
|
};
|
|
var mapFormats = function (userFormats) {
|
|
return foldl(userFormats, function (acc, fmt) {
|
|
if (isNestedFormat(fmt)) {
|
|
var result = mapFormats(fmt.items);
|
|
return {
|
|
customFormats: acc.customFormats.concat(result.customFormats),
|
|
formats: acc.formats.concat([{
|
|
title: fmt.title,
|
|
items: result.formats
|
|
}])
|
|
};
|
|
} else if (isInlineFormat(fmt) || isBlockFormat(fmt) || isSelectorFormat(fmt)) {
|
|
var formatName = 'custom-' + fmt.title.toLowerCase();
|
|
return {
|
|
customFormats: acc.customFormats.concat([{
|
|
name: formatName,
|
|
format: fmt
|
|
}]),
|
|
formats: acc.formats.concat([{
|
|
title: fmt.title,
|
|
format: formatName,
|
|
icon: fmt.icon
|
|
}])
|
|
};
|
|
} else {
|
|
return __assign(__assign({}, acc), { formats: acc.formats.concat(fmt) });
|
|
}
|
|
}, {
|
|
customFormats: [],
|
|
formats: []
|
|
});
|
|
};
|
|
var registerCustomFormats = function (editor, userFormats) {
|
|
var result = mapFormats(userFormats);
|
|
var registerFormats = function (customFormats) {
|
|
each(customFormats, function (fmt) {
|
|
if (!editor.formatter.has(fmt.name)) {
|
|
editor.formatter.register(fmt.name, fmt.format);
|
|
}
|
|
});
|
|
};
|
|
if (editor.formatter) {
|
|
registerFormats(result.customFormats);
|
|
} else {
|
|
editor.on('init', function () {
|
|
registerFormats(result.customFormats);
|
|
});
|
|
}
|
|
return result.formats;
|
|
};
|
|
var getStyleFormats = function (editor) {
|
|
return getUserStyleFormats(editor).map(function (userFormats) {
|
|
var registeredUserFormats = registerCustomFormats(editor, userFormats);
|
|
return isMergeStyleFormats(editor) ? defaultStyleFormats.concat(registeredUserFormats) : registeredUserFormats;
|
|
}).getOr(defaultStyleFormats);
|
|
};
|
|
|
|
var processBasic = function (item, isSelectedFor, getPreviewFor) {
|
|
var formatterSpec = {
|
|
type: 'formatter',
|
|
isSelected: isSelectedFor(item.format),
|
|
getStylePreview: getPreviewFor(item.format)
|
|
};
|
|
return deepMerge(item, formatterSpec);
|
|
};
|
|
var register$3 = function (editor, formats, isSelectedFor, getPreviewFor) {
|
|
var enrichSupported = function (item) {
|
|
return processBasic(item, isSelectedFor, getPreviewFor);
|
|
};
|
|
var enrichMenu = function (item) {
|
|
var submenuSpec = { type: 'submenu' };
|
|
return deepMerge(item, submenuSpec);
|
|
};
|
|
var enrichCustom = function (item) {
|
|
var formatName = generate$1(item.title);
|
|
var customSpec = {
|
|
type: 'formatter',
|
|
format: formatName,
|
|
isSelected: isSelectedFor(formatName),
|
|
getStylePreview: getPreviewFor(formatName)
|
|
};
|
|
var newItem = deepMerge(item, customSpec);
|
|
editor.formatter.register(formatName, newItem);
|
|
return newItem;
|
|
};
|
|
var doEnrich = function (items) {
|
|
return map(items, function (item) {
|
|
var keys$1 = keys(item);
|
|
if (hasNonNullableKey(item, 'items')) {
|
|
var newItems_1 = doEnrich(item.items);
|
|
return deepMerge(enrichMenu(item), {
|
|
getStyleItems: function () {
|
|
return newItems_1;
|
|
}
|
|
});
|
|
} else if (hasNonNullableKey(item, 'format')) {
|
|
return enrichSupported(item);
|
|
} else if (keys$1.length === 1 && contains(keys$1, 'title')) {
|
|
return deepMerge(item, { type: 'separator' });
|
|
} else {
|
|
return enrichCustom(item);
|
|
}
|
|
});
|
|
};
|
|
return doEnrich(formats);
|
|
};
|
|
|
|
var init$7 = function (editor) {
|
|
var isSelectedFor = function (format) {
|
|
return function () {
|
|
return editor.formatter.match(format);
|
|
};
|
|
};
|
|
var getPreviewFor = function (format) {
|
|
return function () {
|
|
var fmt = editor.formatter.get(format);
|
|
return fmt !== undefined ? Option.some({
|
|
tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || 'div' : 'div',
|
|
styles: editor.dom.parseStyle(editor.formatter.getCssText(format))
|
|
}) : Option.none();
|
|
};
|
|
};
|
|
var flatten = function (fmt) {
|
|
var subs = fmt.items;
|
|
return subs !== undefined && subs.length > 0 ? bind(subs, flatten) : [fmt.format];
|
|
};
|
|
var settingsFormats = Cell([]);
|
|
var settingsFlattenedFormats = Cell([]);
|
|
var eventsFormats = Cell([]);
|
|
var eventsFlattenedFormats = Cell([]);
|
|
var replaceSettings = Cell(false);
|
|
editor.on('PreInit', function (_e) {
|
|
var formats = getStyleFormats(editor);
|
|
var enriched = register$3(editor, formats, isSelectedFor, getPreviewFor);
|
|
settingsFormats.set(enriched);
|
|
settingsFlattenedFormats.set(bind(enriched, flatten));
|
|
});
|
|
editor.on('addStyleModifications', function (e) {
|
|
var modifications = register$3(editor, e.items, isSelectedFor, getPreviewFor);
|
|
eventsFormats.set(modifications);
|
|
replaceSettings.set(e.replace);
|
|
eventsFlattenedFormats.set(bind(modifications, flatten));
|
|
});
|
|
var getData = function () {
|
|
var fromSettings = replaceSettings.get() ? [] : settingsFormats.get();
|
|
var fromEvents = eventsFormats.get();
|
|
return fromSettings.concat(fromEvents);
|
|
};
|
|
var getFlattenedKeys = function () {
|
|
var fromSettings = replaceSettings.get() ? [] : settingsFlattenedFormats.get();
|
|
var fromEvents = eventsFlattenedFormats.get();
|
|
return fromSettings.concat(fromEvents);
|
|
};
|
|
return {
|
|
getData: getData,
|
|
getFlattenedKeys: getFlattenedKeys
|
|
};
|
|
};
|
|
|
|
var trim$1 = global$e.trim;
|
|
var hasContentEditableState = function (value) {
|
|
return function (node) {
|
|
if (node && node.nodeType === 1) {
|
|
if (node.contentEditable === value) {
|
|
return true;
|
|
}
|
|
if (node.getAttribute('data-mce-contenteditable') === value) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
};
|
|
var isContentEditableTrue = hasContentEditableState('true');
|
|
var isContentEditableFalse = hasContentEditableState('false');
|
|
var create$8 = function (type, title, url, level, attach) {
|
|
return {
|
|
type: type,
|
|
title: title,
|
|
url: url,
|
|
level: level,
|
|
attach: attach
|
|
};
|
|
};
|
|
var isChildOfContentEditableTrue = function (node) {
|
|
while (node = node.parentNode) {
|
|
var value = node.contentEditable;
|
|
if (value && value !== 'inherit') {
|
|
return isContentEditableTrue(node);
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
var select = function (selector, root) {
|
|
return map(descendants(Element.fromDom(root), selector), function (element) {
|
|
return element.dom();
|
|
});
|
|
};
|
|
var getElementText = function (elm) {
|
|
return elm.innerText || elm.textContent;
|
|
};
|
|
var getOrGenerateId = function (elm) {
|
|
return elm.id ? elm.id : generate$1('h');
|
|
};
|
|
var isAnchor = function (elm) {
|
|
return elm && elm.nodeName === 'A' && (elm.id || elm.name) !== undefined;
|
|
};
|
|
var isValidAnchor = function (elm) {
|
|
return isAnchor(elm) && isEditable(elm);
|
|
};
|
|
var isHeader = function (elm) {
|
|
return elm && /^(H[1-6])$/.test(elm.nodeName);
|
|
};
|
|
var isEditable = function (elm) {
|
|
return isChildOfContentEditableTrue(elm) && !isContentEditableFalse(elm);
|
|
};
|
|
var isValidHeader = function (elm) {
|
|
return isHeader(elm) && isEditable(elm);
|
|
};
|
|
var getLevel = function (elm) {
|
|
return isHeader(elm) ? parseInt(elm.nodeName.substr(1), 10) : 0;
|
|
};
|
|
var headerTarget = function (elm) {
|
|
var headerId = getOrGenerateId(elm);
|
|
var attach = function () {
|
|
elm.id = headerId;
|
|
};
|
|
return create$8('header', getElementText(elm), '#' + headerId, getLevel(elm), attach);
|
|
};
|
|
var anchorTarget = function (elm) {
|
|
var anchorId = elm.id || elm.name;
|
|
var anchorText = getElementText(elm);
|
|
return create$8('anchor', anchorText ? anchorText : '#' + anchorId, '#' + anchorId, 0, noop);
|
|
};
|
|
var getHeaderTargets = function (elms) {
|
|
return map(filter(elms, isValidHeader), headerTarget);
|
|
};
|
|
var getAnchorTargets = function (elms) {
|
|
return map(filter(elms, isValidAnchor), anchorTarget);
|
|
};
|
|
var getTargetElements = function (elm) {
|
|
var elms = select('h1,h2,h3,h4,h5,h6,a:not([href])', elm);
|
|
return elms;
|
|
};
|
|
var hasTitle = function (target) {
|
|
return trim$1(target.title).length > 0;
|
|
};
|
|
var find$5 = function (elm) {
|
|
var elms = getTargetElements(elm);
|
|
return filter(getHeaderTargets(elms).concat(getAnchorTargets(elms)), hasTitle);
|
|
};
|
|
var LinkTargets = { find: find$5 };
|
|
|
|
var STORAGE_KEY = 'tinymce-url-history';
|
|
var HISTORY_LENGTH = 5;
|
|
var isHttpUrl = function (url) {
|
|
return isString(url) && /^https?/.test(url);
|
|
};
|
|
var isArrayOfUrl = function (a) {
|
|
return isArray(a) && a.length <= HISTORY_LENGTH && forall(a, isHttpUrl);
|
|
};
|
|
var isRecordOfUrlArray = function (r) {
|
|
return isObject(r) && find$1(r, function (value) {
|
|
return !isArrayOfUrl(value);
|
|
}).isNone();
|
|
};
|
|
var getAllHistory = function () {
|
|
var unparsedHistory = global$9.getItem(STORAGE_KEY);
|
|
if (unparsedHistory === null) {
|
|
return {};
|
|
}
|
|
var history;
|
|
try {
|
|
history = JSON.parse(unparsedHistory);
|
|
} catch (e) {
|
|
if (e instanceof SyntaxError) {
|
|
domGlobals.console.log('Local storage ' + STORAGE_KEY + ' was not valid JSON', e);
|
|
return {};
|
|
}
|
|
throw e;
|
|
}
|
|
if (!isRecordOfUrlArray(history)) {
|
|
domGlobals.console.log('Local storage ' + STORAGE_KEY + ' was not valid format', history);
|
|
return {};
|
|
}
|
|
return history;
|
|
};
|
|
var setAllHistory = function (history) {
|
|
if (!isRecordOfUrlArray(history)) {
|
|
throw new Error('Bad format for history:\n' + JSON.stringify(history));
|
|
}
|
|
global$9.setItem(STORAGE_KEY, JSON.stringify(history));
|
|
};
|
|
var getHistory = function (fileType) {
|
|
var history = getAllHistory();
|
|
return Object.prototype.hasOwnProperty.call(history, fileType) ? history[fileType] : [];
|
|
};
|
|
var addToHistory = function (url, fileType) {
|
|
if (!isHttpUrl(url)) {
|
|
return;
|
|
}
|
|
var history = getAllHistory();
|
|
var items = Object.prototype.hasOwnProperty.call(history, fileType) ? history[fileType] : [];
|
|
var itemsWithoutUrl = filter(items, function (item) {
|
|
return item !== url;
|
|
});
|
|
history[fileType] = [url].concat(itemsWithoutUrl).slice(0, HISTORY_LENGTH);
|
|
setAllHistory(history);
|
|
};
|
|
|
|
var hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
|
var isTruthy = function (value) {
|
|
return !!value;
|
|
};
|
|
var makeMap = function (value) {
|
|
return map$1(global$e.makeMap(value, /[, ]/), isTruthy);
|
|
};
|
|
var getOpt$1 = function (obj, key) {
|
|
return hasOwnProperty$2.call(obj, key) ? Option.some(obj[key]) : Option.none();
|
|
};
|
|
var getTextSetting = function (settings, name, defaultValue) {
|
|
var value = getOpt$1(settings, name).getOr(defaultValue);
|
|
return isString(value) ? Option.some(value) : Option.none();
|
|
};
|
|
var getPicker = function (settings) {
|
|
return Option.some(settings.file_picker_callback).filter(isFunction);
|
|
};
|
|
var getPickerTypes = function (settings) {
|
|
var optFileTypes = Option.some(settings.file_picker_types).filter(isTruthy);
|
|
var optLegacyTypes = Option.some(settings.file_browser_callback_types).filter(isTruthy);
|
|
var optTypes = optFileTypes.or(optLegacyTypes).map(makeMap);
|
|
return getPicker(settings).fold(function () {
|
|
return false;
|
|
}, function (_picker) {
|
|
return optTypes.fold(function () {
|
|
return true;
|
|
}, function (types) {
|
|
return keys(types).length > 0 ? types : false;
|
|
});
|
|
});
|
|
};
|
|
var getPickerSetting = function (settings, filetype) {
|
|
var pickerTypes = getPickerTypes(settings);
|
|
if (isBoolean(pickerTypes)) {
|
|
return pickerTypes ? getPicker(settings) : Option.none();
|
|
} else {
|
|
return pickerTypes[filetype] ? getPicker(settings) : Option.none();
|
|
}
|
|
};
|
|
var getUrlPicker = function (editor, filetype) {
|
|
return getPickerSetting(editor.settings, filetype).map(function (picker) {
|
|
return function (entry) {
|
|
return Future.nu(function (completer) {
|
|
var handler = function (value, meta) {
|
|
if (!isString(value)) {
|
|
throw new Error('Expected value to be string');
|
|
}
|
|
if (meta !== undefined && !isObject(meta)) {
|
|
throw new Error('Expected meta to be a object');
|
|
}
|
|
var r = {
|
|
value: value,
|
|
meta: meta
|
|
};
|
|
completer(r);
|
|
};
|
|
var meta = __assign({
|
|
filetype: filetype,
|
|
fieldname: entry.fieldname
|
|
}, Option.from(entry.meta).getOr({}));
|
|
picker.call(editor, handler, entry.value, meta);
|
|
});
|
|
};
|
|
});
|
|
};
|
|
var getLinkInformation = function (editor) {
|
|
if (editor.settings.typeahead_urls === false) {
|
|
return Option.none();
|
|
}
|
|
return Option.some({
|
|
targets: LinkTargets.find(editor.getBody()),
|
|
anchorTop: getTextSetting(editor.settings, 'anchor_top', '#top').getOrUndefined(),
|
|
anchorBottom: getTextSetting(editor.settings, 'anchor_bottom', '#bottom').getOrUndefined()
|
|
});
|
|
};
|
|
var getValidationHandler = function (editor) {
|
|
var optValidator = Option.from(editor.settings.file_picker_validator_handler).filter(isFunction);
|
|
return optValidator.orThunk(function () {
|
|
return Option.from(editor.settings.filepicker_validator_handler).filter(isFunction);
|
|
});
|
|
};
|
|
var UrlInputBackstage = function (editor) {
|
|
return {
|
|
getHistory: getHistory,
|
|
addToHistory: addToHistory,
|
|
getLinkInformation: function () {
|
|
return getLinkInformation(editor);
|
|
},
|
|
getValidationHandler: function () {
|
|
return getValidationHandler(editor);
|
|
},
|
|
getUrlPicker: function (filetype) {
|
|
return getUrlPicker(editor, filetype);
|
|
}
|
|
};
|
|
};
|
|
|
|
var init$8 = function (sink, editor, lazyAnchorbar) {
|
|
var contextMenuState = Cell(false);
|
|
var toolbar = HeaderBackstage(editor);
|
|
var backstage = {
|
|
shared: {
|
|
providers: {
|
|
icons: function () {
|
|
return editor.ui.registry.getAll().icons;
|
|
},
|
|
menuItems: function () {
|
|
return editor.ui.registry.getAll().menuItems;
|
|
},
|
|
translate: global$5.translate,
|
|
isReadOnly: function () {
|
|
return editor.mode.isReadOnly();
|
|
}
|
|
},
|
|
interpreter: function (s) {
|
|
return interpretWithoutForm(s, backstage);
|
|
},
|
|
anchors: getAnchors(editor, lazyAnchorbar, toolbar.isPositionedAtTop),
|
|
header: toolbar,
|
|
getSink: function () {
|
|
return Result.value(sink);
|
|
}
|
|
},
|
|
urlinput: UrlInputBackstage(editor),
|
|
styleselect: init$7(editor),
|
|
colorinput: ColorInputBackstage(editor),
|
|
dialog: DialogBackstage(editor),
|
|
isContextMenuOpen: function () {
|
|
return contextMenuState.get();
|
|
},
|
|
setContextMenuState: function (state) {
|
|
return contextMenuState.set(state);
|
|
}
|
|
};
|
|
return backstage;
|
|
};
|
|
|
|
var expandable$1 = constant(function (element, available) {
|
|
setMax$1(element, Math.floor(available));
|
|
});
|
|
|
|
var showContextToolbarEvent = 'contexttoolbar-show';
|
|
var hideContextToolbarEvent = 'contexttoolbar-hide';
|
|
|
|
var schema$k = constant([
|
|
strict$1('items'),
|
|
markers(['itemSelector']),
|
|
field$1('tgroupBehaviours', [Keying])
|
|
]);
|
|
var parts$7 = constant([group({
|
|
name: 'items',
|
|
unit: 'item'
|
|
})]);
|
|
|
|
var factory$9 = function (detail, components, _spec, _externals) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: augment(detail.tgroupBehaviours, [Keying.config({
|
|
mode: 'flow',
|
|
selector: detail.markers.itemSelector
|
|
})]),
|
|
domModification: { attributes: { role: 'toolbar' } }
|
|
};
|
|
};
|
|
var ToolbarGroup = composite$1({
|
|
name: 'ToolbarGroup',
|
|
configFields: schema$k(),
|
|
partFields: parts$7(),
|
|
factory: factory$9
|
|
});
|
|
|
|
var schema$l = constant([
|
|
strict$1('dom'),
|
|
defaulted$1('shell', true),
|
|
field$1('toolbarBehaviours', [Replacing])
|
|
]);
|
|
var enhanceGroups = function () {
|
|
return { behaviours: derive$1([Replacing.config({})]) };
|
|
};
|
|
var parts$8 = constant([optional({
|
|
name: 'groups',
|
|
overrides: enhanceGroups
|
|
})]);
|
|
|
|
var factory$a = function (detail, components, _spec, _externals) {
|
|
var setGroups = function (toolbar, groups) {
|
|
getGroupContainer(toolbar).fold(function () {
|
|
domGlobals.console.error('Toolbar was defined to not be a shell, but no groups container was specified in components');
|
|
throw new Error('Toolbar was defined to not be a shell, but no groups container was specified in components');
|
|
}, function (container) {
|
|
Replacing.set(container, groups);
|
|
});
|
|
};
|
|
var getGroupContainer = function (component) {
|
|
return detail.shell ? Option.some(component) : getPart(component, detail, 'groups');
|
|
};
|
|
var extra = detail.shell ? {
|
|
behaviours: [Replacing.config({})],
|
|
components: []
|
|
} : {
|
|
behaviours: [],
|
|
components: components
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: extra.components,
|
|
behaviours: augment(detail.toolbarBehaviours, extra.behaviours),
|
|
apis: { setGroups: setGroups },
|
|
domModification: { attributes: { role: 'group' } }
|
|
};
|
|
};
|
|
var Toolbar = composite$1({
|
|
name: 'Toolbar',
|
|
configFields: schema$l(),
|
|
partFields: parts$8(),
|
|
factory: factory$a,
|
|
apis: {
|
|
setGroups: function (apis, toolbar, groups) {
|
|
apis.setGroups(toolbar, groups);
|
|
}
|
|
}
|
|
});
|
|
|
|
var generate$6 = function (xs, f) {
|
|
var init = {
|
|
len: 0,
|
|
list: []
|
|
};
|
|
var r = foldl(xs, function (b, a) {
|
|
var value = f(a, b.len);
|
|
return value.fold(constant(b), function (v) {
|
|
return {
|
|
len: v.finish(),
|
|
list: b.list.concat([v])
|
|
};
|
|
});
|
|
}, init);
|
|
return r.list;
|
|
};
|
|
|
|
var output$1 = function (within, extra, withinWidth) {
|
|
return {
|
|
within: constant(within),
|
|
extra: constant(extra),
|
|
withinWidth: constant(withinWidth)
|
|
};
|
|
};
|
|
var apportion = function (units, total, len) {
|
|
var parray = generate$6(units, function (unit, current) {
|
|
var width = len(unit);
|
|
return Option.some({
|
|
element: constant(unit),
|
|
start: constant(current),
|
|
finish: constant(current + width),
|
|
width: constant(width)
|
|
});
|
|
});
|
|
var within = filter(parray, function (unit) {
|
|
return unit.finish() <= total;
|
|
});
|
|
var withinWidth = foldr(within, function (acc, el) {
|
|
return acc + el.width();
|
|
}, 0);
|
|
var extra = parray.slice(within.length);
|
|
return {
|
|
within: constant(within),
|
|
extra: constant(extra),
|
|
withinWidth: constant(withinWidth)
|
|
};
|
|
};
|
|
var toUnit = function (parray) {
|
|
return map(parray, function (unit) {
|
|
return unit.element();
|
|
});
|
|
};
|
|
var fitLast = function (within, extra, withinWidth) {
|
|
var fits = toUnit(within.concat(extra));
|
|
return output$1(fits, [], withinWidth);
|
|
};
|
|
var overflow = function (within, extra, overflower, withinWidth) {
|
|
var fits = toUnit(within).concat([overflower]);
|
|
return output$1(fits, toUnit(extra), withinWidth);
|
|
};
|
|
var fitAll = function (within, extra, withinWidth) {
|
|
return output$1(toUnit(within), [], withinWidth);
|
|
};
|
|
var tryFit = function (total, units, len) {
|
|
var divide = apportion(units, total, len);
|
|
return divide.extra().length === 0 ? Option.some(divide) : Option.none();
|
|
};
|
|
var partition$3 = function (total, units, len, overflower) {
|
|
var divide = tryFit(total, units, len).getOrThunk(function () {
|
|
return apportion(units, total - len(overflower), len);
|
|
});
|
|
var within = divide.within();
|
|
var extra = divide.extra();
|
|
var withinWidth = divide.withinWidth();
|
|
if (extra.length === 1 && extra[0].width() <= len(overflower)) {
|
|
return fitLast(within, extra, withinWidth);
|
|
} else if (extra.length >= 1) {
|
|
return overflow(within, extra, overflower, withinWidth);
|
|
} else {
|
|
return fitAll(within, extra, withinWidth);
|
|
}
|
|
};
|
|
|
|
var setGroups = function (toolbar, storedGroups) {
|
|
var bGroups = map(storedGroups, function (g) {
|
|
return premade$1(g);
|
|
});
|
|
Toolbar.setGroups(toolbar, bGroups);
|
|
};
|
|
var findFocusedComp = function (comps) {
|
|
return findMap(comps, function (comp) {
|
|
return search(comp.element()).bind(function (focusedElm) {
|
|
return comp.getSystem().getByDom(focusedElm).toOption();
|
|
});
|
|
});
|
|
};
|
|
var refresh = function (toolbar, detail, setOverflow) {
|
|
var primary = getPartOrDie(toolbar, detail, 'primary');
|
|
var overflowGroup = Coupling.getCoupled(toolbar, 'overflowGroup');
|
|
set$2(primary.element(), 'visibility', 'hidden');
|
|
var groups = detail.builtGroups.get().concat([overflowGroup]);
|
|
var focusedComp = findFocusedComp(groups);
|
|
setOverflow([]);
|
|
setGroups(primary, groups);
|
|
var availableWidth = get$7(primary.element());
|
|
var overflows = partition$3(availableWidth, detail.builtGroups.get(), function (comp) {
|
|
return get$7(comp.element());
|
|
}, overflowGroup);
|
|
if (overflows.extra().length === 0) {
|
|
Replacing.remove(primary, overflowGroup);
|
|
setOverflow([]);
|
|
} else {
|
|
setGroups(primary, overflows.within());
|
|
setOverflow(overflows.extra());
|
|
}
|
|
remove$6(primary.element(), 'visibility');
|
|
reflow(primary.element());
|
|
focusedComp.each(Focusing.focus);
|
|
};
|
|
|
|
var schema$m = constant([
|
|
field$1('splitToolbarBehaviours', [Coupling]),
|
|
state$1('builtGroups', function () {
|
|
return Cell([]);
|
|
})
|
|
]);
|
|
|
|
var schema$n = constant([
|
|
markers(['overflowToggledClass']),
|
|
optionFunction('getOverflowBounds'),
|
|
strict$1('lazySink'),
|
|
state$1('overflowGroups', function () {
|
|
return Cell([]);
|
|
})
|
|
].concat(schema$m()));
|
|
var parts$9 = constant([
|
|
required({
|
|
factory: Toolbar,
|
|
schema: schema$l(),
|
|
name: 'primary'
|
|
}),
|
|
external$1({
|
|
schema: schema$l(),
|
|
name: 'overflow'
|
|
}),
|
|
external$1({ name: 'overflow-button' }),
|
|
external$1({ name: 'overflow-group' })
|
|
]);
|
|
|
|
var schema$o = constant([
|
|
markers(['toggledClass']),
|
|
strict$1('lazySink'),
|
|
strictFunction('fetch'),
|
|
optionFunction('getBounds'),
|
|
optionObjOf('fireDismissalEventInstead', [defaulted$1('event', dismissRequested())]),
|
|
schema$1()
|
|
]);
|
|
var parts$a = constant([
|
|
external$1({
|
|
name: 'button',
|
|
overrides: function (detail) {
|
|
return {
|
|
dom: { attributes: { 'aria-haspopup': 'true' } },
|
|
buttonBehaviours: derive$1([Toggling.config({
|
|
toggleClass: detail.markers.toggledClass,
|
|
aria: { mode: 'expanded' },
|
|
toggleOnExecute: false
|
|
})])
|
|
};
|
|
}
|
|
}),
|
|
external$1({
|
|
factory: Toolbar,
|
|
schema: schema$l(),
|
|
name: 'toolbar',
|
|
overrides: function (detail) {
|
|
return {
|
|
toolbarBehaviours: derive$1([Keying.config({
|
|
mode: 'cyclic',
|
|
onEscape: function (comp) {
|
|
getPart(comp, detail, 'button').each(Focusing.focus);
|
|
return Option.none();
|
|
}
|
|
})])
|
|
};
|
|
}
|
|
})
|
|
]);
|
|
|
|
var toggle$2 = function (button, externals) {
|
|
var toolbarSandbox = Coupling.getCoupled(button, 'toolbarSandbox');
|
|
if (Sandboxing.isOpen(toolbarSandbox)) {
|
|
Sandboxing.close(toolbarSandbox);
|
|
} else {
|
|
Sandboxing.open(toolbarSandbox, externals.toolbar());
|
|
}
|
|
};
|
|
var position$2 = function (button, toolbar, detail, layouts) {
|
|
var bounds = detail.getBounds.map(function (bounder) {
|
|
return bounder();
|
|
});
|
|
var sink = detail.lazySink(button).getOrDie();
|
|
Positioning.positionWithinBounds(sink, {
|
|
anchor: 'hotspot',
|
|
hotspot: button,
|
|
layouts: layouts,
|
|
overrides: { maxWidthFunction: expandable$1() }
|
|
}, toolbar, bounds);
|
|
};
|
|
var setGroups$1 = function (button, toolbar, detail, layouts, groups) {
|
|
Toolbar.setGroups(toolbar, groups);
|
|
position$2(button, toolbar, detail, layouts);
|
|
Toggling.on(button);
|
|
};
|
|
var makeSandbox$1 = function (button, spec, detail) {
|
|
var ariaOwner = manager();
|
|
var onOpen = function (sandbox, toolbar) {
|
|
detail.fetch().get(function (groups) {
|
|
setGroups$1(button, toolbar, detail, spec.layouts, groups);
|
|
ariaOwner.link(button.element());
|
|
Keying.focusIn(toolbar);
|
|
});
|
|
};
|
|
var onClose = function () {
|
|
Toggling.off(button);
|
|
Focusing.focus(button);
|
|
ariaOwner.unlink(button.element());
|
|
};
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { id: ariaOwner.id }
|
|
},
|
|
behaviours: derive$1([
|
|
Keying.config({
|
|
mode: 'special',
|
|
onEscape: function (comp) {
|
|
Sandboxing.close(comp);
|
|
return Option.some(true);
|
|
}
|
|
}),
|
|
Sandboxing.config({
|
|
onOpen: onOpen,
|
|
onClose: onClose,
|
|
isPartOf: function (container, data, queryElem) {
|
|
return isPartOf(data, queryElem) || isPartOf(button, queryElem);
|
|
},
|
|
getAttachPoint: function () {
|
|
return detail.lazySink(button).getOrDie();
|
|
}
|
|
}),
|
|
Receiving.config({
|
|
channels: __assign(__assign({}, receivingChannel(__assign({ isExtraPart: never }, detail.fireDismissalEventInstead.map(function (fe) {
|
|
return { fireEventInstead: { event: fe.event } };
|
|
}).getOr({})))), receivingChannel$1({
|
|
doReposition: function () {
|
|
Sandboxing.getState(Coupling.getCoupled(button, 'toolbarSandbox')).each(function (toolbar) {
|
|
position$2(button, toolbar, detail, spec.layouts);
|
|
});
|
|
}
|
|
}))
|
|
})
|
|
])
|
|
};
|
|
};
|
|
var factory$b = function (detail, components, spec, externals) {
|
|
return __assign(__assign({}, Button.sketch(__assign(__assign({}, externals.button()), {
|
|
action: function (button) {
|
|
toggle$2(button, externals);
|
|
},
|
|
buttonBehaviours: SketchBehaviours.augment({ dump: externals.button().buttonBehaviours }, [Coupling.config({
|
|
others: {
|
|
toolbarSandbox: function (button) {
|
|
return makeSandbox$1(button, spec, detail);
|
|
}
|
|
}
|
|
})])
|
|
}))), {
|
|
apis: {
|
|
setGroups: function (button, groups) {
|
|
Sandboxing.getState(Coupling.getCoupled(button, 'toolbarSandbox')).each(function (toolbar) {
|
|
setGroups$1(button, toolbar, detail, spec.layouts, groups);
|
|
});
|
|
},
|
|
reposition: function (button) {
|
|
Sandboxing.getState(Coupling.getCoupled(button, 'toolbarSandbox')).each(function (toolbar) {
|
|
position$2(button, toolbar, detail, spec.layouts);
|
|
});
|
|
},
|
|
toggle: function (button) {
|
|
toggle$2(button, externals);
|
|
},
|
|
getToolbar: function (button) {
|
|
return Sandboxing.getState(Coupling.getCoupled(button, 'toolbarSandbox'));
|
|
}
|
|
}
|
|
});
|
|
};
|
|
var FloatingToolbarButton = composite$1({
|
|
name: 'FloatingToolbarButton',
|
|
factory: factory$b,
|
|
configFields: schema$o(),
|
|
partFields: parts$a(),
|
|
apis: {
|
|
setGroups: function (apis, button, groups) {
|
|
apis.setGroups(button, groups);
|
|
},
|
|
reposition: function (apis, button) {
|
|
apis.reposition(button);
|
|
},
|
|
toggle: function (apis, button) {
|
|
apis.toggle(button);
|
|
},
|
|
getToolbar: function (apis, button) {
|
|
return apis.getToolbar(button);
|
|
}
|
|
}
|
|
});
|
|
|
|
var buildGroups = function (comps) {
|
|
return map(comps, function (g) {
|
|
return premade$1(g);
|
|
});
|
|
};
|
|
var refresh$1 = function (toolbar, memFloatingToolbarButton, detail) {
|
|
refresh(toolbar, detail, function (overflowGroups) {
|
|
detail.overflowGroups.set(overflowGroups);
|
|
memFloatingToolbarButton.getOpt(toolbar).each(function (floatingToolbarButton) {
|
|
FloatingToolbarButton.setGroups(floatingToolbarButton, buildGroups(overflowGroups));
|
|
});
|
|
});
|
|
};
|
|
var factory$c = function (detail, components, spec, externals) {
|
|
var memFloatingToolbarButton = record(FloatingToolbarButton.sketch({
|
|
fetch: function () {
|
|
return Future.nu(function (resolve) {
|
|
resolve(buildGroups(detail.overflowGroups.get()));
|
|
});
|
|
},
|
|
layouts: {
|
|
onLtr: function () {
|
|
return [
|
|
southwest$1,
|
|
southeast$1
|
|
];
|
|
},
|
|
onRtl: function () {
|
|
return [
|
|
southeast$1,
|
|
southwest$1
|
|
];
|
|
},
|
|
onBottomLtr: function () {
|
|
return [
|
|
northwest$1,
|
|
northeast$1
|
|
];
|
|
},
|
|
onBottomRtl: function () {
|
|
return [
|
|
northeast$1,
|
|
northwest$1
|
|
];
|
|
}
|
|
},
|
|
getBounds: spec.getOverflowBounds,
|
|
lazySink: detail.lazySink,
|
|
fireDismissalEventInstead: {},
|
|
markers: { toggledClass: detail.markers.overflowToggledClass },
|
|
parts: {
|
|
button: externals['overflow-button'](),
|
|
toolbar: externals.overflow()
|
|
}
|
|
}));
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: augment(detail.splitToolbarBehaviours, [Coupling.config({
|
|
others: {
|
|
overflowGroup: function () {
|
|
return ToolbarGroup.sketch(__assign(__assign({}, externals['overflow-group']()), { items: [memFloatingToolbarButton.asSpec()] }));
|
|
}
|
|
}
|
|
})]),
|
|
apis: {
|
|
setGroups: function (toolbar, groups) {
|
|
detail.builtGroups.set(map(groups, toolbar.getSystem().build));
|
|
refresh$1(toolbar, memFloatingToolbarButton, detail);
|
|
},
|
|
refresh: function (toolbar) {
|
|
return refresh$1(toolbar, memFloatingToolbarButton, detail);
|
|
},
|
|
toggle: function (toolbar) {
|
|
memFloatingToolbarButton.getOpt(toolbar).each(function (floatingToolbarButton) {
|
|
FloatingToolbarButton.toggle(floatingToolbarButton);
|
|
});
|
|
},
|
|
reposition: function (toolbar) {
|
|
memFloatingToolbarButton.getOpt(toolbar).each(function (floatingToolbarButton) {
|
|
FloatingToolbarButton.reposition(floatingToolbarButton);
|
|
});
|
|
},
|
|
getOverflow: function (toolbar) {
|
|
return memFloatingToolbarButton.getOpt(toolbar).bind(function (floatingToolbarButton) {
|
|
return FloatingToolbarButton.getToolbar(floatingToolbarButton);
|
|
});
|
|
}
|
|
},
|
|
domModification: { attributes: { role: 'group' } }
|
|
};
|
|
};
|
|
var SplitFloatingToolbar = composite$1({
|
|
name: 'SplitFloatingToolbar',
|
|
configFields: schema$n(),
|
|
partFields: parts$9(),
|
|
factory: factory$c,
|
|
apis: {
|
|
setGroups: function (apis, toolbar, groups) {
|
|
apis.setGroups(toolbar, groups);
|
|
},
|
|
refresh: function (apis, toolbar) {
|
|
apis.refresh(toolbar);
|
|
},
|
|
reposition: function (apis, toolbar) {
|
|
apis.reposition(toolbar);
|
|
},
|
|
toggle: function (apis, toolbar) {
|
|
apis.toggle(toolbar);
|
|
},
|
|
getOverflow: function (apis, toolbar) {
|
|
return apis.getOverflow(toolbar);
|
|
}
|
|
}
|
|
});
|
|
|
|
var getAnimationRoot = function (component, slideConfig) {
|
|
return slideConfig.getAnimationRoot.fold(function () {
|
|
return component.element();
|
|
}, function (get) {
|
|
return get(component);
|
|
});
|
|
};
|
|
|
|
var getDimensionProperty = function (slideConfig) {
|
|
return slideConfig.dimension.property;
|
|
};
|
|
var getDimension = function (slideConfig, elem) {
|
|
return slideConfig.dimension.getDimension(elem);
|
|
};
|
|
var disableTransitions = function (component, slideConfig) {
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
remove$5(root, [
|
|
slideConfig.shrinkingClass,
|
|
slideConfig.growingClass
|
|
]);
|
|
};
|
|
var setShrunk = function (component, slideConfig) {
|
|
remove$4(component.element(), slideConfig.openClass);
|
|
add$2(component.element(), slideConfig.closedClass);
|
|
set$2(component.element(), getDimensionProperty(slideConfig), '0px');
|
|
reflow(component.element());
|
|
};
|
|
var setGrown = function (component, slideConfig) {
|
|
remove$4(component.element(), slideConfig.closedClass);
|
|
add$2(component.element(), slideConfig.openClass);
|
|
remove$6(component.element(), getDimensionProperty(slideConfig));
|
|
};
|
|
var doImmediateShrink = function (component, slideConfig, slideState, _calculatedSize) {
|
|
slideState.setCollapsed();
|
|
set$2(component.element(), getDimensionProperty(slideConfig), getDimension(slideConfig, component.element()));
|
|
reflow(component.element());
|
|
disableTransitions(component, slideConfig);
|
|
setShrunk(component, slideConfig);
|
|
slideConfig.onStartShrink(component);
|
|
slideConfig.onShrunk(component);
|
|
};
|
|
var doStartShrink = function (component, slideConfig, slideState, calculatedSize) {
|
|
var size = calculatedSize.getOrThunk(function () {
|
|
return getDimension(slideConfig, component.element());
|
|
});
|
|
slideState.setCollapsed();
|
|
set$2(component.element(), getDimensionProperty(slideConfig), size);
|
|
reflow(component.element());
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
remove$4(root, slideConfig.growingClass);
|
|
add$2(root, slideConfig.shrinkingClass);
|
|
setShrunk(component, slideConfig);
|
|
slideConfig.onStartShrink(component);
|
|
};
|
|
var doStartSmartShrink = function (component, slideConfig, slideState) {
|
|
var size = getDimension(slideConfig, component.element());
|
|
var shrinker = size === '0px' ? doImmediateShrink : doStartShrink;
|
|
shrinker(component, slideConfig, slideState, Option.some(size));
|
|
};
|
|
var doStartGrow = function (component, slideConfig, slideState) {
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
var wasShrinking = has$2(root, slideConfig.shrinkingClass);
|
|
var beforeSize = getDimension(slideConfig, component.element());
|
|
setGrown(component, slideConfig);
|
|
var fullSize = getDimension(slideConfig, component.element());
|
|
var startPartialGrow = function () {
|
|
set$2(component.element(), getDimensionProperty(slideConfig), beforeSize);
|
|
reflow(component.element());
|
|
};
|
|
var startCompleteGrow = function () {
|
|
setShrunk(component, slideConfig);
|
|
};
|
|
var setStartSize = wasShrinking ? startPartialGrow : startCompleteGrow;
|
|
setStartSize();
|
|
remove$4(root, slideConfig.shrinkingClass);
|
|
add$2(root, slideConfig.growingClass);
|
|
setGrown(component, slideConfig);
|
|
set$2(component.element(), getDimensionProperty(slideConfig), fullSize);
|
|
slideState.setExpanded();
|
|
slideConfig.onStartGrow(component);
|
|
};
|
|
var refresh$2 = function (component, slideConfig, slideState) {
|
|
if (slideState.isExpanded()) {
|
|
remove$6(component.element(), getDimensionProperty(slideConfig));
|
|
var fullSize = getDimension(slideConfig, component.element());
|
|
set$2(component.element(), getDimensionProperty(slideConfig), fullSize);
|
|
}
|
|
};
|
|
var grow = function (component, slideConfig, slideState) {
|
|
if (!slideState.isExpanded()) {
|
|
doStartGrow(component, slideConfig, slideState);
|
|
}
|
|
};
|
|
var shrink = function (component, slideConfig, slideState) {
|
|
if (slideState.isExpanded()) {
|
|
doStartSmartShrink(component, slideConfig, slideState);
|
|
}
|
|
};
|
|
var immediateShrink = function (component, slideConfig, slideState) {
|
|
if (slideState.isExpanded()) {
|
|
doImmediateShrink(component, slideConfig, slideState, Option.none());
|
|
}
|
|
};
|
|
var hasGrown = function (component, slideConfig, slideState) {
|
|
return slideState.isExpanded();
|
|
};
|
|
var hasShrunk = function (component, slideConfig, slideState) {
|
|
return slideState.isCollapsed();
|
|
};
|
|
var isGrowing = function (component, slideConfig, _slideState) {
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
return has$2(root, slideConfig.growingClass) === true;
|
|
};
|
|
var isShrinking = function (component, slideConfig, _slideState) {
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
return has$2(root, slideConfig.shrinkingClass) === true;
|
|
};
|
|
var isTransitioning = function (component, slideConfig, slideState) {
|
|
return isGrowing(component, slideConfig) === true || isShrinking(component, slideConfig) === true;
|
|
};
|
|
var toggleGrow = function (component, slideConfig, slideState) {
|
|
var f = slideState.isExpanded() ? doStartSmartShrink : doStartGrow;
|
|
f(component, slideConfig, slideState);
|
|
};
|
|
|
|
var SlidingApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
refresh: refresh$2,
|
|
grow: grow,
|
|
shrink: shrink,
|
|
immediateShrink: immediateShrink,
|
|
hasGrown: hasGrown,
|
|
hasShrunk: hasShrunk,
|
|
isGrowing: isGrowing,
|
|
isShrinking: isShrinking,
|
|
isTransitioning: isTransitioning,
|
|
toggleGrow: toggleGrow,
|
|
disableTransitions: disableTransitions
|
|
});
|
|
|
|
var exhibit$6 = function (base, slideConfig, _slideState) {
|
|
var expanded = slideConfig.expanded;
|
|
return expanded ? nu$6({
|
|
classes: [slideConfig.openClass],
|
|
styles: {}
|
|
}) : nu$6({
|
|
classes: [slideConfig.closedClass],
|
|
styles: wrap$1(slideConfig.dimension.property, '0px')
|
|
});
|
|
};
|
|
var events$d = function (slideConfig, slideState) {
|
|
return derive([runOnSource(transitionend(), function (component, simulatedEvent) {
|
|
var raw = simulatedEvent.event().raw();
|
|
if (raw.propertyName === slideConfig.dimension.property) {
|
|
disableTransitions(component, slideConfig);
|
|
if (slideState.isExpanded()) {
|
|
remove$6(component.element(), slideConfig.dimension.property);
|
|
}
|
|
var notify = slideState.isExpanded() ? slideConfig.onGrown : slideConfig.onShrunk;
|
|
notify(component);
|
|
}
|
|
})]);
|
|
};
|
|
|
|
var ActiveSliding = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit$6,
|
|
events: events$d
|
|
});
|
|
|
|
var SlidingSchema = [
|
|
strict$1('closedClass'),
|
|
strict$1('openClass'),
|
|
strict$1('shrinkingClass'),
|
|
strict$1('growingClass'),
|
|
option('getAnimationRoot'),
|
|
onHandler('onShrunk'),
|
|
onHandler('onStartShrink'),
|
|
onHandler('onGrown'),
|
|
onHandler('onStartGrow'),
|
|
defaulted$1('expanded', false),
|
|
strictOf('dimension', choose$1('property', {
|
|
width: [
|
|
output('property', 'width'),
|
|
output('getDimension', function (elem) {
|
|
return get$7(elem) + 'px';
|
|
})
|
|
],
|
|
height: [
|
|
output('property', 'height'),
|
|
output('getDimension', function (elem) {
|
|
return get$6(elem) + 'px';
|
|
})
|
|
]
|
|
}))
|
|
];
|
|
|
|
var init$9 = function (spec) {
|
|
var state = Cell(spec.expanded);
|
|
var readState = function () {
|
|
return 'expanded: ' + state.get();
|
|
};
|
|
return nu$5({
|
|
isExpanded: function () {
|
|
return state.get() === true;
|
|
},
|
|
isCollapsed: function () {
|
|
return state.get() === false;
|
|
},
|
|
setCollapsed: curry(state.set, false),
|
|
setExpanded: curry(state.set, true),
|
|
readState: readState
|
|
});
|
|
};
|
|
|
|
var SlidingState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
init: init$9
|
|
});
|
|
|
|
var Sliding = create$1({
|
|
fields: SlidingSchema,
|
|
name: 'sliding',
|
|
active: ActiveSliding,
|
|
apis: SlidingApis,
|
|
state: SlidingState
|
|
});
|
|
|
|
var schema$p = constant([
|
|
markers([
|
|
'closedClass',
|
|
'openClass',
|
|
'shrinkingClass',
|
|
'growingClass',
|
|
'overflowToggledClass'
|
|
]),
|
|
onHandler('onOpened'),
|
|
onHandler('onClosed')
|
|
].concat(schema$m()));
|
|
var parts$b = constant([
|
|
required({
|
|
factory: Toolbar,
|
|
schema: schema$l(),
|
|
name: 'primary'
|
|
}),
|
|
required({
|
|
factory: Toolbar,
|
|
schema: schema$l(),
|
|
name: 'overflow',
|
|
overrides: function (detail) {
|
|
return {
|
|
toolbarBehaviours: derive$1([
|
|
Sliding.config({
|
|
dimension: { property: 'height' },
|
|
closedClass: detail.markers.closedClass,
|
|
openClass: detail.markers.openClass,
|
|
shrinkingClass: detail.markers.shrinkingClass,
|
|
growingClass: detail.markers.growingClass,
|
|
onShrunk: function (comp) {
|
|
getPart(comp, detail, 'overflow-button').each(function (button) {
|
|
Toggling.off(button);
|
|
Focusing.focus(button);
|
|
});
|
|
detail.onClosed(comp);
|
|
},
|
|
onGrown: function (comp) {
|
|
Keying.focusIn(comp);
|
|
detail.onOpened(comp);
|
|
},
|
|
onStartGrow: function (comp) {
|
|
getPart(comp, detail, 'overflow-button').each(Toggling.on);
|
|
}
|
|
}),
|
|
Keying.config({
|
|
mode: 'acyclic',
|
|
onEscape: function (comp) {
|
|
getPart(comp, detail, 'overflow-button').each(Focusing.focus);
|
|
return Option.some(true);
|
|
}
|
|
})
|
|
])
|
|
};
|
|
}
|
|
}),
|
|
external$1({
|
|
name: 'overflow-button',
|
|
overrides: function (detail) {
|
|
return {
|
|
buttonBehaviours: derive$1([Toggling.config({
|
|
toggleClass: detail.markers.overflowToggledClass,
|
|
aria: { mode: 'pressed' },
|
|
toggleOnExecute: false
|
|
})])
|
|
};
|
|
}
|
|
}),
|
|
external$1({ name: 'overflow-group' })
|
|
]);
|
|
|
|
var toggleToolbar = function (toolbar, detail) {
|
|
getPart(toolbar, detail, 'overflow').each(function (overf) {
|
|
refresh$3(toolbar, detail);
|
|
Sliding.toggleGrow(overf);
|
|
});
|
|
};
|
|
var refresh$3 = function (toolbar, detail) {
|
|
getPart(toolbar, detail, 'overflow').each(function (overflow) {
|
|
refresh(toolbar, detail, function (groups) {
|
|
var builtGroups = map(groups, function (g) {
|
|
return premade$1(g);
|
|
});
|
|
Toolbar.setGroups(overflow, builtGroups);
|
|
});
|
|
getPart(toolbar, detail, 'overflow-button').each(function (button) {
|
|
if (Sliding.hasGrown(overflow)) {
|
|
Toggling.on(button);
|
|
}
|
|
});
|
|
Sliding.refresh(overflow);
|
|
});
|
|
};
|
|
var factory$d = function (detail, components, spec, externals) {
|
|
var toolbarToggleEvent = 'alloy.toolbar.toggle';
|
|
var doSetGroups = function (toolbar, groups) {
|
|
var built = map(groups, toolbar.getSystem().build);
|
|
detail.builtGroups.set(built);
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: augment(detail.splitToolbarBehaviours, [
|
|
Coupling.config({
|
|
others: {
|
|
overflowGroup: function (toolbar) {
|
|
return ToolbarGroup.sketch(__assign(__assign({}, externals['overflow-group']()), {
|
|
items: [Button.sketch(__assign(__assign({}, externals['overflow-button']()), {
|
|
action: function (_button) {
|
|
emit(toolbar, toolbarToggleEvent);
|
|
}
|
|
}))]
|
|
}));
|
|
}
|
|
}
|
|
}),
|
|
config('toolbar-toggle-events', [run(toolbarToggleEvent, function (toolbar) {
|
|
getPart(toolbar, detail, 'overflow').each(function (overf) {
|
|
refresh$3(toolbar, detail);
|
|
Sliding.toggleGrow(overf);
|
|
});
|
|
})])
|
|
]),
|
|
apis: {
|
|
setGroups: function (toolbar, groups) {
|
|
doSetGroups(toolbar, groups);
|
|
refresh$3(toolbar, detail);
|
|
},
|
|
refresh: function (toolbar) {
|
|
return refresh$3(toolbar, detail);
|
|
},
|
|
toggle: function (toolbar) {
|
|
return toggleToolbar(toolbar, detail);
|
|
}
|
|
},
|
|
domModification: { attributes: { role: 'group' } }
|
|
};
|
|
};
|
|
var SplitSlidingToolbar = composite$1({
|
|
name: 'SplitSlidingToolbar',
|
|
configFields: schema$p(),
|
|
partFields: parts$b(),
|
|
factory: factory$d,
|
|
apis: {
|
|
setGroups: function (apis, toolbar, groups) {
|
|
apis.setGroups(toolbar, groups);
|
|
},
|
|
refresh: function (apis, toolbar) {
|
|
apis.refresh(toolbar);
|
|
},
|
|
toggle: function (apis, toolbar) {
|
|
apis.toggle(toolbar);
|
|
}
|
|
}
|
|
});
|
|
|
|
var toolbarHeightChange = constant(generate$1('toolbar-height-change'));
|
|
|
|
var renderToolbarGroupCommon = function (toolbarGroup) {
|
|
var attributes = toolbarGroup.title.fold(function () {
|
|
return {};
|
|
}, function (title) {
|
|
return { attributes: { title: title } };
|
|
});
|
|
return {
|
|
dom: __assign({
|
|
tag: 'div',
|
|
classes: ['tox-toolbar__group']
|
|
}, attributes),
|
|
components: [ToolbarGroup.parts().items({})],
|
|
items: toolbarGroup.items,
|
|
markers: { itemSelector: '*:not(.tox-split-button) > .tox-tbtn:not([disabled]), ' + '.tox-split-button:not([disabled]), ' + '.tox-toolbar-nav-js:not([disabled])' },
|
|
tgroupBehaviours: derive$1([
|
|
Tabstopping.config({}),
|
|
Focusing.config({})
|
|
])
|
|
};
|
|
};
|
|
var renderToolbarGroup = function (toolbarGroup) {
|
|
return ToolbarGroup.sketch(renderToolbarGroupCommon(toolbarGroup));
|
|
};
|
|
var getToolbarbehaviours = function (toolbarSpec, modeName) {
|
|
var onAttached = runOnAttached(function (component) {
|
|
var groups = map(toolbarSpec.initGroups, renderToolbarGroup);
|
|
Toolbar.setGroups(component, groups);
|
|
});
|
|
return derive$1([
|
|
DisablingConfigs.toolbarButton(toolbarSpec.providers.isReadOnly),
|
|
receivingConfig(),
|
|
Keying.config({
|
|
mode: modeName,
|
|
onEscape: toolbarSpec.onEscape,
|
|
selector: '.tox-toolbar__group'
|
|
}),
|
|
config('toolbar-events', [onAttached])
|
|
]);
|
|
};
|
|
var renderMoreToolbarCommon = function (toolbarSpec) {
|
|
var modeName = toolbarSpec.cyclicKeying ? 'cyclic' : 'acyclic';
|
|
return {
|
|
uid: toolbarSpec.uid,
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-toolbar-overlord']
|
|
},
|
|
parts: {
|
|
'overflow-group': renderToolbarGroupCommon({
|
|
title: Option.none(),
|
|
items: []
|
|
}),
|
|
'overflow-button': renderIconButtonSpec({
|
|
name: 'more',
|
|
icon: Option.some('more-drawer'),
|
|
disabled: false,
|
|
tooltip: Option.some('More...'),
|
|
primary: false,
|
|
borderless: false
|
|
}, Option.none(), toolbarSpec.providers)
|
|
},
|
|
splitToolbarBehaviours: getToolbarbehaviours(toolbarSpec, modeName)
|
|
};
|
|
};
|
|
var renderFloatingMoreToolbar = function (toolbarSpec) {
|
|
var baseSpec = renderMoreToolbarCommon(toolbarSpec);
|
|
var overflowXOffset = 4;
|
|
var primary = SplitFloatingToolbar.parts().primary({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-toolbar__primary']
|
|
}
|
|
});
|
|
return SplitFloatingToolbar.sketch(__assign(__assign({}, baseSpec), {
|
|
lazySink: toolbarSpec.getSink,
|
|
getOverflowBounds: function () {
|
|
var headerElem = toolbarSpec.moreDrawerData.lazyHeader().element();
|
|
var headerBounds = absolute$1(headerElem);
|
|
var docElem = documentElement(headerElem);
|
|
var docBounds = absolute$1(docElem);
|
|
var height = Math.max(docElem.dom().scrollHeight, docBounds.height);
|
|
return bounds$1(headerBounds.x + overflowXOffset, docBounds.y, headerBounds.width - overflowXOffset * 2, height);
|
|
},
|
|
parts: __assign(__assign({}, baseSpec.parts), {
|
|
overflow: {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-toolbar__overflow'],
|
|
attributes: toolbarSpec.attributes
|
|
}
|
|
}
|
|
}),
|
|
components: [primary],
|
|
markers: { overflowToggledClass: 'tox-tbtn--enabled' }
|
|
}));
|
|
};
|
|
var renderSlidingMoreToolbar = function (toolbarSpec) {
|
|
var primary = SplitSlidingToolbar.parts().primary({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-toolbar__primary']
|
|
}
|
|
});
|
|
var overflow = SplitSlidingToolbar.parts().overflow({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-toolbar__overflow']
|
|
}
|
|
});
|
|
var baseSpec = renderMoreToolbarCommon(toolbarSpec);
|
|
return SplitSlidingToolbar.sketch(__assign(__assign({}, baseSpec), {
|
|
components: [
|
|
primary,
|
|
overflow
|
|
],
|
|
markers: {
|
|
openClass: 'tox-toolbar__overflow--open',
|
|
closedClass: 'tox-toolbar__overflow--closed',
|
|
growingClass: 'tox-toolbar__overflow--growing',
|
|
shrinkingClass: 'tox-toolbar__overflow--shrinking',
|
|
overflowToggledClass: 'tox-tbtn--enabled'
|
|
},
|
|
onOpened: function (comp) {
|
|
comp.getSystem().broadcastOn([toolbarHeightChange()], { type: 'opened' });
|
|
},
|
|
onClosed: function (comp) {
|
|
comp.getSystem().broadcastOn([toolbarHeightChange()], { type: 'closed' });
|
|
}
|
|
}));
|
|
};
|
|
var renderToolbar = function (toolbarSpec) {
|
|
var modeName = toolbarSpec.cyclicKeying ? 'cyclic' : 'acyclic';
|
|
return Toolbar.sketch({
|
|
uid: toolbarSpec.uid,
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-toolbar'].concat(toolbarSpec.type === ToolbarMode.scrolling ? ['tox-toolbar--scrolling'] : [])
|
|
},
|
|
components: [Toolbar.parts().groups({})],
|
|
toolbarBehaviours: getToolbarbehaviours(toolbarSpec, modeName)
|
|
});
|
|
};
|
|
|
|
var baseToolbarButtonFields = [
|
|
defaultedBoolean('disabled', false),
|
|
optionString('tooltip'),
|
|
optionString('icon'),
|
|
optionString('text'),
|
|
defaultedFunction('onSetup', function () {
|
|
return noop;
|
|
})
|
|
];
|
|
var toolbarButtonSchema = objOf([
|
|
strictString('type'),
|
|
strictFunction('onAction')
|
|
].concat(baseToolbarButtonFields));
|
|
var createToolbarButton = function (spec) {
|
|
return asRaw('toolbarbutton', toolbarButtonSchema, spec);
|
|
};
|
|
|
|
var baseMenuButtonFields = [
|
|
optionString('text'),
|
|
optionString('tooltip'),
|
|
optionString('icon'),
|
|
strictFunction('fetch'),
|
|
defaultedFunction('onSetup', function () {
|
|
return noop;
|
|
})
|
|
];
|
|
|
|
var MenuButtonSchema = objOf(__spreadArrays([strictString('type')], baseMenuButtonFields));
|
|
var createMenuButton = function (spec) {
|
|
return asRaw('menubutton', MenuButtonSchema, spec);
|
|
};
|
|
|
|
var splitButtonSchema = objOf([
|
|
strictString('type'),
|
|
optionString('tooltip'),
|
|
optionString('icon'),
|
|
optionString('text'),
|
|
optionFunction('select'),
|
|
strictFunction('fetch'),
|
|
defaultedFunction('onSetup', function () {
|
|
return noop;
|
|
}),
|
|
defaultedStringEnum('presets', 'normal', [
|
|
'normal',
|
|
'color',
|
|
'listpreview'
|
|
]),
|
|
defaulted$1('columns', 1),
|
|
strictFunction('onAction'),
|
|
strictFunction('onItemAction')
|
|
]);
|
|
var createSplitButton = function (spec) {
|
|
return asRaw('SplitButton', splitButtonSchema, spec);
|
|
};
|
|
|
|
var baseToolbarToggleButtonFields = [defaultedBoolean('active', false)].concat(baseToolbarButtonFields);
|
|
var toggleButtonSchema = objOf(baseToolbarToggleButtonFields.concat([
|
|
strictString('type'),
|
|
strictFunction('onAction')
|
|
]));
|
|
var createToggleButton = function (spec) {
|
|
return asRaw('ToggleButton', toggleButtonSchema, spec);
|
|
};
|
|
|
|
var groupToolbarButtonSchema = objOf([
|
|
strictString('type'),
|
|
strictOf('items', oneOf([
|
|
arrOfObj$1([
|
|
strictString('name'),
|
|
strictArrayOf('items', string)
|
|
]),
|
|
string
|
|
]))
|
|
].concat(baseToolbarButtonFields));
|
|
var createGroupToolbarButton = function (spec) {
|
|
return asRaw('GroupToolbarButton', groupToolbarButtonSchema, spec);
|
|
};
|
|
|
|
var contextBarFields = [
|
|
defaultedFunction('predicate', function () {
|
|
return false;
|
|
}),
|
|
defaultedStringEnum('scope', 'node', [
|
|
'node',
|
|
'editor'
|
|
]),
|
|
defaultedStringEnum('position', 'selection', [
|
|
'node',
|
|
'selection',
|
|
'line'
|
|
])
|
|
];
|
|
var contextButtonFields = baseToolbarButtonFields.concat([
|
|
defaulted$1('type', 'contextformbutton'),
|
|
defaulted$1('primary', false),
|
|
strictFunction('onAction'),
|
|
state$1('original', identity)
|
|
]);
|
|
var contextToggleButtonFields = baseToolbarToggleButtonFields.concat([
|
|
defaulted$1('type', 'contextformbutton'),
|
|
defaulted$1('primary', false),
|
|
strictFunction('onAction'),
|
|
state$1('original', identity)
|
|
]);
|
|
var launchButtonFields = baseToolbarButtonFields.concat([defaulted$1('type', 'contextformbutton')]);
|
|
var launchToggleButtonFields = baseToolbarToggleButtonFields.concat([defaulted$1('type', 'contextformtogglebutton')]);
|
|
var toggleOrNormal = choose$1('type', {
|
|
contextformbutton: contextButtonFields,
|
|
contextformtogglebutton: contextToggleButtonFields
|
|
});
|
|
var contextFormSchema = objOf([
|
|
defaulted$1('type', 'contextform'),
|
|
defaultedFunction('initValue', function () {
|
|
return '';
|
|
}),
|
|
optionString('label'),
|
|
strictArrayOf('commands', toggleOrNormal),
|
|
optionOf('launch', choose$1('type', {
|
|
contextformbutton: launchButtonFields,
|
|
contextformtogglebutton: launchToggleButtonFields
|
|
}))
|
|
].concat(contextBarFields));
|
|
var contextToolbarSchema = objOf([
|
|
defaulted$1('type', 'contexttoolbar'),
|
|
strictString('items')
|
|
].concat(contextBarFields));
|
|
var createContextToolbar = function (spec) {
|
|
return asRaw('ContextToolbar', contextToolbarSchema, spec);
|
|
};
|
|
var createContextForm = function (spec) {
|
|
return asRaw('ContextForm', contextFormSchema, spec);
|
|
};
|
|
|
|
var getState$2 = function (component, replaceConfig, reflectState) {
|
|
return reflectState;
|
|
};
|
|
|
|
var ReflectingApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
getState: getState$2
|
|
});
|
|
|
|
var events$e = function (reflectingConfig, reflectingState) {
|
|
var update = function (component, data) {
|
|
reflectingConfig.updateState.each(function (updateState) {
|
|
var newState = updateState(component, data);
|
|
reflectingState.set(newState);
|
|
});
|
|
reflectingConfig.renderComponents.each(function (renderComponents) {
|
|
var newComponents = renderComponents(data, reflectingState.get());
|
|
var newChildren = map(newComponents, component.getSystem().build);
|
|
replaceChildren(component, newChildren);
|
|
});
|
|
};
|
|
return derive([
|
|
run(receive(), function (component, message) {
|
|
var receivingData = message;
|
|
var channel = reflectingConfig.channel;
|
|
if (contains(receivingData.channels(), channel)) {
|
|
update(component, receivingData.data());
|
|
}
|
|
}),
|
|
runOnAttached(function (comp, _se) {
|
|
reflectingConfig.initialData.each(function (rawData) {
|
|
update(comp, rawData);
|
|
});
|
|
})
|
|
]);
|
|
};
|
|
|
|
var ActiveReflecting = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$e
|
|
});
|
|
|
|
var init$a = function () {
|
|
var cell = Cell(Option.none());
|
|
var set = function (optS) {
|
|
return cell.set(optS);
|
|
};
|
|
var clear = function () {
|
|
return cell.set(Option.none());
|
|
};
|
|
var get = function () {
|
|
return cell.get();
|
|
};
|
|
var readState = function () {
|
|
return cell.get().fold(function () {
|
|
return 'none';
|
|
}, function (x) {
|
|
return x;
|
|
});
|
|
};
|
|
return {
|
|
readState: readState,
|
|
get: get,
|
|
set: set,
|
|
clear: clear
|
|
};
|
|
};
|
|
|
|
var ReflectingState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
init: init$a
|
|
});
|
|
|
|
var ReflectingSchema = [
|
|
strict$1('channel'),
|
|
option('renderComponents'),
|
|
option('updateState'),
|
|
option('initialData')
|
|
];
|
|
|
|
var Reflecting = create$1({
|
|
fields: ReflectingSchema,
|
|
name: 'reflecting',
|
|
active: ActiveReflecting,
|
|
apis: ReflectingApis,
|
|
state: ReflectingState
|
|
});
|
|
|
|
var schema$q = constant([
|
|
strict$1('toggleClass'),
|
|
strict$1('fetch'),
|
|
onStrictHandler('onExecute'),
|
|
defaulted$1('getHotspot', Option.some),
|
|
defaulted$1('getAnchorOverrides', constant({})),
|
|
schema$1(),
|
|
onStrictHandler('onItemExecute'),
|
|
option('lazySink'),
|
|
strict$1('dom'),
|
|
onHandler('onOpen'),
|
|
field$1('splitDropdownBehaviours', [
|
|
Coupling,
|
|
Keying,
|
|
Focusing
|
|
]),
|
|
defaulted$1('matchWidth', false),
|
|
defaulted$1('useMinWidth', false),
|
|
defaulted$1('eventOrder', {}),
|
|
option('role')
|
|
].concat(sandboxFields()));
|
|
var arrowPart = required({
|
|
factory: Button,
|
|
schema: [strict$1('dom')],
|
|
name: 'arrow',
|
|
defaults: function () {
|
|
return { buttonBehaviours: derive$1([Focusing.revoke()]) };
|
|
},
|
|
overrides: function (detail) {
|
|
return {
|
|
dom: {
|
|
tag: 'span',
|
|
attributes: { role: 'presentation' }
|
|
},
|
|
action: function (arrow) {
|
|
arrow.getSystem().getByUid(detail.uid).each(emitExecute);
|
|
},
|
|
buttonBehaviours: derive$1([Toggling.config({
|
|
toggleOnExecute: false,
|
|
toggleClass: detail.toggleClass
|
|
})])
|
|
};
|
|
}
|
|
});
|
|
var buttonPart = required({
|
|
factory: Button,
|
|
schema: [strict$1('dom')],
|
|
name: 'button',
|
|
defaults: function () {
|
|
return { buttonBehaviours: derive$1([Focusing.revoke()]) };
|
|
},
|
|
overrides: function (detail) {
|
|
return {
|
|
dom: {
|
|
tag: 'span',
|
|
attributes: { role: 'presentation' }
|
|
},
|
|
action: function (btn) {
|
|
btn.getSystem().getByUid(detail.uid).each(function (splitDropdown) {
|
|
detail.onExecute(splitDropdown, btn);
|
|
});
|
|
}
|
|
};
|
|
}
|
|
});
|
|
var parts$c = constant([
|
|
arrowPart,
|
|
buttonPart,
|
|
optional({
|
|
factory: {
|
|
sketch: function (spec) {
|
|
return {
|
|
uid: spec.uid,
|
|
dom: {
|
|
tag: 'span',
|
|
styles: { display: 'none' },
|
|
attributes: { 'aria-hidden': 'true' },
|
|
innerHtml: spec.text
|
|
}
|
|
};
|
|
}
|
|
},
|
|
schema: [strict$1('text')],
|
|
name: 'aria-descriptor'
|
|
}),
|
|
external$1({
|
|
schema: [tieredMenuMarkers()],
|
|
name: 'menu',
|
|
defaults: function (detail) {
|
|
return {
|
|
onExecute: function (tmenu, item) {
|
|
tmenu.getSystem().getByUid(detail.uid).each(function (splitDropdown) {
|
|
detail.onItemExecute(splitDropdown, tmenu, item);
|
|
});
|
|
}
|
|
};
|
|
}
|
|
}),
|
|
partType()
|
|
]);
|
|
|
|
var factory$e = function (detail, components, spec, externals) {
|
|
var switchToMenu = function (sandbox) {
|
|
Composing.getCurrent(sandbox).each(function (current) {
|
|
Highlighting.highlightFirst(current);
|
|
Keying.focusIn(current);
|
|
});
|
|
};
|
|
var action = function (component) {
|
|
var onOpenSync = switchToMenu;
|
|
togglePopup(detail, function (x) {
|
|
return x;
|
|
}, component, externals, onOpenSync, HighlightOnOpen.HighlightFirst).get(noop);
|
|
};
|
|
var openMenu = function (comp) {
|
|
action(comp);
|
|
return Option.some(true);
|
|
};
|
|
var executeOnButton = function (comp) {
|
|
var button = getPartOrDie(comp, detail, 'button');
|
|
emitExecute(button);
|
|
return Option.some(true);
|
|
};
|
|
var buttonEvents = __assign(__assign({}, derive([runOnAttached(function (component, _simulatedEvent) {
|
|
var ariaDescriptor = getPart(component, detail, 'aria-descriptor');
|
|
ariaDescriptor.each(function (descriptor) {
|
|
var descriptorId = generate$1('aria');
|
|
set$1(descriptor.element(), 'id', descriptorId);
|
|
set$1(component.element(), 'aria-describedby', descriptorId);
|
|
});
|
|
})])), events$7(Option.some(action)));
|
|
var apis = {
|
|
repositionMenus: function (comp) {
|
|
if (Toggling.isOn(comp)) {
|
|
repositionMenus(comp);
|
|
}
|
|
}
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
apis: apis,
|
|
eventOrder: __assign(__assign({}, detail.eventOrder), {
|
|
'alloy.execute': [
|
|
'disabling',
|
|
'toggling',
|
|
'alloy.base.behaviour'
|
|
]
|
|
}),
|
|
events: buttonEvents,
|
|
behaviours: augment(detail.splitDropdownBehaviours, [
|
|
Coupling.config({
|
|
others: {
|
|
sandbox: function (hotspot) {
|
|
var arrow = getPartOrDie(hotspot, detail, 'arrow');
|
|
var extras = {
|
|
onOpen: function () {
|
|
Toggling.on(arrow);
|
|
Toggling.on(hotspot);
|
|
},
|
|
onClose: function () {
|
|
Toggling.off(arrow);
|
|
Toggling.off(hotspot);
|
|
}
|
|
};
|
|
return makeSandbox(detail, hotspot, extras);
|
|
}
|
|
}
|
|
}),
|
|
Keying.config({
|
|
mode: 'special',
|
|
onSpace: executeOnButton,
|
|
onEnter: executeOnButton,
|
|
onDown: openMenu
|
|
}),
|
|
Focusing.config({}),
|
|
Toggling.config({
|
|
toggleOnExecute: false,
|
|
aria: { mode: 'expanded' }
|
|
})
|
|
]),
|
|
domModification: {
|
|
attributes: {
|
|
'role': detail.role.getOr('button'),
|
|
'aria-haspopup': true
|
|
}
|
|
}
|
|
};
|
|
};
|
|
var SplitDropdown = composite$1({
|
|
name: 'SplitDropdown',
|
|
configFields: schema$q(),
|
|
partFields: parts$c(),
|
|
factory: factory$e,
|
|
apis: {
|
|
repositionMenus: function (apis, comp) {
|
|
return apis.repositionMenus(comp);
|
|
}
|
|
}
|
|
});
|
|
|
|
var getButtonApi = function (component) {
|
|
return {
|
|
isDisabled: function () {
|
|
return Disabling.isDisabled(component);
|
|
},
|
|
setDisabled: function (state) {
|
|
return Disabling.set(component, state);
|
|
}
|
|
};
|
|
};
|
|
var getToggleApi = function (component) {
|
|
return {
|
|
setActive: function (state) {
|
|
Toggling.set(component, state);
|
|
},
|
|
isActive: function () {
|
|
return Toggling.isOn(component);
|
|
},
|
|
isDisabled: function () {
|
|
return Disabling.isDisabled(component);
|
|
},
|
|
setDisabled: function (state) {
|
|
return Disabling.set(component, state);
|
|
}
|
|
};
|
|
};
|
|
var getTooltipAttributes = function (tooltip, providersBackstage) {
|
|
return tooltip.map(function (tooltip) {
|
|
return {
|
|
'aria-label': providersBackstage.translate(tooltip),
|
|
'title': providersBackstage.translate(tooltip)
|
|
};
|
|
}).getOr({});
|
|
};
|
|
var focusButtonEvent = generate$1('focus-button');
|
|
var rtlIcon$1 = [
|
|
'checklist',
|
|
'ordered-list'
|
|
];
|
|
var rtlTransform$1 = [
|
|
'indent',
|
|
'outdent',
|
|
'table-insert-column-after',
|
|
'table-insert-column-before',
|
|
'unordered-list'
|
|
];
|
|
var renderCommonStructure = function (icon, text, tooltip, receiver, behaviours, providersBackstage) {
|
|
var _d;
|
|
var getIconName = function (iconName) {
|
|
return global$5.isRtl() && contains(rtlIcon$1, iconName) ? iconName + '-rtl' : iconName;
|
|
};
|
|
var needsRtlClass = global$5.isRtl() && icon.exists(function (name) {
|
|
return contains(rtlTransform$1, name);
|
|
});
|
|
return {
|
|
dom: {
|
|
tag: 'button',
|
|
classes: ['tox-tbtn'].concat(text.isSome() ? ['tox-tbtn--select'] : []).concat(needsRtlClass ? ['tox-tbtn__icon-rtl'] : []),
|
|
attributes: getTooltipAttributes(tooltip, providersBackstage)
|
|
},
|
|
components: componentRenderPipeline([
|
|
icon.map(function (iconName) {
|
|
return renderIconFromPack(getIconName(iconName), providersBackstage.icons);
|
|
}),
|
|
text.map(function (text) {
|
|
return renderLabel$1(text, 'tox-tbtn', providersBackstage);
|
|
})
|
|
]),
|
|
eventOrder: (_d = {}, _d[mousedown()] = [
|
|
'focusing',
|
|
'alloy.base.behaviour',
|
|
'common-button-display-events'
|
|
], _d),
|
|
buttonBehaviours: derive$1([
|
|
DisablingConfigs.toolbarButton(providersBackstage.isReadOnly),
|
|
receivingConfig(),
|
|
config('common-button-display-events', [run(mousedown(), function (button, se) {
|
|
se.event().prevent();
|
|
emit(button, focusButtonEvent);
|
|
})])
|
|
].concat(receiver.map(function (r) {
|
|
return Reflecting.config({
|
|
channel: r,
|
|
initialData: {
|
|
icon: icon,
|
|
text: text
|
|
},
|
|
renderComponents: function (data, _state) {
|
|
return componentRenderPipeline([
|
|
data.icon.map(function (iconName) {
|
|
return renderIconFromPack(getIconName(iconName), providersBackstage.icons);
|
|
}),
|
|
data.text.map(function (text) {
|
|
return renderLabel$1(text, 'tox-tbtn', providersBackstage);
|
|
})
|
|
]);
|
|
}
|
|
});
|
|
}).toArray()).concat(behaviours.getOr([])))
|
|
};
|
|
};
|
|
var renderFloatingToolbarButton = function (spec, backstage, identifyButtons, attributes) {
|
|
var sharedBackstage = backstage.shared;
|
|
return FloatingToolbarButton.sketch({
|
|
lazySink: sharedBackstage.getSink,
|
|
fetch: function () {
|
|
return Future.nu(function (resolve) {
|
|
resolve(map(identifyButtons(spec.items), renderToolbarGroup));
|
|
});
|
|
},
|
|
markers: { toggledClass: 'tox-tbtn--enabled' },
|
|
parts: {
|
|
button: renderCommonStructure(spec.icon, spec.text, spec.tooltip, Option.none(), Option.none(), sharedBackstage.providers),
|
|
toolbar: {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-toolbar__overflow'],
|
|
attributes: attributes
|
|
}
|
|
}
|
|
}
|
|
});
|
|
};
|
|
var renderCommonToolbarButton = function (spec, specialisation, providersBackstage) {
|
|
var editorOffCell = Cell(noop);
|
|
var structure = renderCommonStructure(spec.icon, spec.text, spec.tooltip, Option.none(), Option.none(), providersBackstage);
|
|
return Button.sketch({
|
|
dom: structure.dom,
|
|
components: structure.components,
|
|
eventOrder: toolbarButtonEventOrder,
|
|
buttonBehaviours: derive$1([
|
|
config('toolbar-button-events', [
|
|
onToolbarButtonExecute({
|
|
onAction: spec.onAction,
|
|
getApi: specialisation.getApi
|
|
}),
|
|
onControlAttached(specialisation, editorOffCell),
|
|
onControlDetached(specialisation, editorOffCell)
|
|
]),
|
|
DisablingConfigs.toolbarButton(function () {
|
|
return spec.disabled || providersBackstage.isReadOnly();
|
|
}),
|
|
receivingConfig()
|
|
].concat(specialisation.toolbarButtonBehaviours))
|
|
});
|
|
};
|
|
var renderToolbarButton = function (spec, providersBackstage) {
|
|
return renderToolbarButtonWith(spec, providersBackstage, []);
|
|
};
|
|
var renderToolbarButtonWith = function (spec, providersBackstage, bonusEvents) {
|
|
return renderCommonToolbarButton(spec, {
|
|
toolbarButtonBehaviours: [].concat(bonusEvents.length > 0 ? [config('toolbarButtonWith', bonusEvents)] : []),
|
|
getApi: getButtonApi,
|
|
onSetup: spec.onSetup
|
|
}, providersBackstage);
|
|
};
|
|
var renderToolbarToggleButton = function (spec, providersBackstage) {
|
|
return renderToolbarToggleButtonWith(spec, providersBackstage, []);
|
|
};
|
|
var renderToolbarToggleButtonWith = function (spec, providersBackstage, bonusEvents) {
|
|
return deepMerge(renderCommonToolbarButton(spec, {
|
|
toolbarButtonBehaviours: [
|
|
Replacing.config({}),
|
|
Toggling.config({
|
|
toggleClass: 'tox-tbtn--enabled',
|
|
aria: { mode: 'pressed' },
|
|
toggleOnExecute: false
|
|
})
|
|
].concat(bonusEvents.length > 0 ? [config('toolbarToggleButtonWith', bonusEvents)] : []),
|
|
getApi: getToggleApi,
|
|
onSetup: spec.onSetup
|
|
}, providersBackstage));
|
|
};
|
|
var fetchChoices = function (getApi, spec, providersBackstage) {
|
|
return function (comp) {
|
|
return Future.nu(function (callback) {
|
|
return spec.fetch(callback);
|
|
}).map(function (items) {
|
|
return Option.from(createTieredDataFrom(deepMerge(createPartialChoiceMenu(generate$1('menu-value'), items, function (value) {
|
|
spec.onItemAction(getApi(comp), value);
|
|
}, spec.columns, spec.presets, ItemResponse$1.CLOSE_ON_EXECUTE, spec.select.getOr(function () {
|
|
return false;
|
|
}), providersBackstage), {
|
|
movement: deriveMenuMovement(spec.columns, spec.presets),
|
|
menuBehaviours: SimpleBehaviours.unnamedEvents(spec.columns !== 'auto' ? [] : [runOnAttached(function (comp, _se) {
|
|
detectSize(comp, 4, classForPreset(spec.presets)).each(function (_d) {
|
|
var numRows = _d.numRows, numColumns = _d.numColumns;
|
|
Keying.setGridSize(comp, numRows, numColumns);
|
|
});
|
|
})])
|
|
})));
|
|
});
|
|
};
|
|
};
|
|
var renderSplitButton = function (spec, sharedBackstage) {
|
|
var _d;
|
|
var displayChannel = generate$1('channel-update-split-dropdown-display');
|
|
var getApi = function (comp) {
|
|
return {
|
|
isDisabled: function () {
|
|
return Disabling.isDisabled(comp);
|
|
},
|
|
setDisabled: function (state) {
|
|
return Disabling.set(comp, state);
|
|
},
|
|
setIconFill: function (id, value) {
|
|
descendant$1(comp.element(), 'svg path[id="' + id + '"], rect[id="' + id + '"]').each(function (underlinePath) {
|
|
set$1(underlinePath, 'fill', value);
|
|
});
|
|
},
|
|
setIconStroke: function (id, value) {
|
|
descendant$1(comp.element(), 'svg path[id="' + id + '"], rect[id="' + id + '"]').each(function (underlinePath) {
|
|
set$1(underlinePath, 'stroke', value);
|
|
});
|
|
},
|
|
setActive: function (state) {
|
|
set$1(comp.element(), 'aria-pressed', state);
|
|
descendant$1(comp.element(), 'span').each(function (button) {
|
|
comp.getSystem().getByDom(button).each(function (buttonComp) {
|
|
return Toggling.set(buttonComp, state);
|
|
});
|
|
});
|
|
},
|
|
isActive: function () {
|
|
return descendant$1(comp.element(), 'span').exists(function (button) {
|
|
return comp.getSystem().getByDom(button).exists(Toggling.isOn);
|
|
});
|
|
}
|
|
};
|
|
};
|
|
var editorOffCell = Cell(noop);
|
|
var specialisation = {
|
|
getApi: getApi,
|
|
onSetup: spec.onSetup
|
|
};
|
|
return SplitDropdown.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-split-button'],
|
|
attributes: __assign({ 'aria-pressed': false }, getTooltipAttributes(spec.tooltip, sharedBackstage.providers))
|
|
},
|
|
onExecute: function (button) {
|
|
spec.onAction(getApi(button));
|
|
},
|
|
onItemExecute: function (_a, _b, _c) {
|
|
},
|
|
splitDropdownBehaviours: derive$1([
|
|
DisablingConfigs.splitButton(sharedBackstage.providers.isReadOnly),
|
|
receivingConfig(),
|
|
config('split-dropdown-events', [
|
|
run(focusButtonEvent, Focusing.focus),
|
|
onControlAttached(specialisation, editorOffCell),
|
|
onControlDetached(specialisation, editorOffCell)
|
|
]),
|
|
Unselecting.config({})
|
|
]),
|
|
eventOrder: (_d = {}, _d[attachedToDom()] = [
|
|
'alloy.base.behaviour',
|
|
'split-dropdown-events'
|
|
], _d),
|
|
toggleClass: 'tox-tbtn--enabled',
|
|
lazySink: sharedBackstage.getSink,
|
|
fetch: fetchChoices(getApi, spec, sharedBackstage.providers),
|
|
parts: { menu: part(false, spec.columns, spec.presets) },
|
|
components: [
|
|
SplitDropdown.parts().button(renderCommonStructure(spec.icon, spec.text, Option.none(), Option.some(displayChannel), Option.some([Toggling.config({
|
|
toggleClass: 'tox-tbtn--enabled',
|
|
toggleOnExecute: false
|
|
})]), sharedBackstage.providers)),
|
|
SplitDropdown.parts().arrow({
|
|
dom: {
|
|
tag: 'button',
|
|
classes: [
|
|
'tox-tbtn',
|
|
'tox-split-button__chevron'
|
|
],
|
|
innerHtml: get$d('chevron-down', sharedBackstage.providers.icons)
|
|
},
|
|
buttonBehaviours: derive$1([
|
|
DisablingConfigs.splitButton(sharedBackstage.providers.isReadOnly),
|
|
receivingConfig()
|
|
])
|
|
}),
|
|
SplitDropdown.parts()['aria-descriptor']({ text: sharedBackstage.providers.translate('To open the popup, press Shift+Enter') })
|
|
]
|
|
});
|
|
};
|
|
|
|
var getFormApi = function (input) {
|
|
return {
|
|
hide: function () {
|
|
return emit(input, sandboxClose());
|
|
},
|
|
getValue: function () {
|
|
return Representing.getValue(input);
|
|
}
|
|
};
|
|
};
|
|
var runOnExecute$1 = function (memInput, original) {
|
|
return run(internalToolbarButtonExecute, function (comp, se) {
|
|
var input = memInput.get(comp);
|
|
var formApi = getFormApi(input);
|
|
original.onAction(formApi, se.event().buttonApi());
|
|
});
|
|
};
|
|
var renderContextButton = function (memInput, button, extras) {
|
|
var _a = button.original, primary = _a.primary, rest = __rest(_a, ['primary']);
|
|
var bridged = getOrDie(createToolbarButton(__assign(__assign({}, rest), {
|
|
type: 'button',
|
|
onAction: function () {
|
|
}
|
|
})));
|
|
return renderToolbarButtonWith(bridged, extras.backstage.shared.providers, [runOnExecute$1(memInput, button)]);
|
|
};
|
|
var renderContextToggleButton = function (memInput, button, extras) {
|
|
var _a = button.original, primary = _a.primary, rest = __rest(_a, ['primary']);
|
|
var bridged = getOrDie(createToggleButton(__assign(__assign({}, rest), {
|
|
type: 'togglebutton',
|
|
onAction: function () {
|
|
}
|
|
})));
|
|
return renderToolbarToggleButtonWith(bridged, extras.backstage.shared.providers, [runOnExecute$1(memInput, button)]);
|
|
};
|
|
var generateOne$1 = function (memInput, button, providersBackstage) {
|
|
var extras = { backstage: { shared: { providers: providersBackstage } } };
|
|
if (button.type === 'contextformtogglebutton') {
|
|
return renderContextToggleButton(memInput, button, extras);
|
|
} else {
|
|
return renderContextButton(memInput, button, extras);
|
|
}
|
|
};
|
|
var generate$7 = function (memInput, buttons, providersBackstage) {
|
|
var mementos = map(buttons, function (button) {
|
|
return record(generateOne$1(memInput, button, providersBackstage));
|
|
});
|
|
var asSpecs = function () {
|
|
return map(mementos, function (mem) {
|
|
return mem.asSpec();
|
|
});
|
|
};
|
|
var findPrimary = function (compInSystem) {
|
|
return findMap(buttons, function (button, i) {
|
|
if (button.primary) {
|
|
return Option.from(mementos[i]).bind(function (mem) {
|
|
return mem.getOpt(compInSystem);
|
|
}).filter(not(Disabling.isDisabled));
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
});
|
|
};
|
|
return {
|
|
asSpecs: asSpecs,
|
|
findPrimary: findPrimary
|
|
};
|
|
};
|
|
|
|
var buildInitGroups = function (ctx, providers) {
|
|
var inputAttributes = ctx.label.fold(function () {
|
|
return {};
|
|
}, function (label) {
|
|
return { 'aria-label': label };
|
|
});
|
|
var memInput = record(Input.sketch({
|
|
inputClasses: [
|
|
'tox-toolbar-textfield',
|
|
'tox-toolbar-nav-js'
|
|
],
|
|
data: ctx.initValue(),
|
|
inputAttributes: inputAttributes,
|
|
selectOnFocus: true,
|
|
inputBehaviours: derive$1([Keying.config({
|
|
mode: 'special',
|
|
onEnter: function (input) {
|
|
return commands.findPrimary(input).map(function (primary) {
|
|
emitExecute(primary);
|
|
return true;
|
|
});
|
|
},
|
|
onLeft: function (comp, se) {
|
|
se.cut();
|
|
return Option.none();
|
|
},
|
|
onRight: function (comp, se) {
|
|
se.cut();
|
|
return Option.none();
|
|
}
|
|
})])
|
|
}));
|
|
var commands = generate$7(memInput, ctx.commands, providers);
|
|
return [
|
|
{
|
|
title: Option.none(),
|
|
items: [memInput.asSpec()]
|
|
},
|
|
{
|
|
title: Option.none(),
|
|
items: commands.asSpecs()
|
|
}
|
|
];
|
|
};
|
|
var renderContextForm = function (toolbarType, ctx, providers) {
|
|
return renderToolbar({
|
|
type: toolbarType,
|
|
uid: generate$1('context-toolbar'),
|
|
initGroups: buildInitGroups(ctx, providers),
|
|
onEscape: Option.none,
|
|
cyclicKeying: true,
|
|
providers: providers
|
|
});
|
|
};
|
|
var ContextForm = {
|
|
renderContextForm: renderContextForm,
|
|
buildInitGroups: buildInitGroups
|
|
};
|
|
|
|
var getHorizontalBounds = function (contentAreaBox, viewportBounds) {
|
|
var x = Math.max(viewportBounds.x, contentAreaBox.x);
|
|
var contentBoxWidth = contentAreaBox.right - x;
|
|
var maxViewportWidth = viewportBounds.width - (x - viewportBounds.x);
|
|
var width = Math.min(contentBoxWidth, maxViewportWidth);
|
|
return {
|
|
x: x,
|
|
width: width
|
|
};
|
|
};
|
|
var getVerticalBounds = function (editor, contentAreaBox, viewportBounds, isToolbarLocationTop) {
|
|
var container = Element.fromDom(editor.getContainer());
|
|
var header = descendant$1(container, '.tox-editor-header').getOr(container);
|
|
var headerBox = box(header);
|
|
var isToolbarBelowContentArea = headerBox.y >= contentAreaBox.bottom;
|
|
var isToolbarAbove = isToolbarLocationTop && !isToolbarBelowContentArea;
|
|
if (editor.inline && isToolbarAbove) {
|
|
return {
|
|
y: Math.max(headerBox.bottom, viewportBounds.y),
|
|
bottom: viewportBounds.bottom
|
|
};
|
|
}
|
|
if (editor.inline && !isToolbarAbove) {
|
|
return {
|
|
y: viewportBounds.y,
|
|
bottom: Math.min(headerBox.y, viewportBounds.bottom)
|
|
};
|
|
}
|
|
var containerBounds = box(container);
|
|
if (isToolbarAbove) {
|
|
return {
|
|
y: Math.max(headerBox.bottom, viewportBounds.y),
|
|
bottom: Math.min(containerBounds.bottom, viewportBounds.bottom)
|
|
};
|
|
}
|
|
return {
|
|
y: Math.max(containerBounds.y, viewportBounds.y),
|
|
bottom: Math.min(headerBox.y, viewportBounds.bottom)
|
|
};
|
|
};
|
|
var getContextToolbarBounds = function (editor, sharedBackstage) {
|
|
var viewportBounds = getBounds(domGlobals.window);
|
|
var contentAreaBox = box(Element.fromDom(editor.getContentAreaContainer()));
|
|
var toolbarOrMenubarEnabled = isMenubarEnabled(editor) || isToolbarEnabled(editor) || isMultipleToolbars(editor);
|
|
var _a = getHorizontalBounds(contentAreaBox, viewportBounds), x = _a.x, width = _a.width;
|
|
if (editor.inline && !toolbarOrMenubarEnabled) {
|
|
return bounds$1(x, viewportBounds.y, width, viewportBounds.height);
|
|
} else {
|
|
var isToolbarTop = sharedBackstage.header.isPositionedAtTop();
|
|
var _b = getVerticalBounds(editor, contentAreaBox, viewportBounds, isToolbarTop), y = _b.y, bottom = _b.bottom;
|
|
return bounds$1(x, y, width, bottom - y);
|
|
}
|
|
};
|
|
|
|
var matchTargetWith = function (elem, candidates) {
|
|
var ctxs = filter(candidates, function (toolbarApi) {
|
|
return toolbarApi.predicate(elem.dom());
|
|
});
|
|
var _a = partition(ctxs, function (t) {
|
|
return t.type === 'contexttoolbar';
|
|
}), pass = _a.pass, fail = _a.fail;
|
|
return {
|
|
contextToolbars: pass,
|
|
contextForms: fail
|
|
};
|
|
};
|
|
var filterByPositionForStartNode = function (toolbars) {
|
|
if (toolbars.length <= 1) {
|
|
return toolbars;
|
|
} else {
|
|
var doesPositionExist = function (value) {
|
|
return exists(toolbars, function (t) {
|
|
return t.position === value;
|
|
});
|
|
};
|
|
var filterToolbarsByPosition = function (value) {
|
|
return filter(toolbars, function (t) {
|
|
return t.position === value;
|
|
});
|
|
};
|
|
var hasSelectionToolbars = doesPositionExist('selection');
|
|
var hasNodeToolbars = doesPositionExist('node');
|
|
if (hasSelectionToolbars || hasNodeToolbars) {
|
|
if (hasNodeToolbars && hasSelectionToolbars) {
|
|
var nodeToolbars = filterToolbarsByPosition('node');
|
|
var selectionToolbars = map(filterToolbarsByPosition('selection'), function (t) {
|
|
return __assign(__assign({}, t), { position: 'node' });
|
|
});
|
|
return nodeToolbars.concat(selectionToolbars);
|
|
} else {
|
|
return hasSelectionToolbars ? filterToolbarsByPosition('selection') : filterToolbarsByPosition('node');
|
|
}
|
|
} else {
|
|
return filterToolbarsByPosition('line');
|
|
}
|
|
}
|
|
};
|
|
var filterByPositionForAncestorNode = function (toolbars) {
|
|
if (toolbars.length <= 1) {
|
|
return toolbars;
|
|
} else {
|
|
var findPosition_1 = function (value) {
|
|
return find(toolbars, function (t) {
|
|
return t.position === value;
|
|
});
|
|
};
|
|
var basePosition = findPosition_1('selection').orThunk(function () {
|
|
return findPosition_1('node');
|
|
}).orThunk(function () {
|
|
return findPosition_1('line');
|
|
}).map(function (t) {
|
|
return t.position;
|
|
});
|
|
return basePosition.fold(function () {
|
|
return [];
|
|
}, function (pos) {
|
|
return filter(toolbars, function (t) {
|
|
return t.position === pos;
|
|
});
|
|
});
|
|
}
|
|
};
|
|
var matchStartNode = function (elem, nodeCandidates, editorCandidates) {
|
|
var nodeMatches = matchTargetWith(elem, nodeCandidates);
|
|
if (nodeMatches.contextForms.length > 0) {
|
|
return Option.some({
|
|
elem: elem,
|
|
toolbars: [nodeMatches.contextForms[0]]
|
|
});
|
|
} else {
|
|
var editorMatches = matchTargetWith(elem, editorCandidates);
|
|
if (editorMatches.contextForms.length > 0) {
|
|
return Option.some({
|
|
elem: elem,
|
|
toolbars: [editorMatches.contextForms[0]]
|
|
});
|
|
} else if (nodeMatches.contextToolbars.length > 0 || editorMatches.contextToolbars.length > 0) {
|
|
var toolbars = filterByPositionForStartNode(nodeMatches.contextToolbars.concat(editorMatches.contextToolbars));
|
|
return Option.some({
|
|
elem: elem,
|
|
toolbars: toolbars
|
|
});
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
}
|
|
};
|
|
var matchAncestor = function (isRoot, startNode, scopes) {
|
|
if (isRoot(startNode)) {
|
|
return Option.none();
|
|
} else {
|
|
return ancestor(startNode, function (ancestorElem) {
|
|
var _a = matchTargetWith(ancestorElem, scopes.inNodeScope), contextToolbars = _a.contextToolbars, contextForms = _a.contextForms;
|
|
var toolbars = contextForms.length > 0 ? contextForms : filterByPositionForAncestorNode(contextToolbars);
|
|
return toolbars.length > 0 ? Option.some({
|
|
elem: ancestorElem,
|
|
toolbars: toolbars
|
|
}) : Option.none();
|
|
}, isRoot);
|
|
}
|
|
};
|
|
var lookup$1 = function (scopes, editor) {
|
|
var rootElem = Element.fromDom(editor.getBody());
|
|
var isRoot = function (elem) {
|
|
return eq$1(elem, rootElem);
|
|
};
|
|
var isOutsideRoot = function (startNode) {
|
|
return !isRoot(startNode) && !contains$2(rootElem, startNode);
|
|
};
|
|
var startNode = Element.fromDom(editor.selection.getNode());
|
|
if (isOutsideRoot(startNode)) {
|
|
return Option.none();
|
|
}
|
|
return matchStartNode(startNode, scopes.inNodeScope, scopes.inEditorScope).orThunk(function () {
|
|
return matchAncestor(isRoot, startNode, scopes);
|
|
});
|
|
};
|
|
|
|
var categorise = function (contextToolbars, navigate) {
|
|
var forms = {};
|
|
var inNodeScope = [];
|
|
var inEditorScope = [];
|
|
var formNavigators = {};
|
|
var lookupTable = {};
|
|
var registerForm = function (key, toolbarApi) {
|
|
var contextForm = getOrDie(createContextForm(toolbarApi));
|
|
forms[key] = contextForm;
|
|
contextForm.launch.map(function (launch) {
|
|
formNavigators['form:' + key + ''] = __assign(__assign({}, toolbarApi.launch), {
|
|
type: launch.type === 'contextformtogglebutton' ? 'togglebutton' : 'button',
|
|
onAction: function () {
|
|
navigate(contextForm);
|
|
}
|
|
});
|
|
});
|
|
if (contextForm.scope === 'editor') {
|
|
inEditorScope.push(contextForm);
|
|
} else {
|
|
inNodeScope.push(contextForm);
|
|
}
|
|
lookupTable[key] = contextForm;
|
|
};
|
|
var registerToolbar = function (key, toolbarApi) {
|
|
createContextToolbar(toolbarApi).each(function (contextToolbar) {
|
|
if (toolbarApi.scope === 'editor') {
|
|
inEditorScope.push(contextToolbar);
|
|
} else {
|
|
inNodeScope.push(contextToolbar);
|
|
}
|
|
lookupTable[key] = contextToolbar;
|
|
});
|
|
};
|
|
var keys$1 = keys(contextToolbars);
|
|
each(keys$1, function (key) {
|
|
var toolbarApi = contextToolbars[key];
|
|
if (toolbarApi.type === 'contextform') {
|
|
registerForm(key, toolbarApi);
|
|
} else if (toolbarApi.type === 'contexttoolbar') {
|
|
registerToolbar(key, toolbarApi);
|
|
}
|
|
});
|
|
return {
|
|
forms: forms,
|
|
inNodeScope: inNodeScope,
|
|
inEditorScope: inEditorScope,
|
|
lookupTable: lookupTable,
|
|
formNavigators: formNavigators
|
|
};
|
|
};
|
|
|
|
var forwardSlideEvent = generate$1('forward-slide');
|
|
var backSlideEvent = generate$1('backward-slide');
|
|
var changeSlideEvent = generate$1('change-slide-event');
|
|
var resizingClass = 'tox-pop--resizing';
|
|
var renderContextToolbar = function (spec) {
|
|
var stack = Cell([]);
|
|
return InlineView.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-pop']
|
|
},
|
|
fireDismissalEventInstead: { event: 'doNotDismissYet' },
|
|
onShow: function (comp) {
|
|
stack.set([]);
|
|
InlineView.getContent(comp).each(function (c) {
|
|
remove$6(c.element(), 'visibility');
|
|
});
|
|
remove$4(comp.element(), resizingClass);
|
|
remove$6(comp.element(), 'width');
|
|
},
|
|
inlineBehaviours: derive$1([
|
|
config('context-toolbar-events', [
|
|
runOnSource(transitionend(), function (comp, _se) {
|
|
remove$4(comp.element(), resizingClass);
|
|
remove$6(comp.element(), 'width');
|
|
}),
|
|
run(changeSlideEvent, function (comp, se) {
|
|
remove$6(comp.element(), 'width');
|
|
var currentWidth = get$7(comp.element());
|
|
InlineView.setContent(comp, se.event().contents());
|
|
add$2(comp.element(), resizingClass);
|
|
var newWidth = get$7(comp.element());
|
|
set$2(comp.element(), 'width', currentWidth + 'px');
|
|
InlineView.getContent(comp).each(function (newContents) {
|
|
se.event().focus().bind(function (f) {
|
|
focus$1(f);
|
|
return search(comp.element());
|
|
}).orThunk(function () {
|
|
Keying.focusIn(newContents);
|
|
return active();
|
|
});
|
|
});
|
|
global$2.setTimeout(function () {
|
|
set$2(comp.element(), 'width', newWidth + 'px');
|
|
}, 0);
|
|
}),
|
|
run(forwardSlideEvent, function (comp, se) {
|
|
InlineView.getContent(comp).each(function (oldContents) {
|
|
stack.set(stack.get().concat([{
|
|
bar: oldContents,
|
|
focus: active()
|
|
}]));
|
|
});
|
|
emitWith(comp, changeSlideEvent, {
|
|
contents: se.event().forwardContents(),
|
|
focus: Option.none()
|
|
});
|
|
}),
|
|
run(backSlideEvent, function (comp, _se) {
|
|
last(stack.get()).each(function (last) {
|
|
stack.set(stack.get().slice(0, stack.get().length - 1));
|
|
emitWith(comp, changeSlideEvent, {
|
|
contents: premade$1(last.bar),
|
|
focus: last.focus
|
|
});
|
|
});
|
|
})
|
|
]),
|
|
Keying.config({
|
|
mode: 'special',
|
|
onEscape: function (comp) {
|
|
return last(stack.get()).fold(function () {
|
|
return spec.onEscape();
|
|
}, function (_) {
|
|
emit(comp, backSlideEvent);
|
|
return Option.some(true);
|
|
});
|
|
}
|
|
})
|
|
]),
|
|
lazySink: function () {
|
|
return Result.value(spec.sink);
|
|
}
|
|
});
|
|
};
|
|
|
|
var generateSelectItems = function (_editor, backstage, spec) {
|
|
var generateItem = function (rawItem, response, disabled, value) {
|
|
var translatedText = backstage.shared.providers.translate(rawItem.title);
|
|
if (rawItem.type === 'separator') {
|
|
return Option.some({
|
|
type: 'separator',
|
|
text: translatedText
|
|
});
|
|
} else if (rawItem.type === 'submenu') {
|
|
var items = bind(rawItem.getStyleItems(), function (si) {
|
|
return validate(si, response, value);
|
|
});
|
|
if (response === 0 && items.length <= 0) {
|
|
return Option.none();
|
|
} else {
|
|
return Option.some({
|
|
type: 'nestedmenuitem',
|
|
text: translatedText,
|
|
disabled: items.length <= 0,
|
|
getSubmenuItems: function () {
|
|
return bind(rawItem.getStyleItems(), function (si) {
|
|
return validate(si, response, value);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
} else {
|
|
return Option.some(__assign({
|
|
type: 'togglemenuitem',
|
|
text: translatedText,
|
|
icon: rawItem.icon,
|
|
active: rawItem.isSelected(value),
|
|
disabled: disabled,
|
|
onAction: spec.onAction(rawItem)
|
|
}, rawItem.getStylePreview().fold(function () {
|
|
return {};
|
|
}, function (preview) {
|
|
return { meta: { style: preview } };
|
|
})));
|
|
}
|
|
};
|
|
var validate = function (item, response, value) {
|
|
var invalid = item.type === 'formatter' && spec.isInvalid(item);
|
|
if (response === 0) {
|
|
return invalid ? [] : generateItem(item, response, false, value).toArray();
|
|
} else {
|
|
return generateItem(item, response, invalid, value).toArray();
|
|
}
|
|
};
|
|
var validateItems = function (preItems) {
|
|
var value = spec.getCurrentValue();
|
|
var response = spec.shouldHide ? 0 : 1;
|
|
return bind(preItems, function (item) {
|
|
return validate(item, response, value);
|
|
});
|
|
};
|
|
var getFetch = function (backstage, getStyleItems) {
|
|
return function (callback) {
|
|
var preItems = getStyleItems();
|
|
var items = validateItems(preItems);
|
|
var menu = build$2(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, false);
|
|
callback(menu);
|
|
};
|
|
};
|
|
return {
|
|
validateItems: validateItems,
|
|
getFetch: getFetch
|
|
};
|
|
};
|
|
var createMenuItems = function (editor, backstage, spec) {
|
|
var dataset = spec.dataset;
|
|
var getStyleItems = dataset.type === 'basic' ? function () {
|
|
return map(dataset.data, function (d) {
|
|
return processBasic(d, spec.isSelectedFor, spec.getPreviewFor);
|
|
});
|
|
} : dataset.getData;
|
|
return {
|
|
items: generateSelectItems(editor, backstage, spec),
|
|
getStyleItems: getStyleItems
|
|
};
|
|
};
|
|
var createSelectButton = function (editor, backstage, spec) {
|
|
var _a = createMenuItems(editor, backstage, spec), items = _a.items, getStyleItems = _a.getStyleItems;
|
|
var getApi = function (comp) {
|
|
return {
|
|
getComponent: function () {
|
|
return comp;
|
|
}
|
|
};
|
|
};
|
|
var onSetup = function (api) {
|
|
spec.setInitialValue.each(function (f) {
|
|
return f(api.getComponent());
|
|
});
|
|
return spec.nodeChangeHandler.map(function (f) {
|
|
var handler = f(api.getComponent());
|
|
editor.on('NodeChange', handler);
|
|
return function () {
|
|
editor.off('NodeChange', handler);
|
|
};
|
|
}).getOr(noop);
|
|
};
|
|
return renderCommonDropdown({
|
|
text: spec.icon.isSome() ? Option.none() : Option.some(''),
|
|
icon: spec.icon,
|
|
tooltip: Option.from(spec.tooltip),
|
|
role: Option.none(),
|
|
fetch: items.getFetch(backstage, getStyleItems),
|
|
onSetup: onSetup,
|
|
getApi: getApi,
|
|
columns: 1,
|
|
presets: 'normal',
|
|
classes: spec.icon.isSome() ? [] : ['bespoke'],
|
|
dropdownBehaviours: []
|
|
}, 'tox-tbtn', backstage.shared);
|
|
};
|
|
|
|
var process = function (rawFormats) {
|
|
return map(rawFormats, function (item) {
|
|
var title = item, format = item;
|
|
var values = item.split('=');
|
|
if (values.length > 1) {
|
|
title = values[0];
|
|
format = values[1];
|
|
}
|
|
return {
|
|
title: title,
|
|
format: format
|
|
};
|
|
});
|
|
};
|
|
var buildBasicStaticDataset = function (data) {
|
|
return {
|
|
type: 'basic',
|
|
data: data
|
|
};
|
|
};
|
|
var Delimiter;
|
|
(function (Delimiter) {
|
|
Delimiter[Delimiter['SemiColon'] = 0] = 'SemiColon';
|
|
Delimiter[Delimiter['Space'] = 1] = 'Space';
|
|
}(Delimiter || (Delimiter = {})));
|
|
var split = function (rawFormats, delimiter) {
|
|
if (delimiter === Delimiter.SemiColon) {
|
|
return rawFormats.replace(/;$/, '').split(';');
|
|
} else {
|
|
return rawFormats.split(' ');
|
|
}
|
|
};
|
|
var buildBasicSettingsDataset = function (editor, settingName, defaults, delimiter) {
|
|
var rawFormats = get(editor.settings, settingName).getOr(defaults);
|
|
var data = process(split(rawFormats, delimiter));
|
|
return {
|
|
type: 'basic',
|
|
data: data
|
|
};
|
|
};
|
|
|
|
var alignMenuItems = [
|
|
{
|
|
title: 'Left',
|
|
icon: 'align-left',
|
|
format: 'alignleft',
|
|
command: 'JustifyLeft'
|
|
},
|
|
{
|
|
title: 'Center',
|
|
icon: 'align-center',
|
|
format: 'aligncenter',
|
|
command: 'JustifyCenter'
|
|
},
|
|
{
|
|
title: 'Right',
|
|
icon: 'align-right',
|
|
format: 'alignright',
|
|
command: 'JustifyRight'
|
|
},
|
|
{
|
|
title: 'Justify',
|
|
icon: 'align-justify',
|
|
format: 'alignjustify',
|
|
command: 'JustifyFull'
|
|
}
|
|
];
|
|
var getSpec = function (editor) {
|
|
var getMatchingValue = function () {
|
|
return find(alignMenuItems, function (item) {
|
|
return editor.formatter.match(item.format);
|
|
});
|
|
};
|
|
var isSelectedFor = function (format) {
|
|
return function () {
|
|
return editor.formatter.match(format);
|
|
};
|
|
};
|
|
var getPreviewFor = function (_format) {
|
|
return function () {
|
|
return Option.none();
|
|
};
|
|
};
|
|
var updateSelectMenuIcon = function (comp) {
|
|
var match = getMatchingValue();
|
|
var alignment = match.fold(function () {
|
|
return 'left';
|
|
}, function (item) {
|
|
return item.title.toLowerCase();
|
|
});
|
|
emitWith(comp, updateMenuIcon, { icon: 'align-' + alignment });
|
|
};
|
|
var nodeChangeHandler = Option.some(function (comp) {
|
|
return function () {
|
|
return updateSelectMenuIcon(comp);
|
|
};
|
|
});
|
|
var setInitialValue = Option.some(function (comp) {
|
|
return updateSelectMenuIcon(comp);
|
|
});
|
|
var dataset = buildBasicStaticDataset(alignMenuItems);
|
|
var onAction = function (rawItem) {
|
|
return function () {
|
|
return find(alignMenuItems, function (item) {
|
|
return item.format === rawItem.format;
|
|
}).each(function (item) {
|
|
return editor.execCommand(item.command);
|
|
});
|
|
};
|
|
};
|
|
return {
|
|
tooltip: 'Align',
|
|
icon: Option.some('align-left'),
|
|
isSelectedFor: isSelectedFor,
|
|
getCurrentValue: constant(Option.none()),
|
|
getPreviewFor: getPreviewFor,
|
|
onAction: onAction,
|
|
setInitialValue: setInitialValue,
|
|
nodeChangeHandler: nodeChangeHandler,
|
|
dataset: dataset,
|
|
shouldHide: false,
|
|
isInvalid: function (item) {
|
|
return !editor.formatter.canApply(item.format);
|
|
}
|
|
};
|
|
};
|
|
var createAlignSelect = function (editor, backstage) {
|
|
return createSelectButton(editor, backstage, getSpec(editor));
|
|
};
|
|
var alignSelectMenu = function (editor, backstage) {
|
|
var menuItems = createMenuItems(editor, backstage, getSpec(editor));
|
|
editor.ui.registry.addNestedMenuItem('align', {
|
|
text: backstage.shared.providers.translate('Align'),
|
|
getSubmenuItems: function () {
|
|
return menuItems.items.validateItems(menuItems.getStyleItems());
|
|
}
|
|
});
|
|
};
|
|
|
|
var defaultFontsFormats = 'Andale Mono=andale mono,monospace;' + 'Arial=arial,helvetica,sans-serif;' + 'Arial Black=arial black,sans-serif;' + 'Book Antiqua=book antiqua,palatino,serif;' + 'Comic Sans MS=comic sans ms,sans-serif;' + 'Courier New=courier new,courier,monospace;' + 'Georgia=georgia,palatino,serif;' + 'Helvetica=helvetica,arial,sans-serif;' + 'Impact=impact,sans-serif;' + 'Symbol=symbol;' + 'Tahoma=tahoma,arial,helvetica,sans-serif;' + 'Terminal=terminal,monaco,monospace;' + 'Times New Roman=times new roman,times,serif;' + 'Trebuchet MS=trebuchet ms,geneva,sans-serif;' + 'Verdana=verdana,geneva,sans-serif;' + 'Webdings=webdings;' + 'Wingdings=wingdings,zapf dingbats';
|
|
var systemStackFonts = [
|
|
'-apple-system',
|
|
'Segoe UI',
|
|
'Roboto',
|
|
'Helvetica Neue',
|
|
'sans-serif'
|
|
];
|
|
var splitFonts = function (fontFamily) {
|
|
var fonts = fontFamily.split(/\s*,\s*/);
|
|
return map(fonts, function (font) {
|
|
return font.replace(/^['"]+|['"]+$/g, '');
|
|
});
|
|
};
|
|
var isSystemFontStack = function (fontFamily) {
|
|
var matchesSystemStack = function () {
|
|
var fonts = splitFonts(fontFamily.toLowerCase());
|
|
return forall(systemStackFonts, function (font) {
|
|
return fonts.indexOf(font.toLowerCase()) > -1;
|
|
});
|
|
};
|
|
return fontFamily.indexOf('-apple-system') === 0 && matchesSystemStack();
|
|
};
|
|
var getSpec$1 = function (editor) {
|
|
var getMatchingValue = function () {
|
|
var getFirstFont = function (fontFamily) {
|
|
return fontFamily ? splitFonts(fontFamily)[0] : '';
|
|
};
|
|
var fontFamily = editor.queryCommandValue('FontName');
|
|
var items = dataset.data;
|
|
var font = fontFamily ? fontFamily.toLowerCase() : '';
|
|
var matchOpt = find(items, function (item) {
|
|
var format = item.format;
|
|
return format.toLowerCase() === font || getFirstFont(format).toLowerCase() === getFirstFont(font).toLowerCase();
|
|
}).orThunk(function () {
|
|
if (isSystemFontStack(font)) {
|
|
return Option.from({
|
|
title: 'System Font',
|
|
format: font
|
|
});
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
});
|
|
return {
|
|
matchOpt: matchOpt,
|
|
font: fontFamily
|
|
};
|
|
};
|
|
var isSelectedFor = function (item) {
|
|
return function (valueOpt) {
|
|
return valueOpt.exists(function (value) {
|
|
return value.format === item;
|
|
});
|
|
};
|
|
};
|
|
var getCurrentValue = function () {
|
|
var matchOpt = getMatchingValue().matchOpt;
|
|
return matchOpt;
|
|
};
|
|
var getPreviewFor = function (item) {
|
|
return function () {
|
|
return Option.some({
|
|
tag: 'div',
|
|
styles: item.indexOf('dings') === -1 ? { 'font-family': item } : {}
|
|
});
|
|
};
|
|
};
|
|
var onAction = function (rawItem) {
|
|
return function () {
|
|
editor.undoManager.transact(function () {
|
|
editor.focus();
|
|
editor.execCommand('FontName', false, rawItem.format);
|
|
});
|
|
};
|
|
};
|
|
var updateSelectMenuText = function (comp) {
|
|
var _a = getMatchingValue(), matchOpt = _a.matchOpt, font = _a.font;
|
|
var text = matchOpt.fold(function () {
|
|
return font;
|
|
}, function (item) {
|
|
return item.title;
|
|
});
|
|
emitWith(comp, updateMenuText, { text: text });
|
|
};
|
|
var nodeChangeHandler = Option.some(function (comp) {
|
|
return function () {
|
|
return updateSelectMenuText(comp);
|
|
};
|
|
});
|
|
var setInitialValue = Option.some(function (comp) {
|
|
return updateSelectMenuText(comp);
|
|
});
|
|
var dataset = buildBasicSettingsDataset(editor, 'font_formats', defaultFontsFormats, Delimiter.SemiColon);
|
|
return {
|
|
tooltip: 'Fonts',
|
|
icon: Option.none(),
|
|
isSelectedFor: isSelectedFor,
|
|
getCurrentValue: getCurrentValue,
|
|
getPreviewFor: getPreviewFor,
|
|
onAction: onAction,
|
|
setInitialValue: setInitialValue,
|
|
nodeChangeHandler: nodeChangeHandler,
|
|
dataset: dataset,
|
|
shouldHide: false,
|
|
isInvalid: function () {
|
|
return false;
|
|
}
|
|
};
|
|
};
|
|
var createFontSelect = function (editor, backstage) {
|
|
return createSelectButton(editor, backstage, getSpec$1(editor));
|
|
};
|
|
var fontSelectMenu = function (editor, backstage) {
|
|
var menuItems = createMenuItems(editor, backstage, getSpec$1(editor));
|
|
editor.ui.registry.addNestedMenuItem('fontformats', {
|
|
text: backstage.shared.providers.translate('Fonts'),
|
|
getSubmenuItems: function () {
|
|
return menuItems.items.validateItems(menuItems.getStyleItems());
|
|
}
|
|
});
|
|
};
|
|
|
|
var defaultFontsizeFormats = '8pt 10pt 12pt 14pt 18pt 24pt 36pt';
|
|
var legacyFontSizes = {
|
|
'8pt': '1',
|
|
'10pt': '2',
|
|
'12pt': '3',
|
|
'14pt': '4',
|
|
'18pt': '5',
|
|
'24pt': '6',
|
|
'36pt': '7'
|
|
};
|
|
var round$1 = function (number, precision) {
|
|
var factor = Math.pow(10, precision);
|
|
return Math.round(number * factor) / factor;
|
|
};
|
|
var toPt = function (fontSize, precision) {
|
|
if (/[0-9.]+px$/.test(fontSize)) {
|
|
return round$1(parseInt(fontSize, 10) * 72 / 96, precision || 0) + 'pt';
|
|
}
|
|
return fontSize;
|
|
};
|
|
var toLegacy = function (fontSize) {
|
|
return get(legacyFontSizes, fontSize).getOr('');
|
|
};
|
|
var getSpec$2 = function (editor) {
|
|
var getMatchingValue = function () {
|
|
var matchOpt = Option.none();
|
|
var items = dataset.data;
|
|
var fontSize = editor.queryCommandValue('FontSize');
|
|
if (fontSize) {
|
|
var _loop_1 = function (precision) {
|
|
var pt = toPt(fontSize, precision);
|
|
var legacy = toLegacy(pt);
|
|
matchOpt = find(items, function (item) {
|
|
return item.format === fontSize || item.format === pt || item.format === legacy;
|
|
});
|
|
};
|
|
for (var precision = 3; matchOpt.isNone() && precision >= 0; precision--) {
|
|
_loop_1(precision);
|
|
}
|
|
}
|
|
return {
|
|
matchOpt: matchOpt,
|
|
size: fontSize
|
|
};
|
|
};
|
|
var isSelectedFor = function (item) {
|
|
return function (valueOpt) {
|
|
return valueOpt.exists(function (value) {
|
|
return value.format === item;
|
|
});
|
|
};
|
|
};
|
|
var getCurrentValue = function () {
|
|
var matchOpt = getMatchingValue().matchOpt;
|
|
return matchOpt;
|
|
};
|
|
var getPreviewFor = constant(constant(Option.none()));
|
|
var onAction = function (rawItem) {
|
|
return function () {
|
|
editor.undoManager.transact(function () {
|
|
editor.focus();
|
|
editor.execCommand('FontSize', false, rawItem.format);
|
|
});
|
|
};
|
|
};
|
|
var updateSelectMenuText = function (comp) {
|
|
var _a = getMatchingValue(), matchOpt = _a.matchOpt, size = _a.size;
|
|
var text = matchOpt.fold(function () {
|
|
return size;
|
|
}, function (match) {
|
|
return match.title;
|
|
});
|
|
emitWith(comp, updateMenuText, { text: text });
|
|
};
|
|
var nodeChangeHandler = Option.some(function (comp) {
|
|
return function () {
|
|
return updateSelectMenuText(comp);
|
|
};
|
|
});
|
|
var setInitialValue = Option.some(function (comp) {
|
|
return updateSelectMenuText(comp);
|
|
});
|
|
var dataset = buildBasicSettingsDataset(editor, 'fontsize_formats', defaultFontsizeFormats, Delimiter.Space);
|
|
return {
|
|
tooltip: 'Font sizes',
|
|
icon: Option.none(),
|
|
isSelectedFor: isSelectedFor,
|
|
getPreviewFor: getPreviewFor,
|
|
getCurrentValue: getCurrentValue,
|
|
onAction: onAction,
|
|
setInitialValue: setInitialValue,
|
|
nodeChangeHandler: nodeChangeHandler,
|
|
dataset: dataset,
|
|
shouldHide: false,
|
|
isInvalid: function () {
|
|
return false;
|
|
}
|
|
};
|
|
};
|
|
var createFontsizeSelect = function (editor, backstage) {
|
|
return createSelectButton(editor, backstage, getSpec$2(editor));
|
|
};
|
|
var fontsizeSelectMenu = function (editor, backstage) {
|
|
var menuItems = createMenuItems(editor, backstage, getSpec$2(editor));
|
|
editor.ui.registry.addNestedMenuItem('fontsizes', {
|
|
text: 'Font sizes',
|
|
getSubmenuItems: function () {
|
|
return menuItems.items.validateItems(menuItems.getStyleItems());
|
|
}
|
|
});
|
|
};
|
|
|
|
var findNearest = function (editor, getStyles, parents) {
|
|
var styles = getStyles();
|
|
return findMap(parents, function (parent) {
|
|
return find(styles, function (fmt) {
|
|
return editor.formatter.matchNode(parent, fmt.format);
|
|
});
|
|
}).orThunk(function () {
|
|
if (editor.formatter.match('p')) {
|
|
return Option.some({
|
|
title: 'Paragraph',
|
|
format: 'p'
|
|
});
|
|
}
|
|
return Option.none();
|
|
});
|
|
};
|
|
var getCurrentSelectionParents = function (editor) {
|
|
var currentNode = editor.selection.getStart(true) || editor.getBody();
|
|
return editor.dom.getParents(currentNode, function () {
|
|
return true;
|
|
}, editor.getBody());
|
|
};
|
|
|
|
var onSetupFormatToggle = function (editor, name) {
|
|
return function (api) {
|
|
var unbindCell = Cell(Option.none());
|
|
var init = function () {
|
|
api.setActive(editor.formatter.match(name));
|
|
var unbind = editor.formatter.formatChanged(name, api.setActive).unbind;
|
|
unbindCell.set(Option.some(unbind));
|
|
};
|
|
editor.initialized ? init() : editor.on('init', init);
|
|
return function () {
|
|
return unbindCell.get().each(function (unbind) {
|
|
return unbind();
|
|
});
|
|
};
|
|
};
|
|
};
|
|
var onActionToggleFormat = function (editor) {
|
|
return function (rawItem) {
|
|
return function () {
|
|
editor.undoManager.transact(function () {
|
|
editor.focus();
|
|
editor.execCommand('mceToggleFormat', false, rawItem.format);
|
|
});
|
|
};
|
|
};
|
|
};
|
|
|
|
var defaultBlocks = 'Paragraph=p;' + 'Heading 1=h1;' + 'Heading 2=h2;' + 'Heading 3=h3;' + 'Heading 4=h4;' + 'Heading 5=h5;' + 'Heading 6=h6;' + 'Preformatted=pre';
|
|
var getSpec$3 = function (editor) {
|
|
var getMatchingValue = function (nodeChangeEvent) {
|
|
return findNearest(editor, function () {
|
|
return dataset.data;
|
|
}, nodeChangeEvent);
|
|
};
|
|
var isSelectedFor = function (format) {
|
|
return function () {
|
|
return editor.formatter.match(format);
|
|
};
|
|
};
|
|
var getPreviewFor = function (format) {
|
|
return function () {
|
|
var fmt = editor.formatter.get(format);
|
|
return Option.some({
|
|
tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || 'div' : 'div',
|
|
styles: editor.dom.parseStyle(editor.formatter.getCssText(format))
|
|
});
|
|
};
|
|
};
|
|
var updateSelectMenuText = function (parents, comp) {
|
|
var detectedFormat = getMatchingValue(parents);
|
|
var text = detectedFormat.fold(function () {
|
|
return 'Paragraph';
|
|
}, function (fmt) {
|
|
return fmt.title;
|
|
});
|
|
emitWith(comp, updateMenuText, { text: text });
|
|
};
|
|
var nodeChangeHandler = Option.some(function (comp) {
|
|
return function (e) {
|
|
return updateSelectMenuText(e.parents, comp);
|
|
};
|
|
});
|
|
var setInitialValue = Option.some(function (comp) {
|
|
var parents = getCurrentSelectionParents(editor);
|
|
updateSelectMenuText(parents, comp);
|
|
});
|
|
var dataset = buildBasicSettingsDataset(editor, 'block_formats', defaultBlocks, Delimiter.SemiColon);
|
|
return {
|
|
tooltip: 'Blocks',
|
|
icon: Option.none(),
|
|
isSelectedFor: isSelectedFor,
|
|
getCurrentValue: constant(Option.none()),
|
|
getPreviewFor: getPreviewFor,
|
|
onAction: onActionToggleFormat(editor),
|
|
setInitialValue: setInitialValue,
|
|
nodeChangeHandler: nodeChangeHandler,
|
|
dataset: dataset,
|
|
shouldHide: false,
|
|
isInvalid: function (item) {
|
|
return !editor.formatter.canApply(item.format);
|
|
}
|
|
};
|
|
};
|
|
var createFormatSelect = function (editor, backstage) {
|
|
return createSelectButton(editor, backstage, getSpec$3(editor));
|
|
};
|
|
var formatSelectMenu = function (editor, backstage) {
|
|
var menuItems = createMenuItems(editor, backstage, getSpec$3(editor));
|
|
editor.ui.registry.addNestedMenuItem('blockformats', {
|
|
text: 'Blocks',
|
|
getSubmenuItems: function () {
|
|
return menuItems.items.validateItems(menuItems.getStyleItems());
|
|
}
|
|
});
|
|
};
|
|
|
|
var getSpec$4 = function (editor, dataset) {
|
|
var isSelectedFor = function (format) {
|
|
return function () {
|
|
return editor.formatter.match(format);
|
|
};
|
|
};
|
|
var getPreviewFor = function (format) {
|
|
return function () {
|
|
var fmt = editor.formatter.get(format);
|
|
return fmt !== undefined ? Option.some({
|
|
tag: fmt.length > 0 ? fmt[0].inline || fmt[0].block || 'div' : 'div',
|
|
styles: editor.dom.parseStyle(editor.formatter.getCssText(format))
|
|
}) : Option.none();
|
|
};
|
|
};
|
|
var updateSelectMenuText = function (parents, comp) {
|
|
var getFormatItems = function (fmt) {
|
|
var subs = fmt.items;
|
|
return subs !== undefined && subs.length > 0 ? bind(subs, getFormatItems) : [{
|
|
title: fmt.title,
|
|
format: fmt.format
|
|
}];
|
|
};
|
|
var flattenedItems = bind(getStyleFormats(editor), getFormatItems);
|
|
var detectedFormat = findNearest(editor, function () {
|
|
return flattenedItems;
|
|
}, parents);
|
|
var text = detectedFormat.fold(function () {
|
|
return 'Paragraph';
|
|
}, function (fmt) {
|
|
return fmt.title;
|
|
});
|
|
emitWith(comp, updateMenuText, { text: text });
|
|
};
|
|
var nodeChangeHandler = Option.some(function (comp) {
|
|
return function (e) {
|
|
return updateSelectMenuText(e.parents, comp);
|
|
};
|
|
});
|
|
var setInitialValue = Option.some(function (comp) {
|
|
var parents = getCurrentSelectionParents(editor);
|
|
updateSelectMenuText(parents, comp);
|
|
});
|
|
return {
|
|
tooltip: 'Formats',
|
|
icon: Option.none(),
|
|
isSelectedFor: isSelectedFor,
|
|
getCurrentValue: constant(Option.none()),
|
|
getPreviewFor: getPreviewFor,
|
|
onAction: onActionToggleFormat(editor),
|
|
setInitialValue: setInitialValue,
|
|
nodeChangeHandler: nodeChangeHandler,
|
|
shouldHide: editor.getParam('style_formats_autohide', false, 'boolean'),
|
|
isInvalid: function (item) {
|
|
return !editor.formatter.canApply(item.format);
|
|
},
|
|
dataset: dataset
|
|
};
|
|
};
|
|
var createStyleSelect = function (editor, backstage) {
|
|
var dataset = __assign({ type: 'advanced' }, backstage.styleselect);
|
|
return createSelectButton(editor, backstage, getSpec$4(editor, dataset));
|
|
};
|
|
var styleSelectMenu = function (editor, backstage) {
|
|
var dataset = __assign({ type: 'advanced' }, backstage.styleselect);
|
|
var menuItems = createMenuItems(editor, backstage, getSpec$4(editor, dataset));
|
|
editor.ui.registry.addNestedMenuItem('formats', {
|
|
text: 'Formats',
|
|
getSubmenuItems: function () {
|
|
return menuItems.items.validateItems(menuItems.getStyleItems());
|
|
}
|
|
});
|
|
};
|
|
|
|
var defaultToolbar = [
|
|
{
|
|
name: 'history',
|
|
items: [
|
|
'undo',
|
|
'redo'
|
|
]
|
|
},
|
|
{
|
|
name: 'styles',
|
|
items: ['styleselect']
|
|
},
|
|
{
|
|
name: 'formatting',
|
|
items: [
|
|
'bold',
|
|
'italic'
|
|
]
|
|
},
|
|
{
|
|
name: 'alignment',
|
|
items: [
|
|
'alignleft',
|
|
'aligncenter',
|
|
'alignright',
|
|
'alignjustify'
|
|
]
|
|
},
|
|
{
|
|
name: 'indentation',
|
|
items: [
|
|
'outdent',
|
|
'indent'
|
|
]
|
|
},
|
|
{
|
|
name: 'permanent pen',
|
|
items: ['permanentpen']
|
|
},
|
|
{
|
|
name: 'comments',
|
|
items: ['addcomment']
|
|
}
|
|
];
|
|
var renderFromBridge = function (bridgeBuilder, render) {
|
|
return function (spec, extras, editor) {
|
|
var internal = bridgeBuilder(spec).mapError(function (errInfo) {
|
|
return formatError(errInfo);
|
|
}).getOrDie();
|
|
return render(internal, extras, editor);
|
|
};
|
|
};
|
|
var types = {
|
|
button: renderFromBridge(createToolbarButton, function (s, extras) {
|
|
return renderToolbarButton(s, extras.backstage.shared.providers);
|
|
}),
|
|
togglebutton: renderFromBridge(createToggleButton, function (s, extras) {
|
|
return renderToolbarToggleButton(s, extras.backstage.shared.providers);
|
|
}),
|
|
menubutton: renderFromBridge(createMenuButton, function (s, extras) {
|
|
return renderMenuButton(s, 'tox-tbtn', extras.backstage, Option.none());
|
|
}),
|
|
splitbutton: renderFromBridge(createSplitButton, function (s, extras) {
|
|
return renderSplitButton(s, extras.backstage.shared);
|
|
}),
|
|
grouptoolbarbutton: renderFromBridge(createGroupToolbarButton, function (s, extras, editor) {
|
|
var _a;
|
|
var buttons = editor.ui.registry.getAll().buttons;
|
|
var identify = function (toolbar) {
|
|
return identifyButtons(editor, {
|
|
buttons: buttons,
|
|
toolbar: toolbar,
|
|
allowToolbarGroups: false
|
|
}, extras, Option.none());
|
|
};
|
|
var attributes = (_a = {}, _a[Attribute] = extras.backstage.shared.header.isPositionedAtTop() ? AttributeValue.TopToBottom : AttributeValue.BottomToTop, _a);
|
|
switch (getToolbarMode(editor)) {
|
|
case ToolbarMode.floating:
|
|
return renderFloatingToolbarButton(s, extras.backstage, identify, attributes);
|
|
default:
|
|
throw new Error('Toolbar groups are only supported when using floating toolbar mode');
|
|
}
|
|
}),
|
|
styleSelectButton: function (editor, extras) {
|
|
return createStyleSelect(editor, extras.backstage);
|
|
},
|
|
fontsizeSelectButton: function (editor, extras) {
|
|
return createFontsizeSelect(editor, extras.backstage);
|
|
},
|
|
fontSelectButton: function (editor, extras) {
|
|
return createFontSelect(editor, extras.backstage);
|
|
},
|
|
formatButton: function (editor, extras) {
|
|
return createFormatSelect(editor, extras.backstage);
|
|
},
|
|
alignMenuButton: function (editor, extras) {
|
|
return createAlignSelect(editor, extras.backstage);
|
|
}
|
|
};
|
|
var extractFrom = function (spec, extras, editor) {
|
|
return get(types, spec.type).fold(function () {
|
|
domGlobals.console.error('skipping button defined by', spec);
|
|
return Option.none();
|
|
}, function (render) {
|
|
return Option.some(render(spec, extras, editor));
|
|
});
|
|
};
|
|
var bespokeButtons = {
|
|
styleselect: types.styleSelectButton,
|
|
fontsizeselect: types.fontsizeSelectButton,
|
|
fontselect: types.fontSelectButton,
|
|
formatselect: types.formatButton,
|
|
align: types.alignMenuButton
|
|
};
|
|
var removeUnusedDefaults = function (buttons) {
|
|
var filteredItemGroups = map(defaultToolbar, function (group) {
|
|
var items = filter(group.items, function (subItem) {
|
|
return has(buttons, subItem) || has(bespokeButtons, subItem);
|
|
});
|
|
return {
|
|
name: group.name,
|
|
items: items
|
|
};
|
|
});
|
|
return filter(filteredItemGroups, function (group) {
|
|
return group.items.length > 0;
|
|
});
|
|
};
|
|
var convertStringToolbar = function (strToolbar) {
|
|
var groupsStrings = strToolbar.split('|');
|
|
return map(groupsStrings, function (g) {
|
|
return { items: g.trim().split(' ') };
|
|
});
|
|
};
|
|
var isToolbarGroupSettingArray = function (toolbar) {
|
|
return isArrayOf(toolbar, function (t) {
|
|
return has(t, 'name') && has(t, 'items');
|
|
});
|
|
};
|
|
var createToolbar = function (toolbarConfig) {
|
|
var toolbar = toolbarConfig.toolbar;
|
|
var buttons = toolbarConfig.buttons;
|
|
if (toolbar === false) {
|
|
return [];
|
|
} else if (toolbar === undefined || toolbar === true) {
|
|
return removeUnusedDefaults(buttons);
|
|
} else if (isString(toolbar)) {
|
|
return convertStringToolbar(toolbar);
|
|
} else if (isToolbarGroupSettingArray(toolbar)) {
|
|
return toolbar;
|
|
} else {
|
|
domGlobals.console.error('Toolbar type should be string, string[], boolean or ToolbarGroup[]');
|
|
return [];
|
|
}
|
|
};
|
|
var lookupButton = function (editor, buttons, toolbarItem, allowToolbarGroups, extras, prefixes) {
|
|
return get(buttons, toolbarItem.toLowerCase()).orThunk(function () {
|
|
return prefixes.bind(function (ps) {
|
|
return findMap(ps, function (prefix) {
|
|
return get(buttons, prefix + toolbarItem.toLowerCase());
|
|
});
|
|
});
|
|
}).fold(function () {
|
|
return get(bespokeButtons, toolbarItem.toLowerCase()).map(function (r) {
|
|
return r(editor, extras);
|
|
}).orThunk(function () {
|
|
return Option.none();
|
|
});
|
|
}, function (spec) {
|
|
if (spec.type === 'grouptoolbarbutton' && !allowToolbarGroups) {
|
|
domGlobals.console.warn('Ignoring the \'' + toolbarItem + '\' toolbar button. Group toolbar buttons are only supported when using floating toolbar mode and cannot be nested.');
|
|
return Option.none();
|
|
} else {
|
|
return extractFrom(spec, extras, editor);
|
|
}
|
|
});
|
|
};
|
|
var identifyButtons = function (editor, toolbarConfig, extras, prefixes) {
|
|
var toolbarGroups = createToolbar(toolbarConfig);
|
|
var groups = map(toolbarGroups, function (group) {
|
|
var items = bind(group.items, function (toolbarItem) {
|
|
return toolbarItem.trim().length === 0 ? [] : lookupButton(editor, toolbarConfig.buttons, toolbarItem, toolbarConfig.allowToolbarGroups, extras, prefixes).toArray();
|
|
});
|
|
return {
|
|
title: Option.from(editor.translate(group.name)),
|
|
items: items
|
|
};
|
|
});
|
|
return filter(groups, function (group) {
|
|
return group.items.length > 0;
|
|
});
|
|
};
|
|
|
|
var bubbleSize = 12;
|
|
var bubbleAlignments$1 = {
|
|
valignCentre: [],
|
|
alignCentre: [],
|
|
alignLeft: ['tox-pop--align-left'],
|
|
alignRight: ['tox-pop--align-right'],
|
|
right: ['tox-pop--right'],
|
|
left: ['tox-pop--left'],
|
|
bottom: ['tox-pop--bottom'],
|
|
top: ['tox-pop--top']
|
|
};
|
|
var anchorOverrides = {
|
|
maxHeightFunction: expandable(),
|
|
maxWidthFunction: expandable$1()
|
|
};
|
|
var desktopAnchorSpecLayouts = {
|
|
onLtr: function () {
|
|
return [
|
|
north$1,
|
|
south$1,
|
|
northeast$1,
|
|
southeast$1,
|
|
northwest$1,
|
|
southwest$1,
|
|
north$3,
|
|
south$3,
|
|
northeast$3,
|
|
southeast$3,
|
|
northwest$3,
|
|
southwest$3
|
|
];
|
|
},
|
|
onRtl: function () {
|
|
return [
|
|
north$1,
|
|
south$1,
|
|
northwest$1,
|
|
southwest$1,
|
|
northeast$1,
|
|
southeast$1,
|
|
north$3,
|
|
south$3,
|
|
northwest$3,
|
|
southwest$3,
|
|
northeast$3,
|
|
southeast$3
|
|
];
|
|
}
|
|
};
|
|
var mobileAnchorSpecLayouts = {
|
|
onLtr: function () {
|
|
return [
|
|
south$1,
|
|
southeast$1,
|
|
southwest$1,
|
|
northeast$1,
|
|
northwest$1,
|
|
north$1,
|
|
north$3,
|
|
south$3,
|
|
northeast$3,
|
|
southeast$3,
|
|
northwest$3,
|
|
southwest$3
|
|
];
|
|
},
|
|
onRtl: function () {
|
|
return [
|
|
south$1,
|
|
southwest$1,
|
|
southeast$1,
|
|
northwest$1,
|
|
northeast$1,
|
|
north$1,
|
|
north$3,
|
|
south$3,
|
|
northwest$3,
|
|
southwest$3,
|
|
northeast$3,
|
|
southeast$3
|
|
];
|
|
}
|
|
};
|
|
var getAnchorLayout = function (position, isTouch) {
|
|
if (position === 'line') {
|
|
return {
|
|
bubble: nu$8(bubbleSize, 0, bubbleAlignments$1),
|
|
layouts: {
|
|
onLtr: function () {
|
|
return [east$1];
|
|
},
|
|
onRtl: function () {
|
|
return [west$1];
|
|
}
|
|
},
|
|
overrides: anchorOverrides
|
|
};
|
|
} else {
|
|
return {
|
|
bubble: nu$8(0, bubbleSize, bubbleAlignments$1),
|
|
layouts: isTouch ? mobileAnchorSpecLayouts : desktopAnchorSpecLayouts,
|
|
overrides: anchorOverrides
|
|
};
|
|
}
|
|
};
|
|
var register$4 = function (editor, registryContextToolbars, sink, extras) {
|
|
var isTouch = detect$3().deviceType.isTouch;
|
|
var contextbar = build$1(renderContextToolbar({
|
|
sink: sink,
|
|
onEscape: function () {
|
|
editor.focus();
|
|
return Option.some(true);
|
|
}
|
|
}));
|
|
var getBounds = function () {
|
|
return getContextToolbarBounds(editor, extras.backstage.shared);
|
|
};
|
|
var isRangeOverlapping = function (aTop, aBottom, bTop, bBottom) {
|
|
return Math.max(aTop, bTop) <= Math.min(aBottom, bBottom);
|
|
};
|
|
var getLastElementVerticalBound = function () {
|
|
var nodeBounds = lastElement.get().map(function (ele) {
|
|
return ele.getBoundingClientRect();
|
|
}).getOrThunk(function () {
|
|
return editor.selection.getRng().getBoundingClientRect();
|
|
});
|
|
var diffTop = editor.inline ? get$8().top() : absolute$1(Element.fromDom(editor.getBody())).y;
|
|
return {
|
|
y: nodeBounds.top + diffTop,
|
|
bottom: nodeBounds.bottom + diffTop
|
|
};
|
|
};
|
|
var shouldContextToolbarHide = function () {
|
|
if (isTouch() && extras.backstage.isContextMenuOpen()) {
|
|
return true;
|
|
}
|
|
var lastElementBounds = getLastElementVerticalBound();
|
|
var contextToolbarBounds = getBounds();
|
|
return !isRangeOverlapping(lastElementBounds.y, lastElementBounds.bottom, contextToolbarBounds.y, contextToolbarBounds.bottom);
|
|
};
|
|
var forceHide = function () {
|
|
InlineView.hide(contextbar);
|
|
};
|
|
var hideOrRepositionIfNecessary = function () {
|
|
lastAnchor.get().each(function (anchor) {
|
|
var contextBarEle = contextbar.element();
|
|
remove$6(contextBarEle, 'display');
|
|
if (shouldContextToolbarHide()) {
|
|
set$2(contextBarEle, 'display', 'none');
|
|
} else {
|
|
Positioning.positionWithinBounds(sink, anchor, contextbar, Option.some(getBounds()));
|
|
}
|
|
});
|
|
};
|
|
var lastAnchor = Cell(Option.none());
|
|
var lastElement = Cell(Option.none());
|
|
var timer = Cell(null);
|
|
var wrapInPopDialog = function (toolbarSpec) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-pop__dialog']
|
|
},
|
|
components: [toolbarSpec],
|
|
behaviours: derive$1([
|
|
Keying.config({ mode: 'acyclic' }),
|
|
config('pop-dialog-wrap-events', [
|
|
runOnAttached(function (comp) {
|
|
editor.shortcuts.add('ctrl+F9', 'focus statusbar', function () {
|
|
return Keying.focusIn(comp);
|
|
});
|
|
}),
|
|
runOnDetached(function (_comp) {
|
|
editor.shortcuts.remove('ctrl+F9');
|
|
})
|
|
])
|
|
])
|
|
};
|
|
};
|
|
var getScopes = cached(function () {
|
|
return categorise(registryContextToolbars, function (toolbarApi) {
|
|
var alloySpec = buildToolbar([toolbarApi]);
|
|
emitWith(contextbar, forwardSlideEvent, { forwardContents: wrapInPopDialog(alloySpec) });
|
|
});
|
|
});
|
|
var buildContextToolbarGroups = function (allButtons, ctx) {
|
|
return identifyButtons(editor, {
|
|
buttons: allButtons,
|
|
toolbar: ctx.items,
|
|
allowToolbarGroups: false
|
|
}, extras, Option.some(['form:']));
|
|
};
|
|
var buildContextMenuGroups = function (ctx, providers) {
|
|
return ContextForm.buildInitGroups(ctx, providers);
|
|
};
|
|
var buildToolbar = function (toolbars) {
|
|
var buttons = editor.ui.registry.getAll().buttons;
|
|
var scopes = getScopes();
|
|
var allButtons = __assign(__assign({}, buttons), scopes.formNavigators);
|
|
var toolbarType = getToolbarMode(editor) === ToolbarMode.scrolling ? ToolbarMode.scrolling : ToolbarMode.default;
|
|
var initGroups = flatten(map(toolbars, function (ctx) {
|
|
return ctx.type === 'contexttoolbar' ? buildContextToolbarGroups(allButtons, ctx) : buildContextMenuGroups(ctx, extras.backstage.shared.providers);
|
|
}));
|
|
return renderToolbar({
|
|
type: toolbarType,
|
|
uid: generate$1('context-toolbar'),
|
|
initGroups: initGroups,
|
|
onEscape: Option.none,
|
|
cyclicKeying: true,
|
|
providers: extras.backstage.shared.providers
|
|
});
|
|
};
|
|
editor.on(showContextToolbarEvent, function (e) {
|
|
var scopes = getScopes();
|
|
get(scopes.lookupTable, e.toolbarKey).each(function (ctx) {
|
|
launchContext([ctx], e.target === editor ? Option.none() : Option.some(e));
|
|
InlineView.getContent(contextbar).each(Keying.focusIn);
|
|
});
|
|
});
|
|
var getAnchor = function (position, element) {
|
|
var anchorage = position === 'node' ? extras.backstage.shared.anchors.node(element) : extras.backstage.shared.anchors.cursor();
|
|
return deepMerge(anchorage, getAnchorLayout(position, isTouch()));
|
|
};
|
|
var launchContext = function (toolbarApi, elem) {
|
|
clearTimer();
|
|
if (isTouch() && extras.backstage.isContextMenuOpen()) {
|
|
return;
|
|
}
|
|
var toolbarSpec = buildToolbar(toolbarApi);
|
|
var sElem = elem.map(Element.fromDom);
|
|
var anchor = getAnchor(toolbarApi[0].position, sElem);
|
|
lastAnchor.set(Option.some(anchor));
|
|
lastElement.set(elem);
|
|
var contextBarEle = contextbar.element();
|
|
remove$6(contextBarEle, 'display');
|
|
InlineView.showWithinBounds(contextbar, anchor, wrapInPopDialog(toolbarSpec), function () {
|
|
return Option.some(getBounds());
|
|
});
|
|
if (shouldContextToolbarHide()) {
|
|
set$2(contextBarEle, 'display', 'none');
|
|
}
|
|
};
|
|
var launchContextToolbar = function () {
|
|
if (!editor.hasFocus()) {
|
|
return;
|
|
}
|
|
var scopes = getScopes();
|
|
lookup$1(scopes, editor).fold(function () {
|
|
lastAnchor.set(Option.none());
|
|
InlineView.hide(contextbar);
|
|
}, function (info) {
|
|
launchContext(info.toolbars, Option.some(info.elem.dom()));
|
|
});
|
|
};
|
|
var clearTimer = function () {
|
|
var current = timer.get();
|
|
if (current !== null) {
|
|
global$2.clearTimeout(current);
|
|
timer.set(null);
|
|
}
|
|
};
|
|
var resetTimer = function (t) {
|
|
clearTimer();
|
|
timer.set(t);
|
|
};
|
|
editor.on('init', function () {
|
|
editor.on(hideContextToolbarEvent, forceHide);
|
|
editor.on('ScrollContent ScrollWindow longpress', hideOrRepositionIfNecessary);
|
|
editor.on('click keyup focus SetContent ObjectResized ResizeEditor', function () {
|
|
resetTimer(global$2.setEditorTimeout(editor, launchContextToolbar, 0));
|
|
});
|
|
editor.on('focusout', function (_e) {
|
|
global$2.setEditorTimeout(editor, function () {
|
|
if (search(sink.element()).isNone() && search(contextbar.element()).isNone()) {
|
|
lastAnchor.set(Option.none());
|
|
InlineView.hide(contextbar);
|
|
}
|
|
}, 0);
|
|
});
|
|
editor.on('SwitchMode', function () {
|
|
if (editor.mode.isReadOnly()) {
|
|
lastAnchor.set(Option.none());
|
|
InlineView.hide(contextbar);
|
|
}
|
|
});
|
|
editor.on('NodeChange', function (_e) {
|
|
search(contextbar.element()).fold(function () {
|
|
resetTimer(global$2.setEditorTimeout(editor, launchContextToolbar, 0));
|
|
}, function (_) {
|
|
});
|
|
});
|
|
});
|
|
};
|
|
|
|
var setup$3 = function (editor, mothership, uiMothership) {
|
|
var broadcastEvent = function (name, evt) {
|
|
each([
|
|
mothership,
|
|
uiMothership
|
|
], function (ship) {
|
|
ship.broadcastEvent(name, evt);
|
|
});
|
|
};
|
|
var broadcastOn = function (channel, message) {
|
|
each([
|
|
mothership,
|
|
uiMothership
|
|
], function (ship) {
|
|
ship.broadcastOn([channel], message);
|
|
});
|
|
};
|
|
var fireDismissPopups = function (evt) {
|
|
return broadcastOn(dismissPopups(), { target: evt.target() });
|
|
};
|
|
var onTouchstart = bind$3(Element.fromDom(domGlobals.document), 'touchstart', fireDismissPopups);
|
|
var onTouchmove = bind$3(Element.fromDom(domGlobals.document), 'touchmove', function (evt) {
|
|
return broadcastEvent(documentTouchmove(), evt);
|
|
});
|
|
var onTouchend = bind$3(Element.fromDom(domGlobals.document), 'touchend', function (evt) {
|
|
return broadcastEvent(documentTouchend(), evt);
|
|
});
|
|
var onMousedown = bind$3(Element.fromDom(domGlobals.document), 'mousedown', fireDismissPopups);
|
|
var onMouseup = bind$3(Element.fromDom(domGlobals.document), 'mouseup', function (evt) {
|
|
if (evt.raw().button === 0) {
|
|
broadcastOn(mouseReleased(), { target: evt.target() });
|
|
}
|
|
});
|
|
var onContentClick = function (raw) {
|
|
return broadcastOn(dismissPopups(), { target: Element.fromDom(raw.target) });
|
|
};
|
|
var onContentMouseup = function (raw) {
|
|
if (raw.button === 0) {
|
|
broadcastOn(mouseReleased(), { target: Element.fromDom(raw.target) });
|
|
}
|
|
};
|
|
var onWindowScroll = function (evt) {
|
|
return broadcastEvent(windowScroll(), fromRawEvent$1(evt));
|
|
};
|
|
var onWindowResize = function (evt) {
|
|
broadcastOn(repositionPopups(), {});
|
|
broadcastEvent(windowResize(), fromRawEvent$1(evt));
|
|
};
|
|
var onEditorResize = function () {
|
|
return broadcastOn(repositionPopups(), {});
|
|
};
|
|
editor.on('PostRender', function () {
|
|
editor.on('click', onContentClick);
|
|
editor.on('tap', onContentClick);
|
|
editor.on('mouseup', onContentMouseup);
|
|
editor.on('ScrollWindow', onWindowScroll);
|
|
editor.on('ResizeWindow', onWindowResize);
|
|
editor.on('ResizeEditor', onEditorResize);
|
|
});
|
|
editor.on('remove', function () {
|
|
editor.off('click', onContentClick);
|
|
editor.off('tap', onContentClick);
|
|
editor.off('mouseup', onContentMouseup);
|
|
editor.off('ScrollWindow', onWindowScroll);
|
|
editor.off('ResizeWindow', onWindowResize);
|
|
editor.off('ResizeEditor', onEditorResize);
|
|
onMousedown.unbind();
|
|
onTouchstart.unbind();
|
|
onTouchmove.unbind();
|
|
onTouchend.unbind();
|
|
onMouseup.unbind();
|
|
});
|
|
editor.on('detach', function () {
|
|
detachSystem(mothership);
|
|
detachSystem(uiMothership);
|
|
mothership.destroy();
|
|
uiMothership.destroy();
|
|
});
|
|
};
|
|
|
|
var parts$d = AlloyParts;
|
|
var partType$1 = PartType;
|
|
|
|
var schema$r = constant([
|
|
defaulted$1('shell', false),
|
|
strict$1('makeItem'),
|
|
defaulted$1('setupItem', noop),
|
|
SketchBehaviours.field('listBehaviours', [Replacing])
|
|
]);
|
|
var customListDetail = function () {
|
|
return { behaviours: derive$1([Replacing.config({})]) };
|
|
};
|
|
var itemsPart = optional({
|
|
name: 'items',
|
|
overrides: customListDetail
|
|
});
|
|
var parts$e = constant([itemsPart]);
|
|
var name$2 = constant('CustomList');
|
|
|
|
var factory$f = function (detail, components, _spec, _external) {
|
|
var setItems = function (list, items) {
|
|
getListContainer(list).fold(function () {
|
|
domGlobals.console.error('Custom List was defined to not be a shell, but no item container was specified in components');
|
|
throw new Error('Custom List was defined to not be a shell, but no item container was specified in components');
|
|
}, function (container) {
|
|
var itemComps = Replacing.contents(container);
|
|
var numListsRequired = items.length;
|
|
var numListsToAdd = numListsRequired - itemComps.length;
|
|
var itemsToAdd = numListsToAdd > 0 ? range(numListsToAdd, function () {
|
|
return detail.makeItem();
|
|
}) : [];
|
|
var itemsToRemove = itemComps.slice(numListsRequired);
|
|
each(itemsToRemove, function (item) {
|
|
return Replacing.remove(container, item);
|
|
});
|
|
each(itemsToAdd, function (item) {
|
|
return Replacing.append(container, item);
|
|
});
|
|
var builtLists = Replacing.contents(container);
|
|
each(builtLists, function (item, i) {
|
|
detail.setupItem(list, item, items[i], i);
|
|
});
|
|
});
|
|
};
|
|
var extra = detail.shell ? {
|
|
behaviours: [Replacing.config({})],
|
|
components: []
|
|
} : {
|
|
behaviours: [],
|
|
components: components
|
|
};
|
|
var getListContainer = function (component) {
|
|
return detail.shell ? Option.some(component) : getPart(component, detail, 'items');
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: extra.components,
|
|
behaviours: augment(detail.listBehaviours, extra.behaviours),
|
|
apis: { setItems: setItems }
|
|
};
|
|
};
|
|
var CustomList = composite$1({
|
|
name: name$2(),
|
|
configFields: schema$r(),
|
|
partFields: parts$e(),
|
|
factory: factory$f,
|
|
apis: {
|
|
setItems: function (apis, list, items) {
|
|
apis.setItems(list, items);
|
|
}
|
|
}
|
|
});
|
|
|
|
var getOffsetParent = function (element) {
|
|
var isFixed = getRaw(element, 'position').is('fixed');
|
|
var offsetParent$1 = isFixed ? Option.none() : offsetParent(element);
|
|
return offsetParent$1.orThunk(function () {
|
|
var marker = Element.fromTag('span');
|
|
return parent(element).bind(function (parent) {
|
|
append(parent, marker);
|
|
var offsetParent$1 = offsetParent(marker);
|
|
remove(marker);
|
|
return offsetParent$1;
|
|
});
|
|
});
|
|
};
|
|
var getOrigin = function (element) {
|
|
return getOffsetParent(element).map(absolute).getOrThunk(function () {
|
|
return Position(0, 0);
|
|
});
|
|
};
|
|
|
|
var morphAdt = Adt.generate([
|
|
{ static: [] },
|
|
{ absolute: ['positionCss'] },
|
|
{ fixed: ['positionCss'] }
|
|
]);
|
|
var appear = function (component, contextualInfo) {
|
|
var elem = component.element();
|
|
add$2(elem, contextualInfo.transitionClass);
|
|
remove$4(elem, contextualInfo.fadeOutClass);
|
|
add$2(elem, contextualInfo.fadeInClass);
|
|
contextualInfo.onShow(component);
|
|
};
|
|
var disappear = function (component, contextualInfo) {
|
|
var elem = component.element();
|
|
add$2(elem, contextualInfo.transitionClass);
|
|
remove$4(elem, contextualInfo.fadeInClass);
|
|
add$2(elem, contextualInfo.fadeOutClass);
|
|
contextualInfo.onHide(component);
|
|
};
|
|
var isPartiallyVisible = function (box, viewport) {
|
|
return box.y < viewport.bottom && box.bottom > viewport.y;
|
|
};
|
|
var isTopCompletelyVisible = function (box, viewport) {
|
|
return box.y >= viewport.y;
|
|
};
|
|
var isBottomCompletelyVisible = function (box, viewport) {
|
|
return box.bottom <= viewport.bottom;
|
|
};
|
|
var isVisibleForModes = function (modes, box, viewport) {
|
|
return forall(modes, function (mode) {
|
|
switch (mode) {
|
|
case 'bottom':
|
|
return isBottomCompletelyVisible(box, viewport);
|
|
case 'top':
|
|
return isTopCompletelyVisible(box, viewport);
|
|
}
|
|
});
|
|
};
|
|
var getPrior = function (elem, state) {
|
|
return state.getInitialPosition().map(function (pos) {
|
|
return bounds$1(pos.bounds.x, pos.bounds.y, get$7(elem), get$6(elem));
|
|
});
|
|
};
|
|
var storePrior = function (elem, box, state) {
|
|
state.setInitialPosition(Option.some({
|
|
style: getAllRaw(elem),
|
|
position: get$4(elem, 'position') || 'static',
|
|
bounds: box
|
|
}));
|
|
};
|
|
var revertToOriginal = function (elem, box$1, state) {
|
|
return state.getInitialPosition().bind(function (position) {
|
|
state.setInitialPosition(Option.none());
|
|
switch (position.position) {
|
|
case 'static':
|
|
return Option.some(morphAdt.static());
|
|
case 'absolute':
|
|
var offsetBox_1 = getOffsetParent(elem).map(box).getOrThunk(function () {
|
|
return box(body());
|
|
});
|
|
return Option.some(morphAdt.absolute(NuPositionCss('absolute', get(position.style, 'left').map(function (_left) {
|
|
return box$1.x - offsetBox_1.x;
|
|
}), get(position.style, 'top').map(function (_top) {
|
|
return box$1.y - offsetBox_1.y;
|
|
}), get(position.style, 'right').map(function (_right) {
|
|
return offsetBox_1.right - box$1.right;
|
|
}), get(position.style, 'bottom').map(function (_bottom) {
|
|
return offsetBox_1.bottom - box$1.bottom;
|
|
}))));
|
|
default:
|
|
return Option.none();
|
|
}
|
|
});
|
|
};
|
|
var morphToOriginal = function (elem, viewport, state) {
|
|
return getPrior(elem, state).filter(function (box) {
|
|
return isVisibleForModes(state.getModes(), box, viewport);
|
|
}).bind(function (box) {
|
|
return revertToOriginal(elem, box, state);
|
|
});
|
|
};
|
|
var morphToFixed = function (elem, viewport, state) {
|
|
var box$1 = box(elem);
|
|
if (!isVisibleForModes(state.getModes(), box$1, viewport)) {
|
|
storePrior(elem, box$1, state);
|
|
var winBox = win();
|
|
var left = box$1.x - winBox.x;
|
|
var top = viewport.y - winBox.y;
|
|
var bottom = winBox.bottom - viewport.bottom;
|
|
var isTop = box$1.y <= viewport.y;
|
|
return Option.some(morphAdt.fixed(NuPositionCss('fixed', Option.some(left), isTop ? Option.some(top) : Option.none(), Option.none(), !isTop ? Option.some(bottom) : Option.none())));
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
};
|
|
var getMorph = function (component, viewport, state) {
|
|
var elem = component.element();
|
|
var isDocked = getRaw(elem, 'position').is('fixed');
|
|
return isDocked ? morphToOriginal(elem, viewport, state) : morphToFixed(elem, viewport, state);
|
|
};
|
|
var getMorphToOriginal = function (component, state) {
|
|
var elem = component.element();
|
|
return getPrior(elem, state).bind(function (box) {
|
|
return revertToOriginal(elem, box, state);
|
|
});
|
|
};
|
|
|
|
var morphToStatic = function (component, config) {
|
|
each([
|
|
'left',
|
|
'right',
|
|
'top',
|
|
'bottom',
|
|
'position'
|
|
], function (prop) {
|
|
return remove$6(component.element(), prop);
|
|
});
|
|
config.onUndocked(component);
|
|
};
|
|
var morphToCoord = function (component, config, position) {
|
|
applyPositionCss(component.element(), position);
|
|
var method = position.position() === 'fixed' ? config.onDocked : config.onUndocked;
|
|
method(component);
|
|
};
|
|
var updateVisibility = function (component, config, state, viewport, morphToDocked) {
|
|
if (morphToDocked === void 0) {
|
|
morphToDocked = false;
|
|
}
|
|
config.contextual.each(function (contextInfo) {
|
|
contextInfo.lazyContext(component).each(function (box) {
|
|
var isVisible = isPartiallyVisible(box, viewport);
|
|
if (isVisible !== state.isVisible()) {
|
|
state.setVisible(isVisible);
|
|
if (morphToDocked && !isVisible) {
|
|
add$3(component.element(), [contextInfo.fadeOutClass]);
|
|
contextInfo.onHide(component);
|
|
} else {
|
|
var method = isVisible ? appear : disappear;
|
|
method(component, contextInfo);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
};
|
|
var refreshInternal = function (component, config, state) {
|
|
var viewport = config.lazyViewport(component);
|
|
var isDocked = state.isDocked();
|
|
if (isDocked) {
|
|
updateVisibility(component, config, state, viewport);
|
|
}
|
|
getMorph(component, viewport, state).each(function (morph) {
|
|
state.setDocked(!isDocked);
|
|
morph.fold(function () {
|
|
return morphToStatic(component, config);
|
|
}, function (position) {
|
|
return morphToCoord(component, config, position);
|
|
}, function (position) {
|
|
updateVisibility(component, config, state, viewport, true);
|
|
morphToCoord(component, config, position);
|
|
});
|
|
});
|
|
};
|
|
var resetInternal = function (component, config, state) {
|
|
var elem = component.element();
|
|
state.setDocked(false);
|
|
getMorphToOriginal(component, state).each(function (morph) {
|
|
morph.fold(function () {
|
|
return morphToStatic(component, config);
|
|
}, function (position) {
|
|
return morphToCoord(component, config, position);
|
|
}, noop);
|
|
});
|
|
state.setVisible(true);
|
|
config.contextual.each(function (contextInfo) {
|
|
remove$5(elem, [
|
|
contextInfo.fadeInClass,
|
|
contextInfo.fadeOutClass,
|
|
contextInfo.transitionClass
|
|
]);
|
|
contextInfo.onShow(component);
|
|
});
|
|
refresh$4(component, config, state);
|
|
};
|
|
var refresh$4 = function (component, config, state) {
|
|
if (component.getSystem().isConnected()) {
|
|
refreshInternal(component, config, state);
|
|
}
|
|
};
|
|
var reset = function (component, config, state) {
|
|
if (state.isDocked()) {
|
|
resetInternal(component, config, state);
|
|
}
|
|
};
|
|
var isDocked = function (component, config, state) {
|
|
return state.isDocked();
|
|
};
|
|
var setModes = function (component, config, state, modes) {
|
|
return state.setModes(modes);
|
|
};
|
|
var getModes = function (component, config, state) {
|
|
return state.getModes();
|
|
};
|
|
|
|
var DockingApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
refresh: refresh$4,
|
|
reset: reset,
|
|
isDocked: isDocked,
|
|
getModes: getModes,
|
|
setModes: setModes
|
|
});
|
|
|
|
var events$f = function (dockInfo, dockState) {
|
|
return derive([
|
|
runOnSource(transitionend(), function (component, simulatedEvent) {
|
|
dockInfo.contextual.each(function (contextInfo) {
|
|
if (has$2(component.element(), contextInfo.transitionClass)) {
|
|
remove$5(component.element(), [
|
|
contextInfo.transitionClass,
|
|
contextInfo.fadeInClass
|
|
]);
|
|
var notify = dockState.isVisible() ? contextInfo.onShown : contextInfo.onHidden;
|
|
notify(component);
|
|
}
|
|
simulatedEvent.stop();
|
|
});
|
|
}),
|
|
run(windowScroll(), function (component, _) {
|
|
refresh$4(component, dockInfo, dockState);
|
|
}),
|
|
run(windowResize(), function (component, _) {
|
|
reset(component, dockInfo, dockState);
|
|
})
|
|
]);
|
|
};
|
|
|
|
var ActiveDocking = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$f
|
|
});
|
|
|
|
var DockingSchema = [
|
|
optionObjOf('contextual', [
|
|
strictString('fadeInClass'),
|
|
strictString('fadeOutClass'),
|
|
strictString('transitionClass'),
|
|
strictFunction('lazyContext'),
|
|
onHandler('onShow'),
|
|
onHandler('onShown'),
|
|
onHandler('onHide'),
|
|
onHandler('onHidden')
|
|
]),
|
|
defaultedFunction('lazyViewport', win),
|
|
defaultedArrayOf('modes', [
|
|
'top',
|
|
'bottom'
|
|
], string),
|
|
onHandler('onDocked'),
|
|
onHandler('onUndocked')
|
|
];
|
|
|
|
var init$b = function (spec) {
|
|
var docked = Cell(false);
|
|
var visible = Cell(true);
|
|
var initialBounds = Cell(Option.none());
|
|
var modes = Cell(spec.modes);
|
|
var readState = function () {
|
|
return 'docked: ' + docked.get() + ', visible: ' + visible.get() + ', modes: ' + modes.get().join(',');
|
|
};
|
|
return nu$5({
|
|
isDocked: docked.get,
|
|
setDocked: docked.set,
|
|
getInitialPosition: initialBounds.get,
|
|
setInitialPosition: initialBounds.set,
|
|
isVisible: visible.get,
|
|
setVisible: visible.set,
|
|
getModes: modes.get,
|
|
setModes: modes.set,
|
|
readState: readState
|
|
});
|
|
};
|
|
|
|
var DockingState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
init: init$b
|
|
});
|
|
|
|
var Docking = create$1({
|
|
fields: DockingSchema,
|
|
name: 'docking',
|
|
active: ActiveDocking,
|
|
apis: DockingApis,
|
|
state: DockingState
|
|
});
|
|
|
|
var visibility = {
|
|
fadeInClass: 'tox-editor-dock-fadein',
|
|
fadeOutClass: 'tox-editor-dock-fadeout',
|
|
transitionClass: 'tox-editor-dock-transition'
|
|
};
|
|
var editorStickyOnClass = 'tox-tinymce--toolbar-sticky-on';
|
|
var editorStickyOffClass = 'tox-tinymce--toolbar-sticky-off';
|
|
var scrollFromBehindHeader = function (e, containerHeader) {
|
|
var doc = owner(containerHeader);
|
|
var viewHeight = doc.dom().defaultView.innerHeight;
|
|
var scrollPos = get$8(doc);
|
|
var markerElement = Element.fromDom(e.elm);
|
|
var markerPos = absolute$1(markerElement);
|
|
var markerHeight = get$6(markerElement);
|
|
var markerTop = markerPos.y;
|
|
var markerBottom = markerTop + markerHeight;
|
|
var editorHeaderPos = absolute(containerHeader);
|
|
var editorHeaderHeight = get$6(containerHeader);
|
|
var editorHeaderTop = editorHeaderPos.top();
|
|
var editorHeaderBottom = editorHeaderTop + editorHeaderHeight;
|
|
var editorHeaderDockedAtTop = Math.abs(editorHeaderTop - scrollPos.top()) < 2;
|
|
var editorHeaderDockedAtBottom = Math.abs(editorHeaderBottom - (scrollPos.top() + viewHeight)) < 2;
|
|
if (editorHeaderDockedAtTop && markerTop < editorHeaderBottom) {
|
|
to(scrollPos.left(), markerTop - editorHeaderHeight, doc);
|
|
} else if (editorHeaderDockedAtBottom && markerBottom > editorHeaderTop) {
|
|
var y = markerTop - viewHeight + markerHeight + editorHeaderHeight;
|
|
to(scrollPos.left(), y, doc);
|
|
}
|
|
};
|
|
var isDockedMode = function (header, mode) {
|
|
return contains(Docking.getModes(header), mode);
|
|
};
|
|
var updateIframeContentFlow = function (header) {
|
|
var getOccupiedHeight = function (elm) {
|
|
return getOuter$1(elm) + (parseInt(get$4(elm, 'margin-top'), 10) || 0) + (parseInt(get$4(elm, 'margin-bottom'), 10) || 0);
|
|
};
|
|
var elm = header.element();
|
|
parent(elm).each(function (parentElem) {
|
|
var padding = 'padding-' + Docking.getModes(header)[0];
|
|
if (Docking.isDocked(header)) {
|
|
var parentWidth = get$7(parentElem);
|
|
set$2(elm, 'width', parentWidth + 'px');
|
|
set$2(parentElem, padding, getOccupiedHeight(elm) + 'px');
|
|
} else {
|
|
remove$6(elm, 'width');
|
|
remove$6(parentElem, padding);
|
|
}
|
|
});
|
|
};
|
|
var updateSinkVisibility = function (sinkElem, visible) {
|
|
if (visible) {
|
|
remove$4(sinkElem, visibility.fadeOutClass);
|
|
add$3(sinkElem, [
|
|
visibility.transitionClass,
|
|
visibility.fadeInClass
|
|
]);
|
|
} else {
|
|
remove$4(sinkElem, visibility.fadeInClass);
|
|
add$3(sinkElem, [
|
|
visibility.fadeOutClass,
|
|
visibility.transitionClass
|
|
]);
|
|
}
|
|
};
|
|
var updateEditorClasses = function (editor, docked) {
|
|
var editorContainer = Element.fromDom(editor.getContainer());
|
|
if (docked) {
|
|
add$2(editorContainer, editorStickyOnClass);
|
|
remove$4(editorContainer, editorStickyOffClass);
|
|
} else {
|
|
add$2(editorContainer, editorStickyOffClass);
|
|
remove$4(editorContainer, editorStickyOnClass);
|
|
}
|
|
};
|
|
var restoreFocus = function (headerElem, focusedElem) {
|
|
var ownerDoc = owner(focusedElem);
|
|
active(ownerDoc).filter(function (activeElm) {
|
|
return !eq$1(focusedElem, activeElm);
|
|
}).filter(function (activeElm) {
|
|
return eq$1(activeElm, Element.fromDom(ownerDoc.dom().body)) || contains$2(headerElem, activeElm);
|
|
}).each(function () {
|
|
return focus$1(focusedElem);
|
|
});
|
|
};
|
|
var findFocusedElem = function (rootElm, lazySink) {
|
|
return search(rootElm).orThunk(function () {
|
|
return lazySink().toOption().bind(function (sink) {
|
|
return search(sink.element());
|
|
});
|
|
});
|
|
};
|
|
var setup$4 = function (editor, sharedBackstage, lazyHeader) {
|
|
if (!editor.inline) {
|
|
if (!sharedBackstage.header.isPositionedAtTop()) {
|
|
editor.on('ResizeEditor', function () {
|
|
lazyHeader().each(Docking.reset);
|
|
});
|
|
}
|
|
editor.on('ResizeWindow ResizeEditor', function () {
|
|
lazyHeader().each(updateIframeContentFlow);
|
|
});
|
|
editor.on('SkinLoaded', function () {
|
|
lazyHeader().each(function (comp) {
|
|
Docking.isDocked(comp) ? Docking.reset(comp) : Docking.refresh(comp);
|
|
});
|
|
});
|
|
editor.on('FullscreenStateChanged', function () {
|
|
lazyHeader().each(Docking.reset);
|
|
});
|
|
}
|
|
editor.on('AfterScrollIntoView', function (e) {
|
|
lazyHeader().each(function (header) {
|
|
Docking.refresh(header);
|
|
var headerElem = header.element();
|
|
if (isVisible(headerElem)) {
|
|
scrollFromBehindHeader(e, headerElem);
|
|
}
|
|
});
|
|
});
|
|
editor.on('PostRender', function () {
|
|
updateEditorClasses(editor, false);
|
|
});
|
|
};
|
|
var isDocked$1 = function (lazyHeader) {
|
|
return lazyHeader().map(Docking.isDocked).getOr(false);
|
|
};
|
|
var getIframeBehaviours = function () {
|
|
var _a;
|
|
return [Receiving.config({ channels: (_a = {}, _a[toolbarHeightChange()] = { onReceive: updateIframeContentFlow }, _a) })];
|
|
};
|
|
var getBehaviours$2 = function (editor, sharedBackstage) {
|
|
var focusedElm = Cell(Option.none());
|
|
var lazySink = sharedBackstage.getSink;
|
|
var runOnSinkElement = function (f) {
|
|
lazySink().each(function (sink) {
|
|
return f(sink.element());
|
|
});
|
|
};
|
|
var onDockingSwitch = function (comp) {
|
|
if (!editor.inline) {
|
|
updateIframeContentFlow(comp);
|
|
}
|
|
updateEditorClasses(editor, Docking.isDocked(comp));
|
|
comp.getSystem().broadcastOn([repositionPopups()], {});
|
|
lazySink().each(function (sink) {
|
|
return sink.getSystem().broadcastOn([repositionPopups()], {});
|
|
});
|
|
};
|
|
var additionalBehaviours = editor.inline ? [] : getIframeBehaviours();
|
|
return __spreadArrays([
|
|
Focusing.config({}),
|
|
Docking.config({
|
|
contextual: __assign({
|
|
lazyContext: function (comp) {
|
|
var headerHeight = getOuter$1(comp.element());
|
|
var container = editor.inline ? editor.getContentAreaContainer() : editor.getContainer();
|
|
var box$1 = box(Element.fromDom(container));
|
|
var boxHeight = box$1.height - headerHeight;
|
|
var topBound = box$1.y + (isDockedMode(comp, 'top') ? 0 : headerHeight);
|
|
return Option.some(bounds$1(box$1.x, topBound, box$1.width, boxHeight));
|
|
},
|
|
onShow: function () {
|
|
runOnSinkElement(function (elem) {
|
|
return updateSinkVisibility(elem, true);
|
|
});
|
|
},
|
|
onShown: function (comp) {
|
|
runOnSinkElement(function (elem) {
|
|
return remove$5(elem, [
|
|
visibility.transitionClass,
|
|
visibility.fadeInClass
|
|
]);
|
|
});
|
|
focusedElm.get().each(function (elem) {
|
|
restoreFocus(comp.element(), elem);
|
|
focusedElm.set(Option.none());
|
|
});
|
|
},
|
|
onHide: function (comp) {
|
|
focusedElm.set(findFocusedElem(comp.element(), lazySink));
|
|
runOnSinkElement(function (elem) {
|
|
return updateSinkVisibility(elem, false);
|
|
});
|
|
},
|
|
onHidden: function () {
|
|
runOnSinkElement(function (elem) {
|
|
return remove$5(elem, [visibility.transitionClass]);
|
|
});
|
|
}
|
|
}, visibility),
|
|
modes: [sharedBackstage.header.getDockingMode()],
|
|
onDocked: onDockingSwitch,
|
|
onUndocked: onDockingSwitch
|
|
})
|
|
], additionalBehaviours);
|
|
};
|
|
|
|
var StickyHeader = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
setup: setup$4,
|
|
isDocked: isDocked$1,
|
|
getBehaviours: getBehaviours$2
|
|
});
|
|
|
|
var setup$5 = noop;
|
|
var isDocked$2 = never;
|
|
var getBehaviours$3 = constant([]);
|
|
|
|
var StaticHeader = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
setup: setup$5,
|
|
isDocked: isDocked$2,
|
|
getBehaviours: getBehaviours$3
|
|
});
|
|
|
|
var renderHeader = function (spec) {
|
|
var editor = spec.editor;
|
|
var getBehaviours = spec.sticky ? getBehaviours$2 : getBehaviours$3;
|
|
return {
|
|
uid: spec.uid,
|
|
dom: spec.dom,
|
|
components: spec.components,
|
|
behaviours: derive$1(getBehaviours(editor, spec.sharedBackstage))
|
|
};
|
|
};
|
|
|
|
var factory$g = function (detail, spec) {
|
|
var setMenus = function (comp, menus) {
|
|
var newMenus = map(menus, function (m) {
|
|
var buttonSpec = {
|
|
type: 'menubutton',
|
|
text: m.text,
|
|
fetch: function (callback) {
|
|
callback(m.getItems());
|
|
}
|
|
};
|
|
var internal = createMenuButton(buttonSpec).mapError(function (errInfo) {
|
|
return formatError(errInfo);
|
|
}).getOrDie();
|
|
return renderMenuButton(internal, 'tox-mbtn', spec.backstage, Option.some('menuitem'));
|
|
});
|
|
Replacing.set(comp, newMenus);
|
|
};
|
|
var apis = {
|
|
focus: Keying.focusIn,
|
|
setMenus: setMenus
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: [],
|
|
behaviours: derive$1([
|
|
Replacing.config({}),
|
|
config('menubar-events', [
|
|
runOnAttached(function (component) {
|
|
detail.onSetup(component);
|
|
}),
|
|
run(mouseover(), function (comp, se) {
|
|
descendant$1(comp.element(), '.' + 'tox-mbtn--active').each(function (activeButton) {
|
|
closest$3(se.event().target(), '.' + 'tox-mbtn').each(function (hoveredButton) {
|
|
if (!eq$1(activeButton, hoveredButton)) {
|
|
comp.getSystem().getByDom(activeButton).each(function (activeComp) {
|
|
comp.getSystem().getByDom(hoveredButton).each(function (hoveredComp) {
|
|
Dropdown.expand(hoveredComp);
|
|
Dropdown.close(activeComp);
|
|
Focusing.focus(hoveredComp);
|
|
});
|
|
});
|
|
}
|
|
});
|
|
});
|
|
}),
|
|
run(focusShifted(), function (comp, se) {
|
|
se.event().prevFocus().bind(function (prev) {
|
|
return comp.getSystem().getByDom(prev).toOption();
|
|
}).each(function (prev) {
|
|
se.event().newFocus().bind(function (nu) {
|
|
return comp.getSystem().getByDom(nu).toOption();
|
|
}).each(function (nu) {
|
|
if (Dropdown.isOpen(prev)) {
|
|
Dropdown.expand(nu);
|
|
Dropdown.close(prev);
|
|
}
|
|
});
|
|
});
|
|
})
|
|
]),
|
|
Keying.config({
|
|
mode: 'flow',
|
|
selector: '.' + 'tox-mbtn',
|
|
onEscape: function (comp) {
|
|
detail.onEscape(comp);
|
|
return Option.some(true);
|
|
}
|
|
}),
|
|
Tabstopping.config({})
|
|
]),
|
|
apis: apis,
|
|
domModification: { attributes: { role: 'menubar' } }
|
|
};
|
|
};
|
|
var SilverMenubar = single$2({
|
|
factory: factory$g,
|
|
name: 'silver.Menubar',
|
|
configFields: [
|
|
strict$1('dom'),
|
|
strict$1('uid'),
|
|
strict$1('onEscape'),
|
|
strict$1('backstage'),
|
|
defaulted$1('onSetup', noop)
|
|
],
|
|
apis: {
|
|
focus: function (apis, comp) {
|
|
apis.focus(comp);
|
|
},
|
|
setMenus: function (apis, comp, menus) {
|
|
apis.setMenus(comp, menus);
|
|
}
|
|
}
|
|
});
|
|
|
|
var owner$4 = 'container';
|
|
var schema$s = [field$1('slotBehaviours', [])];
|
|
var getPartName$1 = function (name) {
|
|
return '<alloy.field.' + name + '>';
|
|
};
|
|
var sketch$2 = function (sSpec) {
|
|
var parts = function () {
|
|
var record = [];
|
|
var slot = function (name, config) {
|
|
record.push(name);
|
|
return generateOne(owner$4, getPartName$1(name), config);
|
|
};
|
|
return {
|
|
slot: slot,
|
|
record: function () {
|
|
return record;
|
|
}
|
|
};
|
|
}();
|
|
var spec = sSpec(parts);
|
|
var partNames = parts.record();
|
|
var fieldParts = map(partNames, function (n) {
|
|
return required({
|
|
name: n,
|
|
pname: getPartName$1(n)
|
|
});
|
|
});
|
|
return composite(owner$4, schema$s, fieldParts, make$7, spec);
|
|
};
|
|
var make$7 = function (detail, components) {
|
|
var getSlotNames = function (_) {
|
|
return getAllPartNames(detail);
|
|
};
|
|
var getSlot = function (container, key) {
|
|
return getPart(container, detail, key);
|
|
};
|
|
var onSlot = function (f, def) {
|
|
return function (container, key) {
|
|
return getPart(container, detail, key).map(function (slot) {
|
|
return f(slot, key);
|
|
}).getOr(def);
|
|
};
|
|
};
|
|
var onSlots = function (f) {
|
|
return function (container, keys) {
|
|
each(keys, function (key) {
|
|
return f(container, key);
|
|
});
|
|
};
|
|
};
|
|
var doShowing = function (comp, _key) {
|
|
return get$2(comp.element(), 'aria-hidden') !== 'true';
|
|
};
|
|
var doShow = function (comp, key) {
|
|
if (!doShowing(comp)) {
|
|
var element = comp.element();
|
|
remove$6(element, 'display');
|
|
remove$1(element, 'aria-hidden');
|
|
emitWith(comp, slotVisibility(), {
|
|
name: key,
|
|
visible: true
|
|
});
|
|
}
|
|
};
|
|
var doHide = function (comp, key) {
|
|
if (doShowing(comp)) {
|
|
var element = comp.element();
|
|
set$2(element, 'display', 'none');
|
|
set$1(element, 'aria-hidden', 'true');
|
|
emitWith(comp, slotVisibility(), {
|
|
name: key,
|
|
visible: false
|
|
});
|
|
}
|
|
};
|
|
var isShowing = onSlot(doShowing, false);
|
|
var hideSlot = onSlot(doHide);
|
|
var hideSlots = onSlots(hideSlot);
|
|
var hideAllSlots = function (container) {
|
|
return hideSlots(container, getSlotNames());
|
|
};
|
|
var showSlot = onSlot(doShow);
|
|
var apis = {
|
|
getSlotNames: getSlotNames,
|
|
getSlot: getSlot,
|
|
isShowing: isShowing,
|
|
hideSlot: hideSlot,
|
|
hideAllSlots: hideAllSlots,
|
|
showSlot: showSlot
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: get$c(detail.slotBehaviours),
|
|
apis: apis
|
|
};
|
|
};
|
|
var slotApis = map$1({
|
|
getSlotNames: function (apis, c) {
|
|
return apis.getSlotNames(c);
|
|
},
|
|
getSlot: function (apis, c, key) {
|
|
return apis.getSlot(c, key);
|
|
},
|
|
isShowing: function (apis, c, key) {
|
|
return apis.isShowing(c, key);
|
|
},
|
|
hideSlot: function (apis, c, key) {
|
|
return apis.hideSlot(c, key);
|
|
},
|
|
hideAllSlots: function (apis, c) {
|
|
return apis.hideAllSlots(c);
|
|
},
|
|
showSlot: function (apis, c, key) {
|
|
return apis.showSlot(c, key);
|
|
}
|
|
}, function (value) {
|
|
return makeApi(value);
|
|
});
|
|
var SlotContainer = __assign(__assign({}, slotApis), { sketch: sketch$2 });
|
|
|
|
var sidebarSchema = objOf([
|
|
optionString('icon'),
|
|
optionString('tooltip'),
|
|
defaultedFunction('onShow', noop),
|
|
defaultedFunction('onHide', noop),
|
|
defaultedFunction('onSetup', function () {
|
|
return noop;
|
|
})
|
|
]);
|
|
var createSidebar = function (spec) {
|
|
return asRaw('sidebar', sidebarSchema, spec);
|
|
};
|
|
|
|
var setup$6 = function (editor) {
|
|
var sidebars = editor.ui.registry.getAll().sidebars;
|
|
each(keys(sidebars), function (name) {
|
|
var spec = sidebars[name];
|
|
var isActive = function () {
|
|
return Option.from(editor.queryCommandValue('ToggleSidebar')).is(name);
|
|
};
|
|
editor.ui.registry.addToggleButton(name, {
|
|
icon: spec.icon,
|
|
tooltip: spec.tooltip,
|
|
onAction: function (buttonApi) {
|
|
editor.execCommand('ToggleSidebar', false, name);
|
|
buttonApi.setActive(isActive());
|
|
},
|
|
onSetup: function (buttonApi) {
|
|
var handleToggle = function () {
|
|
return buttonApi.setActive(isActive());
|
|
};
|
|
editor.on('ToggleSidebar', handleToggle);
|
|
return function () {
|
|
editor.off('ToggleSidebar', handleToggle);
|
|
};
|
|
}
|
|
});
|
|
});
|
|
};
|
|
var getApi = function (comp) {
|
|
return {
|
|
element: function () {
|
|
return comp.element().dom();
|
|
}
|
|
};
|
|
};
|
|
var makePanels = function (parts, panelConfigs) {
|
|
var specs = map(keys(panelConfigs), function (name) {
|
|
var spec = panelConfigs[name];
|
|
var bridged = getOrDie(createSidebar(spec));
|
|
return {
|
|
name: name,
|
|
getApi: getApi,
|
|
onSetup: bridged.onSetup,
|
|
onShow: bridged.onShow,
|
|
onHide: bridged.onHide
|
|
};
|
|
});
|
|
return map(specs, function (spec) {
|
|
var editorOffCell = Cell(noop);
|
|
return parts.slot(spec.name, {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-sidebar__pane']
|
|
},
|
|
behaviours: SimpleBehaviours.unnamedEvents([
|
|
onControlAttached(spec, editorOffCell),
|
|
onControlDetached(spec, editorOffCell),
|
|
run(slotVisibility(), function (sidepanel, se) {
|
|
var data = se.event();
|
|
var optSidePanelSpec = find(specs, function (config) {
|
|
return config.name === data.name();
|
|
});
|
|
optSidePanelSpec.each(function (sidePanelSpec) {
|
|
var handler = data.visible() ? sidePanelSpec.onShow : sidePanelSpec.onHide;
|
|
handler(sidePanelSpec.getApi(sidepanel));
|
|
});
|
|
})
|
|
])
|
|
});
|
|
});
|
|
};
|
|
var makeSidebar = function (panelConfigs) {
|
|
return SlotContainer.sketch(function (parts) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-sidebar__pane-container']
|
|
},
|
|
components: makePanels(parts, panelConfigs),
|
|
slotBehaviours: SimpleBehaviours.unnamedEvents([runOnAttached(function (slotContainer) {
|
|
return SlotContainer.hideAllSlots(slotContainer);
|
|
})])
|
|
};
|
|
});
|
|
};
|
|
var setSidebar = function (sidebar, panelConfigs) {
|
|
var optSlider = Composing.getCurrent(sidebar);
|
|
optSlider.each(function (slider) {
|
|
return Replacing.set(slider, [makeSidebar(panelConfigs)]);
|
|
});
|
|
};
|
|
var toggleSidebar = function (sidebar, name) {
|
|
var optSlider = Composing.getCurrent(sidebar);
|
|
optSlider.each(function (slider) {
|
|
var optSlotContainer = Composing.getCurrent(slider);
|
|
optSlotContainer.each(function (slotContainer) {
|
|
if (Sliding.hasGrown(slider)) {
|
|
if (SlotContainer.isShowing(slotContainer, name)) {
|
|
Sliding.shrink(slider);
|
|
} else {
|
|
SlotContainer.hideAllSlots(slotContainer);
|
|
SlotContainer.showSlot(slotContainer, name);
|
|
}
|
|
} else {
|
|
SlotContainer.hideAllSlots(slotContainer);
|
|
SlotContainer.showSlot(slotContainer, name);
|
|
Sliding.grow(slider);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
var whichSidebar = function (sidebar) {
|
|
var optSlider = Composing.getCurrent(sidebar);
|
|
return optSlider.bind(function (slider) {
|
|
var sidebarOpen = Sliding.isGrowing(slider) || Sliding.hasGrown(slider);
|
|
if (sidebarOpen) {
|
|
var optSlotContainer = Composing.getCurrent(slider);
|
|
return optSlotContainer.bind(function (slotContainer) {
|
|
return find(SlotContainer.getSlotNames(slotContainer), function (name) {
|
|
return SlotContainer.isShowing(slotContainer, name);
|
|
});
|
|
});
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
});
|
|
};
|
|
var fixSize = generate$1('FixSizeEvent');
|
|
var autoSize = generate$1('AutoSizeEvent');
|
|
var renderSidebar = function (spec) {
|
|
return {
|
|
uid: spec.uid,
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-sidebar'],
|
|
attributes: { role: 'complementary' }
|
|
},
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-sidebar__slider']
|
|
},
|
|
components: [],
|
|
behaviours: derive$1([
|
|
Tabstopping.config({}),
|
|
Focusing.config({}),
|
|
Sliding.config({
|
|
dimension: { property: 'width' },
|
|
closedClass: 'tox-sidebar--sliding-closed',
|
|
openClass: 'tox-sidebar--sliding-open',
|
|
shrinkingClass: 'tox-sidebar--sliding-shrinking',
|
|
growingClass: 'tox-sidebar--sliding-growing',
|
|
onShrunk: function (slider) {
|
|
var optSlotContainer = Composing.getCurrent(slider);
|
|
optSlotContainer.each(SlotContainer.hideAllSlots);
|
|
emit(slider, autoSize);
|
|
},
|
|
onGrown: function (slider) {
|
|
emit(slider, autoSize);
|
|
},
|
|
onStartGrow: function (slider) {
|
|
emitWith(slider, fixSize, { width: getRaw(slider.element(), 'width').getOr('') });
|
|
},
|
|
onStartShrink: function (slider) {
|
|
emitWith(slider, fixSize, { width: get$7(slider.element()) + 'px' });
|
|
}
|
|
}),
|
|
Replacing.config({}),
|
|
Composing.config({
|
|
find: function (comp) {
|
|
var children = Replacing.contents(comp);
|
|
return head(children);
|
|
}
|
|
})
|
|
])
|
|
}],
|
|
behaviours: derive$1([
|
|
ComposingConfigs.childAt(0),
|
|
config('sidebar-sliding-events', [
|
|
run(fixSize, function (comp, se) {
|
|
set$2(comp.element(), 'width', se.event().width());
|
|
}),
|
|
run(autoSize, function (comp, _se) {
|
|
remove$6(comp.element(), 'width');
|
|
})
|
|
])
|
|
])
|
|
};
|
|
};
|
|
|
|
var getAttrs = function (elem) {
|
|
var attributes = elem.dom().attributes !== undefined ? elem.dom().attributes : [];
|
|
return foldl(attributes, function (b, attr) {
|
|
var _a;
|
|
if (attr.name === 'class') {
|
|
return b;
|
|
} else {
|
|
return __assign(__assign({}, b), (_a = {}, _a[attr.name] = attr.value, _a));
|
|
}
|
|
}, {});
|
|
};
|
|
var getClasses = function (elem) {
|
|
return Array.prototype.slice.call(elem.dom().classList, 0);
|
|
};
|
|
var fromHtml$2 = function (html) {
|
|
var elem = Element.fromHtml(html);
|
|
var children$1 = children(elem);
|
|
var attrs = getAttrs(elem);
|
|
var classes = getClasses(elem);
|
|
var contents = children$1.length === 0 ? {} : { innerHtml: get$1(elem) };
|
|
return __assign({
|
|
tag: name(elem),
|
|
classes: classes,
|
|
attributes: attrs
|
|
}, contents);
|
|
};
|
|
|
|
var renderSpinner = function (providerBackstage) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { 'aria-label': providerBackstage.translate('Loading...') },
|
|
classes: ['tox-throbber__busy-spinner']
|
|
},
|
|
components: [{ dom: fromHtml$2('<div class="tox-spinner"><div></div><div></div><div></div></div>') }],
|
|
behaviours: derive$1([
|
|
Keying.config({
|
|
mode: 'special',
|
|
onTab: function () {
|
|
return Option.some(true);
|
|
},
|
|
onShiftTab: function () {
|
|
return Option.some(true);
|
|
}
|
|
}),
|
|
Focusing.config({})
|
|
])
|
|
};
|
|
};
|
|
var toggleThrobber = function (comp, state, providerBackstage) {
|
|
var element = comp.element();
|
|
if (state === true) {
|
|
Replacing.set(comp, [renderSpinner(providerBackstage)]);
|
|
remove$6(element, 'display');
|
|
remove$1(element, 'aria-hidden');
|
|
} else {
|
|
Replacing.set(comp, []);
|
|
set$2(element, 'display', 'none');
|
|
set$1(element, 'aria-hidden', 'true');
|
|
}
|
|
};
|
|
var renderThrobber = function (spec) {
|
|
return {
|
|
uid: spec.uid,
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { 'aria-hidden': 'true' },
|
|
classes: ['tox-throbber'],
|
|
styles: { display: 'none' }
|
|
},
|
|
behaviours: derive$1([Replacing.config({})]),
|
|
components: []
|
|
};
|
|
};
|
|
var setup$7 = function (editor, lazyThrobber, sharedBackstage) {
|
|
var throbberState = Cell(false);
|
|
var timer = Cell(Option.none());
|
|
var toggle = function (state) {
|
|
if (state !== throbberState.get()) {
|
|
toggleThrobber(lazyThrobber(), state, sharedBackstage.providers);
|
|
throbberState.set(state);
|
|
}
|
|
};
|
|
editor.on('ProgressState', function (e) {
|
|
timer.get().each(global$2.clearTimeout);
|
|
if (isNumber(e.time)) {
|
|
var timerId = global$2.setEditorTimeout(editor, function () {
|
|
return toggle(e.state);
|
|
}, e.time);
|
|
timer.set(Option.some(timerId));
|
|
} else {
|
|
toggle(e.state);
|
|
timer.set(Option.none());
|
|
}
|
|
});
|
|
};
|
|
|
|
var factory$h = function (detail, components, _spec) {
|
|
var apis = {
|
|
getSocket: function (comp) {
|
|
return parts$d.getPart(comp, detail, 'socket');
|
|
},
|
|
setSidebar: function (comp, panelConfigs) {
|
|
parts$d.getPart(comp, detail, 'sidebar').each(function (sidebar) {
|
|
return setSidebar(sidebar, panelConfigs);
|
|
});
|
|
},
|
|
toggleSidebar: function (comp, name) {
|
|
parts$d.getPart(comp, detail, 'sidebar').each(function (sidebar) {
|
|
return toggleSidebar(sidebar, name);
|
|
});
|
|
},
|
|
whichSidebar: function (comp) {
|
|
return parts$d.getPart(comp, detail, 'sidebar').bind(whichSidebar).getOrNull();
|
|
},
|
|
getHeader: function (comp) {
|
|
return parts$d.getPart(comp, detail, 'header');
|
|
},
|
|
getToolbar: function (comp) {
|
|
return parts$d.getPart(comp, detail, 'toolbar');
|
|
},
|
|
setToolbar: function (comp, groups) {
|
|
parts$d.getPart(comp, detail, 'toolbar').each(function (toolbar) {
|
|
toolbar.getApis().setGroups(toolbar, groups);
|
|
});
|
|
},
|
|
setToolbars: function (comp, toolbars) {
|
|
parts$d.getPart(comp, detail, 'multiple-toolbar').each(function (mToolbar) {
|
|
CustomList.setItems(mToolbar, toolbars);
|
|
});
|
|
},
|
|
refreshToolbar: function (comp) {
|
|
var toolbar = parts$d.getPart(comp, detail, 'toolbar');
|
|
toolbar.each(function (toolbar) {
|
|
return toolbar.getApis().refresh(toolbar);
|
|
});
|
|
},
|
|
getThrobber: function (comp) {
|
|
return parts$d.getPart(comp, detail, 'throbber');
|
|
},
|
|
focusToolbar: function (comp) {
|
|
var optToolbar = parts$d.getPart(comp, detail, 'toolbar').orThunk(function () {
|
|
return parts$d.getPart(comp, detail, 'multiple-toolbar');
|
|
});
|
|
optToolbar.each(function (toolbar) {
|
|
Keying.focusIn(toolbar);
|
|
});
|
|
},
|
|
setMenubar: function (comp, menus) {
|
|
parts$d.getPart(comp, detail, 'menubar').each(function (menubar) {
|
|
SilverMenubar.setMenus(menubar, menus);
|
|
});
|
|
},
|
|
focusMenubar: function (comp) {
|
|
parts$d.getPart(comp, detail, 'menubar').each(function (menubar) {
|
|
SilverMenubar.focus(menubar);
|
|
});
|
|
}
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
apis: apis,
|
|
behaviours: detail.behaviours
|
|
};
|
|
};
|
|
var partMenubar = partType$1.optional({
|
|
factory: SilverMenubar,
|
|
name: 'menubar',
|
|
schema: [strict$1('backstage')]
|
|
});
|
|
var toolbarFactory = function (spec) {
|
|
if (spec.type === ToolbarMode.sliding) {
|
|
return renderSlidingMoreToolbar;
|
|
} else if (spec.type === ToolbarMode.floating) {
|
|
return renderFloatingMoreToolbar;
|
|
} else {
|
|
return renderToolbar;
|
|
}
|
|
};
|
|
var partMultipleToolbar = partType$1.optional({
|
|
factory: {
|
|
sketch: function (spec) {
|
|
return CustomList.sketch({
|
|
uid: spec.uid,
|
|
dom: spec.dom,
|
|
listBehaviours: derive$1([Keying.config({
|
|
mode: 'acyclic',
|
|
selector: '.tox-toolbar'
|
|
})]),
|
|
makeItem: function () {
|
|
return renderToolbar({
|
|
type: spec.type,
|
|
uid: generate$1('multiple-toolbar-item'),
|
|
cyclicKeying: false,
|
|
initGroups: [],
|
|
providers: spec.providers,
|
|
onEscape: function () {
|
|
return Option.none();
|
|
}
|
|
});
|
|
},
|
|
setupItem: function (_mToolbar, tc, data, _index) {
|
|
Toolbar.setGroups(tc, data);
|
|
},
|
|
shell: true
|
|
});
|
|
}
|
|
},
|
|
name: 'multiple-toolbar',
|
|
schema: [
|
|
strict$1('dom'),
|
|
strict$1('onEscape')
|
|
]
|
|
});
|
|
var partToolbar = partType$1.optional({
|
|
factory: {
|
|
sketch: function (spec) {
|
|
var renderer = toolbarFactory(spec);
|
|
var toolbarSpec = {
|
|
type: spec.type,
|
|
uid: spec.uid,
|
|
onEscape: function () {
|
|
spec.onEscape();
|
|
return Option.some(true);
|
|
},
|
|
cyclicKeying: false,
|
|
initGroups: [],
|
|
getSink: spec.getSink,
|
|
providers: spec.providers,
|
|
moreDrawerData: {
|
|
lazyToolbar: spec.lazyToolbar,
|
|
lazyMoreButton: spec.lazyMoreButton,
|
|
lazyHeader: spec.lazyHeader
|
|
},
|
|
attributes: spec.attributes
|
|
};
|
|
return renderer(toolbarSpec);
|
|
}
|
|
},
|
|
name: 'toolbar',
|
|
schema: [
|
|
strict$1('dom'),
|
|
strict$1('onEscape'),
|
|
strict$1('getSink')
|
|
]
|
|
});
|
|
var partHeader = partType$1.optional({
|
|
factory: { sketch: renderHeader },
|
|
name: 'header',
|
|
schema: [strict$1('dom')]
|
|
});
|
|
var partSocket = partType$1.optional({
|
|
name: 'socket',
|
|
schema: [strict$1('dom')]
|
|
});
|
|
var partSidebar = partType$1.optional({
|
|
factory: { sketch: renderSidebar },
|
|
name: 'sidebar',
|
|
schema: [strict$1('dom')]
|
|
});
|
|
var partThrobber = partType$1.optional({
|
|
factory: { sketch: renderThrobber },
|
|
name: 'throbber',
|
|
schema: [strict$1('dom')]
|
|
});
|
|
var OuterContainer = composite$1({
|
|
name: 'OuterContainer',
|
|
factory: factory$h,
|
|
configFields: [
|
|
strict$1('dom'),
|
|
strict$1('behaviours')
|
|
],
|
|
partFields: [
|
|
partHeader,
|
|
partMenubar,
|
|
partToolbar,
|
|
partMultipleToolbar,
|
|
partSocket,
|
|
partSidebar,
|
|
partThrobber
|
|
],
|
|
apis: {
|
|
getSocket: function (apis, comp) {
|
|
return apis.getSocket(comp);
|
|
},
|
|
setSidebar: function (apis, comp, panelConfigs) {
|
|
apis.setSidebar(comp, panelConfigs);
|
|
},
|
|
toggleSidebar: function (apis, comp, name) {
|
|
apis.toggleSidebar(comp, name);
|
|
},
|
|
whichSidebar: function (apis, comp) {
|
|
return apis.whichSidebar(comp);
|
|
},
|
|
getHeader: function (apis, comp) {
|
|
return apis.getHeader(comp);
|
|
},
|
|
getToolbar: function (apis, comp) {
|
|
return apis.getToolbar(comp);
|
|
},
|
|
setToolbar: function (apis, comp, grps) {
|
|
var groups = map(grps, function (grp) {
|
|
return renderToolbarGroup(grp);
|
|
});
|
|
apis.setToolbar(comp, groups);
|
|
},
|
|
setToolbars: function (apis, comp, ts) {
|
|
var renderedToolbars = map(ts, function (g) {
|
|
return map(g, renderToolbarGroup);
|
|
});
|
|
apis.setToolbars(comp, renderedToolbars);
|
|
},
|
|
refreshToolbar: function (apis, comp) {
|
|
return apis.refreshToolbar(comp);
|
|
},
|
|
getThrobber: function (apis, comp) {
|
|
return apis.getThrobber(comp);
|
|
},
|
|
setMenubar: function (apis, comp, menus) {
|
|
apis.setMenubar(comp, menus);
|
|
},
|
|
focusMenubar: function (apis, comp) {
|
|
apis.focusMenubar(comp);
|
|
},
|
|
focusToolbar: function (apis, comp) {
|
|
apis.focusToolbar(comp);
|
|
}
|
|
}
|
|
});
|
|
|
|
var defaultMenubar = 'file edit view insert format tools table help';
|
|
var defaultMenus = {
|
|
file: {
|
|
title: 'File',
|
|
items: 'newdocument restoredraft | preview | print | deleteallconversations'
|
|
},
|
|
edit: {
|
|
title: 'Edit',
|
|
items: 'undo redo | cut copy paste pastetext | selectall | searchreplace'
|
|
},
|
|
view: {
|
|
title: 'View',
|
|
items: 'code | visualaid visualchars visualblocks | spellchecker | preview fullscreen | showcomments'
|
|
},
|
|
insert: {
|
|
title: 'Insert',
|
|
items: 'image link media addcomment pageembed template codesample inserttable | charmap emoticons hr | pagebreak nonbreaking anchor toc | insertdatetime'
|
|
},
|
|
format: {
|
|
title: 'Format',
|
|
items: 'bold italic underline strikethrough superscript subscript codeformat | formats blockformats fontformats fontsizes align | forecolor backcolor | removeformat'
|
|
},
|
|
tools: {
|
|
title: 'Tools',
|
|
items: 'spellchecker spellcheckerlanguage | a11ycheck code wordcount'
|
|
},
|
|
table: {
|
|
title: 'Table',
|
|
items: 'inserttable | cell row column | advtablesort | tableprops deletetable'
|
|
},
|
|
help: {
|
|
title: 'Help',
|
|
items: 'help'
|
|
}
|
|
};
|
|
var make$8 = function (menu, registry, editor) {
|
|
var removedMenuItems = getRemovedMenuItems(editor).split(/[ ,]/);
|
|
return {
|
|
text: menu.title,
|
|
getItems: function () {
|
|
return bind(menu.items, function (i) {
|
|
var itemName = i.toLowerCase();
|
|
if (itemName.trim().length === 0) {
|
|
return [];
|
|
} else if (exists(removedMenuItems, function (removedMenuItem) {
|
|
return removedMenuItem === itemName;
|
|
})) {
|
|
return [];
|
|
} else if (itemName === 'separator' || itemName === '|') {
|
|
return [{ type: 'separator' }];
|
|
} else if (registry.menuItems[itemName]) {
|
|
return [registry.menuItems[itemName]];
|
|
} else {
|
|
return [];
|
|
}
|
|
});
|
|
}
|
|
};
|
|
};
|
|
var parseItemsString = function (items) {
|
|
if (typeof items === 'string') {
|
|
return items.split(' ');
|
|
}
|
|
return items;
|
|
};
|
|
var identifyMenus = function (editor, registry) {
|
|
var rawMenuData = __assign(__assign({}, defaultMenus), registry.menus);
|
|
var userDefinedMenus = keys(registry.menus).length > 0;
|
|
var menubar = registry.menubar === undefined || registry.menubar === true ? parseItemsString(defaultMenubar) : parseItemsString(registry.menubar === false ? '' : registry.menubar);
|
|
var validMenus = filter(menubar, function (menuName) {
|
|
return userDefinedMenus ? registry.menus.hasOwnProperty(menuName) && registry.menus[menuName].hasOwnProperty('items') || defaultMenus.hasOwnProperty(menuName) : defaultMenus.hasOwnProperty(menuName);
|
|
});
|
|
var menus = map(validMenus, function (menuName) {
|
|
var menuData = rawMenuData[menuName];
|
|
return make$8({
|
|
title: menuData.title,
|
|
items: parseItemsString(menuData.items)
|
|
}, registry, editor);
|
|
});
|
|
return filter(menus, function (menu) {
|
|
var isNotSeparator = function (item) {
|
|
return item.type !== 'separator';
|
|
};
|
|
return menu.getItems().length > 0 && exists(menu.getItems(), isNotSeparator);
|
|
});
|
|
};
|
|
|
|
var fireSkinLoaded$1 = function (editor) {
|
|
var done = function () {
|
|
editor._skinLoaded = true;
|
|
fireSkinLoaded(editor);
|
|
};
|
|
return function () {
|
|
if (editor.initialized) {
|
|
done();
|
|
} else {
|
|
editor.on('init', done);
|
|
}
|
|
};
|
|
};
|
|
var fireSkinLoadError$1 = function (editor, err) {
|
|
return function () {
|
|
return fireSkinLoadError(editor, { message: err });
|
|
};
|
|
};
|
|
|
|
var loadSkin = function (isInline, editor) {
|
|
var skinUrl = getSkinUrl(editor);
|
|
var skinUiCss;
|
|
if (skinUrl) {
|
|
skinUiCss = skinUrl + '/skin.min.css';
|
|
editor.contentCSS.push(skinUrl + (isInline ? '/content.inline' : '/content') + '.min.css');
|
|
}
|
|
if (isSkinDisabled(editor) === false && skinUiCss) {
|
|
global$7.DOM.styleSheetLoader.load(skinUiCss, fireSkinLoaded$1(editor), fireSkinLoadError$1(editor, 'Skin could not be loaded'));
|
|
} else {
|
|
fireSkinLoaded$1(editor)();
|
|
}
|
|
};
|
|
var iframe = curry(loadSkin, false);
|
|
var inline = curry(loadSkin, true);
|
|
|
|
var setToolbar = function (editor, uiComponents, rawUiConfig, backstage) {
|
|
var comp = uiComponents.outerContainer;
|
|
var toolbarConfig = rawUiConfig.toolbar;
|
|
var toolbarButtonsConfig = rawUiConfig.buttons;
|
|
if (isArrayOf(toolbarConfig, isString)) {
|
|
var toolbars = toolbarConfig.map(function (t) {
|
|
var config = {
|
|
toolbar: t,
|
|
buttons: toolbarButtonsConfig,
|
|
allowToolbarGroups: rawUiConfig.allowToolbarGroups
|
|
};
|
|
return identifyButtons(editor, config, { backstage: backstage }, Option.none());
|
|
});
|
|
OuterContainer.setToolbars(comp, toolbars);
|
|
} else {
|
|
OuterContainer.setToolbar(comp, identifyButtons(editor, rawUiConfig, { backstage: backstage }, Option.none()));
|
|
}
|
|
};
|
|
|
|
var DOM = global$7.DOM;
|
|
var detection = detect$3();
|
|
var isiOS12 = detection.os.isiOS() && detection.os.version.major <= 12;
|
|
var setupEvents = function (editor) {
|
|
var contentWindow = editor.getWin();
|
|
var initialDocEle = editor.getDoc().documentElement;
|
|
var lastWindowDimensions = Cell(Position(contentWindow.innerWidth, contentWindow.innerHeight));
|
|
var lastDocumentDimensions = Cell(Position(initialDocEle.offsetWidth, initialDocEle.offsetHeight));
|
|
var resizeWindow = function (e) {
|
|
var outer = lastWindowDimensions.get();
|
|
if (outer.left() !== contentWindow.innerWidth || outer.top() !== contentWindow.innerHeight) {
|
|
lastWindowDimensions.set(Position(contentWindow.innerWidth, contentWindow.innerHeight));
|
|
fireResizeContent(editor, e);
|
|
}
|
|
};
|
|
var resizeDocument = function (e) {
|
|
var docEle = editor.getDoc().documentElement;
|
|
var inner = lastDocumentDimensions.get();
|
|
if (inner.left() !== docEle.offsetWidth || inner.top() !== docEle.offsetHeight) {
|
|
lastDocumentDimensions.set(Position(docEle.offsetWidth, docEle.offsetHeight));
|
|
fireResizeContent(editor, e);
|
|
}
|
|
};
|
|
var scroll = function (e) {
|
|
return fireScrollContent(editor, e);
|
|
};
|
|
DOM.bind(contentWindow, 'resize', resizeWindow);
|
|
DOM.bind(contentWindow, 'scroll', scroll);
|
|
var elementLoad = capture$1(Element.fromDom(editor.getBody()), 'load', resizeDocument);
|
|
editor.on('NodeChange', resizeDocument);
|
|
editor.on('remove', function () {
|
|
elementLoad.unbind();
|
|
DOM.unbind(contentWindow, 'resize', resizeWindow);
|
|
DOM.unbind(contentWindow, 'scroll', scroll);
|
|
});
|
|
};
|
|
var render = function (editor, uiComponents, rawUiConfig, backstage, args) {
|
|
var lastToolbarWidth = Cell(0);
|
|
iframe(editor);
|
|
attachSystemAfter(Element.fromDom(args.targetNode), uiComponents.mothership);
|
|
attachSystem(body(), uiComponents.uiMothership);
|
|
editor.on('PostRender', function () {
|
|
setToolbar(editor, uiComponents, rawUiConfig, backstage);
|
|
lastToolbarWidth.set(editor.getWin().innerWidth);
|
|
OuterContainer.setMenubar(uiComponents.outerContainer, identifyMenus(editor, rawUiConfig));
|
|
OuterContainer.setSidebar(uiComponents.outerContainer, rawUiConfig.sidebar);
|
|
setupEvents(editor);
|
|
});
|
|
var socket = OuterContainer.getSocket(uiComponents.outerContainer).getOrDie('Could not find expected socket element');
|
|
if (isiOS12 === true) {
|
|
setAll$1(socket.element(), {
|
|
'overflow': 'scroll',
|
|
'-webkit-overflow-scrolling': 'touch'
|
|
});
|
|
var limit = first(function () {
|
|
editor.fire('ScrollContent');
|
|
}, 20);
|
|
bind$3(socket.element(), 'scroll', limit.throttle);
|
|
}
|
|
setupReadonlyModeSwitch(editor, uiComponents);
|
|
editor.addCommand('ToggleSidebar', function (ui, value) {
|
|
OuterContainer.toggleSidebar(uiComponents.outerContainer, value);
|
|
editor.fire('ToggleSidebar');
|
|
});
|
|
editor.addQueryValueHandler('ToggleSidebar', function () {
|
|
return OuterContainer.whichSidebar(uiComponents.outerContainer);
|
|
});
|
|
var toolbarMode = getToolbarMode(editor);
|
|
var refreshDrawer = function () {
|
|
OuterContainer.refreshToolbar(uiComponents.outerContainer);
|
|
};
|
|
if (toolbarMode === ToolbarMode.sliding || toolbarMode === ToolbarMode.floating) {
|
|
editor.on('ResizeWindow ResizeEditor ResizeContent', function () {
|
|
var width = editor.getWin().innerWidth;
|
|
if (width !== lastToolbarWidth.get()) {
|
|
refreshDrawer();
|
|
lastToolbarWidth.set(width);
|
|
}
|
|
});
|
|
}
|
|
return {
|
|
iframeContainer: socket.element().dom(),
|
|
editorContainer: uiComponents.outerContainer.element().dom()
|
|
};
|
|
};
|
|
|
|
var Iframe = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
render: render
|
|
});
|
|
|
|
var revocable = function (doRevoke) {
|
|
var subject = Cell(Option.none());
|
|
var revoke = function () {
|
|
subject.get().each(doRevoke);
|
|
};
|
|
var clear = function () {
|
|
revoke();
|
|
subject.set(Option.none());
|
|
};
|
|
var set = function (s) {
|
|
revoke();
|
|
subject.set(Option.some(s));
|
|
};
|
|
var isSet = function () {
|
|
return subject.get().isSome();
|
|
};
|
|
return {
|
|
clear: clear,
|
|
isSet: isSet,
|
|
set: set
|
|
};
|
|
};
|
|
var unbindable = function () {
|
|
return revocable(function (s) {
|
|
s.unbind();
|
|
});
|
|
};
|
|
var value$3 = function () {
|
|
var subject = Cell(Option.none());
|
|
var clear = function () {
|
|
subject.set(Option.none());
|
|
};
|
|
var set = function (s) {
|
|
subject.set(Option.some(s));
|
|
};
|
|
var on = function (f) {
|
|
subject.get().each(f);
|
|
};
|
|
var isSet = function () {
|
|
return subject.get().isSome();
|
|
};
|
|
return {
|
|
clear: clear,
|
|
set: set,
|
|
isSet: isSet,
|
|
on: on
|
|
};
|
|
};
|
|
|
|
var parseToInt = function (val) {
|
|
var re = /^[0-9\.]+(|px)$/i;
|
|
if (re.test('' + val)) {
|
|
return Option.some(parseInt('' + val, 10));
|
|
}
|
|
return Option.none();
|
|
};
|
|
var numToPx = function (val) {
|
|
return isNumber(val) ? val + 'px' : val;
|
|
};
|
|
var calcCappedSize = function (size, minSize, maxSize) {
|
|
var minOverride = minSize.filter(function (min) {
|
|
return size < min;
|
|
});
|
|
var maxOverride = maxSize.filter(function (max) {
|
|
return size > max;
|
|
});
|
|
return minOverride.or(maxOverride).getOr(size);
|
|
};
|
|
|
|
var getHeight$1 = function (editor) {
|
|
var baseHeight = getHeightSetting(editor);
|
|
var minHeight = getMinHeightSetting(editor);
|
|
var maxHeight = getMaxHeightSetting(editor);
|
|
return parseToInt(baseHeight).map(function (height) {
|
|
return calcCappedSize(height, minHeight, maxHeight);
|
|
});
|
|
};
|
|
var getHeightWithFallback = function (editor) {
|
|
var height = getHeight$1(editor);
|
|
return height.getOr(getHeightSetting(editor));
|
|
};
|
|
var getWidth$1 = function (editor) {
|
|
var baseWidth = getWidthSetting(editor);
|
|
var minWidth = getMinWidthSetting(editor);
|
|
var maxWidth = getMaxWidthSetting(editor);
|
|
return parseToInt(baseWidth).map(function (width) {
|
|
return calcCappedSize(width, minWidth, maxWidth);
|
|
});
|
|
};
|
|
var getWidthWithFallback = function (editor) {
|
|
var width = getWidth$1(editor);
|
|
return width.getOr(getWidthSetting(editor));
|
|
};
|
|
|
|
var InlineHeader = function (editor, targetElm, uiComponents, backstage, floatContainer) {
|
|
var uiMothership = uiComponents.uiMothership, outerContainer = uiComponents.outerContainer;
|
|
var DOM = global$7.DOM;
|
|
var useFixedToolbarContainer = useFixedContainer(editor);
|
|
var isSticky = isStickyToolbar(editor);
|
|
var editorMaxWidthOpt = getMaxWidthSetting(editor).or(getWidth$1(editor));
|
|
var headerBackstage = backstage.shared.header;
|
|
var isPositionedAtTop = headerBackstage.isPositionedAtTop;
|
|
var toolbarMode = getToolbarMode(editor);
|
|
var isSplitToolbar = toolbarMode === ToolbarMode.sliding || toolbarMode === ToolbarMode.floating;
|
|
var visible = Cell(false);
|
|
var isVisible = function () {
|
|
return visible.get() && !editor.removed;
|
|
};
|
|
var calcToolbarOffset = function (toolbar) {
|
|
return isSplitToolbar ? toolbar.fold(function () {
|
|
return 0;
|
|
}, function (tbar) {
|
|
return tbar.components().length > 1 ? get$6(tbar.components()[1].element()) : 0;
|
|
}) : 0;
|
|
};
|
|
var calcMode = function (container) {
|
|
switch (getToolbarLocation(editor)) {
|
|
case ToolbarLocation.auto:
|
|
var toolbar_1 = OuterContainer.getToolbar(outerContainer);
|
|
var offset = calcToolbarOffset(toolbar_1);
|
|
var toolbarHeight = get$6(container.element()) - offset;
|
|
var targetBounds = box(targetElm);
|
|
var roomAtTop = targetBounds.y > toolbarHeight;
|
|
if (roomAtTop) {
|
|
return 'top';
|
|
} else {
|
|
var doc = documentElement(targetElm);
|
|
var docHeight = Math.max(doc.dom().scrollHeight, get$6(doc));
|
|
var roomAtBottom = targetBounds.bottom < docHeight - toolbarHeight;
|
|
if (roomAtBottom) {
|
|
return 'bottom';
|
|
} else {
|
|
var winBounds = win();
|
|
var isRoomAtBottomViewport = winBounds.bottom < targetBounds.bottom - toolbarHeight;
|
|
return isRoomAtBottomViewport ? 'bottom' : 'top';
|
|
}
|
|
}
|
|
case ToolbarLocation.bottom:
|
|
return 'bottom';
|
|
case ToolbarLocation.top:
|
|
default:
|
|
return 'top';
|
|
}
|
|
};
|
|
var setupMode = function (mode) {
|
|
var container = floatContainer.get();
|
|
Docking.setModes(container, [mode]);
|
|
headerBackstage.setDockingMode(mode);
|
|
var verticalDir = isPositionedAtTop() ? AttributeValue.TopToBottom : AttributeValue.BottomToTop;
|
|
set$1(container.element(), Attribute, verticalDir);
|
|
};
|
|
var updateChromeWidth = function () {
|
|
var maxWidth = editorMaxWidthOpt.getOrThunk(function () {
|
|
var bodyMargin = parseToInt(get$4(body(), 'margin-left')).getOr(0);
|
|
return get$7(body()) - absolute(targetElm).left() + bodyMargin;
|
|
});
|
|
set$2(floatContainer.get().element(), 'max-width', maxWidth + 'px');
|
|
};
|
|
var updateChromePosition = function () {
|
|
var toolbar = OuterContainer.getToolbar(outerContainer);
|
|
var offset = calcToolbarOffset(toolbar);
|
|
var targetBounds = box(targetElm);
|
|
var top = isPositionedAtTop() ? Math.max(targetBounds.y - get$6(floatContainer.get().element()) + offset, 0) : targetBounds.bottom;
|
|
setAll$1(outerContainer.element(), {
|
|
position: 'absolute',
|
|
top: Math.round(top) + 'px',
|
|
left: Math.round(targetBounds.x) + 'px'
|
|
});
|
|
};
|
|
var repositionPopups$1 = function () {
|
|
uiMothership.broadcastOn([repositionPopups()], {});
|
|
};
|
|
var updateChromeUi = function (resetDocking) {
|
|
if (resetDocking === void 0) {
|
|
resetDocking = false;
|
|
}
|
|
if (!isVisible()) {
|
|
return;
|
|
}
|
|
if (!useFixedToolbarContainer) {
|
|
updateChromeWidth();
|
|
}
|
|
if (isSplitToolbar) {
|
|
OuterContainer.refreshToolbar(outerContainer);
|
|
}
|
|
if (!useFixedToolbarContainer) {
|
|
updateChromePosition();
|
|
}
|
|
if (isSticky) {
|
|
var floatContainerComp = floatContainer.get();
|
|
resetDocking ? Docking.reset(floatContainerComp) : Docking.refresh(floatContainerComp);
|
|
}
|
|
repositionPopups$1();
|
|
};
|
|
var updateMode = function (updateUi) {
|
|
if (updateUi === void 0) {
|
|
updateUi = true;
|
|
}
|
|
if (useFixedToolbarContainer || !isSticky || !isVisible()) {
|
|
return;
|
|
}
|
|
var currentMode = headerBackstage.getDockingMode();
|
|
var newMode = calcMode(floatContainer.get());
|
|
if (newMode !== currentMode) {
|
|
setupMode(newMode);
|
|
if (updateUi) {
|
|
updateChromeUi(true);
|
|
}
|
|
}
|
|
};
|
|
var show = function () {
|
|
visible.set(true);
|
|
set$2(outerContainer.element(), 'display', 'flex');
|
|
DOM.addClass(editor.getBody(), 'mce-edit-focus');
|
|
remove$6(uiMothership.element(), 'display');
|
|
updateMode(false);
|
|
updateChromeUi();
|
|
};
|
|
var hide = function () {
|
|
visible.set(false);
|
|
if (uiComponents.outerContainer) {
|
|
set$2(outerContainer.element(), 'display', 'none');
|
|
DOM.removeClass(editor.getBody(), 'mce-edit-focus');
|
|
}
|
|
set$2(uiMothership.element(), 'display', 'none');
|
|
};
|
|
return {
|
|
isVisible: isVisible,
|
|
isPositionedAtTop: isPositionedAtTop,
|
|
show: show,
|
|
hide: hide,
|
|
update: updateChromeUi,
|
|
updateMode: updateMode,
|
|
repositionPopups: repositionPopups$1
|
|
};
|
|
};
|
|
|
|
var getTargetPosAndBounds = function (targetElm, isToolbarTop) {
|
|
var bounds = box(targetElm);
|
|
return {
|
|
pos: isToolbarTop ? bounds.y : bounds.bottom,
|
|
bounds: bounds
|
|
};
|
|
};
|
|
var setupEvents$1 = function (editor, targetElm, ui) {
|
|
var prevPosAndBounds = Cell(getTargetPosAndBounds(targetElm, ui.isPositionedAtTop()));
|
|
var resizeContent = function (e) {
|
|
var _a = getTargetPosAndBounds(targetElm, ui.isPositionedAtTop()), pos = _a.pos, bounds = _a.bounds;
|
|
var _b = prevPosAndBounds.get(), prevPos = _b.pos, prevBounds = _b.bounds;
|
|
var hasResized = bounds.height !== prevBounds.height || bounds.width !== prevBounds.width;
|
|
prevPosAndBounds.set({
|
|
pos: pos,
|
|
bounds: bounds
|
|
});
|
|
if (hasResized) {
|
|
fireResizeContent(editor, e);
|
|
}
|
|
if (ui.isVisible()) {
|
|
if (prevPos !== pos) {
|
|
ui.update(true);
|
|
} else if (hasResized) {
|
|
ui.updateMode();
|
|
ui.repositionPopups();
|
|
}
|
|
}
|
|
};
|
|
editor.on('activate', ui.show);
|
|
editor.on('deactivate', ui.hide);
|
|
editor.on('SkinLoaded ResizeWindow', function () {
|
|
return ui.update(true);
|
|
});
|
|
editor.on('NodeChange keydown', function (e) {
|
|
global$2.requestAnimationFrame(function () {
|
|
return resizeContent(e);
|
|
});
|
|
});
|
|
editor.on('ScrollWindow', function () {
|
|
return ui.updateMode();
|
|
});
|
|
var elementLoad = unbindable();
|
|
elementLoad.set(capture$1(Element.fromDom(editor.getBody()), 'load', resizeContent));
|
|
editor.on('remove', function () {
|
|
elementLoad.clear();
|
|
});
|
|
};
|
|
var render$1 = function (editor, uiComponents, rawUiConfig, backstage, args) {
|
|
var mothership = uiComponents.mothership, uiMothership = uiComponents.uiMothership, outerContainer = uiComponents.outerContainer;
|
|
var floatContainer = Cell(null);
|
|
var targetElm = Element.fromDom(args.targetNode);
|
|
var ui = InlineHeader(editor, targetElm, uiComponents, backstage, floatContainer);
|
|
inline(editor);
|
|
var render = function () {
|
|
if (floatContainer.get()) {
|
|
ui.show();
|
|
return;
|
|
}
|
|
floatContainer.set(OuterContainer.getHeader(outerContainer).getOrDie());
|
|
var uiContainer = getUiContainer(editor);
|
|
attachSystem(uiContainer, mothership);
|
|
attachSystem(uiContainer, uiMothership);
|
|
setToolbar(editor, uiComponents, rawUiConfig, backstage);
|
|
OuterContainer.setMenubar(outerContainer, identifyMenus(editor, rawUiConfig));
|
|
ui.show();
|
|
setupEvents$1(editor, targetElm, ui);
|
|
editor.nodeChanged();
|
|
};
|
|
editor.on('focus', render);
|
|
editor.on('blur hide', ui.hide);
|
|
editor.on('init', function () {
|
|
if (editor.hasFocus()) {
|
|
render();
|
|
}
|
|
});
|
|
setupReadonlyModeSwitch(editor, uiComponents);
|
|
return { editorContainer: outerContainer.element().dom() };
|
|
};
|
|
|
|
var Inline = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
render: render$1
|
|
});
|
|
|
|
var register$5 = function (editor) {
|
|
var alignToolbarButtons = [
|
|
{
|
|
name: 'alignleft',
|
|
text: 'Align left',
|
|
cmd: 'JustifyLeft',
|
|
icon: 'align-left'
|
|
},
|
|
{
|
|
name: 'aligncenter',
|
|
text: 'Align center',
|
|
cmd: 'JustifyCenter',
|
|
icon: 'align-center'
|
|
},
|
|
{
|
|
name: 'alignright',
|
|
text: 'Align right',
|
|
cmd: 'JustifyRight',
|
|
icon: 'align-right'
|
|
},
|
|
{
|
|
name: 'alignjustify',
|
|
text: 'Justify',
|
|
cmd: 'JustifyFull',
|
|
icon: 'align-justify'
|
|
}
|
|
];
|
|
global$e.each(alignToolbarButtons, function (item) {
|
|
editor.ui.registry.addToggleButton(item.name, {
|
|
tooltip: item.text,
|
|
onAction: function () {
|
|
return editor.execCommand(item.cmd);
|
|
},
|
|
icon: item.icon,
|
|
onSetup: onSetupFormatToggle(editor, item.name)
|
|
});
|
|
});
|
|
var alignNoneToolbarButton = {
|
|
name: 'alignnone',
|
|
text: 'No alignment',
|
|
cmd: 'JustifyNone',
|
|
icon: 'align-none'
|
|
};
|
|
editor.ui.registry.addButton(alignNoneToolbarButton.name, {
|
|
tooltip: alignNoneToolbarButton.text,
|
|
onAction: function () {
|
|
return editor.execCommand(alignNoneToolbarButton.cmd);
|
|
},
|
|
icon: alignNoneToolbarButton.icon
|
|
});
|
|
};
|
|
|
|
var toggleFormat = function (editor, fmt) {
|
|
return function () {
|
|
editor.execCommand('mceToggleFormat', false, fmt);
|
|
};
|
|
};
|
|
var registerFormatButtons = function (editor) {
|
|
global$e.each([
|
|
{
|
|
name: 'bold',
|
|
text: 'Bold',
|
|
icon: 'bold'
|
|
},
|
|
{
|
|
name: 'italic',
|
|
text: 'Italic',
|
|
icon: 'italic'
|
|
},
|
|
{
|
|
name: 'underline',
|
|
text: 'Underline',
|
|
icon: 'underline'
|
|
},
|
|
{
|
|
name: 'strikethrough',
|
|
text: 'Strikethrough',
|
|
icon: 'strike-through'
|
|
},
|
|
{
|
|
name: 'subscript',
|
|
text: 'Subscript',
|
|
icon: 'subscript'
|
|
},
|
|
{
|
|
name: 'superscript',
|
|
text: 'Superscript',
|
|
icon: 'superscript'
|
|
}
|
|
], function (btn, _idx) {
|
|
editor.ui.registry.addToggleButton(btn.name, {
|
|
tooltip: btn.text,
|
|
icon: btn.icon,
|
|
onSetup: onSetupFormatToggle(editor, btn.name),
|
|
onAction: toggleFormat(editor, btn.name)
|
|
});
|
|
});
|
|
for (var i = 1; i <= 6; i++) {
|
|
var name_1 = 'h' + i;
|
|
editor.ui.registry.addToggleButton(name_1, {
|
|
text: name_1.toUpperCase(),
|
|
tooltip: 'Heading ' + i,
|
|
onSetup: onSetupFormatToggle(editor, name_1),
|
|
onAction: toggleFormat(editor, name_1)
|
|
});
|
|
}
|
|
};
|
|
var registerCommandButtons = function (editor) {
|
|
global$e.each([
|
|
{
|
|
name: 'cut',
|
|
text: 'Cut',
|
|
action: 'Cut',
|
|
icon: 'cut'
|
|
},
|
|
{
|
|
name: 'copy',
|
|
text: 'Copy',
|
|
action: 'Copy',
|
|
icon: 'copy'
|
|
},
|
|
{
|
|
name: 'paste',
|
|
text: 'Paste',
|
|
action: 'Paste',
|
|
icon: 'paste'
|
|
},
|
|
{
|
|
name: 'help',
|
|
text: 'Help',
|
|
action: 'mceHelp',
|
|
icon: 'help'
|
|
},
|
|
{
|
|
name: 'selectall',
|
|
text: 'Select all',
|
|
action: 'SelectAll',
|
|
icon: 'select-all'
|
|
},
|
|
{
|
|
name: 'newdocument',
|
|
text: 'New document',
|
|
action: 'mceNewDocument',
|
|
icon: 'new-document'
|
|
},
|
|
{
|
|
name: 'removeformat',
|
|
text: 'Clear formatting',
|
|
action: 'RemoveFormat',
|
|
icon: 'remove-formatting'
|
|
},
|
|
{
|
|
name: 'remove',
|
|
text: 'Remove',
|
|
action: 'Delete',
|
|
icon: 'remove'
|
|
}
|
|
], function (btn) {
|
|
editor.ui.registry.addButton(btn.name, {
|
|
tooltip: btn.text,
|
|
icon: btn.icon,
|
|
onAction: function () {
|
|
return editor.execCommand(btn.action);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
var registerCommandToggleButtons = function (editor) {
|
|
global$e.each([{
|
|
name: 'blockquote',
|
|
text: 'Blockquote',
|
|
action: 'mceBlockQuote',
|
|
icon: 'quote'
|
|
}], function (btn) {
|
|
editor.ui.registry.addToggleButton(btn.name, {
|
|
tooltip: btn.text,
|
|
icon: btn.icon,
|
|
onAction: function () {
|
|
return editor.execCommand(btn.action);
|
|
},
|
|
onSetup: onSetupFormatToggle(editor, btn.name)
|
|
});
|
|
});
|
|
};
|
|
var registerButtons = function (editor) {
|
|
registerFormatButtons(editor);
|
|
registerCommandButtons(editor);
|
|
registerCommandToggleButtons(editor);
|
|
};
|
|
var registerMenuItems = function (editor) {
|
|
global$e.each([
|
|
{
|
|
name: 'bold',
|
|
text: 'Bold',
|
|
action: 'Bold',
|
|
icon: 'bold',
|
|
shortcut: 'Meta+B'
|
|
},
|
|
{
|
|
name: 'italic',
|
|
text: 'Italic',
|
|
action: 'Italic',
|
|
icon: 'italic',
|
|
shortcut: 'Meta+I'
|
|
},
|
|
{
|
|
name: 'underline',
|
|
text: 'Underline',
|
|
action: 'Underline',
|
|
icon: 'underline',
|
|
shortcut: 'Meta+U'
|
|
},
|
|
{
|
|
name: 'strikethrough',
|
|
text: 'Strikethrough',
|
|
action: 'Strikethrough',
|
|
icon: 'strike-through',
|
|
shortcut: ''
|
|
},
|
|
{
|
|
name: 'subscript',
|
|
text: 'Subscript',
|
|
action: 'Subscript',
|
|
icon: 'subscript',
|
|
shortcut: ''
|
|
},
|
|
{
|
|
name: 'superscript',
|
|
text: 'Superscript',
|
|
action: 'Superscript',
|
|
icon: 'superscript',
|
|
shortcut: ''
|
|
},
|
|
{
|
|
name: 'removeformat',
|
|
text: 'Clear formatting',
|
|
action: 'RemoveFormat',
|
|
icon: 'remove-formatting',
|
|
shortcut: ''
|
|
},
|
|
{
|
|
name: 'newdocument',
|
|
text: 'New document',
|
|
action: 'mceNewDocument',
|
|
icon: 'new-document',
|
|
shortcut: ''
|
|
},
|
|
{
|
|
name: 'cut',
|
|
text: 'Cut',
|
|
action: 'Cut',
|
|
icon: 'cut',
|
|
shortcut: 'Meta+X'
|
|
},
|
|
{
|
|
name: 'copy',
|
|
text: 'Copy',
|
|
action: 'Copy',
|
|
icon: 'copy',
|
|
shortcut: 'Meta+C'
|
|
},
|
|
{
|
|
name: 'paste',
|
|
text: 'Paste',
|
|
action: 'Paste',
|
|
icon: 'paste',
|
|
shortcut: 'Meta+V'
|
|
},
|
|
{
|
|
name: 'selectall',
|
|
text: 'Select all',
|
|
action: 'SelectAll',
|
|
icon: 'select-all',
|
|
shortcut: 'Meta+A'
|
|
}
|
|
], function (btn) {
|
|
editor.ui.registry.addMenuItem(btn.name, {
|
|
text: btn.text,
|
|
icon: btn.icon,
|
|
shortcut: btn.shortcut,
|
|
onAction: function () {
|
|
return editor.execCommand(btn.action);
|
|
}
|
|
});
|
|
});
|
|
editor.ui.registry.addMenuItem('codeformat', {
|
|
text: 'Code',
|
|
icon: 'sourcecode',
|
|
onAction: toggleFormat(editor, 'code')
|
|
});
|
|
};
|
|
var register$6 = function (editor) {
|
|
registerButtons(editor);
|
|
registerMenuItems(editor);
|
|
};
|
|
|
|
var toggleUndoRedoState = function (api, editor, type) {
|
|
var checkState = function () {
|
|
return editor.undoManager ? editor.undoManager[type]() : false;
|
|
};
|
|
var onUndoStateChange = function () {
|
|
api.setDisabled(editor.mode.isReadOnly() || !checkState());
|
|
};
|
|
api.setDisabled(!checkState());
|
|
editor.on('Undo Redo AddUndo TypingUndo ClearUndos SwitchMode', onUndoStateChange);
|
|
return function () {
|
|
return editor.off('Undo Redo AddUndo TypingUndo ClearUndos SwitchMode', onUndoStateChange);
|
|
};
|
|
};
|
|
var registerMenuItems$1 = function (editor) {
|
|
editor.ui.registry.addMenuItem('undo', {
|
|
text: 'Undo',
|
|
icon: 'undo',
|
|
shortcut: 'Meta+Z',
|
|
onSetup: function (api) {
|
|
return toggleUndoRedoState(api, editor, 'hasUndo');
|
|
},
|
|
onAction: function () {
|
|
return editor.execCommand('undo');
|
|
}
|
|
});
|
|
editor.ui.registry.addMenuItem('redo', {
|
|
text: 'Redo',
|
|
icon: 'redo',
|
|
shortcut: 'Meta+Y',
|
|
onSetup: function (api) {
|
|
return toggleUndoRedoState(api, editor, 'hasRedo');
|
|
},
|
|
onAction: function () {
|
|
return editor.execCommand('redo');
|
|
}
|
|
});
|
|
};
|
|
var registerButtons$1 = function (editor) {
|
|
editor.ui.registry.addButton('undo', {
|
|
tooltip: 'Undo',
|
|
icon: 'undo',
|
|
onSetup: function (api) {
|
|
return toggleUndoRedoState(api, editor, 'hasUndo');
|
|
},
|
|
onAction: function () {
|
|
return editor.execCommand('undo');
|
|
}
|
|
});
|
|
editor.ui.registry.addButton('redo', {
|
|
tooltip: 'Redo',
|
|
icon: 'redo',
|
|
onSetup: function (api) {
|
|
return toggleUndoRedoState(api, editor, 'hasRedo');
|
|
},
|
|
onAction: function () {
|
|
return editor.execCommand('redo');
|
|
}
|
|
});
|
|
};
|
|
var register$7 = function (editor) {
|
|
registerMenuItems$1(editor);
|
|
registerButtons$1(editor);
|
|
};
|
|
|
|
var toggleVisualAidState = function (api, editor) {
|
|
api.setActive(editor.hasVisual);
|
|
var onVisualAid = function (e) {
|
|
api.setActive(e.hasVisual);
|
|
};
|
|
editor.on('VisualAid', onVisualAid);
|
|
return function () {
|
|
return editor.off('VisualAid', onVisualAid);
|
|
};
|
|
};
|
|
var registerMenuItems$2 = function (editor) {
|
|
editor.ui.registry.addToggleMenuItem('visualaid', {
|
|
text: 'Visual aids',
|
|
onSetup: function (api) {
|
|
return toggleVisualAidState(api, editor);
|
|
},
|
|
onAction: function () {
|
|
editor.execCommand('mceToggleVisualAid');
|
|
}
|
|
});
|
|
};
|
|
var registerToolbarButton = function (editor) {
|
|
editor.ui.registry.addButton('visualaid', {
|
|
tooltip: 'Visual aids',
|
|
text: 'Visual aids',
|
|
onAction: function () {
|
|
return editor.execCommand('mceToggleVisualAid');
|
|
}
|
|
});
|
|
};
|
|
var register$8 = function (editor) {
|
|
registerToolbarButton(editor);
|
|
registerMenuItems$2(editor);
|
|
};
|
|
|
|
var toggleOutdentState = function (api, editor) {
|
|
api.setDisabled(!editor.queryCommandState('outdent'));
|
|
var onNodeChange = function () {
|
|
api.setDisabled(!editor.queryCommandState('outdent'));
|
|
};
|
|
editor.on('NodeChange', onNodeChange);
|
|
return function () {
|
|
return editor.off('NodeChange', onNodeChange);
|
|
};
|
|
};
|
|
var registerButtons$2 = function (editor) {
|
|
editor.ui.registry.addButton('outdent', {
|
|
tooltip: 'Decrease indent',
|
|
icon: 'outdent',
|
|
onSetup: function (api) {
|
|
return toggleOutdentState(api, editor);
|
|
},
|
|
onAction: function () {
|
|
return editor.execCommand('outdent');
|
|
}
|
|
});
|
|
editor.ui.registry.addButton('indent', {
|
|
tooltip: 'Increase indent',
|
|
icon: 'indent',
|
|
onAction: function () {
|
|
return editor.execCommand('indent');
|
|
}
|
|
});
|
|
};
|
|
var register$9 = function (editor) {
|
|
registerButtons$2(editor);
|
|
};
|
|
|
|
var register$a = function (editor, backstage) {
|
|
alignSelectMenu(editor, backstage);
|
|
fontSelectMenu(editor, backstage);
|
|
styleSelectMenu(editor, backstage);
|
|
formatSelectMenu(editor, backstage);
|
|
fontsizeSelectMenu(editor, backstage);
|
|
};
|
|
|
|
var setup$8 = function (editor, backstage) {
|
|
register$5(editor);
|
|
register$6(editor);
|
|
register$a(editor, backstage);
|
|
register$7(editor);
|
|
register$1(editor);
|
|
register$8(editor);
|
|
register$9(editor);
|
|
};
|
|
|
|
var nu$d = function (x, y) {
|
|
return {
|
|
anchor: 'makeshift',
|
|
x: x,
|
|
y: y
|
|
};
|
|
};
|
|
var transpose$1 = function (pos, dx, dy) {
|
|
return nu$d(pos.x + dx, pos.y + dy);
|
|
};
|
|
var isTouchEvent$1 = function (e) {
|
|
return e.type === 'longpress' || e.type.indexOf('touch') === 0;
|
|
};
|
|
var fromPageXY = function (e) {
|
|
if (isTouchEvent$1(e)) {
|
|
var touch = e.touches[0];
|
|
return nu$d(touch.pageX, touch.pageY);
|
|
} else {
|
|
return nu$d(e.pageX, e.pageY);
|
|
}
|
|
};
|
|
var fromClientXY = function (e) {
|
|
if (isTouchEvent$1(e)) {
|
|
var touch = e.touches[0];
|
|
return nu$d(touch.clientX, touch.clientY);
|
|
} else {
|
|
return nu$d(e.clientX, e.clientY);
|
|
}
|
|
};
|
|
var transposeContentAreaContainer = function (element, pos) {
|
|
var containerPos = global$7.DOM.getPos(element);
|
|
return transpose$1(pos, containerPos.x, containerPos.y);
|
|
};
|
|
var getPointAnchor = function (editor, e) {
|
|
if (e.type === 'contextmenu' || e.type === 'longpress') {
|
|
if (editor.inline) {
|
|
return fromPageXY(e);
|
|
} else {
|
|
return transposeContentAreaContainer(editor.getContentAreaContainer(), fromClientXY(e));
|
|
}
|
|
} else {
|
|
return getSelectionAnchor(editor);
|
|
}
|
|
};
|
|
var getSelectionAnchor = function (editor) {
|
|
return {
|
|
anchor: 'selection',
|
|
root: Element.fromDom(editor.selection.getNode())
|
|
};
|
|
};
|
|
var getNodeAnchor$1 = function (editor) {
|
|
return {
|
|
anchor: 'node',
|
|
node: Option.some(Element.fromDom(editor.selection.getNode())),
|
|
root: Element.fromDom(editor.getBody())
|
|
};
|
|
};
|
|
|
|
var getAnchorSpec = function (editor, e, isTriggeredByKeyboardEvent) {
|
|
return isTriggeredByKeyboardEvent ? getNodeAnchor$1(editor) : getPointAnchor(editor, e);
|
|
};
|
|
var initAndShow = function (editor, e, buildMenu, backstage, contextmenu, isTriggeredByKeyboardEvent) {
|
|
var items = buildMenu();
|
|
var anchorSpec = getAnchorSpec(editor, e, isTriggeredByKeyboardEvent);
|
|
build$2(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, false).map(function (menuData) {
|
|
e.preventDefault();
|
|
InlineView.showMenuAt(contextmenu, anchorSpec, {
|
|
menu: { markers: markers$1('normal') },
|
|
data: menuData
|
|
});
|
|
});
|
|
};
|
|
|
|
var layouts = {
|
|
onLtr: function () {
|
|
return [
|
|
south$1,
|
|
southeast$1,
|
|
southwest$1,
|
|
northeast$1,
|
|
northwest$1,
|
|
north$1,
|
|
north$3,
|
|
south$3,
|
|
northeast$3,
|
|
southeast$3,
|
|
northwest$3,
|
|
southwest$3
|
|
];
|
|
},
|
|
onRtl: function () {
|
|
return [
|
|
south$1,
|
|
southwest$1,
|
|
southeast$1,
|
|
northwest$1,
|
|
northeast$1,
|
|
north$1,
|
|
north$3,
|
|
south$3,
|
|
northwest$3,
|
|
southwest$3,
|
|
northeast$3,
|
|
southeast$3
|
|
];
|
|
}
|
|
};
|
|
var bubbleSize$1 = 12;
|
|
var bubbleAlignments$2 = {
|
|
valignCentre: [],
|
|
alignCentre: [],
|
|
alignLeft: ['tox-pop--align-left'],
|
|
alignRight: ['tox-pop--align-right'],
|
|
right: ['tox-pop--right'],
|
|
left: ['tox-pop--left'],
|
|
bottom: ['tox-pop--bottom'],
|
|
top: ['tox-pop--top']
|
|
};
|
|
var isTouchWithinSelection = function (editor, e) {
|
|
var selection = editor.selection;
|
|
if (selection.isCollapsed() || e.touches.length < 1) {
|
|
return false;
|
|
} else {
|
|
var touch_1 = e.touches[0];
|
|
var rng = selection.getRng();
|
|
var rngRectOpt = getFirstRect$1(editor.getWin(), Selection.domRange(rng));
|
|
return rngRectOpt.exists(function (rngRect) {
|
|
return rngRect.left() <= touch_1.clientX && rngRect.right() >= touch_1.clientX && rngRect.top() <= touch_1.clientY && rngRect.bottom() >= touch_1.clientY;
|
|
});
|
|
}
|
|
};
|
|
var getAnchorSpec$1 = function (editor, isTriggeredByKeyboardEvent, e) {
|
|
var anchorSpec = isTriggeredByKeyboardEvent ? getNodeAnchor$1(editor) : getPointAnchor(editor, e);
|
|
return __assign({
|
|
bubble: nu$8(0, bubbleSize$1, bubbleAlignments$2),
|
|
layouts: layouts,
|
|
overrides: {
|
|
maxWidthFunction: expandable$1(),
|
|
maxHeightFunction: expandable()
|
|
}
|
|
}, anchorSpec);
|
|
};
|
|
var setupiOSOverrides = function (editor) {
|
|
var originalSelection = editor.selection.getRng();
|
|
var selectionReset = function () {
|
|
global$2.setEditorTimeout(editor, function () {
|
|
editor.selection.setRng(originalSelection);
|
|
}, 10);
|
|
unbindEventListeners();
|
|
};
|
|
editor.once('touchend', selectionReset);
|
|
var preventMousedown = function (e) {
|
|
e.preventDefault();
|
|
e.stopImmediatePropagation();
|
|
};
|
|
editor.on('mousedown', preventMousedown, true);
|
|
var clearSelectionReset = function () {
|
|
return unbindEventListeners();
|
|
};
|
|
editor.once('longpresscancel', clearSelectionReset);
|
|
var unbindEventListeners = function () {
|
|
editor.off('touchend', selectionReset);
|
|
editor.off('longpresscancel', clearSelectionReset);
|
|
editor.off('mousedown', preventMousedown);
|
|
};
|
|
};
|
|
var show = function (editor, e, items, backstage, contextmenu, isTriggeredByKeyboardEvent, highlightImmediately) {
|
|
var anchorSpec = getAnchorSpec$1(editor, isTriggeredByKeyboardEvent, e);
|
|
build$2(items, ItemResponse$1.CLOSE_ON_EXECUTE, backstage, true).map(function (menuData) {
|
|
e.preventDefault();
|
|
InlineView.showMenuWithinBounds(contextmenu, anchorSpec, {
|
|
menu: {
|
|
markers: markers$1('normal'),
|
|
highlightImmediately: highlightImmediately
|
|
},
|
|
data: menuData,
|
|
type: 'horizontal'
|
|
}, function () {
|
|
return Option.some(getContextToolbarBounds(editor, backstage.shared));
|
|
});
|
|
editor.fire(hideContextToolbarEvent);
|
|
});
|
|
};
|
|
var initAndShow$1 = function (editor, e, buildMenu, backstage, contextmenu, isTriggeredByKeyboardEvent) {
|
|
var detection = detect$3();
|
|
var isiOS = detection.os.isiOS();
|
|
var isOSX = detection.os.isOSX();
|
|
var isAndroid = detection.os.isAndroid();
|
|
var isTouch = detection.deviceType.isTouch();
|
|
var shouldHighlightImmediately = function () {
|
|
return !(isAndroid || isiOS || isOSX && isTouch);
|
|
};
|
|
var open = function () {
|
|
var items = buildMenu();
|
|
show(editor, e, items, backstage, contextmenu, isTriggeredByKeyboardEvent, shouldHighlightImmediately());
|
|
};
|
|
if ((isOSX || isiOS) && !isTriggeredByKeyboardEvent) {
|
|
var openiOS_1 = function () {
|
|
setupiOSOverrides(editor);
|
|
open();
|
|
};
|
|
if (isTouchWithinSelection(editor, e)) {
|
|
openiOS_1();
|
|
} else {
|
|
editor.once('selectionchange', openiOS_1);
|
|
editor.once('touchend', function () {
|
|
return editor.off('selectionchange', openiOS_1);
|
|
});
|
|
}
|
|
} else {
|
|
if (isAndroid && !isTriggeredByKeyboardEvent) {
|
|
editor.selection.setCursorLocation(e.target, 0);
|
|
}
|
|
open();
|
|
}
|
|
};
|
|
|
|
var patchPipeConfig = function (config) {
|
|
return typeof config === 'string' ? config.split(/[ ,]/) : config;
|
|
};
|
|
var shouldNeverUseNative = function (editor) {
|
|
return editor.settings.contextmenu_never_use_native || false;
|
|
};
|
|
var getMenuItems = function (editor, name, defaultItems) {
|
|
var contextMenus = editor.ui.registry.getAll().contextMenus;
|
|
return get(editor.settings, name).map(patchPipeConfig).getOrThunk(function () {
|
|
return filter(patchPipeConfig(defaultItems), function (item) {
|
|
return has(contextMenus, item);
|
|
});
|
|
});
|
|
};
|
|
var isContextMenuDisabled = function (editor) {
|
|
return editor.getParam('contextmenu') === false;
|
|
};
|
|
var getContextMenu = function (editor) {
|
|
return getMenuItems(editor, 'contextmenu', 'link linkchecker image imagetools table spellchecker configurepermanentpen');
|
|
};
|
|
|
|
var isSeparator$1 = function (item) {
|
|
return isString(item) ? item === '|' : item.type === 'separator';
|
|
};
|
|
var separator$3 = { type: 'separator' };
|
|
var makeContextItem = function (item) {
|
|
if (isString(item)) {
|
|
return item;
|
|
} else {
|
|
switch (item.type) {
|
|
case 'separator':
|
|
return separator$3;
|
|
case 'submenu':
|
|
return {
|
|
type: 'nestedmenuitem',
|
|
text: item.text,
|
|
icon: item.icon,
|
|
getSubmenuItems: function () {
|
|
var items = item.getSubmenuItems();
|
|
if (isString(items)) {
|
|
return items;
|
|
} else {
|
|
return map(items, makeContextItem);
|
|
}
|
|
}
|
|
};
|
|
default:
|
|
return {
|
|
type: 'menuitem',
|
|
text: item.text,
|
|
icon: item.icon,
|
|
onAction: noarg(item.onAction)
|
|
};
|
|
}
|
|
}
|
|
};
|
|
var addContextMenuGroup = function (xs, groupItems) {
|
|
if (groupItems.length === 0) {
|
|
return xs;
|
|
}
|
|
var lastMenuItem = last(xs).filter(function (item) {
|
|
return !isSeparator$1(item);
|
|
});
|
|
var before = lastMenuItem.fold(function () {
|
|
return [];
|
|
}, function (_) {
|
|
return [separator$3];
|
|
});
|
|
return xs.concat(before).concat(groupItems).concat([separator$3]);
|
|
};
|
|
var generateContextMenu = function (contextMenus, menuConfig, selectedElement) {
|
|
var sections = foldl(menuConfig, function (acc, name) {
|
|
if (has(contextMenus, name)) {
|
|
var items = contextMenus[name].update(selectedElement);
|
|
if (isString(items)) {
|
|
return addContextMenuGroup(acc, items.split(' '));
|
|
} else if (items.length > 0) {
|
|
var allItems = map(items, makeContextItem);
|
|
return addContextMenuGroup(acc, allItems);
|
|
} else {
|
|
return acc;
|
|
}
|
|
} else {
|
|
return acc.concat([name]);
|
|
}
|
|
}, []);
|
|
if (sections.length > 0 && isSeparator$1(sections[sections.length - 1])) {
|
|
sections.pop();
|
|
}
|
|
return sections;
|
|
};
|
|
var isNativeOverrideKeyEvent = function (editor, e) {
|
|
return e.ctrlKey && !shouldNeverUseNative(editor);
|
|
};
|
|
var isTriggeredByKeyboard = function (editor, e) {
|
|
return e.type !== 'longpress' && (e.button !== 2 || e.target === editor.getBody() && e.pointerType === '');
|
|
};
|
|
var setup$9 = function (editor, lazySink, backstage) {
|
|
var detection = detect$3();
|
|
var isTouch = detection.deviceType.isTouch;
|
|
var contextmenu = build$1(InlineView.sketch({
|
|
dom: { tag: 'div' },
|
|
lazySink: lazySink,
|
|
onEscape: function () {
|
|
return editor.focus();
|
|
},
|
|
onShow: function () {
|
|
return backstage.setContextMenuState(true);
|
|
},
|
|
onHide: function () {
|
|
return backstage.setContextMenuState(false);
|
|
},
|
|
fireDismissalEventInstead: {},
|
|
inlineBehaviours: derive$1([config('dismissContextMenu', [run(dismissRequested(), function (comp, _se) {
|
|
Sandboxing.close(comp);
|
|
editor.focus();
|
|
})])])
|
|
}));
|
|
var hideContextMenu = function (_e) {
|
|
return InlineView.hide(contextmenu);
|
|
};
|
|
var showContextMenu = function (e) {
|
|
if (shouldNeverUseNative(editor)) {
|
|
e.preventDefault();
|
|
}
|
|
if (isNativeOverrideKeyEvent(editor, e) || isContextMenuDisabled(editor)) {
|
|
return;
|
|
}
|
|
var isTriggeredByKeyboardEvent = isTriggeredByKeyboard(editor, e);
|
|
var buildMenu = function () {
|
|
var selectedElement = isTriggeredByKeyboardEvent ? editor.selection.getStart(true) : e.target;
|
|
var registry = editor.ui.registry.getAll();
|
|
var menuConfig = getContextMenu(editor);
|
|
return generateContextMenu(registry.contextMenus, menuConfig, selectedElement);
|
|
};
|
|
var initAndShow$2 = isTouch() ? initAndShow$1 : initAndShow;
|
|
initAndShow$2(editor, e, buildMenu, backstage, contextmenu, isTriggeredByKeyboardEvent);
|
|
};
|
|
editor.on('init', function () {
|
|
var hideEvents = 'ResizeEditor ScrollContent ScrollWindow longpresscancel' + (isTouch() ? '' : ' ResizeWindow');
|
|
editor.on(hideEvents, hideContextMenu);
|
|
editor.on('longpress contextmenu', showContextMenu);
|
|
});
|
|
};
|
|
|
|
var adt$c = Adt.generate([
|
|
{
|
|
offset: [
|
|
'x',
|
|
'y'
|
|
]
|
|
},
|
|
{
|
|
absolute: [
|
|
'x',
|
|
'y'
|
|
]
|
|
},
|
|
{
|
|
fixed: [
|
|
'x',
|
|
'y'
|
|
]
|
|
}
|
|
]);
|
|
var subtract = function (change) {
|
|
return function (point) {
|
|
return point.translate(-change.left(), -change.top());
|
|
};
|
|
};
|
|
var add$4 = function (change) {
|
|
return function (point) {
|
|
return point.translate(change.left(), change.top());
|
|
};
|
|
};
|
|
var transform$1 = function (changes) {
|
|
return function (x, y) {
|
|
return foldl(changes, function (rest, f) {
|
|
return f(rest);
|
|
}, Position(x, y));
|
|
};
|
|
};
|
|
var asFixed = function (coord, scroll, origin) {
|
|
return coord.fold(transform$1([
|
|
add$4(origin),
|
|
subtract(scroll)
|
|
]), transform$1([subtract(scroll)]), transform$1([]));
|
|
};
|
|
var asAbsolute = function (coord, scroll, origin) {
|
|
return coord.fold(transform$1([add$4(origin)]), transform$1([]), transform$1([add$4(scroll)]));
|
|
};
|
|
var asOffset = function (coord, scroll, origin) {
|
|
return coord.fold(transform$1([]), transform$1([subtract(origin)]), transform$1([
|
|
add$4(scroll),
|
|
subtract(origin)
|
|
]));
|
|
};
|
|
var withinRange = function (coord1, coord2, xRange, yRange, scroll, origin) {
|
|
var a1 = asAbsolute(coord1, scroll, origin);
|
|
var a2 = asAbsolute(coord2, scroll, origin);
|
|
return Math.abs(a1.left() - a2.left()) <= xRange && Math.abs(a1.top() - a2.top()) <= yRange;
|
|
};
|
|
var getDeltas = function (coord1, coord2, xRange, yRange, scroll, origin) {
|
|
var a1 = asAbsolute(coord1, scroll, origin);
|
|
var a2 = asAbsolute(coord2, scroll, origin);
|
|
var left = Math.abs(a1.left() - a2.left());
|
|
var top = Math.abs(a1.top() - a2.top());
|
|
return Position(left, top);
|
|
};
|
|
var toStyles = function (coord, scroll, origin) {
|
|
var stylesOpt = coord.fold(function (x, y) {
|
|
return {
|
|
position: Option.some('absolute'),
|
|
left: Option.some(x + 'px'),
|
|
top: Option.some(y + 'px')
|
|
};
|
|
}, function (x, y) {
|
|
return {
|
|
position: Option.some('absolute'),
|
|
left: Option.some(x - origin.left() + 'px'),
|
|
top: Option.some(y - origin.top() + 'px')
|
|
};
|
|
}, function (x, y) {
|
|
return {
|
|
position: Option.some('fixed'),
|
|
left: Option.some(x + 'px'),
|
|
top: Option.some(y + 'px')
|
|
};
|
|
});
|
|
return __assign({
|
|
right: Option.none(),
|
|
bottom: Option.none()
|
|
}, stylesOpt);
|
|
};
|
|
var translate$2 = function (coord, deltaX, deltaY) {
|
|
return coord.fold(function (x, y) {
|
|
return offset(x + deltaX, y + deltaY);
|
|
}, function (x, y) {
|
|
return absolute$3(x + deltaX, y + deltaY);
|
|
}, function (x, y) {
|
|
return fixed$1(x + deltaX, y + deltaY);
|
|
});
|
|
};
|
|
var absorb = function (partialCoord, originalCoord, scroll, origin) {
|
|
var absorbOne = function (stencil, nu) {
|
|
return function (optX, optY) {
|
|
var original = stencil(originalCoord, scroll, origin);
|
|
return nu(optX.getOr(original.left()), optY.getOr(original.top()));
|
|
};
|
|
};
|
|
return partialCoord.fold(absorbOne(asOffset, offset), absorbOne(asAbsolute, absolute$3), absorbOne(asFixed, fixed$1));
|
|
};
|
|
var offset = adt$c.offset;
|
|
var absolute$3 = adt$c.absolute;
|
|
var fixed$1 = adt$c.fixed;
|
|
|
|
var parseAttrToInt = function (element, name) {
|
|
var value = get$2(element, name);
|
|
return isUndefined(value) ? NaN : parseInt(value, 10);
|
|
};
|
|
var get$e = function (component, snapsInfo) {
|
|
var element = component.element();
|
|
var x = parseAttrToInt(element, snapsInfo.leftAttr);
|
|
var y = parseAttrToInt(element, snapsInfo.topAttr);
|
|
return isNaN(x) || isNaN(y) ? Option.none() : Option.some(Position(x, y));
|
|
};
|
|
var set$8 = function (component, snapsInfo, pt) {
|
|
var element = component.element();
|
|
set$1(element, snapsInfo.leftAttr, pt.left() + 'px');
|
|
set$1(element, snapsInfo.topAttr, pt.top() + 'px');
|
|
};
|
|
var clear = function (component, snapsInfo) {
|
|
var element = component.element();
|
|
remove$1(element, snapsInfo.leftAttr);
|
|
remove$1(element, snapsInfo.topAttr);
|
|
};
|
|
|
|
var getCoords = function (component, snapInfo, coord, delta) {
|
|
return get$e(component, snapInfo).fold(function () {
|
|
return coord;
|
|
}, function (fixed) {
|
|
return fixed$1(fixed.left() + delta.left(), fixed.top() + delta.top());
|
|
});
|
|
};
|
|
var moveOrSnap = function (component, snapInfo, coord, delta, scroll, origin) {
|
|
var newCoord = getCoords(component, snapInfo, coord, delta);
|
|
var snap = snapInfo.mustSnap ? findClosestSnap(component, snapInfo, newCoord, scroll, origin) : findSnap(component, snapInfo, newCoord, scroll, origin);
|
|
var fixedCoord = asFixed(newCoord, scroll, origin);
|
|
set$8(component, snapInfo, fixedCoord);
|
|
return snap.fold(function () {
|
|
return {
|
|
coord: fixed$1(fixedCoord.left(), fixedCoord.top()),
|
|
extra: Option.none()
|
|
};
|
|
}, function (spanned) {
|
|
return {
|
|
coord: spanned.output,
|
|
extra: spanned.extra
|
|
};
|
|
});
|
|
};
|
|
var stopDrag = function (component, snapInfo) {
|
|
clear(component, snapInfo);
|
|
};
|
|
var findMatchingSnap = function (snaps, newCoord, scroll, origin) {
|
|
return findMap(snaps, function (snap) {
|
|
var sensor = snap.sensor;
|
|
var inRange = withinRange(newCoord, sensor, snap.range.left(), snap.range.top(), scroll, origin);
|
|
return inRange ? Option.some({
|
|
output: absorb(snap.output, newCoord, scroll, origin),
|
|
extra: snap.extra
|
|
}) : Option.none();
|
|
});
|
|
};
|
|
var findClosestSnap = function (component, snapInfo, newCoord, scroll, origin) {
|
|
var snaps = snapInfo.getSnapPoints(component);
|
|
var matchSnap = findMatchingSnap(snaps, newCoord, scroll, origin);
|
|
return matchSnap.orThunk(function () {
|
|
var bestSnap = foldl(snaps, function (acc, snap) {
|
|
var sensor = snap.sensor;
|
|
var deltas = getDeltas(newCoord, sensor, snap.range.left(), snap.range.top(), scroll, origin);
|
|
return acc.deltas.fold(function () {
|
|
return {
|
|
deltas: Option.some(deltas),
|
|
snap: Option.some(snap)
|
|
};
|
|
}, function (bestDeltas) {
|
|
var currAvg = (deltas.left() + deltas.top()) / 2;
|
|
var bestAvg = (bestDeltas.left() + bestDeltas.top()) / 2;
|
|
if (currAvg <= bestAvg) {
|
|
return {
|
|
deltas: Option.some(deltas),
|
|
snap: Option.some(snap)
|
|
};
|
|
} else {
|
|
return acc;
|
|
}
|
|
});
|
|
}, {
|
|
deltas: Option.none(),
|
|
snap: Option.none()
|
|
});
|
|
return bestSnap.snap.map(function (snap) {
|
|
return {
|
|
output: absorb(snap.output, newCoord, scroll, origin),
|
|
extra: snap.extra
|
|
};
|
|
});
|
|
});
|
|
};
|
|
var findSnap = function (component, snapInfo, newCoord, scroll, origin) {
|
|
var snaps = snapInfo.getSnapPoints(component);
|
|
return findMatchingSnap(snaps, newCoord, scroll, origin);
|
|
};
|
|
var snapTo = function (snap, scroll, origin) {
|
|
return {
|
|
coord: absorb(snap.output, snap.output, scroll, origin),
|
|
extra: snap.extra
|
|
};
|
|
};
|
|
|
|
var snapTo$1 = function (component, dragConfig, _state, snap) {
|
|
var target = dragConfig.getTarget(component.element());
|
|
if (dragConfig.repositionTarget) {
|
|
var doc = owner(component.element());
|
|
var scroll = get$8(doc);
|
|
var origin = getOrigin(target);
|
|
var snapPin = snapTo(snap, scroll, origin);
|
|
var styles = toStyles(snapPin.coord, scroll, origin);
|
|
setOptions(target, styles);
|
|
}
|
|
};
|
|
|
|
var DraggingApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
snapTo: snapTo$1
|
|
});
|
|
|
|
var initialAttribute = 'data-initial-z-index';
|
|
var resetZIndex = function (blocker) {
|
|
parent(blocker.element()).filter(isElement).each(function (root) {
|
|
getOpt(root, initialAttribute).fold(function () {
|
|
return remove$6(root, 'z-index');
|
|
}, function (zIndex) {
|
|
return set$2(root, 'z-index', zIndex);
|
|
});
|
|
remove$1(root, initialAttribute);
|
|
});
|
|
};
|
|
var changeZIndex = function (blocker) {
|
|
parent(blocker.element()).filter(isElement).each(function (root) {
|
|
getRaw(root, 'z-index').each(function (zindex) {
|
|
set$1(root, initialAttribute, zindex);
|
|
});
|
|
set$2(root, 'z-index', get$4(blocker.element(), 'z-index'));
|
|
});
|
|
};
|
|
var instigate = function (anyComponent, blocker) {
|
|
anyComponent.getSystem().addToGui(blocker);
|
|
changeZIndex(blocker);
|
|
};
|
|
var discard = function (blocker) {
|
|
resetZIndex(blocker);
|
|
blocker.getSystem().removeFromGui(blocker);
|
|
};
|
|
var createComponent = function (component, blockerClass, blockerEvents) {
|
|
return component.getSystem().build(Container.sketch({
|
|
dom: {
|
|
styles: {
|
|
'left': '0px',
|
|
'top': '0px',
|
|
'width': '100%',
|
|
'height': '100%',
|
|
'position': 'fixed',
|
|
'z-index': '1000000000000000'
|
|
},
|
|
classes: [blockerClass]
|
|
},
|
|
events: blockerEvents
|
|
}));
|
|
};
|
|
|
|
var SnapSchema = optionObjOf('snaps', [
|
|
strict$1('getSnapPoints'),
|
|
onHandler('onSensor'),
|
|
strict$1('leftAttr'),
|
|
strict$1('topAttr'),
|
|
defaulted$1('lazyViewport', win),
|
|
defaulted$1('mustSnap', false)
|
|
]);
|
|
|
|
var schema$t = [
|
|
defaulted$1('useFixed', never),
|
|
strict$1('blockerClass'),
|
|
defaulted$1('getTarget', identity),
|
|
defaulted$1('onDrag', noop),
|
|
defaulted$1('repositionTarget', true),
|
|
defaulted$1('onDrop', noop),
|
|
defaultedFunction('getBounds', win),
|
|
SnapSchema
|
|
];
|
|
|
|
var getCurrentCoord = function (target) {
|
|
return lift3(getRaw(target, 'left'), getRaw(target, 'top'), getRaw(target, 'position'), function (left, top, position) {
|
|
var nu = position === 'fixed' ? fixed$1 : offset;
|
|
return nu(parseInt(left, 10), parseInt(top, 10));
|
|
}).getOrThunk(function () {
|
|
var location = absolute(target);
|
|
return absolute$3(location.left(), location.top());
|
|
});
|
|
};
|
|
var clampCoords = function (component, coords, scroll, origin, startData) {
|
|
var bounds = startData.bounds;
|
|
var absoluteCoord = asAbsolute(coords, scroll, origin);
|
|
var newX = clamp(absoluteCoord.left(), bounds.x, bounds.x + bounds.width - startData.width);
|
|
var newY = clamp(absoluteCoord.top(), bounds.y, bounds.y + bounds.height - startData.height);
|
|
var newCoords = absolute$3(newX, newY);
|
|
return coords.fold(function () {
|
|
var offset$1 = asOffset(newCoords, scroll, origin);
|
|
return offset(offset$1.left(), offset$1.top());
|
|
}, function () {
|
|
return newCoords;
|
|
}, function () {
|
|
var fixed = asFixed(newCoords, scroll, origin);
|
|
return fixed$1(fixed.left(), fixed.top());
|
|
});
|
|
};
|
|
var calcNewCoord = function (component, optSnaps, currentCoord, scroll, origin, delta, startData) {
|
|
var newCoord = optSnaps.fold(function () {
|
|
var translated = translate$2(currentCoord, delta.left(), delta.top());
|
|
var fixedCoord = asFixed(translated, scroll, origin);
|
|
return fixed$1(fixedCoord.left(), fixedCoord.top());
|
|
}, function (snapInfo) {
|
|
var snapping = moveOrSnap(component, snapInfo, currentCoord, delta, scroll, origin);
|
|
snapping.extra.each(function (extra) {
|
|
snapInfo.onSensor(component, extra);
|
|
});
|
|
return snapping.coord;
|
|
});
|
|
return clampCoords(component, newCoord, scroll, origin, startData);
|
|
};
|
|
var dragBy = function (component, dragConfig, startData, delta) {
|
|
var target = dragConfig.getTarget(component.element());
|
|
if (dragConfig.repositionTarget) {
|
|
var doc = owner(component.element());
|
|
var scroll = get$8(doc);
|
|
var origin = getOrigin(target);
|
|
var currentCoord = getCurrentCoord(target);
|
|
var newCoord = calcNewCoord(component, dragConfig.snaps, currentCoord, scroll, origin, delta, startData);
|
|
var styles = toStyles(newCoord, scroll, origin);
|
|
setOptions(target, styles);
|
|
}
|
|
dragConfig.onDrag(component, target, delta);
|
|
};
|
|
|
|
var calcStartData = function (dragConfig, comp) {
|
|
return {
|
|
bounds: dragConfig.getBounds(),
|
|
height: getOuter$1(comp.element()),
|
|
width: getOuter$2(comp.element())
|
|
};
|
|
};
|
|
var move$1 = function (component, dragConfig, dragState, dragMode, event) {
|
|
var delta = dragState.update(dragMode, event);
|
|
var dragStartData = dragState.getStartData().getOrThunk(function () {
|
|
return calcStartData(dragConfig, component);
|
|
});
|
|
delta.each(function (dlt) {
|
|
dragBy(component, dragConfig, dragStartData, dlt);
|
|
});
|
|
};
|
|
var stop = function (component, blocker, dragConfig, dragState) {
|
|
blocker.each(discard);
|
|
dragConfig.snaps.each(function (snapInfo) {
|
|
stopDrag(component, snapInfo);
|
|
});
|
|
var target = dragConfig.getTarget(component.element());
|
|
dragState.reset();
|
|
dragConfig.onDrop(component, target);
|
|
};
|
|
var handlers = function (events) {
|
|
return function (dragConfig, dragState) {
|
|
var updateStartState = function (comp) {
|
|
dragState.setStartData(calcStartData(dragConfig, comp));
|
|
};
|
|
return derive(__spreadArrays([run(windowScroll(), function (comp) {
|
|
dragState.getStartData().each(function () {
|
|
return updateStartState(comp);
|
|
});
|
|
})], events(dragConfig, dragState, updateStartState)));
|
|
};
|
|
};
|
|
|
|
var init$c = function (dragApi) {
|
|
return derive([
|
|
run(mousedown(), dragApi.forceDrop),
|
|
run(mouseup(), dragApi.drop),
|
|
run(mousemove(), function (comp, simulatedEvent) {
|
|
dragApi.move(simulatedEvent.event());
|
|
}),
|
|
run(mouseout(), dragApi.delayDrop)
|
|
]);
|
|
};
|
|
|
|
var getData$1 = function (event) {
|
|
return Option.from(Position(event.x(), event.y()));
|
|
};
|
|
var getDelta$1 = function (old, nu) {
|
|
return Position(nu.left() - old.left(), nu.top() - old.top());
|
|
};
|
|
|
|
var MouseData = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
getData: getData$1,
|
|
getDelta: getDelta$1
|
|
});
|
|
|
|
var events$g = function (dragConfig, dragState, updateStartState) {
|
|
return [run(mousedown(), function (component, simulatedEvent) {
|
|
var raw = simulatedEvent.event().raw();
|
|
if (raw.button !== 0) {
|
|
return;
|
|
}
|
|
simulatedEvent.stop();
|
|
var stop$1 = function () {
|
|
return stop(component, Option.some(blocker), dragConfig, dragState);
|
|
};
|
|
var delayDrop = DelayedFunction(stop$1, 200);
|
|
var dragApi = {
|
|
drop: stop$1,
|
|
delayDrop: delayDrop.schedule,
|
|
forceDrop: stop$1,
|
|
move: function (event) {
|
|
delayDrop.cancel();
|
|
move$1(component, dragConfig, dragState, MouseData, event);
|
|
}
|
|
};
|
|
var blocker = createComponent(component, dragConfig.blockerClass, init$c(dragApi));
|
|
var start = function () {
|
|
updateStartState(component);
|
|
instigate(component, blocker);
|
|
};
|
|
start();
|
|
})];
|
|
};
|
|
var schema$u = __spreadArrays(schema$t, [output('dragger', { handlers: handlers(events$g) })]);
|
|
|
|
var init$d = function (dragApi) {
|
|
return derive([
|
|
run(touchstart(), dragApi.forceDrop),
|
|
run(touchend(), dragApi.drop),
|
|
run(touchcancel(), dragApi.drop),
|
|
run(touchmove(), function (comp, simulatedEvent) {
|
|
dragApi.move(simulatedEvent.event());
|
|
})
|
|
]);
|
|
};
|
|
|
|
var getDataFrom = function (touches) {
|
|
var touch = touches[0];
|
|
return Option.some(Position(touch.clientX, touch.clientY));
|
|
};
|
|
var getData$2 = function (event) {
|
|
var raw = event.raw();
|
|
var touches = raw.touches;
|
|
return touches.length === 1 ? getDataFrom(touches) : Option.none();
|
|
};
|
|
var getDelta$2 = function (old, nu) {
|
|
return Position(nu.left() - old.left(), nu.top() - old.top());
|
|
};
|
|
|
|
var TouchData = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
getData: getData$2,
|
|
getDelta: getDelta$2
|
|
});
|
|
|
|
var events$h = function (dragConfig, dragState, updateStartState) {
|
|
var blockerCell = Cell(Option.none());
|
|
return [
|
|
run(touchstart(), function (component, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
var stop$1 = function () {
|
|
stop(component, blockerCell.get(), dragConfig, dragState);
|
|
blockerCell.set(Option.none());
|
|
};
|
|
var dragApi = {
|
|
drop: stop$1,
|
|
delayDrop: function () {
|
|
},
|
|
forceDrop: stop$1,
|
|
move: function (event) {
|
|
move$1(component, dragConfig, dragState, TouchData, event);
|
|
}
|
|
};
|
|
var blocker = createComponent(component, dragConfig.blockerClass, init$d(dragApi));
|
|
blockerCell.set(Option.some(blocker));
|
|
var start = function () {
|
|
updateStartState(component);
|
|
instigate(component, blocker);
|
|
};
|
|
start();
|
|
}),
|
|
run(touchmove(), function (component, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
move$1(component, dragConfig, dragState, TouchData, simulatedEvent.event());
|
|
}),
|
|
run(touchend(), function (component, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
stop(component, blockerCell.get(), dragConfig, dragState);
|
|
blockerCell.set(Option.none());
|
|
}),
|
|
run(touchcancel(), function (component) {
|
|
stop(component, blockerCell.get(), dragConfig, dragState);
|
|
blockerCell.set(Option.none());
|
|
})
|
|
];
|
|
};
|
|
var schema$v = __spreadArrays(schema$t, [output('dragger', { handlers: handlers(events$h) })]);
|
|
|
|
var events$i = function (dragConfig, dragState, updateStartState) {
|
|
return __spreadArrays(events$g(dragConfig, dragState, updateStartState), events$h(dragConfig, dragState, updateStartState));
|
|
};
|
|
var schema$w = __spreadArrays(schema$t, [output('dragger', { handlers: handlers(events$i) })]);
|
|
|
|
var mouse = schema$u;
|
|
var touch = schema$v;
|
|
var mouseOrTouch = schema$w;
|
|
|
|
var DraggingBranches = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
mouse: mouse,
|
|
touch: touch,
|
|
mouseOrTouch: mouseOrTouch
|
|
});
|
|
|
|
var init$e = function () {
|
|
var previous = Option.none();
|
|
var startData = Option.none();
|
|
var reset = function () {
|
|
previous = Option.none();
|
|
startData = Option.none();
|
|
};
|
|
var calculateDelta = function (mode, nu) {
|
|
var result = previous.map(function (old) {
|
|
return mode.getDelta(old, nu);
|
|
});
|
|
previous = Option.some(nu);
|
|
return result;
|
|
};
|
|
var update = function (mode, dragEvent) {
|
|
return mode.getData(dragEvent).bind(function (nuData) {
|
|
return calculateDelta(mode, nuData);
|
|
});
|
|
};
|
|
var setStartData = function (data) {
|
|
startData = Option.some(data);
|
|
};
|
|
var getStartData = function () {
|
|
return startData;
|
|
};
|
|
var readState = constant({});
|
|
return nu$5({
|
|
readState: readState,
|
|
reset: reset,
|
|
update: update,
|
|
getStartData: getStartData,
|
|
setStartData: setStartData
|
|
});
|
|
};
|
|
|
|
var DragState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
init: init$e
|
|
});
|
|
|
|
var Dragging = createModes$1({
|
|
branchKey: 'mode',
|
|
branches: DraggingBranches,
|
|
name: 'dragging',
|
|
active: {
|
|
events: function (dragConfig, dragState) {
|
|
var dragger = dragConfig.dragger;
|
|
return dragger.handlers(dragConfig, dragState);
|
|
}
|
|
},
|
|
extra: {
|
|
snap: function (sConfig) {
|
|
return {
|
|
sensor: sConfig.sensor,
|
|
range: sConfig.range,
|
|
output: sConfig.output,
|
|
extra: Option.from(sConfig.extra)
|
|
};
|
|
}
|
|
},
|
|
state: DragState,
|
|
apis: DraggingApis
|
|
});
|
|
|
|
var snapWidth = 40;
|
|
var snapOffset = snapWidth / 2;
|
|
var calcSnap = function (selectorOpt, td, x, y, width, height) {
|
|
return selectorOpt.fold(function () {
|
|
return Dragging.snap({
|
|
sensor: absolute$3(x - snapOffset, y - snapOffset),
|
|
range: Position(width, height),
|
|
output: absolute$3(Option.some(x), Option.some(y)),
|
|
extra: { td: td }
|
|
});
|
|
}, function (selectorHandle) {
|
|
var sensorLeft = x - snapOffset;
|
|
var sensorTop = y - snapOffset;
|
|
var sensorWidth = snapWidth;
|
|
var sensorHeight = snapWidth;
|
|
var rect = selectorHandle.element().dom().getBoundingClientRect();
|
|
return Dragging.snap({
|
|
sensor: absolute$3(sensorLeft, sensorTop),
|
|
range: Position(sensorWidth, sensorHeight),
|
|
output: absolute$3(Option.some(x - rect.width / 2), Option.some(y - rect.height / 2)),
|
|
extra: { td: td }
|
|
});
|
|
});
|
|
};
|
|
var getSnapsConfig = function (getSnapPoints, cell, onChange) {
|
|
var isSameCell = function (cellOpt, td) {
|
|
return cellOpt.exists(function (currentTd) {
|
|
return eq$1(currentTd, td);
|
|
});
|
|
};
|
|
return {
|
|
getSnapPoints: getSnapPoints,
|
|
leftAttr: 'data-drag-left',
|
|
topAttr: 'data-drag-top',
|
|
onSensor: function (component, extra) {
|
|
var td = extra.td;
|
|
if (!isSameCell(cell.get(), td)) {
|
|
cell.set(Option.some(td));
|
|
onChange(td);
|
|
}
|
|
},
|
|
mustSnap: true
|
|
};
|
|
};
|
|
var createSelector = function (snaps) {
|
|
return record(Button.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-selector']
|
|
},
|
|
buttonBehaviours: derive$1([
|
|
Dragging.config({
|
|
mode: 'mouseOrTouch',
|
|
blockerClass: 'blocker',
|
|
snaps: snaps
|
|
}),
|
|
Unselecting.config({})
|
|
]),
|
|
eventOrder: {
|
|
mousedown: [
|
|
'dragging',
|
|
'alloy.base.behaviour'
|
|
],
|
|
touchstart: [
|
|
'dragging',
|
|
'alloy.base.behaviour'
|
|
]
|
|
}
|
|
}));
|
|
};
|
|
var setup$a = function (editor, sink) {
|
|
var tlTds = Cell([]);
|
|
var brTds = Cell([]);
|
|
var isVisible = Cell(false);
|
|
var startCell = Cell(Option.none());
|
|
var finishCell = Cell(Option.none());
|
|
var getTopLeftSnap = function (td) {
|
|
var box = absolute$1(td);
|
|
return calcSnap(memTopLeft.getOpt(sink), td, box.x, box.y, box.width, box.height);
|
|
};
|
|
var getTopLeftSnaps = function () {
|
|
return map(tlTds.get(), function (td) {
|
|
return getTopLeftSnap(td);
|
|
});
|
|
};
|
|
var getBottomRightSnap = function (td) {
|
|
var box = absolute$1(td);
|
|
return calcSnap(memBottomRight.getOpt(sink), td, box.right, box.bottom, box.width, box.height);
|
|
};
|
|
var getBottomRightSnaps = function () {
|
|
return map(brTds.get(), function (td) {
|
|
return getBottomRightSnap(td);
|
|
});
|
|
};
|
|
var topLeftSnaps = getSnapsConfig(getTopLeftSnaps, startCell, function (start) {
|
|
finishCell.get().each(function (finish) {
|
|
editor.fire('TableSelectorChange', {
|
|
start: start,
|
|
finish: finish
|
|
});
|
|
});
|
|
});
|
|
var bottomRightSnaps = getSnapsConfig(getBottomRightSnaps, finishCell, function (finish) {
|
|
startCell.get().each(function (start) {
|
|
editor.fire('TableSelectorChange', {
|
|
start: start,
|
|
finish: finish
|
|
});
|
|
});
|
|
});
|
|
var memTopLeft = createSelector(topLeftSnaps);
|
|
var memBottomRight = createSelector(bottomRightSnaps);
|
|
var topLeft = build$1(memTopLeft.asSpec());
|
|
var bottomRight = build$1(memBottomRight.asSpec());
|
|
var showOrHideHandle = function (selector, cell, isAbove, isBelow) {
|
|
var cellRect = cell.dom().getBoundingClientRect();
|
|
remove$6(selector.element(), 'display');
|
|
var viewportHeight = defaultView(Element.fromDom(editor.getBody())).dom().innerHeight;
|
|
var aboveViewport = isAbove(cellRect);
|
|
var belowViewport = isBelow(cellRect, viewportHeight);
|
|
if (aboveViewport || belowViewport) {
|
|
set$2(selector.element(), 'display', 'none');
|
|
}
|
|
};
|
|
var snapTo = function (selector, cell, getSnapConfig, pos) {
|
|
var snap = getSnapConfig(cell);
|
|
Dragging.snapTo(selector, snap);
|
|
var isAbove = function (rect) {
|
|
return rect[pos] < 0;
|
|
};
|
|
var isBelow = function (rect, viewportHeight) {
|
|
return rect[pos] > viewportHeight;
|
|
};
|
|
showOrHideHandle(selector, cell, isAbove, isBelow);
|
|
};
|
|
var snapTopLeft = function (cell) {
|
|
return snapTo(topLeft, cell, getTopLeftSnap, 'top');
|
|
};
|
|
var snapLastTopLeft = function () {
|
|
return startCell.get().each(snapTopLeft);
|
|
};
|
|
var snapBottomRight = function (cell) {
|
|
return snapTo(bottomRight, cell, getBottomRightSnap, 'bottom');
|
|
};
|
|
var snapLastBottomRight = function () {
|
|
return finishCell.get().each(snapBottomRight);
|
|
};
|
|
if (detect$3().deviceType.isTouch()) {
|
|
editor.on('TableSelectionChange', function (e) {
|
|
if (!isVisible.get()) {
|
|
attach$1(sink, topLeft);
|
|
attach$1(sink, bottomRight);
|
|
isVisible.set(true);
|
|
}
|
|
startCell.set(Option.some(e.start));
|
|
finishCell.set(Option.some(e.finish));
|
|
e.otherCells.each(function (otherCells) {
|
|
tlTds.set(otherCells.upOrLeftCells);
|
|
brTds.set(otherCells.downOrRightCells);
|
|
snapTopLeft(e.start);
|
|
snapBottomRight(e.finish);
|
|
});
|
|
});
|
|
editor.on('ResizeEditor ResizeWindow ScrollContent', function () {
|
|
snapLastTopLeft();
|
|
snapLastBottomRight();
|
|
});
|
|
editor.on('TableSelectionClear', function () {
|
|
if (isVisible.get()) {
|
|
detach(topLeft);
|
|
detach(bottomRight);
|
|
isVisible.set(false);
|
|
}
|
|
startCell.set(Option.none());
|
|
finishCell.set(Option.none());
|
|
});
|
|
}
|
|
};
|
|
|
|
var ResizeTypes;
|
|
(function (ResizeTypes) {
|
|
ResizeTypes[ResizeTypes['None'] = 0] = 'None';
|
|
ResizeTypes[ResizeTypes['Both'] = 1] = 'Both';
|
|
ResizeTypes[ResizeTypes['Vertical'] = 2] = 'Vertical';
|
|
}(ResizeTypes || (ResizeTypes = {})));
|
|
var getDimensions = function (editor, deltas, resizeType, originalHeight, originalWidth) {
|
|
var dimensions = {};
|
|
dimensions.height = calcCappedSize(originalHeight + deltas.top(), getMinHeightSetting(editor), getMaxHeightSetting(editor));
|
|
if (resizeType === ResizeTypes.Both) {
|
|
dimensions.width = calcCappedSize(originalWidth + deltas.left(), getMinWidthSetting(editor), getMaxWidthSetting(editor));
|
|
}
|
|
return dimensions;
|
|
};
|
|
var resize$3 = function (editor, deltas, resizeType) {
|
|
var container = Element.fromDom(editor.getContainer());
|
|
var dimensions = getDimensions(editor, deltas, resizeType, get$6(container), get$7(container));
|
|
each$1(dimensions, function (val, dim) {
|
|
return set$2(container, dim, numToPx(val));
|
|
});
|
|
fireResizeEditor(editor);
|
|
};
|
|
|
|
var isHidden$1 = function (elm) {
|
|
if (elm.nodeType === 1) {
|
|
if (elm.nodeName === 'BR' || !!elm.getAttribute('data-mce-bogus')) {
|
|
return true;
|
|
}
|
|
if (elm.getAttribute('data-mce-type') === 'bookmark') {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
var renderElementPath = function (editor, settings, providersBackstage) {
|
|
if (!settings.delimiter) {
|
|
settings.delimiter = '\xBB';
|
|
}
|
|
var getDataPath = function (data) {
|
|
var parts = data || [];
|
|
var newPathElements = map(parts, function (part, index) {
|
|
return Button.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-statusbar__path-item'],
|
|
attributes: {
|
|
'role': 'button',
|
|
'data-index': index,
|
|
'tab-index': -1,
|
|
'aria-level': index + 1
|
|
},
|
|
innerHtml: part.name
|
|
},
|
|
action: function (_btn) {
|
|
editor.focus();
|
|
editor.selection.select(part.element);
|
|
editor.nodeChanged();
|
|
},
|
|
buttonBehaviours: derive$1([
|
|
DisablingConfigs.button(providersBackstage.isReadOnly),
|
|
receivingConfig()
|
|
])
|
|
});
|
|
});
|
|
var divider = {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-statusbar__path-divider'],
|
|
attributes: { 'aria-hidden': true },
|
|
innerHtml: ' ' + settings.delimiter + ' '
|
|
}
|
|
};
|
|
return foldl(newPathElements.slice(1), function (acc, element) {
|
|
var newAcc = acc;
|
|
newAcc.push(divider);
|
|
newAcc.push(element);
|
|
return newAcc;
|
|
}, [newPathElements[0]]);
|
|
};
|
|
var updatePath = function (parents) {
|
|
var newPath = [];
|
|
var i = parents.length;
|
|
while (i-- > 0) {
|
|
var parent_1 = parents[i];
|
|
if (parent_1.nodeType === 1 && !isHidden$1(parent_1)) {
|
|
var args = editor.fire('ResolveName', {
|
|
name: parent_1.nodeName.toLowerCase(),
|
|
target: parent_1
|
|
});
|
|
if (!args.isDefaultPrevented()) {
|
|
newPath.push({
|
|
name: args.name,
|
|
element: parent_1
|
|
});
|
|
}
|
|
if (args.isPropagationStopped()) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
return newPath;
|
|
};
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-statusbar__path'],
|
|
attributes: { role: 'navigation' }
|
|
},
|
|
behaviours: derive$1([
|
|
Keying.config({
|
|
mode: 'flow',
|
|
selector: 'div[role=button]'
|
|
}),
|
|
Disabling.config({ disabled: providersBackstage.isReadOnly }),
|
|
receivingConfig(),
|
|
Tabstopping.config({}),
|
|
Replacing.config({}),
|
|
config('elementPathEvents', [runOnAttached(function (comp, _e) {
|
|
editor.shortcuts.add('alt+F11', 'focus statusbar elementpath', function () {
|
|
return Keying.focusIn(comp);
|
|
});
|
|
editor.on('NodeChange', function (e) {
|
|
var newPath = updatePath(e.parents);
|
|
if (newPath.length > 0) {
|
|
Replacing.set(comp, getDataPath(newPath));
|
|
} else {
|
|
Replacing.set(comp, []);
|
|
}
|
|
});
|
|
})])
|
|
]),
|
|
components: []
|
|
};
|
|
};
|
|
|
|
var renderWordCount = function (editor, providersBackstage) {
|
|
var replaceCountText = function (comp, count, mode) {
|
|
return Replacing.set(comp, [text(providersBackstage.translate([
|
|
'{0} ' + mode,
|
|
count[mode]
|
|
]))]);
|
|
};
|
|
return Button.sketch({
|
|
dom: {
|
|
tag: 'button',
|
|
classes: ['tox-statusbar__wordcount']
|
|
},
|
|
components: [],
|
|
buttonBehaviours: derive$1([
|
|
DisablingConfigs.button(providersBackstage.isReadOnly),
|
|
receivingConfig(),
|
|
Tabstopping.config({}),
|
|
Replacing.config({}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: {
|
|
mode: 'words',
|
|
count: {
|
|
words: 0,
|
|
characters: 0
|
|
}
|
|
}
|
|
}
|
|
}),
|
|
config('wordcount-events', [
|
|
runOnExecute(function (comp) {
|
|
var currentVal = Representing.getValue(comp);
|
|
var newMode = currentVal.mode === 'words' ? 'characters' : 'words';
|
|
Representing.setValue(comp, {
|
|
mode: newMode,
|
|
count: currentVal.count
|
|
});
|
|
replaceCountText(comp, currentVal.count, newMode);
|
|
}),
|
|
runOnAttached(function (comp) {
|
|
editor.on('wordCountUpdate', function (e) {
|
|
var mode = Representing.getValue(comp).mode;
|
|
Representing.setValue(comp, {
|
|
mode: mode,
|
|
count: e.wordCount
|
|
});
|
|
replaceCountText(comp, e.wordCount, mode);
|
|
});
|
|
})
|
|
])
|
|
]),
|
|
eventOrder: {
|
|
'alloy.execute': [
|
|
'disabling',
|
|
'alloy.base.behaviour',
|
|
'wordcount-events'
|
|
]
|
|
}
|
|
});
|
|
};
|
|
|
|
var renderStatusbar = function (editor, providersBackstage) {
|
|
var renderResizeHandlerIcon = function (resizeType) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-statusbar__resize-handle'],
|
|
attributes: {
|
|
'title': providersBackstage.translate('Resize'),
|
|
'aria-hidden': 'true'
|
|
},
|
|
innerHtml: get$d('resize-handle', providersBackstage.icons)
|
|
},
|
|
behaviours: derive$1([Dragging.config({
|
|
mode: 'mouse',
|
|
repositionTarget: false,
|
|
onDrag: function (comp, target, delta) {
|
|
resize$3(editor, delta, resizeType);
|
|
},
|
|
blockerClass: 'tox-blocker'
|
|
})])
|
|
};
|
|
};
|
|
var renderBranding = function () {
|
|
var label = global$5.translate([
|
|
'Powered by {0}',
|
|
'Tiny'
|
|
]);
|
|
var linkHtml = '<a href="https://www.tiny.cloud/?utm_campaign=editor_referral&utm_medium=poweredby&utm_source=tinymce&utm_content=v5" rel="noopener" target="_blank" tabindex="-1" aria-label="' + label + '">' + label + '</a>';
|
|
return {
|
|
dom: {
|
|
tag: 'span',
|
|
classes: ['tox-statusbar__branding'],
|
|
innerHtml: linkHtml
|
|
}
|
|
};
|
|
};
|
|
var getResizeType = function (editor) {
|
|
var fallback = !contains$1(editor.settings.plugins, 'autoresize');
|
|
var resize = editor.getParam('resize', fallback);
|
|
if (resize === false) {
|
|
return ResizeTypes.None;
|
|
} else if (resize === 'both') {
|
|
return ResizeTypes.Both;
|
|
} else {
|
|
return ResizeTypes.Vertical;
|
|
}
|
|
};
|
|
var getTextComponents = function () {
|
|
var components = [];
|
|
if (editor.getParam('elementpath', true, 'boolean')) {
|
|
components.push(renderElementPath(editor, {}, providersBackstage));
|
|
}
|
|
if (contains$1(editor.settings.plugins, 'wordcount')) {
|
|
components.push(renderWordCount(editor, providersBackstage));
|
|
}
|
|
if (editor.getParam('branding', true, 'boolean')) {
|
|
components.push(renderBranding());
|
|
}
|
|
if (components.length > 0) {
|
|
return [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-statusbar__text-container']
|
|
},
|
|
components: components
|
|
}];
|
|
}
|
|
return [];
|
|
};
|
|
var getComponents = function () {
|
|
var components = getTextComponents();
|
|
var resizeType = getResizeType(editor);
|
|
if (resizeType !== ResizeTypes.None) {
|
|
components.push(renderResizeHandlerIcon(resizeType));
|
|
}
|
|
return components;
|
|
};
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-statusbar']
|
|
},
|
|
components: getComponents()
|
|
};
|
|
};
|
|
|
|
var setup$b = function (editor) {
|
|
var _a;
|
|
var isInline = editor.inline;
|
|
var mode = isInline ? Inline : Iframe;
|
|
var header = isStickyToolbar(editor) ? StickyHeader : StaticHeader;
|
|
var lazyOuterContainer = Option.none();
|
|
var platform = detect$3();
|
|
var isIE = platform.browser.isIE();
|
|
var platformClasses = isIE ? ['tox-platform-ie'] : [];
|
|
var isTouch = platform.deviceType.isTouch();
|
|
var touchPlatformClass = 'tox-platform-touch';
|
|
var deviceClasses = isTouch ? [touchPlatformClass] : [];
|
|
var isToolbarBottom = isToolbarLocationBottom(editor);
|
|
var dirAttributes = global$5.isRtl() ? { attributes: { dir: 'rtl' } } : {};
|
|
var verticalDirAttributes = { attributes: (_a = {}, _a[Attribute] = isToolbarBottom ? AttributeValue.BottomToTop : AttributeValue.TopToBottom, _a) };
|
|
var lazyHeader = function () {
|
|
return lazyOuterContainer.bind(OuterContainer.getHeader);
|
|
};
|
|
var isHeaderDocked = function () {
|
|
return header.isDocked(lazyHeader);
|
|
};
|
|
var sink = build$1({
|
|
dom: __assign({
|
|
tag: 'div',
|
|
classes: [
|
|
'tox',
|
|
'tox-silver-sink',
|
|
'tox-tinymce-aux'
|
|
].concat(platformClasses).concat(deviceClasses)
|
|
}, dirAttributes),
|
|
behaviours: derive$1([Positioning.config({
|
|
useFixed: function () {
|
|
return isHeaderDocked();
|
|
}
|
|
})])
|
|
});
|
|
var lazySink = function () {
|
|
return Result.value(sink);
|
|
};
|
|
var memAnchorBar = record({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-anchorbar']
|
|
}
|
|
});
|
|
var lazyAnchorBar = function () {
|
|
return lazyOuterContainer.bind(function (container) {
|
|
return memAnchorBar.getOpt(container);
|
|
}).getOrDie('Could not find a anchor bar element');
|
|
};
|
|
var lazyToolbar = function () {
|
|
return lazyOuterContainer.bind(function (container) {
|
|
return OuterContainer.getToolbar(container);
|
|
}).getOrDie('Could not find more toolbar element');
|
|
};
|
|
var lazyThrobber = function () {
|
|
return lazyOuterContainer.bind(function (container) {
|
|
return OuterContainer.getThrobber(container);
|
|
}).getOrDie('Could not find throbber element');
|
|
};
|
|
var backstage = init$8(sink, editor, lazyAnchorBar);
|
|
var partMenubar = OuterContainer.parts().menubar({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-menubar']
|
|
},
|
|
backstage: backstage,
|
|
onEscape: function () {
|
|
editor.focus();
|
|
}
|
|
});
|
|
var toolbarMode = getToolbarMode(editor);
|
|
var partToolbar = OuterContainer.parts().toolbar(__assign({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-toolbar']
|
|
},
|
|
getSink: lazySink,
|
|
providers: backstage.shared.providers,
|
|
onEscape: function () {
|
|
editor.focus();
|
|
},
|
|
type: toolbarMode,
|
|
lazyToolbar: lazyToolbar,
|
|
lazyHeader: function () {
|
|
return lazyHeader().getOrDie('Could not find header element');
|
|
}
|
|
}, verticalDirAttributes));
|
|
var partMultipleToolbar = OuterContainer.parts()['multiple-toolbar']({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-toolbar-overlord']
|
|
},
|
|
providers: backstage.shared.providers,
|
|
onEscape: function () {
|
|
},
|
|
type: toolbarMode
|
|
});
|
|
var partSocket = OuterContainer.parts().socket({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-edit-area']
|
|
}
|
|
});
|
|
var partSidebar = OuterContainer.parts().sidebar({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-sidebar']
|
|
}
|
|
});
|
|
var partThrobber = OuterContainer.parts().throbber({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-throbber']
|
|
},
|
|
backstage: backstage
|
|
});
|
|
var sb = editor.getParam('statusbar', true, 'boolean');
|
|
var statusbar = sb && !isInline ? Option.some(renderStatusbar(editor, backstage.shared.providers)) : Option.none();
|
|
var socketSidebarContainer = {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-sidebar-wrap']
|
|
},
|
|
components: [
|
|
partSocket,
|
|
partSidebar
|
|
]
|
|
};
|
|
var hasMultipleToolbar = isMultipleToolbars(editor);
|
|
var hasToolbar = isToolbarEnabled(editor);
|
|
var hasMenubar = isMenubarEnabled(editor);
|
|
var getPartToolbar = function () {
|
|
if (hasMultipleToolbar) {
|
|
return [partMultipleToolbar];
|
|
} else if (hasToolbar) {
|
|
return [partToolbar];
|
|
} else {
|
|
return [];
|
|
}
|
|
};
|
|
var partHeader = OuterContainer.parts().header({
|
|
dom: __assign({
|
|
tag: 'div',
|
|
classes: ['tox-editor-header']
|
|
}, verticalDirAttributes),
|
|
components: flatten([
|
|
hasMenubar ? [partMenubar] : [],
|
|
getPartToolbar(),
|
|
useFixedContainer(editor) ? [] : [memAnchorBar.asSpec()]
|
|
]),
|
|
sticky: isStickyToolbar(editor),
|
|
editor: editor,
|
|
sharedBackstage: backstage.shared
|
|
});
|
|
var editorComponents = flatten([
|
|
isToolbarBottom ? [] : [partHeader],
|
|
isInline ? [] : [socketSidebarContainer],
|
|
isToolbarBottom ? [partHeader] : []
|
|
]);
|
|
var editorContainer = {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-editor-container']
|
|
},
|
|
components: editorComponents
|
|
};
|
|
var containerComponents = flatten([
|
|
[editorContainer],
|
|
isInline ? [] : statusbar.toArray(),
|
|
[partThrobber]
|
|
]);
|
|
var isHidden = isDistractionFree(editor);
|
|
var attributes = __assign(__assign({ role: 'application' }, global$5.isRtl() ? { dir: 'rtl' } : {}), isHidden ? { 'aria-hidden': 'true' } : {});
|
|
var outerContainer = build$1(OuterContainer.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox',
|
|
'tox-tinymce'
|
|
].concat(isInline ? ['tox-tinymce-inline'] : []).concat(isToolbarBottom ? ['tox-tinymce--toolbar-bottom'] : []).concat(deviceClasses).concat(platformClasses),
|
|
styles: __assign({ visibility: 'hidden' }, isHidden ? {
|
|
opacity: '0',
|
|
border: '0'
|
|
} : {}),
|
|
attributes: attributes
|
|
},
|
|
components: containerComponents,
|
|
behaviours: derive$1([Keying.config({
|
|
mode: 'cyclic',
|
|
selector: '.tox-menubar, .tox-toolbar, .tox-toolbar__primary, .tox-toolbar__overflow--open, .tox-sidebar__overflow--open, .tox-statusbar__path, .tox-statusbar__wordcount, .tox-statusbar__branding a'
|
|
})])
|
|
}));
|
|
lazyOuterContainer = Option.some(outerContainer);
|
|
editor.shortcuts.add('alt+F9', 'focus menubar', function () {
|
|
OuterContainer.focusMenubar(outerContainer);
|
|
});
|
|
editor.shortcuts.add('alt+F10', 'focus toolbar', function () {
|
|
OuterContainer.focusToolbar(outerContainer);
|
|
});
|
|
var mothership = takeover(outerContainer);
|
|
var uiMothership = takeover(sink);
|
|
setup$3(editor, mothership, uiMothership);
|
|
var getUi = function () {
|
|
var channels = {
|
|
broadcastAll: uiMothership.broadcast,
|
|
broadcastOn: uiMothership.broadcastOn,
|
|
register: function () {
|
|
}
|
|
};
|
|
return { channels: channels };
|
|
};
|
|
var setEditorSize = function () {
|
|
var parsedHeight = numToPx(getHeightWithFallback(editor));
|
|
var parsedWidth = numToPx(getWidthWithFallback(editor));
|
|
if (!editor.inline) {
|
|
if (isValidValue('div', 'width', parsedWidth)) {
|
|
set$2(outerContainer.element(), 'width', parsedWidth);
|
|
}
|
|
if (isValidValue('div', 'height', parsedHeight)) {
|
|
set$2(outerContainer.element(), 'height', parsedHeight);
|
|
} else {
|
|
set$2(outerContainer.element(), 'height', '200px');
|
|
}
|
|
}
|
|
return parsedHeight;
|
|
};
|
|
var renderUI = function () {
|
|
header.setup(editor, backstage.shared, lazyHeader);
|
|
setup$8(editor, backstage);
|
|
setup$9(editor, lazySink, backstage);
|
|
setup$6(editor);
|
|
setup$7(editor, lazyThrobber, backstage.shared);
|
|
map$1(getToolbarGroups(editor), function (toolbarGroupButtonConfig, name) {
|
|
editor.ui.registry.addGroupToolbarButton(name, toolbarGroupButtonConfig);
|
|
});
|
|
var _a = editor.ui.registry.getAll(), buttons = _a.buttons, menuItems = _a.menuItems, contextToolbars = _a.contextToolbars, sidebars = _a.sidebars;
|
|
var toolbarOpt = getMultipleToolbarsSetting(editor);
|
|
var rawUiConfig = {
|
|
menuItems: menuItems,
|
|
menus: !editor.settings.menu ? {} : map$1(editor.settings.menu, function (menu) {
|
|
return __assign(__assign({}, menu), { items: menu.items });
|
|
}),
|
|
menubar: editor.settings.menubar,
|
|
toolbar: toolbarOpt.getOrThunk(function () {
|
|
return editor.getParam('toolbar', true);
|
|
}),
|
|
allowToolbarGroups: toolbarMode === ToolbarMode.floating,
|
|
buttons: buttons,
|
|
sidebar: sidebars
|
|
};
|
|
register$4(editor, contextToolbars, sink, { backstage: backstage });
|
|
setup$a(editor, sink);
|
|
var elm = editor.getElement();
|
|
var height = setEditorSize();
|
|
var uiComponents = {
|
|
mothership: mothership,
|
|
uiMothership: uiMothership,
|
|
outerContainer: outerContainer
|
|
};
|
|
var args = {
|
|
targetNode: elm,
|
|
height: height
|
|
};
|
|
return mode.render(editor, uiComponents, rawUiConfig, backstage, args);
|
|
};
|
|
return {
|
|
mothership: mothership,
|
|
uiMothership: uiMothership,
|
|
backstage: backstage,
|
|
renderUI: renderUI,
|
|
getUi: getUi
|
|
};
|
|
};
|
|
|
|
var describedBy = function (describedElement, describeElement) {
|
|
var describeId = Option.from(get$2(describedElement, 'id')).fold(function () {
|
|
var id = generate$1('dialog-describe');
|
|
set$1(describeElement, 'id', id);
|
|
return id;
|
|
}, identity);
|
|
set$1(describedElement, 'aria-describedby', describeId);
|
|
};
|
|
|
|
var labelledBy = function (labelledElement, labelElement) {
|
|
var labelId = Option.from(get$2(labelledElement, 'id')).fold(function () {
|
|
var id = generate$1('dialog-label');
|
|
set$1(labelElement, 'id', id);
|
|
return id;
|
|
}, identity);
|
|
set$1(labelledElement, 'aria-labelledby', labelId);
|
|
};
|
|
|
|
var schema$x = constant([
|
|
strict$1('lazySink'),
|
|
option('dragBlockClass'),
|
|
defaultedFunction('getBounds', win),
|
|
defaulted$1('useTabstopAt', constant(true)),
|
|
defaulted$1('eventOrder', {}),
|
|
field$1('modalBehaviours', [Keying]),
|
|
onKeyboardHandler('onExecute'),
|
|
onStrictKeyboardHandler('onEscape')
|
|
]);
|
|
var basic = { sketch: identity };
|
|
var parts$f = constant([
|
|
optional({
|
|
name: 'draghandle',
|
|
overrides: function (detail, spec) {
|
|
return {
|
|
behaviours: derive$1([Dragging.config({
|
|
mode: 'mouse',
|
|
getTarget: function (handle) {
|
|
return ancestor$2(handle, '[role="dialog"]').getOr(handle);
|
|
},
|
|
blockerClass: detail.dragBlockClass.getOrDie(new Error('The drag blocker class was not specified for a dialog with a drag handle: \n' + JSON.stringify(spec, null, 2)).message),
|
|
getBounds: detail.getDragBounds
|
|
})])
|
|
};
|
|
}
|
|
}),
|
|
required({
|
|
schema: [strict$1('dom')],
|
|
name: 'title'
|
|
}),
|
|
required({
|
|
factory: basic,
|
|
schema: [strict$1('dom')],
|
|
name: 'close'
|
|
}),
|
|
required({
|
|
factory: basic,
|
|
schema: [strict$1('dom')],
|
|
name: 'body'
|
|
}),
|
|
optional({
|
|
factory: basic,
|
|
schema: [strict$1('dom')],
|
|
name: 'footer'
|
|
}),
|
|
external$1({
|
|
factory: {
|
|
sketch: function (spec, detail) {
|
|
return __assign(__assign({}, spec), {
|
|
dom: detail.dom,
|
|
components: detail.components
|
|
});
|
|
}
|
|
},
|
|
schema: [
|
|
defaulted$1('dom', {
|
|
tag: 'div',
|
|
styles: {
|
|
position: 'fixed',
|
|
left: '0px',
|
|
top: '0px',
|
|
right: '0px',
|
|
bottom: '0px'
|
|
}
|
|
}),
|
|
defaulted$1('components', [])
|
|
],
|
|
name: 'blocker'
|
|
})
|
|
]);
|
|
|
|
var factory$i = function (detail, components, spec, externals) {
|
|
var dialogBusyEvent = generate$1('alloy.dialog.busy');
|
|
var dialogIdleEvent = generate$1('alloy.dialog.idle');
|
|
var busyBehaviours = derive$1([
|
|
Keying.config({
|
|
mode: 'special',
|
|
onTab: function () {
|
|
return Option.some(true);
|
|
},
|
|
onShiftTab: function () {
|
|
return Option.some(true);
|
|
}
|
|
}),
|
|
Focusing.config({})
|
|
]);
|
|
var showDialog = function (dialog) {
|
|
var sink = detail.lazySink(dialog).getOrDie();
|
|
var busyComp = Cell(Option.none());
|
|
var externalBlocker = externals.blocker();
|
|
var blocker = sink.getSystem().build(__assign(__assign({}, externalBlocker), {
|
|
components: externalBlocker.components.concat([premade$1(dialog)]),
|
|
behaviours: derive$1([
|
|
Focusing.config({}),
|
|
config('dialog-blocker-events', [
|
|
runOnSource(focusin(), function () {
|
|
Keying.focusIn(dialog);
|
|
}),
|
|
run(dialogIdleEvent, function (_blocker, _se) {
|
|
if (has$1(dialog.element(), 'aria-busy')) {
|
|
remove$1(dialog.element(), 'aria-busy');
|
|
busyComp.get().each(function (bc) {
|
|
return Replacing.remove(dialog, bc);
|
|
});
|
|
}
|
|
}),
|
|
run(dialogBusyEvent, function (blocker, se) {
|
|
set$1(dialog.element(), 'aria-busy', 'true');
|
|
var getBusySpec = se.event().getBusySpec();
|
|
busyComp.get().each(function (bc) {
|
|
Replacing.remove(dialog, bc);
|
|
});
|
|
var busySpec = getBusySpec(dialog, busyBehaviours);
|
|
var busy = blocker.getSystem().build(busySpec);
|
|
busyComp.set(Option.some(busy));
|
|
Replacing.append(dialog, premade$1(busy));
|
|
if (busy.hasConfigured(Keying)) {
|
|
Keying.focusIn(busy);
|
|
}
|
|
})
|
|
])
|
|
])
|
|
}));
|
|
attach$1(sink, blocker);
|
|
Keying.focusIn(dialog);
|
|
};
|
|
var hideDialog = function (dialog) {
|
|
parent(dialog.element()).each(function (blockerDom) {
|
|
dialog.getSystem().getByDom(blockerDom).each(function (blocker) {
|
|
detach(blocker);
|
|
});
|
|
});
|
|
};
|
|
var getDialogBody = function (dialog) {
|
|
return getPartOrDie(dialog, detail, 'body');
|
|
};
|
|
var getDialogFooter = function (dialog) {
|
|
return getPartOrDie(dialog, detail, 'footer');
|
|
};
|
|
var setBusy = function (dialog, getBusySpec) {
|
|
emitWith(dialog, dialogBusyEvent, { getBusySpec: getBusySpec });
|
|
};
|
|
var setIdle = function (dialog) {
|
|
emit(dialog, dialogIdleEvent);
|
|
};
|
|
var modalEventsId = generate$1('modal-events');
|
|
var eventOrder = __assign(__assign({}, detail.eventOrder), { 'alloy.system.attached': [modalEventsId].concat(detail.eventOrder['alloy.system.attached'] || []) });
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
apis: {
|
|
show: showDialog,
|
|
hide: hideDialog,
|
|
getBody: getDialogBody,
|
|
getFooter: getDialogFooter,
|
|
setIdle: setIdle,
|
|
setBusy: setBusy
|
|
},
|
|
eventOrder: eventOrder,
|
|
domModification: {
|
|
attributes: {
|
|
'role': 'dialog',
|
|
'aria-modal': 'true'
|
|
}
|
|
},
|
|
behaviours: augment(detail.modalBehaviours, [
|
|
Replacing.config({}),
|
|
Keying.config({
|
|
mode: 'cyclic',
|
|
onEnter: detail.onExecute,
|
|
onEscape: detail.onEscape,
|
|
useTabstopAt: detail.useTabstopAt
|
|
}),
|
|
config(modalEventsId, [runOnAttached(function (c) {
|
|
labelledBy(c.element(), getPartOrDie(c, detail, 'title').element());
|
|
describedBy(c.element(), getPartOrDie(c, detail, 'body').element());
|
|
})])
|
|
])
|
|
};
|
|
};
|
|
var ModalDialog = composite$1({
|
|
name: 'ModalDialog',
|
|
configFields: schema$x(),
|
|
partFields: parts$f(),
|
|
factory: factory$i,
|
|
apis: {
|
|
show: function (apis, dialog) {
|
|
apis.show(dialog);
|
|
},
|
|
hide: function (apis, dialog) {
|
|
apis.hide(dialog);
|
|
},
|
|
getBody: function (apis, dialog) {
|
|
return apis.getBody(dialog);
|
|
},
|
|
getFooter: function (apis, dialog) {
|
|
return apis.getFooter(dialog);
|
|
},
|
|
setBusy: function (apis, dialog, getBusySpec) {
|
|
apis.setBusy(dialog, getBusySpec);
|
|
},
|
|
setIdle: function (apis, dialog) {
|
|
apis.setIdle(dialog);
|
|
}
|
|
}
|
|
});
|
|
|
|
var alertBannerFields = [
|
|
strictString('type'),
|
|
strictString('text'),
|
|
strictStringEnum('level', [
|
|
'info',
|
|
'warn',
|
|
'error',
|
|
'success'
|
|
]),
|
|
strictString('icon'),
|
|
defaulted$1('url', '')
|
|
];
|
|
var alertBannerSchema = objOf(alertBannerFields);
|
|
|
|
var createBarFields = function (itemsField) {
|
|
return [
|
|
strictString('type'),
|
|
itemsField
|
|
];
|
|
};
|
|
|
|
var buttonFields = [
|
|
strictString('type'),
|
|
strictString('text'),
|
|
defaultedBoolean('disabled', false),
|
|
defaultedBoolean('primary', false),
|
|
field('name', 'name', defaultedThunk(function () {
|
|
return generate$1('button-name');
|
|
}), string),
|
|
optionString('icon'),
|
|
defaultedBoolean('borderless', false)
|
|
];
|
|
var buttonSchema = objOf(buttonFields);
|
|
|
|
var checkboxFields = [
|
|
strictString('type'),
|
|
strictString('name'),
|
|
strictString('label'),
|
|
defaultedBoolean('disabled', false)
|
|
];
|
|
var checkboxSchema = objOf(checkboxFields);
|
|
var checkboxDataProcessor = boolean;
|
|
|
|
var formComponentFields = [
|
|
strictString('type'),
|
|
strictString('name')
|
|
];
|
|
var formComponentWithLabelFields = formComponentFields.concat([optionString('label')]);
|
|
|
|
var colorInputFields = formComponentWithLabelFields;
|
|
var colorInputSchema = objOf(colorInputFields);
|
|
var colorInputDataProcessor = string;
|
|
|
|
var colorPickerFields = formComponentWithLabelFields;
|
|
var colorPickerSchema = objOf(colorPickerFields);
|
|
var colorPickerDataProcessor = string;
|
|
|
|
var dropZoneFields = formComponentWithLabelFields;
|
|
var dropZoneSchema = objOf(dropZoneFields);
|
|
var dropZoneDataProcessor = arrOfVal();
|
|
|
|
var createGridFields = function (itemsField) {
|
|
return [
|
|
strictString('type'),
|
|
strictNumber('columns'),
|
|
itemsField
|
|
];
|
|
};
|
|
|
|
var iframeFields = formComponentWithLabelFields.concat([defaultedBoolean('sandboxed', true)]);
|
|
var iframeSchema = objOf(iframeFields);
|
|
var iframeDataProcessor = string;
|
|
|
|
var inputFields = formComponentWithLabelFields.concat([
|
|
optionString('inputMode'),
|
|
optionString('placeholder'),
|
|
defaultedBoolean('maximized', false),
|
|
defaultedBoolean('disabled', false)
|
|
]);
|
|
var inputSchema = objOf(inputFields);
|
|
var inputDataProcessor = string;
|
|
|
|
var selectBoxFields = formComponentWithLabelFields.concat([
|
|
strictArrayOfObj('items', [
|
|
strictString('text'),
|
|
strictString('value')
|
|
]),
|
|
defaultedNumber('size', 1),
|
|
defaultedBoolean('disabled', false)
|
|
]);
|
|
var selectBoxSchema = objOf(selectBoxFields);
|
|
var selectBoxDataProcessor = string;
|
|
|
|
var sizeInputFields = formComponentWithLabelFields.concat([
|
|
defaultedBoolean('constrain', true),
|
|
defaultedBoolean('disabled', false)
|
|
]);
|
|
var sizeInputSchema = objOf(sizeInputFields);
|
|
var sizeInputDataProcessor = objOf([
|
|
strictString('width'),
|
|
strictString('height')
|
|
]);
|
|
|
|
var textAreaFields = formComponentWithLabelFields.concat([
|
|
optionString('placeholder'),
|
|
defaultedBoolean('maximized', false),
|
|
defaultedBoolean('disabled', false)
|
|
]);
|
|
var textAreaSchema = objOf(textAreaFields);
|
|
var textAreaDataProcessor = string;
|
|
|
|
var urlInputFields = formComponentWithLabelFields.concat([
|
|
defaultedStringEnum('filetype', 'file', [
|
|
'image',
|
|
'media',
|
|
'file'
|
|
]),
|
|
defaulted$1('disabled', false)
|
|
]);
|
|
var urlInputSchema = objOf(urlInputFields);
|
|
var urlInputDataProcessor = objOf([
|
|
strictString('value'),
|
|
defaulted$1('meta', {})
|
|
]);
|
|
|
|
var customEditorFields = formComponentFields.concat([
|
|
defaultedString('tag', 'textarea'),
|
|
strictString('scriptId'),
|
|
strictString('scriptUrl'),
|
|
defaultedPostMsg('settings', undefined)
|
|
]);
|
|
var customEditorFieldsOld = formComponentFields.concat([
|
|
defaultedString('tag', 'textarea'),
|
|
strictFunction('init')
|
|
]);
|
|
var customEditorSchema = valueOf(function (v) {
|
|
return asRaw('customeditor.old', objOfOnly(customEditorFieldsOld), v).orThunk(function () {
|
|
return asRaw('customeditor.new', objOfOnly(customEditorFields), v);
|
|
});
|
|
});
|
|
var customEditorDataProcessor = string;
|
|
|
|
var htmlPanelFields = [
|
|
strictString('type'),
|
|
strictString('html'),
|
|
defaultedStringEnum('presets', 'presentation', [
|
|
'presentation',
|
|
'document'
|
|
])
|
|
];
|
|
var htmlPanelSchema = objOf(htmlPanelFields);
|
|
|
|
var imageToolsFields = formComponentWithLabelFields.concat([strictOf('currentState', objOf([
|
|
strict$1('blob'),
|
|
strictString('url')
|
|
]))]);
|
|
var imageToolsSchema = objOf(imageToolsFields);
|
|
|
|
var collectionFields = formComponentWithLabelFields.concat([defaulted$1('columns', 'auto')]);
|
|
var collectionSchema = objOf(collectionFields);
|
|
var collectionDataProcessor = arrOfObj$1([
|
|
strictString('value'),
|
|
strictString('text'),
|
|
strictString('icon')
|
|
]);
|
|
|
|
var createLabelFields = function (itemsField) {
|
|
return [
|
|
strictString('type'),
|
|
strictString('label'),
|
|
itemsField
|
|
];
|
|
};
|
|
|
|
var tableFields = [
|
|
strictString('type'),
|
|
strictArrayOf('header', string),
|
|
strictArrayOf('cells', arrOf(string))
|
|
];
|
|
var tableSchema = objOf(tableFields);
|
|
|
|
var createItemsField = function (name) {
|
|
return field('items', 'items', strict(), arrOf(valueOf(function (v) {
|
|
return asRaw('Checking item of ' + name, itemSchema$2, v).fold(function (sErr) {
|
|
return Result.error(formatError(sErr));
|
|
}, function (passValue) {
|
|
return Result.value(passValue);
|
|
});
|
|
})));
|
|
};
|
|
var itemSchema$2 = valueThunkOf(function () {
|
|
return chooseProcessor('type', {
|
|
alertbanner: alertBannerSchema,
|
|
bar: objOf(createBarFields(createItemsField('bar'))),
|
|
button: buttonSchema,
|
|
checkbox: checkboxSchema,
|
|
colorinput: colorInputSchema,
|
|
colorpicker: colorPickerSchema,
|
|
dropzone: dropZoneSchema,
|
|
grid: objOf(createGridFields(createItemsField('grid'))),
|
|
iframe: iframeSchema,
|
|
input: inputSchema,
|
|
selectbox: selectBoxSchema,
|
|
sizeinput: sizeInputSchema,
|
|
textarea: textAreaSchema,
|
|
urlinput: urlInputSchema,
|
|
customeditor: customEditorSchema,
|
|
htmlpanel: htmlPanelSchema,
|
|
imagetools: imageToolsSchema,
|
|
collection: collectionSchema,
|
|
label: objOf(createLabelFields(createItemsField('label'))),
|
|
table: tableSchema,
|
|
panel: panelSchema
|
|
});
|
|
});
|
|
var panelFields = [
|
|
strictString('type'),
|
|
defaulted$1('classes', []),
|
|
strictArrayOf('items', itemSchema$2)
|
|
];
|
|
var panelSchema = objOf(panelFields);
|
|
|
|
var tabFields = [
|
|
field('name', 'name', defaultedThunk(function () {
|
|
return generate$1('tab-name');
|
|
}), string),
|
|
strictString('title'),
|
|
strictArrayOf('items', itemSchema$2)
|
|
];
|
|
var tabPanelFields = [
|
|
strictString('type'),
|
|
strictArrayOfObj('tabs', tabFields)
|
|
];
|
|
var tabPanelSchema = objOf(tabPanelFields);
|
|
|
|
var dialogToggleMenuItemSchema = objOf([
|
|
strictString('type'),
|
|
strictString('name')
|
|
].concat(commonMenuItemFields));
|
|
var dialogToggleMenuItemDataProcessor = boolean;
|
|
|
|
var baseButtonFields = [
|
|
field('name', 'name', defaultedThunk(function () {
|
|
return generate$1('button-name');
|
|
}), string),
|
|
optionString('icon'),
|
|
defaultedStringEnum('align', 'end', [
|
|
'start',
|
|
'end'
|
|
]),
|
|
defaultedBoolean('primary', false),
|
|
defaultedBoolean('disabled', false)
|
|
];
|
|
var dialogButtonFields = __spreadArrays(baseButtonFields, [strictString('text')]);
|
|
var normalButtonFields = __spreadArrays([strictStringEnum('type', [
|
|
'submit',
|
|
'cancel',
|
|
'custom'
|
|
])], dialogButtonFields);
|
|
var menuButtonFields = __spreadArrays([
|
|
strictStringEnum('type', ['menu']),
|
|
optionString('text'),
|
|
optionString('tooltip'),
|
|
optionString('icon'),
|
|
strictArrayOf('items', dialogToggleMenuItemSchema)
|
|
], baseButtonFields);
|
|
var dialogButtonSchema = choose$1('type', {
|
|
submit: normalButtonFields,
|
|
cancel: normalButtonFields,
|
|
custom: normalButtonFields,
|
|
menu: menuButtonFields
|
|
});
|
|
|
|
var dialogButtonFields$1 = dialogButtonFields;
|
|
var dialogButtonSchema$1 = dialogButtonSchema;
|
|
var dialogSchema = objOf([
|
|
strictString('title'),
|
|
strictOf('body', chooseProcessor('type', {
|
|
panel: panelSchema,
|
|
tabpanel: tabPanelSchema
|
|
})),
|
|
defaultedString('size', 'normal'),
|
|
strictArrayOf('buttons', dialogButtonSchema$1),
|
|
defaulted$1('initialData', {}),
|
|
defaultedFunction('onAction', noop),
|
|
defaultedFunction('onChange', noop),
|
|
defaultedFunction('onSubmit', noop),
|
|
defaultedFunction('onClose', noop),
|
|
defaultedFunction('onCancel', noop),
|
|
defaulted$1('onTabChange', noop)
|
|
]);
|
|
var createDialog = function (spec) {
|
|
return asRaw('dialog', dialogSchema, spec);
|
|
};
|
|
|
|
var getAllObjects = function (obj) {
|
|
if (isObject(obj)) {
|
|
return [obj].concat(bind(values(obj), getAllObjects));
|
|
} else if (isArray(obj)) {
|
|
return bind(obj, getAllObjects);
|
|
} else {
|
|
return [];
|
|
}
|
|
};
|
|
|
|
var isNamedItem = function (obj) {
|
|
return isString(obj.type) && isString(obj.name);
|
|
};
|
|
var dataProcessors = {
|
|
checkbox: checkboxDataProcessor,
|
|
colorinput: colorInputDataProcessor,
|
|
colorpicker: colorPickerDataProcessor,
|
|
dropzone: dropZoneDataProcessor,
|
|
input: inputDataProcessor,
|
|
iframe: iframeDataProcessor,
|
|
sizeinput: sizeInputDataProcessor,
|
|
selectbox: selectBoxDataProcessor,
|
|
size: sizeInputDataProcessor,
|
|
textarea: textAreaDataProcessor,
|
|
urlinput: urlInputDataProcessor,
|
|
customeditor: customEditorDataProcessor,
|
|
collection: collectionDataProcessor,
|
|
togglemenuitem: dialogToggleMenuItemDataProcessor
|
|
};
|
|
var getDataProcessor = function (item) {
|
|
return Option.from(dataProcessors[item.type]);
|
|
};
|
|
var getNamedItems = function (structure) {
|
|
return filter(getAllObjects(structure), isNamedItem);
|
|
};
|
|
|
|
var createDataValidator = function (structure) {
|
|
var namedItems = getNamedItems(structure);
|
|
var fields = bind(namedItems, function (item) {
|
|
return getDataProcessor(item).fold(function () {
|
|
return [];
|
|
}, function (schema) {
|
|
return [strictOf(item.name, schema)];
|
|
});
|
|
});
|
|
return objOf(fields);
|
|
};
|
|
|
|
var urlDialogButtonSchema = objOf(__spreadArrays([strictStringEnum('type', [
|
|
'cancel',
|
|
'custom'
|
|
])], dialogButtonFields$1));
|
|
var urlDialogSchema = objOf([
|
|
strictString('title'),
|
|
strictString('url'),
|
|
optionNumber('height'),
|
|
optionNumber('width'),
|
|
optionArrayOf('buttons', urlDialogButtonSchema),
|
|
defaultedFunction('onAction', noop),
|
|
defaultedFunction('onCancel', noop),
|
|
defaultedFunction('onClose', noop),
|
|
defaultedFunction('onMessage', noop)
|
|
]);
|
|
var createUrlDialog = function (spec) {
|
|
return asRaw('dialog', urlDialogSchema, spec);
|
|
};
|
|
|
|
var extract$1 = function (structure) {
|
|
var internalDialog = getOrDie(createDialog(structure));
|
|
var dataValidator = createDataValidator(structure);
|
|
var initialData = structure.initialData;
|
|
return {
|
|
internalDialog: internalDialog,
|
|
dataValidator: dataValidator,
|
|
initialData: initialData
|
|
};
|
|
};
|
|
var DialogManager = {
|
|
open: function (factory, structure) {
|
|
var extraction = extract$1(structure);
|
|
return factory(extraction.internalDialog, extraction.initialData, extraction.dataValidator);
|
|
},
|
|
openUrl: function (factory, structure) {
|
|
var internalDialog = getOrDie(createUrlDialog(structure));
|
|
return factory(internalDialog);
|
|
},
|
|
redial: function (structure) {
|
|
return extract$1(structure);
|
|
}
|
|
};
|
|
|
|
var toValidValues = function (values) {
|
|
var errors = [];
|
|
var result = {};
|
|
each$1(values, function (value, name) {
|
|
value.fold(function () {
|
|
errors.push(name);
|
|
}, function (v) {
|
|
result[name] = v;
|
|
});
|
|
});
|
|
return errors.length > 0 ? Result.error(errors) : Result.value(result);
|
|
};
|
|
|
|
var renderBodyPanel = function (spec, backstage) {
|
|
var memForm = record(Form.sketch(function (parts) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form'].concat(spec.classes)
|
|
},
|
|
components: map(spec.items, function (item) {
|
|
return interpretInForm(parts, item, backstage);
|
|
})
|
|
};
|
|
}));
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__body']
|
|
},
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__body-content']
|
|
},
|
|
components: [memForm.asSpec()]
|
|
}],
|
|
behaviours: derive$1([
|
|
Keying.config({
|
|
mode: 'acyclic',
|
|
useTabstopAt: not(isPseudoStop)
|
|
}),
|
|
ComposingConfigs.memento(memForm),
|
|
RepresentingConfigs.memento(memForm, {
|
|
postprocess: function (formValue) {
|
|
return toValidValues(formValue).fold(function (err) {
|
|
domGlobals.console.error(err);
|
|
return {};
|
|
}, function (vals) {
|
|
return vals;
|
|
});
|
|
}
|
|
})
|
|
])
|
|
};
|
|
};
|
|
|
|
var factory$j = function (detail, _spec) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: detail.components,
|
|
events: events$7(detail.action),
|
|
behaviours: augment(detail.tabButtonBehaviours, [
|
|
Focusing.config({}),
|
|
Keying.config({
|
|
mode: 'execution',
|
|
useSpace: true,
|
|
useEnter: true
|
|
}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: detail.value
|
|
}
|
|
})
|
|
]),
|
|
domModification: detail.domModification
|
|
};
|
|
};
|
|
var TabButton = single$2({
|
|
name: 'TabButton',
|
|
configFields: [
|
|
defaulted$1('uid', undefined),
|
|
strict$1('value'),
|
|
field('dom', 'dom', mergeWithThunk(function () {
|
|
return {
|
|
attributes: {
|
|
'role': 'tab',
|
|
'id': generate$1('aria'),
|
|
'aria-selected': 'false'
|
|
}
|
|
};
|
|
}), anyValue$1()),
|
|
option('action'),
|
|
defaulted$1('domModification', {}),
|
|
field$1('tabButtonBehaviours', [
|
|
Focusing,
|
|
Keying,
|
|
Representing
|
|
]),
|
|
strict$1('view')
|
|
],
|
|
factory: factory$j
|
|
});
|
|
|
|
var schema$y = constant([
|
|
strict$1('tabs'),
|
|
strict$1('dom'),
|
|
defaulted$1('clickToDismiss', false),
|
|
field$1('tabbarBehaviours', [
|
|
Highlighting,
|
|
Keying
|
|
]),
|
|
markers([
|
|
'tabClass',
|
|
'selectedClass'
|
|
])
|
|
]);
|
|
var tabsPart = group({
|
|
factory: TabButton,
|
|
name: 'tabs',
|
|
unit: 'tab',
|
|
overrides: function (barDetail) {
|
|
var dismissTab$1 = function (tabbar, button) {
|
|
Highlighting.dehighlight(tabbar, button);
|
|
emitWith(tabbar, dismissTab(), {
|
|
tabbar: tabbar,
|
|
button: button
|
|
});
|
|
};
|
|
var changeTab$1 = function (tabbar, button) {
|
|
Highlighting.highlight(tabbar, button);
|
|
emitWith(tabbar, changeTab(), {
|
|
tabbar: tabbar,
|
|
button: button
|
|
});
|
|
};
|
|
return {
|
|
action: function (button) {
|
|
var tabbar = button.getSystem().getByUid(barDetail.uid).getOrDie();
|
|
var activeButton = Highlighting.isHighlighted(tabbar, button);
|
|
var response = function () {
|
|
if (activeButton && barDetail.clickToDismiss) {
|
|
return dismissTab$1;
|
|
} else if (!activeButton) {
|
|
return changeTab$1;
|
|
} else {
|
|
return noop;
|
|
}
|
|
}();
|
|
response(tabbar, button);
|
|
},
|
|
domModification: { classes: [barDetail.markers.tabClass] }
|
|
};
|
|
}
|
|
});
|
|
var parts$g = constant([tabsPart]);
|
|
|
|
var factory$k = function (detail, components, _spec, _externals) {
|
|
return {
|
|
'uid': detail.uid,
|
|
'dom': detail.dom,
|
|
components: components,
|
|
'debug.sketcher': 'Tabbar',
|
|
'domModification': { attributes: { role: 'tablist' } },
|
|
'behaviours': augment(detail.tabbarBehaviours, [
|
|
Highlighting.config({
|
|
highlightClass: detail.markers.selectedClass,
|
|
itemClass: detail.markers.tabClass,
|
|
onHighlight: function (tabbar, tab) {
|
|
set$1(tab.element(), 'aria-selected', 'true');
|
|
},
|
|
onDehighlight: function (tabbar, tab) {
|
|
set$1(tab.element(), 'aria-selected', 'false');
|
|
}
|
|
}),
|
|
Keying.config({
|
|
mode: 'flow',
|
|
getInitial: function (tabbar) {
|
|
return Highlighting.getHighlighted(tabbar).map(function (tab) {
|
|
return tab.element();
|
|
});
|
|
},
|
|
selector: '.' + detail.markers.tabClass,
|
|
executeOnMove: true
|
|
})
|
|
])
|
|
};
|
|
};
|
|
var Tabbar = composite$1({
|
|
name: 'Tabbar',
|
|
configFields: schema$y(),
|
|
partFields: parts$g(),
|
|
factory: factory$k
|
|
});
|
|
|
|
var factory$l = function (detail, _spec) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
behaviours: augment(detail.tabviewBehaviours, [Replacing.config({})]),
|
|
domModification: { attributes: { role: 'tabpanel' } }
|
|
};
|
|
};
|
|
var Tabview = single$2({
|
|
name: 'Tabview',
|
|
configFields: [field$1('tabviewBehaviours', [Replacing])],
|
|
factory: factory$l
|
|
});
|
|
|
|
var schema$z = constant([
|
|
defaulted$1('selectFirst', true),
|
|
onHandler('onChangeTab'),
|
|
onHandler('onDismissTab'),
|
|
defaulted$1('tabs', []),
|
|
field$1('tabSectionBehaviours', [])
|
|
]);
|
|
var barPart = required({
|
|
factory: Tabbar,
|
|
schema: [
|
|
strict$1('dom'),
|
|
strictObjOf('markers', [
|
|
strict$1('tabClass'),
|
|
strict$1('selectedClass')
|
|
])
|
|
],
|
|
name: 'tabbar',
|
|
defaults: function (detail) {
|
|
return { tabs: detail.tabs };
|
|
}
|
|
});
|
|
var viewPart = required({
|
|
factory: Tabview,
|
|
name: 'tabview'
|
|
});
|
|
var parts$h = constant([
|
|
barPart,
|
|
viewPart
|
|
]);
|
|
|
|
var factory$m = function (detail, components, _spec, _externals) {
|
|
var changeTab$1 = function (button) {
|
|
var tabValue = Representing.getValue(button);
|
|
getPart(button, detail, 'tabview').each(function (tabview) {
|
|
var tabWithValue = find(detail.tabs, function (t) {
|
|
return t.value === tabValue;
|
|
});
|
|
tabWithValue.each(function (tabData) {
|
|
var panel = tabData.view();
|
|
getOpt(button.element(), 'id').each(function (id) {
|
|
set$1(tabview.element(), 'aria-labelledby', id);
|
|
});
|
|
Replacing.set(tabview, panel);
|
|
detail.onChangeTab(tabview, button, panel);
|
|
});
|
|
});
|
|
};
|
|
var changeTabBy = function (section, byPred) {
|
|
getPart(section, detail, 'tabbar').each(function (tabbar) {
|
|
byPred(tabbar).each(emitExecute);
|
|
});
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: get$c(detail.tabSectionBehaviours),
|
|
events: derive(flatten([
|
|
detail.selectFirst ? [runOnAttached(function (section, _simulatedEvent) {
|
|
changeTabBy(section, Highlighting.getFirst);
|
|
})] : [],
|
|
[
|
|
run(changeTab(), function (section, simulatedEvent) {
|
|
var button = simulatedEvent.event().button();
|
|
changeTab$1(button);
|
|
}),
|
|
run(dismissTab(), function (section, simulatedEvent) {
|
|
var button = simulatedEvent.event().button();
|
|
detail.onDismissTab(section, button);
|
|
})
|
|
]
|
|
])),
|
|
apis: {
|
|
getViewItems: function (section) {
|
|
return getPart(section, detail, 'tabview').map(function (tabview) {
|
|
return Replacing.contents(tabview);
|
|
}).getOr([]);
|
|
},
|
|
showTab: function (section, tabKey) {
|
|
var getTabIfNotActive = function (tabbar) {
|
|
var candidates = Highlighting.getCandidates(tabbar);
|
|
var optTab = find(candidates, function (c) {
|
|
return Representing.getValue(c) === tabKey;
|
|
});
|
|
return optTab.filter(function (tab) {
|
|
return !Highlighting.isHighlighted(tabbar, tab);
|
|
});
|
|
};
|
|
changeTabBy(section, getTabIfNotActive);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
var TabSection = composite$1({
|
|
name: 'TabSection',
|
|
configFields: schema$z(),
|
|
partFields: parts$h(),
|
|
factory: factory$m,
|
|
apis: {
|
|
getViewItems: function (apis, component) {
|
|
return apis.getViewItems(component);
|
|
},
|
|
showTab: function (apis, component, tabKey) {
|
|
apis.showTab(component, tabKey);
|
|
}
|
|
}
|
|
});
|
|
|
|
var measureHeights = function (allTabs, tabview, tabviewComp) {
|
|
return map(allTabs, function (_tab, i) {
|
|
Replacing.set(tabviewComp, allTabs[i].view());
|
|
var rect = tabview.dom().getBoundingClientRect();
|
|
Replacing.set(tabviewComp, []);
|
|
return rect.height;
|
|
});
|
|
};
|
|
var getMaxHeight = function (heights) {
|
|
return head(sort(heights, function (a, b) {
|
|
if (a > b) {
|
|
return -1;
|
|
} else if (a < b) {
|
|
return +1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}));
|
|
};
|
|
var getMaxTabviewHeight = function (dialog, tabview, tablist) {
|
|
var documentElement$1 = documentElement(dialog).dom();
|
|
var rootElm = ancestor$2(dialog, '.tox-dialog-wrap').getOr(dialog);
|
|
var isFixed = get$4(rootElm, 'position') === 'fixed';
|
|
var maxHeight;
|
|
if (isFixed) {
|
|
maxHeight = Math.max(documentElement$1.clientHeight, domGlobals.window.innerHeight);
|
|
} else {
|
|
maxHeight = Math.max(documentElement$1.offsetHeight, documentElement$1.scrollHeight);
|
|
}
|
|
var tabviewHeight = get$6(tabview);
|
|
var isTabListBeside = tabview.dom().offsetLeft >= tablist.dom().offsetLeft + get$7(tablist);
|
|
var currentTabHeight = isTabListBeside ? Math.max(get$6(tablist), tabviewHeight) : tabviewHeight;
|
|
var dialogTopMargin = parseInt(get$4(dialog, 'margin-top'), 10) || 0;
|
|
var dialogBottomMargin = parseInt(get$4(dialog, 'margin-bottom'), 10) || 0;
|
|
var dialogHeight = get$6(dialog) + dialogTopMargin + dialogBottomMargin;
|
|
var chromeHeight = dialogHeight - currentTabHeight;
|
|
return maxHeight - chromeHeight;
|
|
};
|
|
var showTab = function (allTabs, comp) {
|
|
head(allTabs).each(function (tab) {
|
|
return TabSection.showTab(comp, tab.value);
|
|
});
|
|
};
|
|
var setTabviewHeight = function (tabview, height) {
|
|
set$2(tabview, 'height', height + 'px');
|
|
if (!detect$3().browser.isIE()) {
|
|
set$2(tabview, 'flex-basis', height + 'px');
|
|
} else {
|
|
remove$6(tabview, 'flex-basis');
|
|
}
|
|
};
|
|
var updateTabviewHeight = function (dialogBody, tabview, maxTabHeight) {
|
|
ancestor$2(dialogBody, '[role="dialog"]').each(function (dialog) {
|
|
descendant$1(dialog, '[role="tablist"]').each(function (tablist) {
|
|
maxTabHeight.get().map(function (height) {
|
|
set$2(tabview, 'height', '0');
|
|
set$2(tabview, 'flex-basis', '0');
|
|
return Math.min(height, getMaxTabviewHeight(dialog, tabview, tablist));
|
|
}).each(function (height) {
|
|
setTabviewHeight(tabview, height);
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var getTabview = function (dialog) {
|
|
return descendant$1(dialog, '[role="tabpanel"]');
|
|
};
|
|
var setMode = function (allTabs) {
|
|
var smartTabHeight = function () {
|
|
var maxTabHeight = Cell(Option.none());
|
|
var extraEvents = [
|
|
runOnAttached(function (comp) {
|
|
var dialog = comp.element();
|
|
getTabview(dialog).each(function (tabview) {
|
|
set$2(tabview, 'visibility', 'hidden');
|
|
comp.getSystem().getByDom(tabview).toOption().each(function (tabviewComp) {
|
|
var heights = measureHeights(allTabs, tabview, tabviewComp);
|
|
var maxTabHeightOpt = getMaxHeight(heights);
|
|
maxTabHeight.set(maxTabHeightOpt);
|
|
});
|
|
updateTabviewHeight(dialog, tabview, maxTabHeight);
|
|
remove$6(tabview, 'visibility');
|
|
showTab(allTabs, comp);
|
|
global$2.requestAnimationFrame(function () {
|
|
updateTabviewHeight(dialog, tabview, maxTabHeight);
|
|
});
|
|
});
|
|
}),
|
|
run(windowResize(), function (comp) {
|
|
var dialog = comp.element();
|
|
getTabview(dialog).each(function (tabview) {
|
|
updateTabviewHeight(dialog, tabview, maxTabHeight);
|
|
});
|
|
}),
|
|
run(formResizeEvent, function (comp, _se) {
|
|
var dialog = comp.element();
|
|
getTabview(dialog).each(function (tabview) {
|
|
var oldFocus = active();
|
|
set$2(tabview, 'visibility', 'hidden');
|
|
var oldHeight = getRaw(tabview, 'height').map(function (h) {
|
|
return parseInt(h, 10);
|
|
});
|
|
remove$6(tabview, 'height');
|
|
remove$6(tabview, 'flex-basis');
|
|
var newHeight = tabview.dom().getBoundingClientRect().height;
|
|
var hasGrown = oldHeight.forall(function (h) {
|
|
return newHeight > h;
|
|
});
|
|
if (hasGrown) {
|
|
maxTabHeight.set(Option.from(newHeight));
|
|
updateTabviewHeight(dialog, tabview, maxTabHeight);
|
|
} else {
|
|
oldHeight.each(function (h) {
|
|
setTabviewHeight(tabview, h);
|
|
});
|
|
}
|
|
remove$6(tabview, 'visibility');
|
|
oldFocus.each(focus$1);
|
|
});
|
|
})
|
|
];
|
|
var selectFirst = false;
|
|
return {
|
|
extraEvents: extraEvents,
|
|
selectFirst: selectFirst
|
|
};
|
|
}();
|
|
var naiveTabHeight = function () {
|
|
var extraEvents = [];
|
|
var selectFirst = true;
|
|
return {
|
|
extraEvents: extraEvents,
|
|
selectFirst: selectFirst
|
|
};
|
|
}();
|
|
return {
|
|
smartTabHeight: smartTabHeight,
|
|
naiveTabHeight: naiveTabHeight
|
|
};
|
|
};
|
|
|
|
var SendDataToSectionChannel = 'send-data-to-section';
|
|
var SendDataToViewChannel = 'send-data-to-view';
|
|
var renderTabPanel = function (spec, backstage) {
|
|
var storedValue = Cell({});
|
|
var updateDataWithForm = function (form) {
|
|
var formData = Representing.getValue(form);
|
|
var validData = toValidValues(formData).getOr({});
|
|
var currentData = storedValue.get();
|
|
var newData = deepMerge(currentData, validData);
|
|
storedValue.set(newData);
|
|
};
|
|
var setDataOnForm = function (form) {
|
|
var tabData = storedValue.get();
|
|
Representing.setValue(form, tabData);
|
|
};
|
|
var oldTab = Cell(null);
|
|
var allTabs = map(spec.tabs, function (tab) {
|
|
return {
|
|
value: tab.name,
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__body-nav-item'],
|
|
innerHtml: backstage.shared.providers.translate(tab.title)
|
|
},
|
|
view: function () {
|
|
return [Form.sketch(function (parts) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-form']
|
|
},
|
|
components: map(tab.items, function (item) {
|
|
return interpretInForm(parts, item, backstage);
|
|
}),
|
|
formBehaviours: derive$1([
|
|
Keying.config({
|
|
mode: 'acyclic',
|
|
useTabstopAt: not(isPseudoStop)
|
|
}),
|
|
config('TabView.form.events', [
|
|
runOnAttached(setDataOnForm),
|
|
runOnDetached(updateDataWithForm)
|
|
]),
|
|
Receiving.config({
|
|
channels: wrapAll$1([
|
|
{
|
|
key: SendDataToSectionChannel,
|
|
value: { onReceive: updateDataWithForm }
|
|
},
|
|
{
|
|
key: SendDataToViewChannel,
|
|
value: { onReceive: setDataOnForm }
|
|
}
|
|
])
|
|
})
|
|
])
|
|
};
|
|
})];
|
|
}
|
|
};
|
|
});
|
|
var tabMode = setMode(allTabs).smartTabHeight;
|
|
return TabSection.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__body']
|
|
},
|
|
onChangeTab: function (section, button, _viewItems) {
|
|
var name = Representing.getValue(button);
|
|
emitWith(section, formTabChangeEvent, {
|
|
name: name,
|
|
oldName: oldTab.get()
|
|
});
|
|
oldTab.set(name);
|
|
},
|
|
tabs: allTabs,
|
|
components: [
|
|
TabSection.parts().tabbar({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__body-nav']
|
|
},
|
|
components: [Tabbar.parts().tabs({})],
|
|
markers: {
|
|
tabClass: 'tox-tab',
|
|
selectedClass: 'tox-dialog__body-nav-item--active'
|
|
},
|
|
tabbarBehaviours: derive$1([Tabstopping.config({})])
|
|
}),
|
|
TabSection.parts().tabview({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__body-content']
|
|
}
|
|
})
|
|
],
|
|
selectFirst: tabMode.selectFirst,
|
|
tabSectionBehaviours: derive$1([
|
|
config('tabpanel', tabMode.extraEvents),
|
|
Keying.config({ mode: 'acyclic' }),
|
|
Composing.config({
|
|
find: function (comp) {
|
|
return head(TabSection.getViewItems(comp));
|
|
}
|
|
}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (tsection) {
|
|
tsection.getSystem().broadcastOn([SendDataToSectionChannel], {});
|
|
return storedValue.get();
|
|
},
|
|
setValue: function (tsection, value) {
|
|
storedValue.set(value);
|
|
tsection.getSystem().broadcastOn([SendDataToViewChannel], {});
|
|
}
|
|
}
|
|
})
|
|
])
|
|
});
|
|
};
|
|
|
|
var dialogChannel = generate$1('update-dialog');
|
|
var titleChannel = generate$1('update-title');
|
|
var bodyChannel = generate$1('update-body');
|
|
var footerChannel = generate$1('update-footer');
|
|
var bodySendMessageChannel = generate$1('body-send-message');
|
|
|
|
var renderBody = function (spec, id, backstage, ariaAttrs) {
|
|
var renderComponents = function (incoming) {
|
|
switch (incoming.body.type) {
|
|
case 'tabpanel': {
|
|
return [renderTabPanel(incoming.body, backstage)];
|
|
}
|
|
default: {
|
|
return [renderBodyPanel(incoming.body, backstage)];
|
|
}
|
|
}
|
|
};
|
|
var updateState = function (_comp, incoming) {
|
|
return Option.some({
|
|
isTabPanel: function () {
|
|
return incoming.body.type === 'tabpanel';
|
|
}
|
|
});
|
|
};
|
|
var ariaAttributes = { 'aria-live': 'polite' };
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__content-js'],
|
|
attributes: __assign(__assign({}, id.map(function (x) {
|
|
return { id: x };
|
|
}).getOr({})), ariaAttrs ? ariaAttributes : {})
|
|
},
|
|
components: [],
|
|
behaviours: derive$1([
|
|
ComposingConfigs.childAt(0),
|
|
Reflecting.config({
|
|
channel: bodyChannel,
|
|
updateState: updateState,
|
|
renderComponents: renderComponents,
|
|
initialData: spec
|
|
})
|
|
])
|
|
};
|
|
};
|
|
var renderInlineBody = function (spec, contentId, backstage, ariaAttrs) {
|
|
return renderBody(spec, Option.some(contentId), backstage, ariaAttrs);
|
|
};
|
|
var renderModalBody = function (spec, backstage) {
|
|
var bodySpec = renderBody(spec, Option.none(), backstage, false);
|
|
return ModalDialog.parts().body(bodySpec);
|
|
};
|
|
var renderIframeBody = function (spec) {
|
|
var bodySpec = {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__content-js']
|
|
},
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__body-iframe']
|
|
},
|
|
components: [craft({
|
|
dom: {
|
|
tag: 'iframe',
|
|
attributes: { src: spec.url }
|
|
},
|
|
behaviours: derive$1([
|
|
Tabstopping.config({}),
|
|
Focusing.config({})
|
|
])
|
|
})]
|
|
}],
|
|
behaviours: derive$1([Keying.config({
|
|
mode: 'acyclic',
|
|
useTabstopAt: not(isPseudoStop)
|
|
})])
|
|
};
|
|
return ModalDialog.parts().body(bodySpec);
|
|
};
|
|
|
|
var isTouch = global$6.deviceType.isTouch();
|
|
var hiddenHeader = function (title, close) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
styles: { display: 'none' },
|
|
classes: ['tox-dialog__header']
|
|
},
|
|
components: [
|
|
title,
|
|
close
|
|
]
|
|
};
|
|
};
|
|
var pClose = function (onClose, providersBackstage) {
|
|
return ModalDialog.parts().close(Button.sketch({
|
|
dom: {
|
|
tag: 'button',
|
|
classes: [
|
|
'tox-button',
|
|
'tox-button--icon',
|
|
'tox-button--naked'
|
|
],
|
|
attributes: {
|
|
'type': 'button',
|
|
'aria-label': providersBackstage.translate('Close')
|
|
}
|
|
},
|
|
action: onClose,
|
|
buttonBehaviours: derive$1([Tabstopping.config({})])
|
|
}));
|
|
};
|
|
var pUntitled = function () {
|
|
return ModalDialog.parts().title({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__title'],
|
|
innerHtml: '',
|
|
styles: { display: 'none' }
|
|
}
|
|
});
|
|
};
|
|
var pBodyMessage = function (message, providersBackstage) {
|
|
return ModalDialog.parts().body({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__body']
|
|
},
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__body-content']
|
|
},
|
|
components: [{ dom: fromHtml$2('<p>' + providersBackstage.translate(message) + '</p>') }]
|
|
}]
|
|
});
|
|
};
|
|
var pFooter = function (buttons) {
|
|
return ModalDialog.parts().footer({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__footer']
|
|
},
|
|
components: buttons
|
|
});
|
|
};
|
|
var pFooterGroup = function (startButtons, endButtons) {
|
|
return [
|
|
Container.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__footer-start']
|
|
},
|
|
components: startButtons
|
|
}),
|
|
Container.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__footer-end']
|
|
},
|
|
components: endButtons
|
|
})
|
|
];
|
|
};
|
|
var renderDialog = function (spec) {
|
|
var _a;
|
|
var dialogClass = 'tox-dialog';
|
|
var blockerClass = dialogClass + '-wrap';
|
|
var blockerBackdropClass = blockerClass + '__backdrop';
|
|
var scrollLockClass = dialogClass + '__disable-scroll';
|
|
return ModalDialog.sketch({
|
|
lazySink: spec.lazySink,
|
|
onEscape: function (comp) {
|
|
spec.onEscape(comp);
|
|
return Option.some(true);
|
|
},
|
|
useTabstopAt: function (elem) {
|
|
return !isPseudoStop(elem);
|
|
},
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [dialogClass].concat(spec.extraClasses),
|
|
styles: __assign({ position: 'relative' }, spec.extraStyles)
|
|
},
|
|
components: __spreadArrays([
|
|
spec.header,
|
|
spec.body
|
|
], spec.footer.toArray()),
|
|
parts: {
|
|
blocker: {
|
|
dom: fromHtml$2('<div class="' + blockerClass + '"></div>'),
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: isTouch ? [
|
|
blockerBackdropClass,
|
|
blockerBackdropClass + '--opaque'
|
|
] : [blockerBackdropClass]
|
|
}
|
|
}]
|
|
}
|
|
},
|
|
dragBlockClass: blockerClass,
|
|
modalBehaviours: derive$1(__spreadArrays([
|
|
Focusing.config({}),
|
|
config('dialog-events', spec.dialogEvents.concat([runOnSource(focusin(), function (comp, _se) {
|
|
Keying.focusIn(comp);
|
|
})])),
|
|
config('scroll-lock', [
|
|
runOnAttached(function () {
|
|
add$2(body(), scrollLockClass);
|
|
}),
|
|
runOnDetached(function () {
|
|
remove$4(body(), scrollLockClass);
|
|
})
|
|
])
|
|
], spec.extraBehaviours)),
|
|
eventOrder: __assign((_a = {}, _a[execute()] = ['dialog-events'], _a[attachedToDom()] = [
|
|
'scroll-lock',
|
|
'dialog-events',
|
|
'alloy.base.behaviour'
|
|
], _a[detachedFromDom()] = [
|
|
'alloy.base.behaviour',
|
|
'dialog-events',
|
|
'scroll-lock'
|
|
], _a), spec.eventOrder)
|
|
});
|
|
};
|
|
|
|
var renderClose = function (providersBackstage) {
|
|
return Button.sketch({
|
|
dom: {
|
|
tag: 'button',
|
|
classes: [
|
|
'tox-button',
|
|
'tox-button--icon',
|
|
'tox-button--naked'
|
|
],
|
|
attributes: {
|
|
'type': 'button',
|
|
'aria-label': providersBackstage.translate('Close'),
|
|
'title': providersBackstage.translate('Close')
|
|
}
|
|
},
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-icon'],
|
|
innerHtml: '<svg width="24" height="24" xmlns="http://www.w3.org/2000/svg">' + '<path d="M17.953 7.453L13.422 12l4.531 4.547-1.406 1.406L12 ' + '13.422l-4.547 4.531-1.406-1.406L10.578 12 6.047 ' + '7.453l1.406-1.406L12 10.578l4.547-4.531z" ' + 'fill-rule="evenodd"></path></svg>'
|
|
}
|
|
}],
|
|
action: function (comp) {
|
|
emit(comp, formCancelEvent);
|
|
}
|
|
});
|
|
};
|
|
var renderTitle = function (spec, id, providersBackstage) {
|
|
var renderComponents = function (data) {
|
|
return [text(providersBackstage.translate(data.title))];
|
|
};
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__title'],
|
|
attributes: __assign({}, id.map(function (x) {
|
|
return { id: x };
|
|
}).getOr({}))
|
|
},
|
|
components: renderComponents(spec),
|
|
behaviours: derive$1([Reflecting.config({
|
|
channel: titleChannel,
|
|
renderComponents: renderComponents
|
|
})])
|
|
};
|
|
};
|
|
var renderDragHandle = function () {
|
|
return { dom: fromHtml$2('<div class="tox-dialog__draghandle"></div>') };
|
|
};
|
|
var renderInlineHeader = function (spec, titleId, providersBackstage) {
|
|
return Container.sketch({
|
|
dom: fromHtml$2('<div class="tox-dialog__header"></div>'),
|
|
components: [
|
|
renderTitle(spec, Option.some(titleId), providersBackstage),
|
|
renderDragHandle(),
|
|
renderClose(providersBackstage)
|
|
],
|
|
containerBehaviours: derive$1([Dragging.config({
|
|
mode: 'mouse',
|
|
blockerClass: 'blocker',
|
|
getTarget: function (handle) {
|
|
return closest$3(handle, '[role="dialog"]').getOrDie();
|
|
},
|
|
snaps: {
|
|
getSnapPoints: function () {
|
|
return [];
|
|
},
|
|
leftAttr: 'data-drag-left',
|
|
topAttr: 'data-drag-top'
|
|
}
|
|
})])
|
|
});
|
|
};
|
|
var renderModalHeader = function (spec, providersBackstage) {
|
|
var pTitle = ModalDialog.parts().title(renderTitle(spec, Option.none(), providersBackstage));
|
|
var pHandle = ModalDialog.parts().draghandle(renderDragHandle());
|
|
var pClose = ModalDialog.parts().close(renderClose(providersBackstage));
|
|
var components = [pTitle].concat(spec.draggable ? [pHandle] : []).concat([pClose]);
|
|
return Container.sketch({
|
|
dom: fromHtml$2('<div class="tox-dialog__header"></div>'),
|
|
components: components
|
|
});
|
|
};
|
|
|
|
var getHeader = function (title, backstage) {
|
|
return renderModalHeader({
|
|
title: backstage.shared.providers.translate(title),
|
|
draggable: backstage.dialog.isDraggableModal()
|
|
}, backstage.shared.providers);
|
|
};
|
|
var getEventExtras = function (lazyDialog, extra) {
|
|
return {
|
|
onClose: function () {
|
|
return extra.closeWindow();
|
|
},
|
|
onBlock: function (blockEvent) {
|
|
ModalDialog.setBusy(lazyDialog(), function (d, bs) {
|
|
return {
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__busy-spinner'],
|
|
attributes: { 'aria-label': blockEvent.message() },
|
|
styles: {
|
|
left: '0px',
|
|
right: '0px',
|
|
bottom: '0px',
|
|
top: '0px',
|
|
position: 'absolute'
|
|
}
|
|
},
|
|
behaviours: bs,
|
|
components: [{ dom: fromHtml$2('<div class="tox-spinner"><div></div><div></div><div></div></div>') }]
|
|
};
|
|
});
|
|
},
|
|
onUnblock: function () {
|
|
ModalDialog.setIdle(lazyDialog());
|
|
}
|
|
};
|
|
};
|
|
var renderModalDialog = function (spec, initialData, dialogEvents, backstage) {
|
|
var _a;
|
|
var updateState = function (_comp, incoming) {
|
|
return Option.some(incoming);
|
|
};
|
|
return build$1(renderDialog(__assign(__assign({}, spec), {
|
|
lazySink: backstage.shared.getSink,
|
|
extraBehaviours: __spreadArrays([
|
|
Reflecting.config({
|
|
channel: dialogChannel,
|
|
updateState: updateState,
|
|
initialData: initialData
|
|
}),
|
|
RepresentingConfigs.memory({})
|
|
], spec.extraBehaviours),
|
|
onEscape: function (comp) {
|
|
emit(comp, formCancelEvent);
|
|
},
|
|
dialogEvents: dialogEvents,
|
|
eventOrder: (_a = {}, _a[receive()] = [
|
|
'reflecting',
|
|
'receiving'
|
|
], _a[attachedToDom()] = [
|
|
'scroll-lock',
|
|
'reflecting',
|
|
'messages',
|
|
'dialog-events',
|
|
'alloy.base.behaviour'
|
|
], _a[detachedFromDom()] = [
|
|
'alloy.base.behaviour',
|
|
'dialog-events',
|
|
'messages',
|
|
'reflecting',
|
|
'scroll-lock'
|
|
], _a)
|
|
})));
|
|
};
|
|
var mapMenuButtons = function (buttons) {
|
|
var mapItems = function (button) {
|
|
var items = map(button.items, function (item) {
|
|
var cell = Cell(false);
|
|
return __assign(__assign({}, item), { storage: cell });
|
|
});
|
|
return __assign(__assign({}, button), { items: items });
|
|
};
|
|
return map(buttons, function (button) {
|
|
if (button.type === 'menu') {
|
|
return mapItems(button);
|
|
}
|
|
return button;
|
|
});
|
|
};
|
|
var extractCellsToObject = function (buttons) {
|
|
return foldl(buttons, function (acc, button) {
|
|
if (button.type === 'menu') {
|
|
var menuButton = button;
|
|
return foldl(menuButton.items, function (innerAcc, item) {
|
|
innerAcc[item.name] = item.storage;
|
|
return innerAcc;
|
|
}, acc);
|
|
}
|
|
return acc;
|
|
}, {});
|
|
};
|
|
|
|
var initCommonEvents = function (fireApiEvent, extras) {
|
|
return [
|
|
runWithTarget(focusin(), onFocus$1),
|
|
fireApiEvent(formCloseEvent, function (_api, spec) {
|
|
extras.onClose();
|
|
spec.onClose();
|
|
}),
|
|
fireApiEvent(formCancelEvent, function (api, spec, _event, self) {
|
|
spec.onCancel(api);
|
|
emit(self, formCloseEvent);
|
|
}),
|
|
run(formUnblockEvent, function (_c, _se) {
|
|
return extras.onUnblock();
|
|
}),
|
|
run(formBlockEvent, function (_c, se) {
|
|
return extras.onBlock(se.event());
|
|
})
|
|
];
|
|
};
|
|
var initUrlDialog = function (getInstanceApi, extras) {
|
|
var fireApiEvent = function (eventName, f) {
|
|
return run(eventName, function (c, se) {
|
|
withSpec(c, function (spec, _c) {
|
|
f(getInstanceApi(), spec, se.event(), c);
|
|
});
|
|
});
|
|
};
|
|
var withSpec = function (c, f) {
|
|
Reflecting.getState(c).get().each(function (currentDialog) {
|
|
f(currentDialog, c);
|
|
});
|
|
};
|
|
return __spreadArrays(initCommonEvents(fireApiEvent, extras), [fireApiEvent(formActionEvent, function (api, spec, event) {
|
|
spec.onAction(api, { name: event.name() });
|
|
})]);
|
|
};
|
|
var initDialog = function (getInstanceApi, extras, getSink) {
|
|
var fireApiEvent = function (eventName, f) {
|
|
return run(eventName, function (c, se) {
|
|
withSpec(c, function (spec, _c) {
|
|
f(getInstanceApi(), spec, se.event(), c);
|
|
});
|
|
});
|
|
};
|
|
var withSpec = function (c, f) {
|
|
Reflecting.getState(c).get().each(function (currentDialogInit) {
|
|
f(currentDialogInit.internalDialog, c);
|
|
});
|
|
};
|
|
return __spreadArrays(initCommonEvents(fireApiEvent, extras), [
|
|
fireApiEvent(formSubmitEvent, function (api, spec) {
|
|
return spec.onSubmit(api);
|
|
}),
|
|
fireApiEvent(formChangeEvent, function (api, spec, event) {
|
|
spec.onChange(api, { name: event.name() });
|
|
}),
|
|
fireApiEvent(formActionEvent, function (api, spec, event, component) {
|
|
var focusIn = function () {
|
|
return Keying.focusIn(component);
|
|
};
|
|
var isDisabled = function (focused) {
|
|
return has$1(focused, 'disabled') || getOpt(focused, 'aria-disabled').exists(function (val) {
|
|
return val === 'true';
|
|
});
|
|
};
|
|
var current = active();
|
|
spec.onAction(api, {
|
|
name: event.name(),
|
|
value: event.value()
|
|
});
|
|
active().fold(focusIn, function (focused) {
|
|
if (isDisabled(focused)) {
|
|
focusIn();
|
|
} else if (current.exists(function (cur) {
|
|
return contains$2(focused, cur) && isDisabled(cur);
|
|
})) {
|
|
focusIn();
|
|
} else {
|
|
getSink().toOption().filter(function (sink) {
|
|
return !contains$2(sink.element(), focused);
|
|
}).each(focusIn);
|
|
}
|
|
});
|
|
}),
|
|
fireApiEvent(formTabChangeEvent, function (api, spec, event) {
|
|
spec.onTabChange(api, {
|
|
newTabName: event.name(),
|
|
oldTabName: event.oldName()
|
|
});
|
|
}),
|
|
runOnDetached(function (component) {
|
|
var api = getInstanceApi();
|
|
Representing.setValue(component, api.getData());
|
|
})
|
|
]);
|
|
};
|
|
var SilverDialogEvents = {
|
|
initUrlDialog: initUrlDialog,
|
|
initDialog: initDialog
|
|
};
|
|
|
|
var makeButton = function (button, backstage) {
|
|
return renderFooterButton(button, button.type, backstage);
|
|
};
|
|
var lookup$2 = function (compInSystem, footerButtons, buttonName) {
|
|
return find(footerButtons, function (button) {
|
|
return button.name === buttonName;
|
|
}).bind(function (memButton) {
|
|
return memButton.memento.getOpt(compInSystem);
|
|
});
|
|
};
|
|
var renderComponents = function (_data, state) {
|
|
var footerButtons = state.map(function (s) {
|
|
return s.footerButtons;
|
|
}).getOr([]);
|
|
var buttonGroups = partition(footerButtons, function (button) {
|
|
return button.align === 'start';
|
|
});
|
|
var makeGroup = function (edge, buttons) {
|
|
return Container.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: ['tox-dialog__footer-' + edge]
|
|
},
|
|
components: map(buttons, function (button) {
|
|
return button.memento.asSpec();
|
|
})
|
|
});
|
|
};
|
|
var startButtons = makeGroup('start', buttonGroups.pass);
|
|
var endButtons = makeGroup('end', buttonGroups.fail);
|
|
return [
|
|
startButtons,
|
|
endButtons
|
|
];
|
|
};
|
|
var renderFooter = function (initSpec, backstage) {
|
|
var updateState = function (_comp, data) {
|
|
var footerButtons = map(data.buttons, function (button) {
|
|
var memButton = record(makeButton(button, backstage));
|
|
return {
|
|
name: button.name,
|
|
align: button.align,
|
|
memento: memButton
|
|
};
|
|
});
|
|
var lookupByName = function (compInSystem, buttonName) {
|
|
return lookup$2(compInSystem, footerButtons, buttonName);
|
|
};
|
|
return Option.some({
|
|
lookupByName: lookupByName,
|
|
footerButtons: footerButtons
|
|
});
|
|
};
|
|
return {
|
|
dom: fromHtml$2('<div class="tox-dialog__footer"></div>'),
|
|
components: [],
|
|
behaviours: derive$1([Reflecting.config({
|
|
channel: footerChannel,
|
|
initialData: initSpec,
|
|
updateState: updateState,
|
|
renderComponents: renderComponents
|
|
})])
|
|
};
|
|
};
|
|
var renderInlineFooter = function (initSpec, backstage) {
|
|
return renderFooter(initSpec, backstage);
|
|
};
|
|
var renderModalFooter = function (initSpec, backstage) {
|
|
return ModalDialog.parts().footer(renderFooter(initSpec, backstage));
|
|
};
|
|
|
|
var getCompByName = function (access, name) {
|
|
var root = access.getRoot();
|
|
if (root.getSystem().isConnected()) {
|
|
var form_1 = Composing.getCurrent(access.getFormWrapper()).getOr(access.getFormWrapper());
|
|
return Form.getField(form_1, name).fold(function () {
|
|
var footer = access.getFooter();
|
|
var footerState = Reflecting.getState(footer);
|
|
return footerState.get().bind(function (f) {
|
|
return f.lookupByName(form_1, name);
|
|
});
|
|
}, function (comp) {
|
|
return Option.some(comp);
|
|
});
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
};
|
|
var validateData = function (access, data) {
|
|
var root = access.getRoot();
|
|
return Reflecting.getState(root).get().map(function (dialogState) {
|
|
return getOrDie(asRaw('data', dialogState.dataValidator, data));
|
|
}).getOr(data);
|
|
};
|
|
var getDialogApi = function (access, doRedial, menuItemStates) {
|
|
var withRoot = function (f) {
|
|
var root = access.getRoot();
|
|
if (root.getSystem().isConnected()) {
|
|
f(root);
|
|
}
|
|
};
|
|
var getData = function () {
|
|
var root = access.getRoot();
|
|
var valueComp = root.getSystem().isConnected() ? access.getFormWrapper() : root;
|
|
var representedValues = Representing.getValue(valueComp);
|
|
var menuItemCurrentState = map$1(menuItemStates, function (cell) {
|
|
return cell.get();
|
|
});
|
|
return __assign(__assign({}, representedValues), menuItemCurrentState);
|
|
};
|
|
var setData = function (newData) {
|
|
withRoot(function (_) {
|
|
var prevData = instanceApi.getData();
|
|
var mergedData = __assign(__assign({}, prevData), newData);
|
|
var newInternalData = validateData(access, mergedData);
|
|
var form = access.getFormWrapper();
|
|
Representing.setValue(form, newInternalData);
|
|
each$1(menuItemStates, function (v, k) {
|
|
if (has(mergedData, k)) {
|
|
v.set(mergedData[k]);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
var disable = function (name) {
|
|
getCompByName(access, name).each(Disabling.disable);
|
|
};
|
|
var enable = function (name) {
|
|
getCompByName(access, name).each(Disabling.enable);
|
|
};
|
|
var focus = function (name) {
|
|
getCompByName(access, name).each(Focusing.focus);
|
|
};
|
|
var block = function (message) {
|
|
if (!isString(message)) {
|
|
throw new Error('The dialogInstanceAPI.block function should be passed a blocking message of type string as an argument');
|
|
}
|
|
withRoot(function (root) {
|
|
emitWith(root, formBlockEvent, { message: message });
|
|
});
|
|
};
|
|
var unblock = function () {
|
|
withRoot(function (root) {
|
|
emit(root, formUnblockEvent);
|
|
});
|
|
};
|
|
var showTab = function (name) {
|
|
withRoot(function (_) {
|
|
var body = access.getBody();
|
|
var bodyState = Reflecting.getState(body);
|
|
if (bodyState.get().exists(function (b) {
|
|
return b.isTabPanel();
|
|
})) {
|
|
Composing.getCurrent(body).each(function (tabSection) {
|
|
TabSection.showTab(tabSection, name);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var redial = function (d) {
|
|
withRoot(function (root) {
|
|
var dialogInit = doRedial(d);
|
|
root.getSystem().broadcastOn([dialogChannel], dialogInit);
|
|
root.getSystem().broadcastOn([titleChannel], dialogInit.internalDialog);
|
|
root.getSystem().broadcastOn([bodyChannel], dialogInit.internalDialog);
|
|
root.getSystem().broadcastOn([footerChannel], dialogInit.internalDialog);
|
|
instanceApi.setData(dialogInit.initialData);
|
|
});
|
|
};
|
|
var close = function () {
|
|
withRoot(function (root) {
|
|
emit(root, formCloseEvent);
|
|
});
|
|
};
|
|
var instanceApi = {
|
|
getData: getData,
|
|
setData: setData,
|
|
disable: disable,
|
|
enable: enable,
|
|
focus: focus,
|
|
block: block,
|
|
unblock: unblock,
|
|
showTab: showTab,
|
|
redial: redial,
|
|
close: close
|
|
};
|
|
return instanceApi;
|
|
};
|
|
|
|
var renderDialog$1 = function (dialogInit, extra, backstage) {
|
|
var header = getHeader(dialogInit.internalDialog.title, backstage);
|
|
var body = renderModalBody({ body: dialogInit.internalDialog.body }, backstage);
|
|
var storagedMenuButtons = mapMenuButtons(dialogInit.internalDialog.buttons);
|
|
var objOfCells = extractCellsToObject(storagedMenuButtons);
|
|
var footer = renderModalFooter({ buttons: storagedMenuButtons }, backstage);
|
|
var dialogEvents = SilverDialogEvents.initDialog(function () {
|
|
return instanceApi;
|
|
}, getEventExtras(function () {
|
|
return dialog;
|
|
}, extra), backstage.shared.getSink);
|
|
var dialogSize = dialogInit.internalDialog.size !== 'normal' ? dialogInit.internalDialog.size === 'large' ? ['tox-dialog--width-lg'] : ['tox-dialog--width-md'] : [];
|
|
var spec = {
|
|
header: header,
|
|
body: body,
|
|
footer: Option.some(footer),
|
|
extraClasses: dialogSize,
|
|
extraBehaviours: [],
|
|
extraStyles: {}
|
|
};
|
|
var dialog = renderModalDialog(spec, dialogInit, dialogEvents, backstage);
|
|
var modalAccess = function () {
|
|
var getForm = function () {
|
|
var outerForm = ModalDialog.getBody(dialog);
|
|
return Composing.getCurrent(outerForm).getOr(outerForm);
|
|
};
|
|
return {
|
|
getRoot: function () {
|
|
return dialog;
|
|
},
|
|
getBody: function () {
|
|
return ModalDialog.getBody(dialog);
|
|
},
|
|
getFooter: function () {
|
|
return ModalDialog.getFooter(dialog);
|
|
},
|
|
getFormWrapper: getForm
|
|
};
|
|
}();
|
|
var instanceApi = getDialogApi(modalAccess, extra.redial, objOfCells);
|
|
return {
|
|
dialog: dialog,
|
|
instanceApi: instanceApi
|
|
};
|
|
};
|
|
|
|
var renderInlineDialog = function (dialogInit, extra, backstage, ariaAttrs) {
|
|
var _a, _b;
|
|
var dialogLabelId = generate$1('dialog-label');
|
|
var dialogContentId = generate$1('dialog-content');
|
|
var updateState = function (_comp, incoming) {
|
|
return Option.some(incoming);
|
|
};
|
|
var memHeader = record(renderInlineHeader({
|
|
title: dialogInit.internalDialog.title,
|
|
draggable: true
|
|
}, dialogLabelId, backstage.shared.providers));
|
|
var memBody = record(renderInlineBody({ body: dialogInit.internalDialog.body }, dialogContentId, backstage, ariaAttrs));
|
|
var storagedMenuButtons = mapMenuButtons(dialogInit.internalDialog.buttons);
|
|
var objOfCells = extractCellsToObject(storagedMenuButtons);
|
|
var memFooter = record(renderInlineFooter({ buttons: storagedMenuButtons }, backstage));
|
|
var dialogEvents = SilverDialogEvents.initDialog(function () {
|
|
return instanceApi;
|
|
}, {
|
|
onBlock: function () {
|
|
},
|
|
onUnblock: function () {
|
|
},
|
|
onClose: function () {
|
|
return extra.closeWindow();
|
|
}
|
|
}, backstage.shared.getSink);
|
|
var dialog = build$1({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
'tox-dialog',
|
|
'tox-dialog-inline'
|
|
],
|
|
attributes: (_a = { role: 'dialog' }, _a['aria-labelledby'] = dialogLabelId, _a['aria-describedby'] = '' + dialogContentId, _a)
|
|
},
|
|
eventOrder: (_b = {}, _b[receive()] = [
|
|
Reflecting.name(),
|
|
Receiving.name()
|
|
], _b[execute()] = ['execute-on-form'], _b[attachedToDom()] = [
|
|
'reflecting',
|
|
'execute-on-form'
|
|
], _b),
|
|
behaviours: derive$1([
|
|
Keying.config({
|
|
mode: 'cyclic',
|
|
onEscape: function (c) {
|
|
emit(c, formCloseEvent);
|
|
return Option.some(true);
|
|
},
|
|
useTabstopAt: function (elem) {
|
|
return !isPseudoStop(elem) && (name(elem) !== 'button' || get$2(elem, 'disabled') !== 'disabled');
|
|
}
|
|
}),
|
|
Reflecting.config({
|
|
channel: dialogChannel,
|
|
updateState: updateState,
|
|
initialData: dialogInit
|
|
}),
|
|
Focusing.config({}),
|
|
config('execute-on-form', dialogEvents.concat([runOnSource(focusin(), function (comp, _se) {
|
|
Keying.focusIn(comp);
|
|
})])),
|
|
RepresentingConfigs.memory({})
|
|
]),
|
|
components: [
|
|
memHeader.asSpec(),
|
|
memBody.asSpec(),
|
|
memFooter.asSpec()
|
|
]
|
|
});
|
|
var instanceApi = getDialogApi({
|
|
getRoot: function () {
|
|
return dialog;
|
|
},
|
|
getFooter: function () {
|
|
return memFooter.get(dialog);
|
|
},
|
|
getBody: function () {
|
|
return memBody.get(dialog);
|
|
},
|
|
getFormWrapper: function () {
|
|
var body = memBody.get(dialog);
|
|
return Composing.getCurrent(body).getOr(body);
|
|
}
|
|
}, extra.redial, objOfCells);
|
|
return {
|
|
dialog: dialog,
|
|
instanceApi: instanceApi
|
|
};
|
|
};
|
|
|
|
var global$g = tinymce.util.Tools.resolve('tinymce.util.URI');
|
|
|
|
var getUrlDialogApi = function (root) {
|
|
var withRoot = function (f) {
|
|
if (root.getSystem().isConnected()) {
|
|
f(root);
|
|
}
|
|
};
|
|
var block = function (message) {
|
|
if (!isString(message)) {
|
|
throw new Error('The urlDialogInstanceAPI.block function should be passed a blocking message of type string as an argument');
|
|
}
|
|
withRoot(function (root) {
|
|
emitWith(root, formBlockEvent, { message: message });
|
|
});
|
|
};
|
|
var unblock = function () {
|
|
withRoot(function (root) {
|
|
emit(root, formUnblockEvent);
|
|
});
|
|
};
|
|
var close = function () {
|
|
withRoot(function (root) {
|
|
emit(root, formCloseEvent);
|
|
});
|
|
};
|
|
var sendMessage = function (data) {
|
|
withRoot(function (root) {
|
|
root.getSystem().broadcastOn([bodySendMessageChannel], data);
|
|
});
|
|
};
|
|
return {
|
|
block: block,
|
|
unblock: unblock,
|
|
close: close,
|
|
sendMessage: sendMessage
|
|
};
|
|
};
|
|
|
|
var SUPPORTED_MESSAGE_ACTIONS = [
|
|
'insertContent',
|
|
'setContent',
|
|
'execCommand',
|
|
'close',
|
|
'block',
|
|
'unblock'
|
|
];
|
|
var isSupportedMessage = function (data) {
|
|
return isObject(data) && SUPPORTED_MESSAGE_ACTIONS.indexOf(data.mceAction) !== -1;
|
|
};
|
|
var isCustomMessage = function (data) {
|
|
return !isSupportedMessage(data) && isObject(data) && has(data, 'mceAction');
|
|
};
|
|
var handleMessage = function (editor, api, data) {
|
|
switch (data.mceAction) {
|
|
case 'insertContent':
|
|
editor.insertContent(data.content);
|
|
break;
|
|
case 'setContent':
|
|
editor.setContent(data.content);
|
|
break;
|
|
case 'execCommand':
|
|
var ui = isBoolean(data.ui) ? data.ui : false;
|
|
editor.execCommand(data.cmd, ui, data.value);
|
|
break;
|
|
case 'close':
|
|
api.close();
|
|
break;
|
|
case 'block':
|
|
api.block(data.message);
|
|
break;
|
|
case 'unblock':
|
|
api.unblock();
|
|
break;
|
|
}
|
|
};
|
|
var renderUrlDialog = function (internalDialog, extra, editor, backstage) {
|
|
var _a;
|
|
var header = getHeader(internalDialog.title, backstage);
|
|
var body = renderIframeBody(internalDialog);
|
|
var footer = internalDialog.buttons.bind(function (buttons) {
|
|
if (buttons.length === 0) {
|
|
return Option.none();
|
|
} else {
|
|
return Option.some(renderModalFooter({ buttons: buttons }, backstage));
|
|
}
|
|
});
|
|
var dialogEvents = SilverDialogEvents.initUrlDialog(function () {
|
|
return instanceApi;
|
|
}, getEventExtras(function () {
|
|
return dialog;
|
|
}, extra));
|
|
var styles = __assign(__assign({}, internalDialog.height.fold(function () {
|
|
return {};
|
|
}, function (height) {
|
|
return {
|
|
'height': height + 'px',
|
|
'max-height': height + 'px'
|
|
};
|
|
})), internalDialog.width.fold(function () {
|
|
return {};
|
|
}, function (width) {
|
|
return {
|
|
'width': width + 'px',
|
|
'max-width': width + 'px'
|
|
};
|
|
}));
|
|
var classes = internalDialog.width.isNone() && internalDialog.height.isNone() ? ['tox-dialog--width-lg'] : [];
|
|
var iframeUri = new global$g(internalDialog.url, { base_uri: new global$g(domGlobals.window.location.href) });
|
|
var iframeDomain = iframeUri.protocol + '://' + iframeUri.host + (iframeUri.port ? ':' + iframeUri.port : '');
|
|
var messageHandlerUnbinder = Cell(Option.none());
|
|
var extraBehaviours = [
|
|
config('messages', [
|
|
runOnAttached(function () {
|
|
var unbind = bind$3(Element.fromDom(domGlobals.window), 'message', function (e) {
|
|
if (iframeUri.isSameOrigin(new global$g(e.raw().origin))) {
|
|
var data = e.raw().data;
|
|
if (isSupportedMessage(data)) {
|
|
handleMessage(editor, instanceApi, data);
|
|
} else if (isCustomMessage(data)) {
|
|
internalDialog.onMessage(instanceApi, data);
|
|
}
|
|
}
|
|
});
|
|
messageHandlerUnbinder.set(Option.some(unbind));
|
|
}),
|
|
runOnDetached(function () {
|
|
messageHandlerUnbinder.get().each(function (unbinder) {
|
|
return unbinder.unbind();
|
|
});
|
|
})
|
|
]),
|
|
Receiving.config({
|
|
channels: (_a = {}, _a[bodySendMessageChannel] = {
|
|
onReceive: function (comp, data) {
|
|
descendant$1(comp.element(), 'iframe').each(function (iframeEle) {
|
|
var iframeWin = iframeEle.dom().contentWindow;
|
|
iframeWin.postMessage(data, iframeDomain);
|
|
});
|
|
}
|
|
}, _a)
|
|
})
|
|
];
|
|
var spec = {
|
|
header: header,
|
|
body: body,
|
|
footer: footer,
|
|
extraClasses: classes,
|
|
extraBehaviours: extraBehaviours,
|
|
extraStyles: styles
|
|
};
|
|
var dialog = renderModalDialog(spec, internalDialog, dialogEvents, backstage);
|
|
var instanceApi = getUrlDialogApi(dialog);
|
|
return {
|
|
dialog: dialog,
|
|
instanceApi: instanceApi
|
|
};
|
|
};
|
|
|
|
var setup$c = function (extras) {
|
|
var sharedBackstage = extras.backstage.shared;
|
|
var open = function (message, callback) {
|
|
var closeDialog = function () {
|
|
ModalDialog.hide(alertDialog);
|
|
callback();
|
|
};
|
|
var memFooterClose = record(renderFooterButton({
|
|
name: 'close-alert',
|
|
text: 'OK',
|
|
primary: true,
|
|
align: 'end',
|
|
disabled: false,
|
|
icon: Option.none()
|
|
}, 'cancel', extras.backstage));
|
|
var titleSpec = pUntitled();
|
|
var closeSpec = pClose(closeDialog, sharedBackstage.providers);
|
|
var alertDialog = build$1(renderDialog({
|
|
lazySink: function () {
|
|
return sharedBackstage.getSink();
|
|
},
|
|
header: hiddenHeader(titleSpec, closeSpec),
|
|
body: pBodyMessage(message, sharedBackstage.providers),
|
|
footer: Option.some(pFooter(pFooterGroup([], [memFooterClose.asSpec()]))),
|
|
onEscape: closeDialog,
|
|
extraClasses: ['tox-alert-dialog'],
|
|
extraBehaviours: [],
|
|
extraStyles: {},
|
|
dialogEvents: [run(formCancelEvent, closeDialog)],
|
|
eventOrder: {}
|
|
}));
|
|
ModalDialog.show(alertDialog);
|
|
var footerCloseButton = memFooterClose.get(alertDialog);
|
|
Focusing.focus(footerCloseButton);
|
|
};
|
|
return { open: open };
|
|
};
|
|
|
|
var setup$d = function (extras) {
|
|
var sharedBackstage = extras.backstage.shared;
|
|
var open = function (message, callback) {
|
|
var closeDialog = function (state) {
|
|
ModalDialog.hide(confirmDialog);
|
|
callback(state);
|
|
};
|
|
var memFooterYes = record(renderFooterButton({
|
|
name: 'yes',
|
|
text: 'Yes',
|
|
primary: true,
|
|
align: 'end',
|
|
disabled: false,
|
|
icon: Option.none()
|
|
}, 'submit', extras.backstage));
|
|
var footerNo = renderFooterButton({
|
|
name: 'no',
|
|
text: 'No',
|
|
primary: false,
|
|
align: 'end',
|
|
disabled: false,
|
|
icon: Option.none()
|
|
}, 'cancel', extras.backstage);
|
|
var titleSpec = pUntitled();
|
|
var closeSpec = pClose(function () {
|
|
return closeDialog(false);
|
|
}, sharedBackstage.providers);
|
|
var confirmDialog = build$1(renderDialog({
|
|
lazySink: function () {
|
|
return sharedBackstage.getSink();
|
|
},
|
|
header: hiddenHeader(titleSpec, closeSpec),
|
|
body: pBodyMessage(message, sharedBackstage.providers),
|
|
footer: Option.some(pFooter(pFooterGroup([], [
|
|
footerNo,
|
|
memFooterYes.asSpec()
|
|
]))),
|
|
onEscape: function () {
|
|
return closeDialog(false);
|
|
},
|
|
extraClasses: ['tox-confirm-dialog'],
|
|
extraBehaviours: [],
|
|
extraStyles: {},
|
|
dialogEvents: [
|
|
run(formCancelEvent, function () {
|
|
return closeDialog(false);
|
|
}),
|
|
run(formSubmitEvent, function () {
|
|
return closeDialog(true);
|
|
})
|
|
],
|
|
eventOrder: {}
|
|
}));
|
|
ModalDialog.show(confirmDialog);
|
|
var footerYesButton = memFooterYes.get(confirmDialog);
|
|
Focusing.focus(footerYesButton);
|
|
};
|
|
return { open: open };
|
|
};
|
|
|
|
var validateData$1 = function (data, validator) {
|
|
return getOrDie(asRaw('data', validator, data));
|
|
};
|
|
var isAlertOrConfirmDialog = function (target) {
|
|
return closest$4(target, '.tox-alert-dialog') || closest$4(target, '.tox-confirm-dialog');
|
|
};
|
|
var inlineAdditionalBehaviours = function (editor, isStickyToolbar, isToolbarLocationTop) {
|
|
if (isStickyToolbar && isToolbarLocationTop) {
|
|
return [];
|
|
} else {
|
|
return [Docking.config({
|
|
contextual: {
|
|
lazyContext: function () {
|
|
return Option.some(box(Element.fromDom(editor.getContentAreaContainer())));
|
|
},
|
|
fadeInClass: 'tox-dialog-dock-fadein',
|
|
fadeOutClass: 'tox-dialog-dock-fadeout',
|
|
transitionClass: 'tox-dialog-dock-transition'
|
|
},
|
|
modes: ['top']
|
|
})];
|
|
}
|
|
};
|
|
var setup$e = function (extras) {
|
|
var backstage = extras.backstage;
|
|
var editor = extras.editor;
|
|
var isStickyToolbar$1 = isStickyToolbar(editor);
|
|
var alertDialog = setup$c(extras);
|
|
var confirmDialog = setup$d(extras);
|
|
var open = function (config, params, closeWindow) {
|
|
if (params !== undefined && params.inline === 'toolbar') {
|
|
return openInlineDialog(config, backstage.shared.anchors.inlineDialog(), closeWindow, params.ariaAttrs);
|
|
} else if (params !== undefined && params.inline === 'cursor') {
|
|
return openInlineDialog(config, backstage.shared.anchors.cursor(), closeWindow, params.ariaAttrs);
|
|
} else {
|
|
return openModalDialog(config, closeWindow);
|
|
}
|
|
};
|
|
var openUrl = function (config, closeWindow) {
|
|
return openModalUrlDialog(config, closeWindow);
|
|
};
|
|
var openModalUrlDialog = function (config, closeWindow) {
|
|
var factory = function (contents) {
|
|
var dialog = renderUrlDialog(contents, {
|
|
closeWindow: function () {
|
|
ModalDialog.hide(dialog.dialog);
|
|
closeWindow(dialog.instanceApi);
|
|
}
|
|
}, editor, backstage);
|
|
ModalDialog.show(dialog.dialog);
|
|
return dialog.instanceApi;
|
|
};
|
|
return DialogManager.openUrl(factory, config);
|
|
};
|
|
var openModalDialog = function (config, closeWindow) {
|
|
var factory = function (contents, internalInitialData, dataValidator) {
|
|
var initialData = internalInitialData;
|
|
var dialogInit = {
|
|
dataValidator: dataValidator,
|
|
initialData: initialData,
|
|
internalDialog: contents
|
|
};
|
|
var dialog = renderDialog$1(dialogInit, {
|
|
redial: DialogManager.redial,
|
|
closeWindow: function () {
|
|
ModalDialog.hide(dialog.dialog);
|
|
closeWindow(dialog.instanceApi);
|
|
}
|
|
}, backstage);
|
|
ModalDialog.show(dialog.dialog);
|
|
dialog.instanceApi.setData(initialData);
|
|
return dialog.instanceApi;
|
|
};
|
|
return DialogManager.open(factory, config);
|
|
};
|
|
var openInlineDialog = function (config$1, anchor, closeWindow, ariaAttrs) {
|
|
var factory = function (contents, internalInitialData, dataValidator) {
|
|
var initialData = validateData$1(internalInitialData, dataValidator);
|
|
var inlineDialog = value$3();
|
|
var isToolbarLocationTop = backstage.shared.header.isPositionedAtTop();
|
|
var dialogInit = {
|
|
dataValidator: dataValidator,
|
|
initialData: initialData,
|
|
internalDialog: contents
|
|
};
|
|
var refreshDocking = function () {
|
|
return inlineDialog.on(function (dialog) {
|
|
InlineView.reposition(dialog);
|
|
Docking.refresh(dialog);
|
|
});
|
|
};
|
|
var dialogUi = renderInlineDialog(dialogInit, {
|
|
redial: DialogManager.redial,
|
|
closeWindow: function () {
|
|
inlineDialog.on(InlineView.hide);
|
|
editor.off('ResizeEditor', refreshDocking);
|
|
inlineDialog.clear();
|
|
closeWindow(dialogUi.instanceApi);
|
|
}
|
|
}, backstage, ariaAttrs);
|
|
var inlineDialogComp = build$1(InlineView.sketch(__assign(__assign({
|
|
lazySink: backstage.shared.getSink,
|
|
dom: {
|
|
tag: 'div',
|
|
classes: []
|
|
},
|
|
fireDismissalEventInstead: {}
|
|
}, isToolbarLocationTop ? {} : { fireRepositionEventInstead: {} }), {
|
|
inlineBehaviours: derive$1(__spreadArrays([config('window-manager-inline-events', [run(dismissRequested(), function (_comp, _se) {
|
|
emit(dialogUi.dialog, formCancelEvent);
|
|
})])], inlineAdditionalBehaviours(editor, isStickyToolbar$1, isToolbarLocationTop))),
|
|
isExtraPart: function (_comp, target) {
|
|
return isAlertOrConfirmDialog(target);
|
|
}
|
|
})));
|
|
inlineDialog.set(inlineDialogComp);
|
|
InlineView.showWithin(inlineDialogComp, anchor, premade$1(dialogUi.dialog), Option.some(body()));
|
|
if (!isStickyToolbar$1 || !isToolbarLocationTop) {
|
|
Docking.refresh(inlineDialogComp);
|
|
editor.on('ResizeEditor', refreshDocking);
|
|
}
|
|
dialogUi.instanceApi.setData(initialData);
|
|
Keying.focusIn(dialogUi.dialog);
|
|
return dialogUi.instanceApi;
|
|
};
|
|
return DialogManager.open(factory, config$1);
|
|
};
|
|
var confirm = function (message, callback) {
|
|
confirmDialog.open(message, function (state) {
|
|
callback(state);
|
|
});
|
|
};
|
|
var alert = function (message, callback) {
|
|
alertDialog.open(message, function () {
|
|
callback();
|
|
});
|
|
};
|
|
var close = function (instanceApi) {
|
|
instanceApi.close();
|
|
};
|
|
return {
|
|
open: open,
|
|
openUrl: openUrl,
|
|
alert: alert,
|
|
close: close,
|
|
confirm: confirm
|
|
};
|
|
};
|
|
|
|
function Theme () {
|
|
global$1.add('silver', function (editor) {
|
|
var _a = setup$b(editor), uiMothership = _a.uiMothership, backstage = _a.backstage, renderUI = _a.renderUI, getUi = _a.getUi;
|
|
Autocompleter.register(editor, backstage.shared);
|
|
var windowMgr = setup$e({
|
|
editor: editor,
|
|
backstage: backstage
|
|
});
|
|
return {
|
|
renderUI: renderUI,
|
|
getWindowManagerImpl: constant(windowMgr),
|
|
getNotificationManagerImpl: function () {
|
|
return NotificationManagerImpl(editor, { backstage: backstage }, uiMothership);
|
|
},
|
|
ui: getUi()
|
|
};
|
|
});
|
|
}
|
|
|
|
Theme();
|
|
|
|
}(window));
|
|
|
|
/**
|
|
* Copyright (c) Tiny Technologies, Inc. All rights reserved.
|
|
* Licensed under the LGPL or a commercial license.
|
|
* For LGPL see License.txt in the project root for license information.
|
|
* For commercial licenses see https://www.tiny.cloud/
|
|
*
|
|
* Version: 5.3.1 (2020-05-27)
|
|
*/
|
|
(function (domGlobals) {
|
|
'use strict';
|
|
|
|
var __assign = function () {
|
|
__assign = Object.assign || function __assign(t) {
|
|
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
s = arguments[i];
|
|
for (var p in s)
|
|
if (Object.prototype.hasOwnProperty.call(s, p))
|
|
t[p] = s[p];
|
|
}
|
|
return t;
|
|
};
|
|
return __assign.apply(this, arguments);
|
|
};
|
|
function __rest(s, e) {
|
|
var t = {};
|
|
for (var p in s)
|
|
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
t[p] = s[p];
|
|
if (s != null && typeof Object.getOwnPropertySymbols === 'function')
|
|
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
t[p[i]] = s[p[i]];
|
|
}
|
|
return t;
|
|
}
|
|
function __spreadArrays() {
|
|
for (var s = 0, i = 0, il = arguments.length; i < il; i++)
|
|
s += arguments[i].length;
|
|
for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
|
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
|
r[k] = a[j];
|
|
return r;
|
|
}
|
|
|
|
var noop = function () {
|
|
};
|
|
var compose = function (fa, fb) {
|
|
return function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
return fa(fb.apply(null, args));
|
|
};
|
|
};
|
|
var constant = function (value) {
|
|
return function () {
|
|
return value;
|
|
};
|
|
};
|
|
var identity = function (x) {
|
|
return x;
|
|
};
|
|
function curry(fn) {
|
|
var initialArgs = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
initialArgs[_i - 1] = arguments[_i];
|
|
}
|
|
return function () {
|
|
var restArgs = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
restArgs[_i] = arguments[_i];
|
|
}
|
|
var all = initialArgs.concat(restArgs);
|
|
return fn.apply(null, all);
|
|
};
|
|
}
|
|
var not = function (f) {
|
|
return function (t) {
|
|
return !f(t);
|
|
};
|
|
};
|
|
var die = function (msg) {
|
|
return function () {
|
|
throw new Error(msg);
|
|
};
|
|
};
|
|
var apply = function (f) {
|
|
return f();
|
|
};
|
|
var never = constant(false);
|
|
var always = constant(true);
|
|
|
|
var none = function () {
|
|
return NONE;
|
|
};
|
|
var NONE = function () {
|
|
var eq = function (o) {
|
|
return o.isNone();
|
|
};
|
|
var call = function (thunk) {
|
|
return thunk();
|
|
};
|
|
var id = function (n) {
|
|
return n;
|
|
};
|
|
var me = {
|
|
fold: function (n, _s) {
|
|
return n();
|
|
},
|
|
is: never,
|
|
isSome: never,
|
|
isNone: always,
|
|
getOr: id,
|
|
getOrThunk: call,
|
|
getOrDie: function (msg) {
|
|
throw new Error(msg || 'error: getOrDie called on none.');
|
|
},
|
|
getOrNull: constant(null),
|
|
getOrUndefined: constant(undefined),
|
|
or: id,
|
|
orThunk: call,
|
|
map: none,
|
|
each: noop,
|
|
bind: none,
|
|
exists: never,
|
|
forall: always,
|
|
filter: none,
|
|
equals: eq,
|
|
equals_: eq,
|
|
toArray: function () {
|
|
return [];
|
|
},
|
|
toString: constant('none()')
|
|
};
|
|
return me;
|
|
}();
|
|
var some = function (a) {
|
|
var constant_a = constant(a);
|
|
var self = function () {
|
|
return me;
|
|
};
|
|
var bind = function (f) {
|
|
return f(a);
|
|
};
|
|
var me = {
|
|
fold: function (n, s) {
|
|
return s(a);
|
|
},
|
|
is: function (v) {
|
|
return a === v;
|
|
},
|
|
isSome: always,
|
|
isNone: never,
|
|
getOr: constant_a,
|
|
getOrThunk: constant_a,
|
|
getOrDie: constant_a,
|
|
getOrNull: constant_a,
|
|
getOrUndefined: constant_a,
|
|
or: self,
|
|
orThunk: self,
|
|
map: function (f) {
|
|
return some(f(a));
|
|
},
|
|
each: function (f) {
|
|
f(a);
|
|
},
|
|
bind: bind,
|
|
exists: bind,
|
|
forall: bind,
|
|
filter: function (f) {
|
|
return f(a) ? me : NONE;
|
|
},
|
|
toArray: function () {
|
|
return [a];
|
|
},
|
|
toString: function () {
|
|
return 'some(' + a + ')';
|
|
},
|
|
equals: function (o) {
|
|
return o.is(a);
|
|
},
|
|
equals_: function (o, elementEq) {
|
|
return o.fold(never, function (b) {
|
|
return elementEq(a, b);
|
|
});
|
|
}
|
|
};
|
|
return me;
|
|
};
|
|
var from = function (value) {
|
|
return value === null || value === undefined ? NONE : some(value);
|
|
};
|
|
var Option = {
|
|
some: some,
|
|
none: none,
|
|
from: from
|
|
};
|
|
|
|
var keys = Object.keys;
|
|
var hasOwnProperty = Object.hasOwnProperty;
|
|
var each = function (obj, f) {
|
|
var props = keys(obj);
|
|
for (var k = 0, len = props.length; k < len; k++) {
|
|
var i = props[k];
|
|
var x = obj[i];
|
|
f(x, i);
|
|
}
|
|
};
|
|
var map = function (obj, f) {
|
|
return tupleMap(obj, function (x, i) {
|
|
return {
|
|
k: i,
|
|
v: f(x, i)
|
|
};
|
|
});
|
|
};
|
|
var tupleMap = function (obj, f) {
|
|
var r = {};
|
|
each(obj, function (x, i) {
|
|
var tuple = f(x, i);
|
|
r[tuple.k] = tuple.v;
|
|
});
|
|
return r;
|
|
};
|
|
var objAcc = function (r) {
|
|
return function (x, i) {
|
|
r[i] = x;
|
|
};
|
|
};
|
|
var internalFilter = function (obj, pred, onTrue, onFalse) {
|
|
var r = {};
|
|
each(obj, function (x, i) {
|
|
(pred(x, i) ? onTrue : onFalse)(x, i);
|
|
});
|
|
return r;
|
|
};
|
|
var filter = function (obj, pred) {
|
|
var t = {};
|
|
internalFilter(obj, pred, objAcc(t), noop);
|
|
return t;
|
|
};
|
|
var mapToArray = function (obj, f) {
|
|
var r = [];
|
|
each(obj, function (value, name) {
|
|
r.push(f(value, name));
|
|
});
|
|
return r;
|
|
};
|
|
var find = function (obj, pred) {
|
|
var props = keys(obj);
|
|
for (var k = 0, len = props.length; k < len; k++) {
|
|
var i = props[k];
|
|
var x = obj[i];
|
|
if (pred(x, i, obj)) {
|
|
return Option.some(x);
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var values = function (obj) {
|
|
return mapToArray(obj, function (v) {
|
|
return v;
|
|
});
|
|
};
|
|
var get = function (obj, key) {
|
|
return has(obj, key) ? Option.from(obj[key]) : Option.none();
|
|
};
|
|
var has = function (obj, key) {
|
|
return hasOwnProperty.call(obj, key);
|
|
};
|
|
var hasNonNullableKey = function (obj, key) {
|
|
return has(obj, key) && obj[key] !== undefined && obj[key] !== null;
|
|
};
|
|
|
|
var cached = function (f) {
|
|
var called = false;
|
|
var r;
|
|
return function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
if (!called) {
|
|
called = true;
|
|
r = f.apply(null, args);
|
|
}
|
|
return r;
|
|
};
|
|
};
|
|
|
|
var firstMatch = function (regexes, s) {
|
|
for (var i = 0; i < regexes.length; i++) {
|
|
var x = regexes[i];
|
|
if (x.test(s)) {
|
|
return x;
|
|
}
|
|
}
|
|
return undefined;
|
|
};
|
|
var find$1 = function (regexes, agent) {
|
|
var r = firstMatch(regexes, agent);
|
|
if (!r) {
|
|
return {
|
|
major: 0,
|
|
minor: 0
|
|
};
|
|
}
|
|
var group = function (i) {
|
|
return Number(agent.replace(r, '$' + i));
|
|
};
|
|
return nu(group(1), group(2));
|
|
};
|
|
var detect = function (versionRegexes, agent) {
|
|
var cleanedAgent = String(agent).toLowerCase();
|
|
if (versionRegexes.length === 0) {
|
|
return unknown();
|
|
}
|
|
return find$1(versionRegexes, cleanedAgent);
|
|
};
|
|
var unknown = function () {
|
|
return nu(0, 0);
|
|
};
|
|
var nu = function (major, minor) {
|
|
return {
|
|
major: major,
|
|
minor: minor
|
|
};
|
|
};
|
|
var Version = {
|
|
nu: nu,
|
|
detect: detect,
|
|
unknown: unknown
|
|
};
|
|
|
|
var edge = 'Edge';
|
|
var chrome = 'Chrome';
|
|
var ie = 'IE';
|
|
var opera = 'Opera';
|
|
var firefox = 'Firefox';
|
|
var safari = 'Safari';
|
|
var unknown$1 = function () {
|
|
return nu$1({
|
|
current: undefined,
|
|
version: Version.unknown()
|
|
});
|
|
};
|
|
var nu$1 = function (info) {
|
|
var current = info.current;
|
|
var version = info.version;
|
|
var isBrowser = function (name) {
|
|
return function () {
|
|
return current === name;
|
|
};
|
|
};
|
|
return {
|
|
current: current,
|
|
version: version,
|
|
isEdge: isBrowser(edge),
|
|
isChrome: isBrowser(chrome),
|
|
isIE: isBrowser(ie),
|
|
isOpera: isBrowser(opera),
|
|
isFirefox: isBrowser(firefox),
|
|
isSafari: isBrowser(safari)
|
|
};
|
|
};
|
|
var Browser = {
|
|
unknown: unknown$1,
|
|
nu: nu$1,
|
|
edge: constant(edge),
|
|
chrome: constant(chrome),
|
|
ie: constant(ie),
|
|
opera: constant(opera),
|
|
firefox: constant(firefox),
|
|
safari: constant(safari)
|
|
};
|
|
|
|
var windows = 'Windows';
|
|
var ios = 'iOS';
|
|
var android = 'Android';
|
|
var linux = 'Linux';
|
|
var osx = 'OSX';
|
|
var solaris = 'Solaris';
|
|
var freebsd = 'FreeBSD';
|
|
var chromeos = 'ChromeOS';
|
|
var unknown$2 = function () {
|
|
return nu$2({
|
|
current: undefined,
|
|
version: Version.unknown()
|
|
});
|
|
};
|
|
var nu$2 = function (info) {
|
|
var current = info.current;
|
|
var version = info.version;
|
|
var isOS = function (name) {
|
|
return function () {
|
|
return current === name;
|
|
};
|
|
};
|
|
return {
|
|
current: current,
|
|
version: version,
|
|
isWindows: isOS(windows),
|
|
isiOS: isOS(ios),
|
|
isAndroid: isOS(android),
|
|
isOSX: isOS(osx),
|
|
isLinux: isOS(linux),
|
|
isSolaris: isOS(solaris),
|
|
isFreeBSD: isOS(freebsd),
|
|
isChromeOS: isOS(chromeos)
|
|
};
|
|
};
|
|
var OperatingSystem = {
|
|
unknown: unknown$2,
|
|
nu: nu$2,
|
|
windows: constant(windows),
|
|
ios: constant(ios),
|
|
android: constant(android),
|
|
linux: constant(linux),
|
|
osx: constant(osx),
|
|
solaris: constant(solaris),
|
|
freebsd: constant(freebsd),
|
|
chromeos: constant(chromeos)
|
|
};
|
|
|
|
var DeviceType = function (os, browser, userAgent, mediaMatch) {
|
|
var isiPad = os.isiOS() && /ipad/i.test(userAgent) === true;
|
|
var isiPhone = os.isiOS() && !isiPad;
|
|
var isMobile = os.isiOS() || os.isAndroid();
|
|
var isTouch = isMobile || mediaMatch('(pointer:coarse)');
|
|
var isTablet = isiPad || !isiPhone && isMobile && mediaMatch('(min-device-width:768px)');
|
|
var isPhone = isiPhone || isMobile && !isTablet;
|
|
var iOSwebview = browser.isSafari() && os.isiOS() && /safari/i.test(userAgent) === false;
|
|
var isDesktop = !isPhone && !isTablet && !iOSwebview;
|
|
return {
|
|
isiPad: constant(isiPad),
|
|
isiPhone: constant(isiPhone),
|
|
isTablet: constant(isTablet),
|
|
isPhone: constant(isPhone),
|
|
isTouch: constant(isTouch),
|
|
isAndroid: os.isAndroid,
|
|
isiOS: os.isiOS,
|
|
isWebView: constant(iOSwebview),
|
|
isDesktop: constant(isDesktop)
|
|
};
|
|
};
|
|
|
|
var typeOf = function (x) {
|
|
var t = typeof x;
|
|
if (x === null) {
|
|
return 'null';
|
|
} else if (t === 'object' && (Array.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'Array')) {
|
|
return 'array';
|
|
} else if (t === 'object' && (String.prototype.isPrototypeOf(x) || x.constructor && x.constructor.name === 'String')) {
|
|
return 'string';
|
|
} else {
|
|
return t;
|
|
}
|
|
};
|
|
var isType = function (type) {
|
|
return function (value) {
|
|
return typeOf(value) === type;
|
|
};
|
|
};
|
|
var isSimpleType = function (type) {
|
|
return function (value) {
|
|
return typeof value === type;
|
|
};
|
|
};
|
|
var isString = isType('string');
|
|
var isObject = isType('object');
|
|
var isArray = isType('array');
|
|
var isBoolean = isSimpleType('boolean');
|
|
var isFunction = isSimpleType('function');
|
|
var isNumber = isSimpleType('number');
|
|
|
|
var nativeSlice = Array.prototype.slice;
|
|
var nativeIndexOf = Array.prototype.indexOf;
|
|
var nativePush = Array.prototype.push;
|
|
var rawIndexOf = function (ts, t) {
|
|
return nativeIndexOf.call(ts, t);
|
|
};
|
|
var contains = function (xs, x) {
|
|
return rawIndexOf(xs, x) > -1;
|
|
};
|
|
var exists = function (xs, pred) {
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
if (pred(x, i)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
var map$1 = function (xs, f) {
|
|
var len = xs.length;
|
|
var r = new Array(len);
|
|
for (var i = 0; i < len; i++) {
|
|
var x = xs[i];
|
|
r[i] = f(x, i);
|
|
}
|
|
return r;
|
|
};
|
|
var each$1 = function (xs, f) {
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
f(x, i);
|
|
}
|
|
};
|
|
var eachr = function (xs, f) {
|
|
for (var i = xs.length - 1; i >= 0; i--) {
|
|
var x = xs[i];
|
|
f(x, i);
|
|
}
|
|
};
|
|
var filter$1 = function (xs, pred) {
|
|
var r = [];
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
if (pred(x, i)) {
|
|
r.push(x);
|
|
}
|
|
}
|
|
return r;
|
|
};
|
|
var foldr = function (xs, f, acc) {
|
|
eachr(xs, function (x) {
|
|
acc = f(acc, x);
|
|
});
|
|
return acc;
|
|
};
|
|
var foldl = function (xs, f, acc) {
|
|
each$1(xs, function (x) {
|
|
acc = f(acc, x);
|
|
});
|
|
return acc;
|
|
};
|
|
var findUntil = function (xs, pred, until) {
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
if (pred(x, i)) {
|
|
return Option.some(x);
|
|
} else if (until(x, i)) {
|
|
break;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var find$2 = function (xs, pred) {
|
|
return findUntil(xs, pred, never);
|
|
};
|
|
var findIndex = function (xs, pred) {
|
|
for (var i = 0, len = xs.length; i < len; i++) {
|
|
var x = xs[i];
|
|
if (pred(x, i)) {
|
|
return Option.some(i);
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var flatten = function (xs) {
|
|
var r = [];
|
|
for (var i = 0, len = xs.length; i < len; ++i) {
|
|
if (!isArray(xs[i])) {
|
|
throw new Error('Arr.flatten item ' + i + ' was not an array, input: ' + xs);
|
|
}
|
|
nativePush.apply(r, xs[i]);
|
|
}
|
|
return r;
|
|
};
|
|
var bind = function (xs, f) {
|
|
return flatten(map$1(xs, f));
|
|
};
|
|
var forall = function (xs, pred) {
|
|
for (var i = 0, len = xs.length; i < len; ++i) {
|
|
var x = xs[i];
|
|
if (pred(x, i) !== true) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
var reverse = function (xs) {
|
|
var r = nativeSlice.call(xs, 0);
|
|
r.reverse();
|
|
return r;
|
|
};
|
|
var difference = function (a1, a2) {
|
|
return filter$1(a1, function (x) {
|
|
return !contains(a2, x);
|
|
});
|
|
};
|
|
var pure = function (x) {
|
|
return [x];
|
|
};
|
|
var sort = function (xs, comparator) {
|
|
var copy = nativeSlice.call(xs, 0);
|
|
copy.sort(comparator);
|
|
return copy;
|
|
};
|
|
var findMap = function (arr, f) {
|
|
for (var i = 0; i < arr.length; i++) {
|
|
var r = f(arr[i], i);
|
|
if (r.isSome()) {
|
|
return r;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
|
|
var detect$1 = function (candidates, userAgent) {
|
|
var agent = String(userAgent).toLowerCase();
|
|
return find$2(candidates, function (candidate) {
|
|
return candidate.search(agent);
|
|
});
|
|
};
|
|
var detectBrowser = function (browsers, userAgent) {
|
|
return detect$1(browsers, userAgent).map(function (browser) {
|
|
var version = Version.detect(browser.versionRegexes, userAgent);
|
|
return {
|
|
current: browser.name,
|
|
version: version
|
|
};
|
|
});
|
|
};
|
|
var detectOs = function (oses, userAgent) {
|
|
return detect$1(oses, userAgent).map(function (os) {
|
|
var version = Version.detect(os.versionRegexes, userAgent);
|
|
return {
|
|
current: os.name,
|
|
version: version
|
|
};
|
|
});
|
|
};
|
|
var UaString = {
|
|
detectBrowser: detectBrowser,
|
|
detectOs: detectOs
|
|
};
|
|
|
|
var checkRange = function (str, substr, start) {
|
|
return substr === '' || str.length >= substr.length && str.substr(start, start + substr.length) === substr;
|
|
};
|
|
var supplant = function (str, obj) {
|
|
var isStringOrNumber = function (a) {
|
|
var t = typeof a;
|
|
return t === 'string' || t === 'number';
|
|
};
|
|
return str.replace(/\$\{([^{}]*)\}/g, function (fullMatch, key) {
|
|
var value = obj[key];
|
|
return isStringOrNumber(value) ? value.toString() : fullMatch;
|
|
});
|
|
};
|
|
var contains$1 = function (str, substr) {
|
|
return str.indexOf(substr) !== -1;
|
|
};
|
|
var endsWith = function (str, suffix) {
|
|
return checkRange(str, suffix, str.length - suffix.length);
|
|
};
|
|
var blank = function (r) {
|
|
return function (s) {
|
|
return s.replace(r, '');
|
|
};
|
|
};
|
|
var trim = blank(/^\s+|\s+$/g);
|
|
|
|
var normalVersionRegex = /.*?version\/\ ?([0-9]+)\.([0-9]+).*/;
|
|
var checkContains = function (target) {
|
|
return function (uastring) {
|
|
return contains$1(uastring, target);
|
|
};
|
|
};
|
|
var browsers = [
|
|
{
|
|
name: 'Edge',
|
|
versionRegexes: [/.*?edge\/ ?([0-9]+)\.([0-9]+)$/],
|
|
search: function (uastring) {
|
|
return contains$1(uastring, 'edge/') && contains$1(uastring, 'chrome') && contains$1(uastring, 'safari') && contains$1(uastring, 'applewebkit');
|
|
}
|
|
},
|
|
{
|
|
name: 'Chrome',
|
|
versionRegexes: [
|
|
/.*?chrome\/([0-9]+)\.([0-9]+).*/,
|
|
normalVersionRegex
|
|
],
|
|
search: function (uastring) {
|
|
return contains$1(uastring, 'chrome') && !contains$1(uastring, 'chromeframe');
|
|
}
|
|
},
|
|
{
|
|
name: 'IE',
|
|
versionRegexes: [
|
|
/.*?msie\ ?([0-9]+)\.([0-9]+).*/,
|
|
/.*?rv:([0-9]+)\.([0-9]+).*/
|
|
],
|
|
search: function (uastring) {
|
|
return contains$1(uastring, 'msie') || contains$1(uastring, 'trident');
|
|
}
|
|
},
|
|
{
|
|
name: 'Opera',
|
|
versionRegexes: [
|
|
normalVersionRegex,
|
|
/.*?opera\/([0-9]+)\.([0-9]+).*/
|
|
],
|
|
search: checkContains('opera')
|
|
},
|
|
{
|
|
name: 'Firefox',
|
|
versionRegexes: [/.*?firefox\/\ ?([0-9]+)\.([0-9]+).*/],
|
|
search: checkContains('firefox')
|
|
},
|
|
{
|
|
name: 'Safari',
|
|
versionRegexes: [
|
|
normalVersionRegex,
|
|
/.*?cpu os ([0-9]+)_([0-9]+).*/
|
|
],
|
|
search: function (uastring) {
|
|
return (contains$1(uastring, 'safari') || contains$1(uastring, 'mobile/')) && contains$1(uastring, 'applewebkit');
|
|
}
|
|
}
|
|
];
|
|
var oses = [
|
|
{
|
|
name: 'Windows',
|
|
search: checkContains('win'),
|
|
versionRegexes: [/.*?windows\ nt\ ?([0-9]+)\.([0-9]+).*/]
|
|
},
|
|
{
|
|
name: 'iOS',
|
|
search: function (uastring) {
|
|
return contains$1(uastring, 'iphone') || contains$1(uastring, 'ipad');
|
|
},
|
|
versionRegexes: [
|
|
/.*?version\/\ ?([0-9]+)\.([0-9]+).*/,
|
|
/.*cpu os ([0-9]+)_([0-9]+).*/,
|
|
/.*cpu iphone os ([0-9]+)_([0-9]+).*/
|
|
]
|
|
},
|
|
{
|
|
name: 'Android',
|
|
search: checkContains('android'),
|
|
versionRegexes: [/.*?android\ ?([0-9]+)\.([0-9]+).*/]
|
|
},
|
|
{
|
|
name: 'OSX',
|
|
search: checkContains('mac os x'),
|
|
versionRegexes: [/.*?mac\ os\ x\ ?([0-9]+)_([0-9]+).*/]
|
|
},
|
|
{
|
|
name: 'Linux',
|
|
search: checkContains('linux'),
|
|
versionRegexes: []
|
|
},
|
|
{
|
|
name: 'Solaris',
|
|
search: checkContains('sunos'),
|
|
versionRegexes: []
|
|
},
|
|
{
|
|
name: 'FreeBSD',
|
|
search: checkContains('freebsd'),
|
|
versionRegexes: []
|
|
},
|
|
{
|
|
name: 'ChromeOS',
|
|
search: checkContains('cros'),
|
|
versionRegexes: [/.*?chrome\/([0-9]+)\.([0-9]+).*/]
|
|
}
|
|
];
|
|
var PlatformInfo = {
|
|
browsers: constant(browsers),
|
|
oses: constant(oses)
|
|
};
|
|
|
|
var detect$2 = function (userAgent, mediaMatch) {
|
|
var browsers = PlatformInfo.browsers();
|
|
var oses = PlatformInfo.oses();
|
|
var browser = UaString.detectBrowser(browsers, userAgent).fold(Browser.unknown, Browser.nu);
|
|
var os = UaString.detectOs(oses, userAgent).fold(OperatingSystem.unknown, OperatingSystem.nu);
|
|
var deviceType = DeviceType(os, browser, userAgent, mediaMatch);
|
|
return {
|
|
browser: browser,
|
|
os: os,
|
|
deviceType: deviceType
|
|
};
|
|
};
|
|
var PlatformDetection = { detect: detect$2 };
|
|
|
|
var mediaMatch = function (query) {
|
|
return domGlobals.window.matchMedia(query).matches;
|
|
};
|
|
var platform = cached(function () {
|
|
return PlatformDetection.detect(domGlobals.navigator.userAgent, mediaMatch);
|
|
});
|
|
var detect$3 = function () {
|
|
return platform();
|
|
};
|
|
|
|
var touchstart = constant('touchstart');
|
|
var touchmove = constant('touchmove');
|
|
var touchend = constant('touchend');
|
|
var mousedown = constant('mousedown');
|
|
var mousemove = constant('mousemove');
|
|
var mouseup = constant('mouseup');
|
|
var mouseover = constant('mouseover');
|
|
var keydown = constant('keydown');
|
|
var keyup = constant('keyup');
|
|
var input = constant('input');
|
|
var change = constant('change');
|
|
var click = constant('click');
|
|
var transitionend = constant('transitionend');
|
|
var selectstart = constant('selectstart');
|
|
|
|
var alloy = { tap: constant('alloy.tap') };
|
|
var focus = constant('alloy.focus');
|
|
var postBlur = constant('alloy.blur.post');
|
|
var postPaste = constant('alloy.paste.post');
|
|
var receive = constant('alloy.receive');
|
|
var execute = constant('alloy.execute');
|
|
var focusItem = constant('alloy.focus.item');
|
|
var tap = alloy.tap;
|
|
var longpress = constant('alloy.longpress');
|
|
var systemInit = constant('alloy.system.init');
|
|
var attachedToDom = constant('alloy.system.attached');
|
|
var detachedFromDom = constant('alloy.system.detached');
|
|
var focusShifted = constant('alloy.focusmanager.shifted');
|
|
var highlight = constant('alloy.highlight');
|
|
var dehighlight = constant('alloy.dehighlight');
|
|
|
|
var emit = function (component, event) {
|
|
dispatchWith(component, component.element(), event, {});
|
|
};
|
|
var emitWith = function (component, event, properties) {
|
|
dispatchWith(component, component.element(), event, properties);
|
|
};
|
|
var emitExecute = function (component) {
|
|
emit(component, execute());
|
|
};
|
|
var dispatch = function (component, target, event) {
|
|
dispatchWith(component, target, event, {});
|
|
};
|
|
var dispatchWith = function (component, target, event, properties) {
|
|
var data = __assign({ target: target }, properties);
|
|
component.getSystem().triggerEvent(event, target, map(data, constant));
|
|
};
|
|
var dispatchEvent = function (component, target, event, simulatedEvent) {
|
|
component.getSystem().triggerEvent(event, target, simulatedEvent.event());
|
|
};
|
|
var dispatchFocus = function (component, target) {
|
|
component.getSystem().triggerFocus(target, component.element());
|
|
};
|
|
|
|
var fromHtml = function (html, scope) {
|
|
var doc = scope || domGlobals.document;
|
|
var div = doc.createElement('div');
|
|
div.innerHTML = html;
|
|
if (!div.hasChildNodes() || div.childNodes.length > 1) {
|
|
domGlobals.console.error('HTML does not have a single root node', html);
|
|
throw new Error('HTML must have a single root node');
|
|
}
|
|
return fromDom(div.childNodes[0]);
|
|
};
|
|
var fromTag = function (tag, scope) {
|
|
var doc = scope || domGlobals.document;
|
|
var node = doc.createElement(tag);
|
|
return fromDom(node);
|
|
};
|
|
var fromText = function (text, scope) {
|
|
var doc = scope || domGlobals.document;
|
|
var node = doc.createTextNode(text);
|
|
return fromDom(node);
|
|
};
|
|
var fromDom = function (node) {
|
|
if (node === null || node === undefined) {
|
|
throw new Error('Node cannot be null or undefined');
|
|
}
|
|
return { dom: constant(node) };
|
|
};
|
|
var fromPoint = function (docElm, x, y) {
|
|
var doc = docElm.dom();
|
|
return Option.from(doc.elementFromPoint(x, y)).map(fromDom);
|
|
};
|
|
var Element = {
|
|
fromHtml: fromHtml,
|
|
fromTag: fromTag,
|
|
fromText: fromText,
|
|
fromDom: fromDom,
|
|
fromPoint: fromPoint
|
|
};
|
|
|
|
var Global = typeof domGlobals.window !== 'undefined' ? domGlobals.window : Function('return this;')();
|
|
|
|
var DOCUMENT = 9;
|
|
var ELEMENT = 1;
|
|
var TEXT = 3;
|
|
|
|
var name = function (element) {
|
|
var r = element.dom().nodeName;
|
|
return r.toLowerCase();
|
|
};
|
|
var type = function (element) {
|
|
return element.dom().nodeType;
|
|
};
|
|
var isType$1 = function (t) {
|
|
return function (element) {
|
|
return type(element) === t;
|
|
};
|
|
};
|
|
var isElement = isType$1(ELEMENT);
|
|
var isText = isType$1(TEXT);
|
|
|
|
var inBody = function (element) {
|
|
var dom = isText(element) ? element.dom().parentNode : element.dom();
|
|
return dom !== undefined && dom !== null && dom.ownerDocument.body.contains(dom);
|
|
};
|
|
var body = function () {
|
|
return getBody(Element.fromDom(domGlobals.document));
|
|
};
|
|
var getBody = function (doc) {
|
|
var b = doc.dom().body;
|
|
if (b === null || b === undefined) {
|
|
throw new Error('Body is not available yet');
|
|
}
|
|
return Element.fromDom(b);
|
|
};
|
|
|
|
var ELEMENT$1 = ELEMENT;
|
|
var DOCUMENT$1 = DOCUMENT;
|
|
var is = function (element, selector) {
|
|
var dom = element.dom();
|
|
if (dom.nodeType !== ELEMENT$1) {
|
|
return false;
|
|
} else {
|
|
var elem = dom;
|
|
if (elem.matches !== undefined) {
|
|
return elem.matches(selector);
|
|
} else if (elem.msMatchesSelector !== undefined) {
|
|
return elem.msMatchesSelector(selector);
|
|
} else if (elem.webkitMatchesSelector !== undefined) {
|
|
return elem.webkitMatchesSelector(selector);
|
|
} else if (elem.mozMatchesSelector !== undefined) {
|
|
return elem.mozMatchesSelector(selector);
|
|
} else {
|
|
throw new Error('Browser lacks native selectors');
|
|
}
|
|
}
|
|
};
|
|
var bypassSelector = function (dom) {
|
|
return dom.nodeType !== ELEMENT$1 && dom.nodeType !== DOCUMENT$1 || dom.childElementCount === 0;
|
|
};
|
|
var all = function (selector, scope) {
|
|
var base = scope === undefined ? domGlobals.document : scope.dom();
|
|
return bypassSelector(base) ? [] : map$1(base.querySelectorAll(selector), Element.fromDom);
|
|
};
|
|
var one = function (selector, scope) {
|
|
var base = scope === undefined ? domGlobals.document : scope.dom();
|
|
return bypassSelector(base) ? Option.none() : Option.from(base.querySelector(selector)).map(Element.fromDom);
|
|
};
|
|
|
|
var eq = function (e1, e2) {
|
|
return e1.dom() === e2.dom();
|
|
};
|
|
|
|
var owner = function (element) {
|
|
return Element.fromDom(element.dom().ownerDocument);
|
|
};
|
|
var defaultView = function (element) {
|
|
return Element.fromDom(element.dom().ownerDocument.defaultView);
|
|
};
|
|
var parent = function (element) {
|
|
return Option.from(element.dom().parentNode).map(Element.fromDom);
|
|
};
|
|
var parents = function (element, isRoot) {
|
|
var stop = isFunction(isRoot) ? isRoot : never;
|
|
var dom = element.dom();
|
|
var ret = [];
|
|
while (dom.parentNode !== null && dom.parentNode !== undefined) {
|
|
var rawParent = dom.parentNode;
|
|
var p = Element.fromDom(rawParent);
|
|
ret.push(p);
|
|
if (stop(p) === true) {
|
|
break;
|
|
} else {
|
|
dom = rawParent;
|
|
}
|
|
}
|
|
return ret;
|
|
};
|
|
var siblings = function (element) {
|
|
var filterSelf = function (elements) {
|
|
return filter$1(elements, function (x) {
|
|
return !eq(element, x);
|
|
});
|
|
};
|
|
return parent(element).map(children).map(filterSelf).getOr([]);
|
|
};
|
|
var nextSibling = function (element) {
|
|
return Option.from(element.dom().nextSibling).map(Element.fromDom);
|
|
};
|
|
var children = function (element) {
|
|
return map$1(element.dom().childNodes, Element.fromDom);
|
|
};
|
|
var child = function (element, index) {
|
|
var cs = element.dom().childNodes;
|
|
return Option.from(cs[index]).map(Element.fromDom);
|
|
};
|
|
var firstChild = function (element) {
|
|
return child(element, 0);
|
|
};
|
|
|
|
var before = function (marker, element) {
|
|
var parent$1 = parent(marker);
|
|
parent$1.each(function (v) {
|
|
v.dom().insertBefore(element.dom(), marker.dom());
|
|
});
|
|
};
|
|
var after = function (marker, element) {
|
|
var sibling = nextSibling(marker);
|
|
sibling.fold(function () {
|
|
var parent$1 = parent(marker);
|
|
parent$1.each(function (v) {
|
|
append(v, element);
|
|
});
|
|
}, function (v) {
|
|
before(v, element);
|
|
});
|
|
};
|
|
var prepend = function (parent, element) {
|
|
var firstChild$1 = firstChild(parent);
|
|
firstChild$1.fold(function () {
|
|
append(parent, element);
|
|
}, function (v) {
|
|
parent.dom().insertBefore(element.dom(), v.dom());
|
|
});
|
|
};
|
|
var append = function (parent, element) {
|
|
parent.dom().appendChild(element.dom());
|
|
};
|
|
var appendAt = function (parent, element, index) {
|
|
child(parent, index).fold(function () {
|
|
append(parent, element);
|
|
}, function (v) {
|
|
before(v, element);
|
|
});
|
|
};
|
|
|
|
var append$1 = function (parent, elements) {
|
|
each$1(elements, function (x) {
|
|
append(parent, x);
|
|
});
|
|
};
|
|
|
|
var empty = function (element) {
|
|
element.dom().textContent = '';
|
|
each$1(children(element), function (rogue) {
|
|
remove(rogue);
|
|
});
|
|
};
|
|
var remove = function (element) {
|
|
var dom = element.dom();
|
|
if (dom.parentNode !== null) {
|
|
dom.parentNode.removeChild(dom);
|
|
}
|
|
};
|
|
|
|
var fireDetaching = function (component) {
|
|
emit(component, detachedFromDom());
|
|
var children = component.components();
|
|
each$1(children, fireDetaching);
|
|
};
|
|
var fireAttaching = function (component) {
|
|
var children = component.components();
|
|
each$1(children, fireAttaching);
|
|
emit(component, attachedToDom());
|
|
};
|
|
var attach = function (parent, child) {
|
|
append(parent.element(), child.element());
|
|
};
|
|
var detachChildren = function (component) {
|
|
each$1(component.components(), function (childComp) {
|
|
return remove(childComp.element());
|
|
});
|
|
empty(component.element());
|
|
component.syncComponents();
|
|
};
|
|
var replaceChildren = function (component, newChildren) {
|
|
var subs = component.components();
|
|
detachChildren(component);
|
|
var deleted = difference(subs, newChildren);
|
|
each$1(deleted, function (comp) {
|
|
fireDetaching(comp);
|
|
component.getSystem().removeFromWorld(comp);
|
|
});
|
|
each$1(newChildren, function (childComp) {
|
|
if (!childComp.getSystem().isConnected()) {
|
|
component.getSystem().addToWorld(childComp);
|
|
attach(component, childComp);
|
|
if (inBody(component.element())) {
|
|
fireAttaching(childComp);
|
|
}
|
|
} else {
|
|
attach(component, childComp);
|
|
}
|
|
component.syncComponents();
|
|
});
|
|
};
|
|
|
|
var attach$1 = function (parent, child) {
|
|
attachWith(parent, child, append);
|
|
};
|
|
var attachWith = function (parent, child, insertion) {
|
|
parent.getSystem().addToWorld(child);
|
|
insertion(parent.element(), child.element());
|
|
if (inBody(parent.element())) {
|
|
fireAttaching(child);
|
|
}
|
|
parent.syncComponents();
|
|
};
|
|
var doDetach = function (component) {
|
|
fireDetaching(component);
|
|
remove(component.element());
|
|
component.getSystem().removeFromWorld(component);
|
|
};
|
|
var detach = function (component) {
|
|
var parent$1 = parent(component.element()).bind(function (p) {
|
|
return component.getSystem().getByDom(p).toOption();
|
|
});
|
|
doDetach(component);
|
|
parent$1.each(function (p) {
|
|
p.syncComponents();
|
|
});
|
|
};
|
|
var attachSystemAfter = function (element, guiSystem) {
|
|
attachSystemWith(element, guiSystem, after);
|
|
};
|
|
var attachSystemWith = function (element, guiSystem, inserter) {
|
|
inserter(element, guiSystem.element());
|
|
var children$1 = children(guiSystem.element());
|
|
each$1(children$1, function (child) {
|
|
guiSystem.getByDom(child).each(fireAttaching);
|
|
});
|
|
};
|
|
var detachSystem = function (guiSystem) {
|
|
var children$1 = children(guiSystem.element());
|
|
each$1(children$1, function (child) {
|
|
guiSystem.getByDom(child).each(fireDetaching);
|
|
});
|
|
remove(guiSystem.element());
|
|
};
|
|
|
|
var value = function (o) {
|
|
var is = function (v) {
|
|
return o === v;
|
|
};
|
|
var or = function (_opt) {
|
|
return value(o);
|
|
};
|
|
var orThunk = function (_f) {
|
|
return value(o);
|
|
};
|
|
var map = function (f) {
|
|
return value(f(o));
|
|
};
|
|
var mapError = function (_f) {
|
|
return value(o);
|
|
};
|
|
var each = function (f) {
|
|
f(o);
|
|
};
|
|
var bind = function (f) {
|
|
return f(o);
|
|
};
|
|
var fold = function (_, onValue) {
|
|
return onValue(o);
|
|
};
|
|
var exists = function (f) {
|
|
return f(o);
|
|
};
|
|
var forall = function (f) {
|
|
return f(o);
|
|
};
|
|
var toOption = function () {
|
|
return Option.some(o);
|
|
};
|
|
return {
|
|
is: is,
|
|
isValue: always,
|
|
isError: never,
|
|
getOr: constant(o),
|
|
getOrThunk: constant(o),
|
|
getOrDie: constant(o),
|
|
or: or,
|
|
orThunk: orThunk,
|
|
fold: fold,
|
|
map: map,
|
|
mapError: mapError,
|
|
each: each,
|
|
bind: bind,
|
|
exists: exists,
|
|
forall: forall,
|
|
toOption: toOption
|
|
};
|
|
};
|
|
var error = function (message) {
|
|
var getOrThunk = function (f) {
|
|
return f();
|
|
};
|
|
var getOrDie = function () {
|
|
return die(String(message))();
|
|
};
|
|
var or = function (opt) {
|
|
return opt;
|
|
};
|
|
var orThunk = function (f) {
|
|
return f();
|
|
};
|
|
var map = function (_f) {
|
|
return error(message);
|
|
};
|
|
var mapError = function (f) {
|
|
return error(f(message));
|
|
};
|
|
var bind = function (_f) {
|
|
return error(message);
|
|
};
|
|
var fold = function (onError, _) {
|
|
return onError(message);
|
|
};
|
|
return {
|
|
is: never,
|
|
isValue: never,
|
|
isError: always,
|
|
getOr: identity,
|
|
getOrThunk: getOrThunk,
|
|
getOrDie: getOrDie,
|
|
or: or,
|
|
orThunk: orThunk,
|
|
fold: fold,
|
|
map: map,
|
|
mapError: mapError,
|
|
each: noop,
|
|
bind: bind,
|
|
exists: never,
|
|
forall: always,
|
|
toOption: Option.none
|
|
};
|
|
};
|
|
var fromOption = function (opt, err) {
|
|
return opt.fold(function () {
|
|
return error(err);
|
|
}, value);
|
|
};
|
|
var Result = {
|
|
value: value,
|
|
error: error,
|
|
fromOption: fromOption
|
|
};
|
|
|
|
var generate = function (cases) {
|
|
if (!isArray(cases)) {
|
|
throw new Error('cases must be an array');
|
|
}
|
|
if (cases.length === 0) {
|
|
throw new Error('there must be at least one case');
|
|
}
|
|
var constructors = [];
|
|
var adt = {};
|
|
each$1(cases, function (acase, count) {
|
|
var keys$1 = keys(acase);
|
|
if (keys$1.length !== 1) {
|
|
throw new Error('one and only one name per case');
|
|
}
|
|
var key = keys$1[0];
|
|
var value = acase[key];
|
|
if (adt[key] !== undefined) {
|
|
throw new Error('duplicate key detected:' + key);
|
|
} else if (key === 'cata') {
|
|
throw new Error('cannot have a case named cata (sorry)');
|
|
} else if (!isArray(value)) {
|
|
throw new Error('case arguments must be an array');
|
|
}
|
|
constructors.push(key);
|
|
adt[key] = function () {
|
|
var argLength = arguments.length;
|
|
if (argLength !== value.length) {
|
|
throw new Error('Wrong number of arguments to case ' + key + '. Expected ' + value.length + ' (' + value + '), got ' + argLength);
|
|
}
|
|
var args = new Array(argLength);
|
|
for (var i = 0; i < args.length; i++) {
|
|
args[i] = arguments[i];
|
|
}
|
|
var match = function (branches) {
|
|
var branchKeys = keys(branches);
|
|
if (constructors.length !== branchKeys.length) {
|
|
throw new Error('Wrong number of arguments to match. Expected: ' + constructors.join(',') + '\nActual: ' + branchKeys.join(','));
|
|
}
|
|
var allReqd = forall(constructors, function (reqKey) {
|
|
return contains(branchKeys, reqKey);
|
|
});
|
|
if (!allReqd) {
|
|
throw new Error('Not all branches were specified when using match. Specified: ' + branchKeys.join(', ') + '\nRequired: ' + constructors.join(', '));
|
|
}
|
|
return branches[key].apply(null, args);
|
|
};
|
|
return {
|
|
fold: function () {
|
|
if (arguments.length !== cases.length) {
|
|
throw new Error('Wrong number of arguments to fold. Expected ' + cases.length + ', got ' + arguments.length);
|
|
}
|
|
var target = arguments[count];
|
|
return target.apply(null, args);
|
|
},
|
|
match: match,
|
|
log: function (label) {
|
|
domGlobals.console.log(label, {
|
|
constructors: constructors,
|
|
constructor: key,
|
|
params: args
|
|
});
|
|
}
|
|
};
|
|
};
|
|
});
|
|
return adt;
|
|
};
|
|
var Adt = { generate: generate };
|
|
|
|
var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
var shallow = function (old, nu) {
|
|
return nu;
|
|
};
|
|
var deep = function (old, nu) {
|
|
var bothObjects = isObject(old) && isObject(nu);
|
|
return bothObjects ? deepMerge(old, nu) : nu;
|
|
};
|
|
var baseMerge = function (merger) {
|
|
return function () {
|
|
var objects = new Array(arguments.length);
|
|
for (var i = 0; i < objects.length; i++) {
|
|
objects[i] = arguments[i];
|
|
}
|
|
if (objects.length === 0) {
|
|
throw new Error('Can\'t merge zero objects');
|
|
}
|
|
var ret = {};
|
|
for (var j = 0; j < objects.length; j++) {
|
|
var curObject = objects[j];
|
|
for (var key in curObject) {
|
|
if (hasOwnProperty$1.call(curObject, key)) {
|
|
ret[key] = merger(ret[key], curObject[key]);
|
|
}
|
|
}
|
|
}
|
|
return ret;
|
|
};
|
|
};
|
|
var deepMerge = baseMerge(deep);
|
|
var merge = baseMerge(shallow);
|
|
|
|
var SimpleResultType;
|
|
(function (SimpleResultType) {
|
|
SimpleResultType[SimpleResultType['Error'] = 0] = 'Error';
|
|
SimpleResultType[SimpleResultType['Value'] = 1] = 'Value';
|
|
}(SimpleResultType || (SimpleResultType = {})));
|
|
var fold = function (res, onError, onValue) {
|
|
return res.stype === SimpleResultType.Error ? onError(res.serror) : onValue(res.svalue);
|
|
};
|
|
var partition = function (results) {
|
|
var values = [];
|
|
var errors = [];
|
|
each$1(results, function (obj) {
|
|
fold(obj, function (err) {
|
|
return errors.push(err);
|
|
}, function (val) {
|
|
return values.push(val);
|
|
});
|
|
});
|
|
return {
|
|
values: values,
|
|
errors: errors
|
|
};
|
|
};
|
|
var mapError = function (res, f) {
|
|
if (res.stype === SimpleResultType.Error) {
|
|
return {
|
|
stype: SimpleResultType.Error,
|
|
serror: f(res.serror)
|
|
};
|
|
} else {
|
|
return res;
|
|
}
|
|
};
|
|
var map$2 = function (res, f) {
|
|
if (res.stype === SimpleResultType.Value) {
|
|
return {
|
|
stype: SimpleResultType.Value,
|
|
svalue: f(res.svalue)
|
|
};
|
|
} else {
|
|
return res;
|
|
}
|
|
};
|
|
var bind$1 = function (res, f) {
|
|
if (res.stype === SimpleResultType.Value) {
|
|
return f(res.svalue);
|
|
} else {
|
|
return res;
|
|
}
|
|
};
|
|
var bindError = function (res, f) {
|
|
if (res.stype === SimpleResultType.Error) {
|
|
return f(res.serror);
|
|
} else {
|
|
return res;
|
|
}
|
|
};
|
|
var svalue = function (v) {
|
|
return {
|
|
stype: SimpleResultType.Value,
|
|
svalue: v
|
|
};
|
|
};
|
|
var serror = function (e) {
|
|
return {
|
|
stype: SimpleResultType.Error,
|
|
serror: e
|
|
};
|
|
};
|
|
var toResult = function (res) {
|
|
return fold(res, Result.error, Result.value);
|
|
};
|
|
var fromResult = function (res) {
|
|
return res.fold(serror, svalue);
|
|
};
|
|
var SimpleResult = {
|
|
fromResult: fromResult,
|
|
toResult: toResult,
|
|
svalue: svalue,
|
|
partition: partition,
|
|
serror: serror,
|
|
bind: bind$1,
|
|
bindError: bindError,
|
|
map: map$2,
|
|
mapError: mapError,
|
|
fold: fold
|
|
};
|
|
|
|
var adt = Adt.generate([
|
|
{ strict: [] },
|
|
{ defaultedThunk: ['fallbackThunk'] },
|
|
{ asOption: [] },
|
|
{ asDefaultedOptionThunk: ['fallbackThunk'] },
|
|
{ mergeWithThunk: ['baseThunk'] }
|
|
]);
|
|
var defaulted = function (fallback) {
|
|
return adt.defaultedThunk(constant(fallback));
|
|
};
|
|
var mergeWith = function (base) {
|
|
return adt.mergeWithThunk(constant(base));
|
|
};
|
|
var strict = adt.strict;
|
|
var asOption = adt.asOption;
|
|
var defaultedThunk = adt.defaultedThunk;
|
|
var asDefaultedOptionThunk = adt.asDefaultedOptionThunk;
|
|
var mergeWithThunk = adt.mergeWithThunk;
|
|
|
|
var exclude = function (obj, fields) {
|
|
var r = {};
|
|
each(obj, function (v, k) {
|
|
if (!contains(fields, k)) {
|
|
r[k] = v;
|
|
}
|
|
});
|
|
return r;
|
|
};
|
|
|
|
var wrap = function (key, value) {
|
|
var _a;
|
|
return _a = {}, _a[key] = value, _a;
|
|
};
|
|
var wrapAll = function (keyvalues) {
|
|
var r = {};
|
|
each$1(keyvalues, function (kv) {
|
|
r[kv.key] = kv.value;
|
|
});
|
|
return r;
|
|
};
|
|
|
|
var comparison = Adt.generate([
|
|
{
|
|
bothErrors: [
|
|
'error1',
|
|
'error2'
|
|
]
|
|
},
|
|
{
|
|
firstError: [
|
|
'error1',
|
|
'value2'
|
|
]
|
|
},
|
|
{
|
|
secondError: [
|
|
'value1',
|
|
'error2'
|
|
]
|
|
},
|
|
{
|
|
bothValues: [
|
|
'value1',
|
|
'value2'
|
|
]
|
|
}
|
|
]);
|
|
var partition$1 = function (results) {
|
|
var errors = [];
|
|
var values = [];
|
|
each$1(results, function (result) {
|
|
result.fold(function (err) {
|
|
errors.push(err);
|
|
}, function (value) {
|
|
values.push(value);
|
|
});
|
|
});
|
|
return {
|
|
errors: errors,
|
|
values: values
|
|
};
|
|
};
|
|
|
|
var exclude$1 = function (obj, fields) {
|
|
return exclude(obj, fields);
|
|
};
|
|
var wrap$1 = function (key, value) {
|
|
return wrap(key, value);
|
|
};
|
|
var wrapAll$1 = function (keyvalues) {
|
|
return wrapAll(keyvalues);
|
|
};
|
|
var mergeValues = function (values, base) {
|
|
return values.length === 0 ? Result.value(base) : Result.value(deepMerge(base, merge.apply(undefined, values)));
|
|
};
|
|
var mergeErrors = function (errors) {
|
|
return Result.error(flatten(errors));
|
|
};
|
|
var consolidate = function (objs, base) {
|
|
var partitions = partition$1(objs);
|
|
return partitions.errors.length > 0 ? mergeErrors(partitions.errors) : mergeValues(partitions.values, base);
|
|
};
|
|
|
|
var mergeValues$1 = function (values, base) {
|
|
return values.length > 0 ? SimpleResult.svalue(deepMerge(base, merge.apply(undefined, values))) : SimpleResult.svalue(base);
|
|
};
|
|
var mergeErrors$1 = function (errors) {
|
|
return compose(SimpleResult.serror, flatten)(errors);
|
|
};
|
|
var consolidateObj = function (objects, base) {
|
|
var partition = SimpleResult.partition(objects);
|
|
return partition.errors.length > 0 ? mergeErrors$1(partition.errors) : mergeValues$1(partition.values, base);
|
|
};
|
|
var consolidateArr = function (objects) {
|
|
var partitions = SimpleResult.partition(objects);
|
|
return partitions.errors.length > 0 ? mergeErrors$1(partitions.errors) : SimpleResult.svalue(partitions.values);
|
|
};
|
|
var ResultCombine = {
|
|
consolidateObj: consolidateObj,
|
|
consolidateArr: consolidateArr
|
|
};
|
|
|
|
var formatObj = function (input) {
|
|
return isObject(input) && keys(input).length > 100 ? ' removed due to size' : JSON.stringify(input, null, 2);
|
|
};
|
|
var formatErrors = function (errors) {
|
|
var es = errors.length > 10 ? errors.slice(0, 10).concat([{
|
|
path: [],
|
|
getErrorInfo: function () {
|
|
return '... (only showing first ten failures)';
|
|
}
|
|
}]) : errors;
|
|
return map$1(es, function (e) {
|
|
return 'Failed path: (' + e.path.join(' > ') + ')\n' + e.getErrorInfo();
|
|
});
|
|
};
|
|
|
|
var nu$3 = function (path, getErrorInfo) {
|
|
return SimpleResult.serror([{
|
|
path: path,
|
|
getErrorInfo: getErrorInfo
|
|
}]);
|
|
};
|
|
var missingStrict = function (path, key, obj) {
|
|
return nu$3(path, function () {
|
|
return 'Could not find valid *strict* value for "' + key + '" in ' + formatObj(obj);
|
|
});
|
|
};
|
|
var missingKey = function (path, key) {
|
|
return nu$3(path, function () {
|
|
return 'Choice schema did not contain choice key: "' + key + '"';
|
|
});
|
|
};
|
|
var missingBranch = function (path, branches, branch) {
|
|
return nu$3(path, function () {
|
|
return 'The chosen schema: "' + branch + '" did not exist in branches: ' + formatObj(branches);
|
|
});
|
|
};
|
|
var unsupportedFields = function (path, unsupported) {
|
|
return nu$3(path, function () {
|
|
return 'There are unsupported fields: [' + unsupported.join(', ') + '] specified';
|
|
});
|
|
};
|
|
var custom = function (path, err) {
|
|
return nu$3(path, function () {
|
|
return err;
|
|
});
|
|
};
|
|
|
|
var adt$1 = Adt.generate([
|
|
{
|
|
field: [
|
|
'key',
|
|
'okey',
|
|
'presence',
|
|
'prop'
|
|
]
|
|
},
|
|
{
|
|
state: [
|
|
'okey',
|
|
'instantiator'
|
|
]
|
|
}
|
|
]);
|
|
var strictAccess = function (path, obj, key) {
|
|
return get(obj, key).fold(function () {
|
|
return missingStrict(path, key, obj);
|
|
}, SimpleResult.svalue);
|
|
};
|
|
var fallbackAccess = function (obj, key, fallbackThunk) {
|
|
var v = get(obj, key).fold(function () {
|
|
return fallbackThunk(obj);
|
|
}, identity);
|
|
return SimpleResult.svalue(v);
|
|
};
|
|
var optionAccess = function (obj, key) {
|
|
return SimpleResult.svalue(get(obj, key));
|
|
};
|
|
var optionDefaultedAccess = function (obj, key, fallback) {
|
|
var opt = get(obj, key).map(function (val) {
|
|
return val === true ? fallback(obj) : val;
|
|
});
|
|
return SimpleResult.svalue(opt);
|
|
};
|
|
var cExtractOne = function (path, obj, field, strength) {
|
|
return field.fold(function (key, okey, presence, prop) {
|
|
var bundle = function (av) {
|
|
var result = prop.extract(path.concat([key]), strength, av);
|
|
return SimpleResult.map(result, function (res) {
|
|
return wrap(okey, strength(res));
|
|
});
|
|
};
|
|
var bundleAsOption = function (optValue) {
|
|
return optValue.fold(function () {
|
|
var outcome = wrap(okey, strength(Option.none()));
|
|
return SimpleResult.svalue(outcome);
|
|
}, function (ov) {
|
|
var result = prop.extract(path.concat([key]), strength, ov);
|
|
return SimpleResult.map(result, function (res) {
|
|
return wrap(okey, strength(Option.some(res)));
|
|
});
|
|
});
|
|
};
|
|
return function () {
|
|
return presence.fold(function () {
|
|
return SimpleResult.bind(strictAccess(path, obj, key), bundle);
|
|
}, function (fallbackThunk) {
|
|
return SimpleResult.bind(fallbackAccess(obj, key, fallbackThunk), bundle);
|
|
}, function () {
|
|
return SimpleResult.bind(optionAccess(obj, key), bundleAsOption);
|
|
}, function (fallbackThunk) {
|
|
return SimpleResult.bind(optionDefaultedAccess(obj, key, fallbackThunk), bundleAsOption);
|
|
}, function (baseThunk) {
|
|
var base = baseThunk(obj);
|
|
var result = SimpleResult.map(fallbackAccess(obj, key, constant({})), function (v) {
|
|
return deepMerge(base, v);
|
|
});
|
|
return SimpleResult.bind(result, bundle);
|
|
});
|
|
}();
|
|
}, function (okey, instantiator) {
|
|
var state = instantiator(obj);
|
|
return SimpleResult.svalue(wrap(okey, strength(state)));
|
|
});
|
|
};
|
|
var cExtract = function (path, obj, fields, strength) {
|
|
var results = map$1(fields, function (field) {
|
|
return cExtractOne(path, obj, field, strength);
|
|
});
|
|
return ResultCombine.consolidateObj(results, {});
|
|
};
|
|
var value$1 = function (validator) {
|
|
var extract = function (path, strength, val) {
|
|
return SimpleResult.bindError(validator(val, strength), function (err) {
|
|
return custom(path, err);
|
|
});
|
|
};
|
|
var toString = function () {
|
|
return 'val';
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var getSetKeys = function (obj) {
|
|
return keys(filter(obj, function (value) {
|
|
return value !== undefined && value !== null;
|
|
}));
|
|
};
|
|
var objOfOnly = function (fields) {
|
|
var delegate = objOf(fields);
|
|
var fieldNames = foldr(fields, function (acc, f) {
|
|
return f.fold(function (key) {
|
|
return deepMerge(acc, wrap$1(key, true));
|
|
}, constant(acc));
|
|
}, {});
|
|
var extract = function (path, strength, o) {
|
|
var keys = isBoolean(o) ? [] : getSetKeys(o);
|
|
var extra = filter$1(keys, function (k) {
|
|
return !hasNonNullableKey(fieldNames, k);
|
|
});
|
|
return extra.length === 0 ? delegate.extract(path, strength, o) : unsupportedFields(path, extra);
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: delegate.toString
|
|
};
|
|
};
|
|
var objOf = function (fields) {
|
|
var extract = function (path, strength, o) {
|
|
return cExtract(path, o, fields, strength);
|
|
};
|
|
var toString = function () {
|
|
var fieldStrings = map$1(fields, function (field) {
|
|
return field.fold(function (key, okey, presence, prop) {
|
|
return key + ' -> ' + prop.toString();
|
|
}, function (okey, _instantiator) {
|
|
return 'state(' + okey + ')';
|
|
});
|
|
});
|
|
return 'obj{\n' + fieldStrings.join('\n') + '}';
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var arrOf = function (prop) {
|
|
var extract = function (path, strength, array) {
|
|
var results = map$1(array, function (a, i) {
|
|
return prop.extract(path.concat(['[' + i + ']']), strength, a);
|
|
});
|
|
return ResultCombine.consolidateArr(results);
|
|
};
|
|
var toString = function () {
|
|
return 'array(' + prop.toString() + ')';
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var setOf = function (validator, prop) {
|
|
var validateKeys = function (path, keys) {
|
|
return arrOf(value$1(validator)).extract(path, identity, keys);
|
|
};
|
|
var extract = function (path, strength, o) {
|
|
var keys$1 = keys(o);
|
|
var validatedKeys = validateKeys(path, keys$1);
|
|
return SimpleResult.bind(validatedKeys, function (validKeys) {
|
|
var schema = map$1(validKeys, function (vk) {
|
|
return adt$1.field(vk, vk, strict(), prop);
|
|
});
|
|
return objOf(schema).extract(path, strength, o);
|
|
});
|
|
};
|
|
var toString = function () {
|
|
return 'setOf(' + prop.toString() + ')';
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
var anyValue = constant(value$1(SimpleResult.svalue));
|
|
var state = adt$1.state;
|
|
var field = adt$1.field;
|
|
|
|
var chooseFrom = function (path, strength, input, branches, ch) {
|
|
var fields = get(branches, ch);
|
|
return fields.fold(function () {
|
|
return missingBranch(path, branches, ch);
|
|
}, function (vp) {
|
|
return vp.extract(path.concat(['branch: ' + ch]), strength, input);
|
|
});
|
|
};
|
|
var choose = function (key, branches) {
|
|
var extract = function (path, strength, input) {
|
|
var choice = get(input, key);
|
|
return choice.fold(function () {
|
|
return missingKey(path, key);
|
|
}, function (chosen) {
|
|
return chooseFrom(path, strength, input, branches, chosen);
|
|
});
|
|
};
|
|
var toString = function () {
|
|
return 'chooseOn(' + key + '). Possible values: ' + keys(branches);
|
|
};
|
|
return {
|
|
extract: extract,
|
|
toString: toString
|
|
};
|
|
};
|
|
|
|
var _anyValue = value$1(SimpleResult.svalue);
|
|
var valueOf = function (validator) {
|
|
return value$1(function (v) {
|
|
return validator(v).fold(SimpleResult.serror, SimpleResult.svalue);
|
|
});
|
|
};
|
|
var setOf$1 = function (validator, prop) {
|
|
return setOf(function (v) {
|
|
return SimpleResult.fromResult(validator(v));
|
|
}, prop);
|
|
};
|
|
var extract = function (label, prop, strength, obj) {
|
|
var res = prop.extract([label], strength, obj);
|
|
return SimpleResult.mapError(res, function (errs) {
|
|
return {
|
|
input: obj,
|
|
errors: errs
|
|
};
|
|
});
|
|
};
|
|
var asRaw = function (label, prop, obj) {
|
|
return SimpleResult.toResult(extract(label, prop, identity, obj));
|
|
};
|
|
var getOrDie = function (extraction) {
|
|
return extraction.fold(function (errInfo) {
|
|
throw new Error(formatError(errInfo));
|
|
}, identity);
|
|
};
|
|
var asRawOrDie = function (label, prop, obj) {
|
|
return getOrDie(asRaw(label, prop, obj));
|
|
};
|
|
var formatError = function (errInfo) {
|
|
return 'Errors: \n' + formatErrors(errInfo.errors).join('\n') + '\n\nInput object: ' + formatObj(errInfo.input);
|
|
};
|
|
var choose$1 = function (key, branches) {
|
|
return choose(key, map(branches, objOf));
|
|
};
|
|
var anyValue$1 = constant(_anyValue);
|
|
var typedValue = function (validator, expectedType) {
|
|
return value$1(function (a) {
|
|
var actualType = typeof a;
|
|
return validator(a) ? SimpleResult.svalue(a) : SimpleResult.serror('Expected type: ' + expectedType + ' but got: ' + actualType);
|
|
});
|
|
};
|
|
var functionProcessor = typedValue(isFunction, 'function');
|
|
|
|
var strict$1 = function (key) {
|
|
return field(key, key, strict(), anyValue());
|
|
};
|
|
var strictOf = function (key, schema) {
|
|
return field(key, key, strict(), schema);
|
|
};
|
|
var strictFunction = function (key) {
|
|
return strictOf(key, functionProcessor);
|
|
};
|
|
var forbid = function (key, message) {
|
|
return field(key, key, asOption(), value$1(function (_v) {
|
|
return SimpleResult.serror('The field: ' + key + ' is forbidden. ' + message);
|
|
}));
|
|
};
|
|
var strictObjOf = function (key, objSchema) {
|
|
return field(key, key, strict(), objOf(objSchema));
|
|
};
|
|
var option = function (key) {
|
|
return field(key, key, asOption(), anyValue());
|
|
};
|
|
var optionOf = function (key, schema) {
|
|
return field(key, key, asOption(), schema);
|
|
};
|
|
var optionObjOf = function (key, objSchema) {
|
|
return optionOf(key, objOf(objSchema));
|
|
};
|
|
var optionObjOfOnly = function (key, objSchema) {
|
|
return optionOf(key, objOfOnly(objSchema));
|
|
};
|
|
var defaulted$1 = function (key, fallback) {
|
|
return field(key, key, defaulted(fallback), anyValue());
|
|
};
|
|
var defaultedOf = function (key, fallback, schema) {
|
|
return field(key, key, defaulted(fallback), schema);
|
|
};
|
|
var defaultedFunction = function (key, fallback) {
|
|
return defaultedOf(key, fallback, functionProcessor);
|
|
};
|
|
var defaultedObjOf = function (key, fallback, objSchema) {
|
|
return defaultedOf(key, fallback, objOf(objSchema));
|
|
};
|
|
var state$1 = function (okey, instantiator) {
|
|
return state(okey, instantiator);
|
|
};
|
|
|
|
var ensureIsRoot = function (isRoot) {
|
|
return isFunction(isRoot) ? isRoot : constant(false);
|
|
};
|
|
var ancestor = function (scope, transform, isRoot) {
|
|
var element = scope.dom();
|
|
var stop = ensureIsRoot(isRoot);
|
|
while (element.parentNode) {
|
|
element = element.parentNode;
|
|
var el = Element.fromDom(element);
|
|
var transformed = transform(el);
|
|
if (transformed.isSome()) {
|
|
return transformed;
|
|
} else if (stop(el)) {
|
|
break;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var closest = function (scope, transform, isRoot) {
|
|
var current = transform(scope);
|
|
var stop = ensureIsRoot(isRoot);
|
|
return current.orThunk(function () {
|
|
return stop(scope) ? Option.none() : ancestor(scope, transform, stop);
|
|
});
|
|
};
|
|
|
|
var isSource = function (component, simulatedEvent) {
|
|
return eq(component.element(), simulatedEvent.event().target());
|
|
};
|
|
|
|
var nu$4 = function (parts) {
|
|
if (!hasNonNullableKey(parts, 'can') && !hasNonNullableKey(parts, 'abort') && !hasNonNullableKey(parts, 'run')) {
|
|
throw new Error('EventHandler defined by: ' + JSON.stringify(parts, null, 2) + ' does not have can, abort, or run!');
|
|
}
|
|
return asRawOrDie('Extracting event.handler', objOfOnly([
|
|
defaulted$1('can', constant(true)),
|
|
defaulted$1('abort', constant(false)),
|
|
defaulted$1('run', noop)
|
|
]), parts);
|
|
};
|
|
var all$1 = function (handlers, f) {
|
|
return function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
return foldl(handlers, function (acc, handler) {
|
|
return acc && f(handler).apply(undefined, args);
|
|
}, true);
|
|
};
|
|
};
|
|
var any = function (handlers, f) {
|
|
return function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
return foldl(handlers, function (acc, handler) {
|
|
return acc || f(handler).apply(undefined, args);
|
|
}, false);
|
|
};
|
|
};
|
|
var read = function (handler) {
|
|
return isFunction(handler) ? {
|
|
can: constant(true),
|
|
abort: constant(false),
|
|
run: handler
|
|
} : handler;
|
|
};
|
|
var fuse = function (handlers) {
|
|
var can = all$1(handlers, function (handler) {
|
|
return handler.can;
|
|
});
|
|
var abort = any(handlers, function (handler) {
|
|
return handler.abort;
|
|
});
|
|
var run = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
each$1(handlers, function (handler) {
|
|
handler.run.apply(undefined, args);
|
|
});
|
|
};
|
|
return nu$4({
|
|
can: can,
|
|
abort: abort,
|
|
run: run
|
|
});
|
|
};
|
|
|
|
var derive = function (configs) {
|
|
return wrapAll$1(configs);
|
|
};
|
|
var abort = function (name, predicate) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({ abort: predicate })
|
|
};
|
|
};
|
|
var can = function (name, predicate) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({ can: predicate })
|
|
};
|
|
};
|
|
var run = function (name, handler) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({ run: handler })
|
|
};
|
|
};
|
|
var runActionExtra = function (name, action, extra) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({
|
|
run: function (component, simulatedEvent) {
|
|
action.apply(undefined, [
|
|
component,
|
|
simulatedEvent
|
|
].concat(extra));
|
|
}
|
|
})
|
|
};
|
|
};
|
|
var runOnName = function (name) {
|
|
return function (handler) {
|
|
return run(name, handler);
|
|
};
|
|
};
|
|
var runOnSourceName = function (name) {
|
|
return function (handler) {
|
|
return {
|
|
key: name,
|
|
value: nu$4({
|
|
run: function (component, simulatedEvent) {
|
|
if (isSource(component, simulatedEvent)) {
|
|
handler(component, simulatedEvent);
|
|
}
|
|
}
|
|
})
|
|
};
|
|
};
|
|
};
|
|
var redirectToUid = function (name, uid) {
|
|
return run(name, function (component, simulatedEvent) {
|
|
component.getSystem().getByUid(uid).each(function (redirectee) {
|
|
dispatchEvent(redirectee, redirectee.element(), name, simulatedEvent);
|
|
});
|
|
});
|
|
};
|
|
var redirectToPart = function (name, detail, partName) {
|
|
var uid = detail.partUids[partName];
|
|
return redirectToUid(name, uid);
|
|
};
|
|
var cutter = function (name) {
|
|
return run(name, function (component, simulatedEvent) {
|
|
simulatedEvent.cut();
|
|
});
|
|
};
|
|
var stopper = function (name) {
|
|
return run(name, function (component, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
});
|
|
};
|
|
var runOnSource = function (name, f) {
|
|
return runOnSourceName(name)(f);
|
|
};
|
|
var runOnAttached = runOnSourceName(attachedToDom());
|
|
var runOnDetached = runOnSourceName(detachedFromDom());
|
|
var runOnInit = runOnSourceName(systemInit());
|
|
var runOnExecute = runOnName(execute());
|
|
|
|
var markAsBehaviourApi = function (f, apiName, apiFunction) {
|
|
var delegate = apiFunction.toString();
|
|
var endIndex = delegate.indexOf(')') + 1;
|
|
var openBracketIndex = delegate.indexOf('(');
|
|
var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
|
|
f.toFunctionAnnotation = function () {
|
|
return {
|
|
name: apiName,
|
|
parameters: cleanParameters(parameters.slice(0, 1).concat(parameters.slice(3)))
|
|
};
|
|
};
|
|
return f;
|
|
};
|
|
var cleanParameters = function (parameters) {
|
|
return map$1(parameters, function (p) {
|
|
return endsWith(p, '/*') ? p.substring(0, p.length - '/*'.length) : p;
|
|
});
|
|
};
|
|
var markAsExtraApi = function (f, extraName) {
|
|
var delegate = f.toString();
|
|
var endIndex = delegate.indexOf(')') + 1;
|
|
var openBracketIndex = delegate.indexOf('(');
|
|
var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
|
|
f.toFunctionAnnotation = function () {
|
|
return {
|
|
name: extraName,
|
|
parameters: cleanParameters(parameters)
|
|
};
|
|
};
|
|
return f;
|
|
};
|
|
var markAsSketchApi = function (f, apiFunction) {
|
|
var delegate = apiFunction.toString();
|
|
var endIndex = delegate.indexOf(')') + 1;
|
|
var openBracketIndex = delegate.indexOf('(');
|
|
var parameters = delegate.substring(openBracketIndex + 1, endIndex - 1).split(/,\s*/);
|
|
f.toFunctionAnnotation = function () {
|
|
return {
|
|
name: 'OVERRIDE',
|
|
parameters: cleanParameters(parameters.slice(1))
|
|
};
|
|
};
|
|
return f;
|
|
};
|
|
|
|
var nu$5 = function (s) {
|
|
return {
|
|
classes: s.classes !== undefined ? s.classes : [],
|
|
attributes: s.attributes !== undefined ? s.attributes : {},
|
|
styles: s.styles !== undefined ? s.styles : {}
|
|
};
|
|
};
|
|
var merge$1 = function (defnA, mod) {
|
|
return __assign(__assign({}, defnA), {
|
|
attributes: __assign(__assign({}, defnA.attributes), mod.attributes),
|
|
styles: __assign(__assign({}, defnA.styles), mod.styles),
|
|
classes: defnA.classes.concat(mod.classes)
|
|
});
|
|
};
|
|
|
|
var executeEvent = function (bConfig, bState, executor) {
|
|
return runOnExecute(function (component) {
|
|
executor(component, bConfig, bState);
|
|
});
|
|
};
|
|
var loadEvent = function (bConfig, bState, f) {
|
|
return runOnInit(function (component, _simulatedEvent) {
|
|
f(component, bConfig, bState);
|
|
});
|
|
};
|
|
var create = function (schema, name, active, apis, extra, state) {
|
|
var configSchema = objOfOnly(schema);
|
|
var schemaSchema = optionObjOf(name, [optionObjOfOnly('config', schema)]);
|
|
return doCreate(configSchema, schemaSchema, name, active, apis, extra, state);
|
|
};
|
|
var createModes = function (modes, name, active, apis, extra, state) {
|
|
var configSchema = modes;
|
|
var schemaSchema = optionObjOf(name, [optionOf('config', modes)]);
|
|
return doCreate(configSchema, schemaSchema, name, active, apis, extra, state);
|
|
};
|
|
var wrapApi = function (bName, apiFunction, apiName) {
|
|
var f = function (component) {
|
|
var rest = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
rest[_i - 1] = arguments[_i];
|
|
}
|
|
var args = [component].concat(rest);
|
|
return component.config({ name: constant(bName) }).fold(function () {
|
|
throw new Error('We could not find any behaviour configuration for: ' + bName + '. Using API: ' + apiName);
|
|
}, function (info) {
|
|
var rest = Array.prototype.slice.call(args, 1);
|
|
return apiFunction.apply(undefined, [
|
|
component,
|
|
info.config,
|
|
info.state
|
|
].concat(rest));
|
|
});
|
|
};
|
|
return markAsBehaviourApi(f, apiName, apiFunction);
|
|
};
|
|
var revokeBehaviour = function (name) {
|
|
return {
|
|
key: name,
|
|
value: undefined
|
|
};
|
|
};
|
|
var doCreate = function (configSchema, schemaSchema, name, active, apis, extra, state) {
|
|
var getConfig = function (info) {
|
|
return hasNonNullableKey(info, name) ? info[name]() : Option.none();
|
|
};
|
|
var wrappedApis = map(apis, function (apiF, apiName) {
|
|
return wrapApi(name, apiF, apiName);
|
|
});
|
|
var wrappedExtra = map(extra, function (extraF, extraName) {
|
|
return markAsExtraApi(extraF, extraName);
|
|
});
|
|
var me = __assign(__assign(__assign({}, wrappedExtra), wrappedApis), {
|
|
revoke: curry(revokeBehaviour, name),
|
|
config: function (spec) {
|
|
var prepared = asRawOrDie(name + '-config', configSchema, spec);
|
|
return {
|
|
key: name,
|
|
value: {
|
|
config: prepared,
|
|
me: me,
|
|
configAsRaw: cached(function () {
|
|
return asRawOrDie(name + '-config', configSchema, spec);
|
|
}),
|
|
initialConfig: spec,
|
|
state: state
|
|
}
|
|
};
|
|
},
|
|
schema: function () {
|
|
return schemaSchema;
|
|
},
|
|
exhibit: function (info, base) {
|
|
return getConfig(info).bind(function (behaviourInfo) {
|
|
return get(active, 'exhibit').map(function (exhibitor) {
|
|
return exhibitor(base, behaviourInfo.config, behaviourInfo.state);
|
|
});
|
|
}).getOr(nu$5({}));
|
|
},
|
|
name: function () {
|
|
return name;
|
|
},
|
|
handlers: function (info) {
|
|
return getConfig(info).map(function (behaviourInfo) {
|
|
var getEvents = get(active, 'events').getOr(function () {
|
|
return {};
|
|
});
|
|
return getEvents(behaviourInfo.config, behaviourInfo.state);
|
|
}).getOr({});
|
|
}
|
|
});
|
|
return me;
|
|
};
|
|
|
|
var NoState = {
|
|
init: function () {
|
|
return nu$6({
|
|
readState: function () {
|
|
return 'No State required';
|
|
}
|
|
});
|
|
}
|
|
};
|
|
var nu$6 = function (spec) {
|
|
return spec;
|
|
};
|
|
|
|
var derive$1 = function (capabilities) {
|
|
return wrapAll$1(capabilities);
|
|
};
|
|
var simpleSchema = objOfOnly([
|
|
strict$1('fields'),
|
|
strict$1('name'),
|
|
defaulted$1('active', {}),
|
|
defaulted$1('apis', {}),
|
|
defaulted$1('state', NoState),
|
|
defaulted$1('extra', {})
|
|
]);
|
|
var create$1 = function (data) {
|
|
var value = asRawOrDie('Creating behaviour: ' + data.name, simpleSchema, data);
|
|
return create(value.fields, value.name, value.active, value.apis, value.extra, value.state);
|
|
};
|
|
var modeSchema = objOfOnly([
|
|
strict$1('branchKey'),
|
|
strict$1('branches'),
|
|
strict$1('name'),
|
|
defaulted$1('active', {}),
|
|
defaulted$1('apis', {}),
|
|
defaulted$1('state', NoState),
|
|
defaulted$1('extra', {})
|
|
]);
|
|
var createModes$1 = function (data) {
|
|
var value = asRawOrDie('Creating behaviour: ' + data.name, modeSchema, data);
|
|
return createModes(choose$1(value.branchKey, value.branches), value.name, value.active, value.apis, value.extra, value.state);
|
|
};
|
|
var revoke = constant(undefined);
|
|
|
|
var rawSet = function (dom, key, value) {
|
|
if (isString(value) || isBoolean(value) || isNumber(value)) {
|
|
dom.setAttribute(key, value + '');
|
|
} else {
|
|
domGlobals.console.error('Invalid call to Attr.set. Key ', key, ':: Value ', value, ':: Element ', dom);
|
|
throw new Error('Attribute value was not simple');
|
|
}
|
|
};
|
|
var set = function (element, key, value) {
|
|
rawSet(element.dom(), key, value);
|
|
};
|
|
var setAll = function (element, attrs) {
|
|
var dom = element.dom();
|
|
each(attrs, function (v, k) {
|
|
rawSet(dom, k, v);
|
|
});
|
|
};
|
|
var get$1 = function (element, key) {
|
|
var v = element.dom().getAttribute(key);
|
|
return v === null ? undefined : v;
|
|
};
|
|
var getOpt = function (element, key) {
|
|
return Option.from(get$1(element, key));
|
|
};
|
|
var has$1 = function (element, key) {
|
|
var dom = element.dom();
|
|
return dom && dom.hasAttribute ? dom.hasAttribute(key) : false;
|
|
};
|
|
var remove$1 = function (element, key) {
|
|
element.dom().removeAttribute(key);
|
|
};
|
|
|
|
var read$1 = function (element, attr) {
|
|
var value = get$1(element, attr);
|
|
return value === undefined || value === '' ? [] : value.split(' ');
|
|
};
|
|
var add = function (element, attr, id) {
|
|
var old = read$1(element, attr);
|
|
var nu = old.concat([id]);
|
|
set(element, attr, nu.join(' '));
|
|
return true;
|
|
};
|
|
var remove$2 = function (element, attr, id) {
|
|
var nu = filter$1(read$1(element, attr), function (v) {
|
|
return v !== id;
|
|
});
|
|
if (nu.length > 0) {
|
|
set(element, attr, nu.join(' '));
|
|
} else {
|
|
remove$1(element, attr);
|
|
}
|
|
return false;
|
|
};
|
|
|
|
var supports = function (element) {
|
|
return element.dom().classList !== undefined;
|
|
};
|
|
var get$2 = function (element) {
|
|
return read$1(element, 'class');
|
|
};
|
|
var add$1 = function (element, clazz) {
|
|
return add(element, 'class', clazz);
|
|
};
|
|
var remove$3 = function (element, clazz) {
|
|
return remove$2(element, 'class', clazz);
|
|
};
|
|
|
|
var add$2 = function (element, clazz) {
|
|
if (supports(element)) {
|
|
element.dom().classList.add(clazz);
|
|
} else {
|
|
add$1(element, clazz);
|
|
}
|
|
};
|
|
var cleanClass = function (element) {
|
|
var classList = supports(element) ? element.dom().classList : get$2(element);
|
|
if (classList.length === 0) {
|
|
remove$1(element, 'class');
|
|
}
|
|
};
|
|
var remove$4 = function (element, clazz) {
|
|
if (supports(element)) {
|
|
var classList = element.dom().classList;
|
|
classList.remove(clazz);
|
|
} else {
|
|
remove$3(element, clazz);
|
|
}
|
|
cleanClass(element);
|
|
};
|
|
var has$2 = function (element, clazz) {
|
|
return supports(element) && element.dom().classList.contains(clazz);
|
|
};
|
|
|
|
var swap = function (element, addCls, removeCls) {
|
|
remove$4(element, removeCls);
|
|
add$2(element, addCls);
|
|
};
|
|
var toAlpha = function (component, swapConfig, _swapState) {
|
|
swap(component.element(), swapConfig.alpha, swapConfig.omega);
|
|
};
|
|
var toOmega = function (component, swapConfig, _swapState) {
|
|
swap(component.element(), swapConfig.omega, swapConfig.alpha);
|
|
};
|
|
var clear = function (component, swapConfig, _swapState) {
|
|
remove$4(component.element(), swapConfig.alpha);
|
|
remove$4(component.element(), swapConfig.omega);
|
|
};
|
|
var isAlpha = function (component, swapConfig, _swapState) {
|
|
return has$2(component.element(), swapConfig.alpha);
|
|
};
|
|
var isOmega = function (component, swapConfig, _swapState) {
|
|
return has$2(component.element(), swapConfig.omega);
|
|
};
|
|
|
|
var SwapApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
toAlpha: toAlpha,
|
|
toOmega: toOmega,
|
|
isAlpha: isAlpha,
|
|
isOmega: isOmega,
|
|
clear: clear
|
|
});
|
|
|
|
var SwapSchema = [
|
|
strict$1('alpha'),
|
|
strict$1('omega')
|
|
];
|
|
|
|
var Swapping = create$1({
|
|
fields: SwapSchema,
|
|
name: 'swapping',
|
|
apis: SwapApis
|
|
});
|
|
|
|
var Cell = function (initial) {
|
|
var value = initial;
|
|
var get = function () {
|
|
return value;
|
|
};
|
|
var set = function (v) {
|
|
value = v;
|
|
};
|
|
return {
|
|
get: get,
|
|
set: set
|
|
};
|
|
};
|
|
|
|
function ClosestOrAncestor (is, ancestor, scope, a, isRoot) {
|
|
return is(scope, a) ? Option.some(scope) : isFunction(isRoot) && isRoot(scope) ? Option.none() : ancestor(scope, a, isRoot);
|
|
}
|
|
|
|
var ancestor$1 = function (scope, predicate, isRoot) {
|
|
var element = scope.dom();
|
|
var stop = isFunction(isRoot) ? isRoot : constant(false);
|
|
while (element.parentNode) {
|
|
element = element.parentNode;
|
|
var el = Element.fromDom(element);
|
|
if (predicate(el)) {
|
|
return Option.some(el);
|
|
} else if (stop(el)) {
|
|
break;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
var closest$1 = function (scope, predicate, isRoot) {
|
|
var is = function (s, test) {
|
|
return test(s);
|
|
};
|
|
return ClosestOrAncestor(is, ancestor$1, scope, predicate, isRoot);
|
|
};
|
|
var descendant = function (scope, predicate) {
|
|
var descend = function (node) {
|
|
for (var i = 0; i < node.childNodes.length; i++) {
|
|
var child_1 = Element.fromDom(node.childNodes[i]);
|
|
if (predicate(child_1)) {
|
|
return Option.some(child_1);
|
|
}
|
|
var res = descend(node.childNodes[i]);
|
|
if (res.isSome()) {
|
|
return res;
|
|
}
|
|
}
|
|
return Option.none();
|
|
};
|
|
return descend(scope.dom());
|
|
};
|
|
|
|
var focus$1 = function (element) {
|
|
return element.dom().focus();
|
|
};
|
|
var blur = function (element) {
|
|
return element.dom().blur();
|
|
};
|
|
var hasFocus = function (element) {
|
|
var doc = owner(element).dom();
|
|
return element.dom() === doc.activeElement;
|
|
};
|
|
var active = function (_doc) {
|
|
var doc = _doc !== undefined ? _doc.dom() : domGlobals.document;
|
|
return Option.from(doc.activeElement).map(Element.fromDom);
|
|
};
|
|
var search = function (element) {
|
|
return active(owner(element)).filter(function (e) {
|
|
return element.dom().contains(e.dom());
|
|
});
|
|
};
|
|
|
|
var global$1 = tinymce.util.Tools.resolve('tinymce.dom.DOMUtils');
|
|
|
|
var global$2 = tinymce.util.Tools.resolve('tinymce.ThemeManager');
|
|
|
|
var openLink = function (target) {
|
|
var link = domGlobals.document.createElement('a');
|
|
link.target = '_blank';
|
|
link.href = target.href;
|
|
link.rel = 'noreferrer noopener';
|
|
var nuEvt = domGlobals.document.createEvent('MouseEvents');
|
|
nuEvt.initMouseEvent('click', true, true, domGlobals.window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
domGlobals.document.body.appendChild(link);
|
|
link.dispatchEvent(nuEvt);
|
|
domGlobals.document.body.removeChild(link);
|
|
};
|
|
|
|
var isSkinDisabled = function (editor) {
|
|
return editor.settings.skin === false;
|
|
};
|
|
var readOnlyOnInit = function (_editor) {
|
|
return false;
|
|
};
|
|
|
|
var formatChanged = 'formatChanged';
|
|
var orientationChanged = 'orientationChanged';
|
|
var dropupDismissed = 'dropupDismissed';
|
|
|
|
var fromHtml$1 = function (html, scope) {
|
|
var doc = scope || domGlobals.document;
|
|
var div = doc.createElement('div');
|
|
div.innerHTML = html;
|
|
return children(Element.fromDom(div));
|
|
};
|
|
|
|
var get$3 = function (element) {
|
|
return element.dom().innerHTML;
|
|
};
|
|
var set$1 = function (element, content) {
|
|
var owner$1 = owner(element);
|
|
var docDom = owner$1.dom();
|
|
var fragment = Element.fromDom(docDom.createDocumentFragment());
|
|
var contentElements = fromHtml$1(content, docDom);
|
|
append$1(fragment, contentElements);
|
|
empty(element);
|
|
append(element, fragment);
|
|
};
|
|
var getOuter = function (element) {
|
|
var container = Element.fromTag('div');
|
|
var clone = Element.fromDom(element.dom().cloneNode(true));
|
|
append(container, clone);
|
|
return get$3(container);
|
|
};
|
|
|
|
var clone = function (original, isDeep) {
|
|
return Element.fromDom(original.dom().cloneNode(isDeep));
|
|
};
|
|
var shallow$1 = function (original) {
|
|
return clone(original, false);
|
|
};
|
|
|
|
var getHtml = function (element) {
|
|
var clone = shallow$1(element);
|
|
return getOuter(clone);
|
|
};
|
|
|
|
var element = function (elem) {
|
|
return getHtml(elem);
|
|
};
|
|
|
|
var chooseChannels = function (channels, message) {
|
|
return message.universal() ? channels : filter$1(channels, function (ch) {
|
|
return contains(message.channels(), ch);
|
|
});
|
|
};
|
|
var events = function (receiveConfig) {
|
|
return derive([run(receive(), function (component, message) {
|
|
var channelMap = receiveConfig.channels;
|
|
var channels = keys(channelMap);
|
|
var receivingData = message;
|
|
var targetChannels = chooseChannels(channels, receivingData);
|
|
each$1(targetChannels, function (ch) {
|
|
var channelInfo = channelMap[ch];
|
|
var channelSchema = channelInfo.schema;
|
|
var data = asRawOrDie('channel[' + ch + '] data\nReceiver: ' + element(component.element()), channelSchema, receivingData.data());
|
|
channelInfo.onReceive(component, data);
|
|
});
|
|
})]);
|
|
};
|
|
|
|
var ActiveReceiving = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events
|
|
});
|
|
|
|
var unknown$3 = 'unknown';
|
|
var EventConfiguration;
|
|
(function (EventConfiguration) {
|
|
EventConfiguration[EventConfiguration['STOP'] = 0] = 'STOP';
|
|
EventConfiguration[EventConfiguration['NORMAL'] = 1] = 'NORMAL';
|
|
EventConfiguration[EventConfiguration['LOGGING'] = 2] = 'LOGGING';
|
|
}(EventConfiguration || (EventConfiguration = {})));
|
|
var eventConfig = Cell({});
|
|
var makeEventLogger = function (eventName, initialTarget) {
|
|
var sequence = [];
|
|
var startTime = new Date().getTime();
|
|
return {
|
|
logEventCut: function (_name, target, purpose) {
|
|
sequence.push({
|
|
outcome: 'cut',
|
|
target: target,
|
|
purpose: purpose
|
|
});
|
|
},
|
|
logEventStopped: function (_name, target, purpose) {
|
|
sequence.push({
|
|
outcome: 'stopped',
|
|
target: target,
|
|
purpose: purpose
|
|
});
|
|
},
|
|
logNoParent: function (_name, target, purpose) {
|
|
sequence.push({
|
|
outcome: 'no-parent',
|
|
target: target,
|
|
purpose: purpose
|
|
});
|
|
},
|
|
logEventNoHandlers: function (_name, target) {
|
|
sequence.push({
|
|
outcome: 'no-handlers-left',
|
|
target: target
|
|
});
|
|
},
|
|
logEventResponse: function (_name, target, purpose) {
|
|
sequence.push({
|
|
outcome: 'response',
|
|
purpose: purpose,
|
|
target: target
|
|
});
|
|
},
|
|
write: function () {
|
|
var finishTime = new Date().getTime();
|
|
if (contains([
|
|
'mousemove',
|
|
'mouseover',
|
|
'mouseout',
|
|
systemInit()
|
|
], eventName)) {
|
|
return;
|
|
}
|
|
domGlobals.console.log(eventName, {
|
|
event: eventName,
|
|
time: finishTime - startTime,
|
|
target: initialTarget.dom(),
|
|
sequence: map$1(sequence, function (s) {
|
|
if (!contains([
|
|
'cut',
|
|
'stopped',
|
|
'response'
|
|
], s.outcome)) {
|
|
return s.outcome;
|
|
} else {
|
|
return '{' + s.purpose + '} ' + s.outcome + ' at (' + element(s.target) + ')';
|
|
}
|
|
})
|
|
});
|
|
}
|
|
};
|
|
};
|
|
var processEvent = function (eventName, initialTarget, f) {
|
|
var status = get(eventConfig.get(), eventName).orThunk(function () {
|
|
var patterns = keys(eventConfig.get());
|
|
return findMap(patterns, function (p) {
|
|
return eventName.indexOf(p) > -1 ? Option.some(eventConfig.get()[p]) : Option.none();
|
|
});
|
|
}).getOr(EventConfiguration.NORMAL);
|
|
switch (status) {
|
|
case EventConfiguration.NORMAL:
|
|
return f(noLogger());
|
|
case EventConfiguration.LOGGING: {
|
|
var logger = makeEventLogger(eventName, initialTarget);
|
|
var output = f(logger);
|
|
logger.write();
|
|
return output;
|
|
}
|
|
case EventConfiguration.STOP:
|
|
return true;
|
|
}
|
|
};
|
|
var path = [
|
|
'alloy/data/Fields',
|
|
'alloy/debugging/Debugging'
|
|
];
|
|
var getTrace = function () {
|
|
var err = new Error();
|
|
if (err.stack !== undefined) {
|
|
var lines = err.stack.split('\n');
|
|
return find$2(lines, function (line) {
|
|
return line.indexOf('alloy') > 0 && !exists(path, function (p) {
|
|
return line.indexOf(p) > -1;
|
|
});
|
|
}).getOr(unknown$3);
|
|
} else {
|
|
return unknown$3;
|
|
}
|
|
};
|
|
var ignoreEvent = {
|
|
logEventCut: noop,
|
|
logEventStopped: noop,
|
|
logNoParent: noop,
|
|
logEventNoHandlers: noop,
|
|
logEventResponse: noop,
|
|
write: noop
|
|
};
|
|
var monitorEvent = function (eventName, initialTarget, f) {
|
|
return processEvent(eventName, initialTarget, f);
|
|
};
|
|
var noLogger = constant(ignoreEvent);
|
|
|
|
var menuFields = constant([
|
|
strict$1('menu'),
|
|
strict$1('selectedMenu')
|
|
]);
|
|
var itemFields = constant([
|
|
strict$1('item'),
|
|
strict$1('selectedItem')
|
|
]);
|
|
var schema = constant(objOf(itemFields().concat(menuFields())));
|
|
var itemSchema = constant(objOf(itemFields()));
|
|
|
|
var _initSize = strictObjOf('initSize', [
|
|
strict$1('numColumns'),
|
|
strict$1('numRows')
|
|
]);
|
|
var itemMarkers = function () {
|
|
return strictOf('markers', itemSchema());
|
|
};
|
|
var tieredMenuMarkers = function () {
|
|
return strictObjOf('markers', [strict$1('backgroundMenu')].concat(menuFields()).concat(itemFields()));
|
|
};
|
|
var markers = function (required) {
|
|
return strictObjOf('markers', map$1(required, strict$1));
|
|
};
|
|
var onPresenceHandler = function (label, fieldName, presence) {
|
|
var trace = getTrace();
|
|
return field(fieldName, fieldName, presence, valueOf(function (f) {
|
|
return Result.value(function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
return f.apply(undefined, args);
|
|
});
|
|
}));
|
|
};
|
|
var onHandler = function (fieldName) {
|
|
return onPresenceHandler('onHandler', fieldName, defaulted(noop));
|
|
};
|
|
var onKeyboardHandler = function (fieldName) {
|
|
return onPresenceHandler('onKeyboardHandler', fieldName, defaulted(Option.none));
|
|
};
|
|
var onStrictHandler = function (fieldName) {
|
|
return onPresenceHandler('onHandler', fieldName, strict());
|
|
};
|
|
var onStrictKeyboardHandler = function (fieldName) {
|
|
return onPresenceHandler('onKeyboardHandler', fieldName, strict());
|
|
};
|
|
var output = function (name, value) {
|
|
return state$1(name, constant(value));
|
|
};
|
|
var snapshot = function (name) {
|
|
return state$1(name, identity);
|
|
};
|
|
var initSize = constant(_initSize);
|
|
|
|
var ReceivingSchema = [strictOf('channels', setOf$1(Result.value, objOfOnly([
|
|
onStrictHandler('onReceive'),
|
|
defaulted$1('schema', anyValue$1())
|
|
])))];
|
|
|
|
var Receiving = create$1({
|
|
fields: ReceivingSchema,
|
|
name: 'receiving',
|
|
active: ActiveReceiving
|
|
});
|
|
|
|
var updateAriaState = function (component, toggleConfig, toggleState) {
|
|
var ariaInfo = toggleConfig.aria;
|
|
ariaInfo.update(component, ariaInfo, toggleState.get());
|
|
};
|
|
var updateClass = function (component, toggleConfig, toggleState) {
|
|
toggleConfig.toggleClass.each(function (toggleClass) {
|
|
if (toggleState.get()) {
|
|
add$2(component.element(), toggleClass);
|
|
} else {
|
|
remove$4(component.element(), toggleClass);
|
|
}
|
|
});
|
|
};
|
|
var toggle = function (component, toggleConfig, toggleState) {
|
|
set$2(component, toggleConfig, toggleState, !toggleState.get());
|
|
};
|
|
var on = function (component, toggleConfig, toggleState) {
|
|
toggleState.set(true);
|
|
updateClass(component, toggleConfig, toggleState);
|
|
updateAriaState(component, toggleConfig, toggleState);
|
|
};
|
|
var off = function (component, toggleConfig, toggleState) {
|
|
toggleState.set(false);
|
|
updateClass(component, toggleConfig, toggleState);
|
|
updateAriaState(component, toggleConfig, toggleState);
|
|
};
|
|
var set$2 = function (component, toggleConfig, toggleState, state) {
|
|
var action = state ? on : off;
|
|
action(component, toggleConfig, toggleState);
|
|
};
|
|
var isOn = function (component, toggleConfig, toggleState) {
|
|
return toggleState.get();
|
|
};
|
|
var onLoad = function (component, toggleConfig, toggleState) {
|
|
set$2(component, toggleConfig, toggleState, toggleConfig.selected);
|
|
};
|
|
|
|
var ToggleApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
onLoad: onLoad,
|
|
toggle: toggle,
|
|
isOn: isOn,
|
|
on: on,
|
|
off: off,
|
|
set: set$2
|
|
});
|
|
|
|
var exhibit = function () {
|
|
return nu$5({});
|
|
};
|
|
var events$1 = function (toggleConfig, toggleState) {
|
|
var execute = executeEvent(toggleConfig, toggleState, toggle);
|
|
var load = loadEvent(toggleConfig, toggleState, onLoad);
|
|
return derive(flatten([
|
|
toggleConfig.toggleOnExecute ? [execute] : [],
|
|
[load]
|
|
]));
|
|
};
|
|
|
|
var ActiveToggle = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit,
|
|
events: events$1
|
|
});
|
|
|
|
var SetupBehaviourCellState = function (initialState) {
|
|
var init = function () {
|
|
var cell = Cell(initialState);
|
|
var get = function () {
|
|
return cell.get();
|
|
};
|
|
var set = function (newState) {
|
|
return cell.set(newState);
|
|
};
|
|
var clear = function () {
|
|
return cell.set(initialState);
|
|
};
|
|
var readState = function () {
|
|
return cell.get();
|
|
};
|
|
return {
|
|
get: get,
|
|
set: set,
|
|
clear: clear,
|
|
readState: readState
|
|
};
|
|
};
|
|
return { init: init };
|
|
};
|
|
|
|
var updatePressed = function (component, ariaInfo, status) {
|
|
set(component.element(), 'aria-pressed', status);
|
|
if (ariaInfo.syncWithExpanded) {
|
|
updateExpanded(component, ariaInfo, status);
|
|
}
|
|
};
|
|
var updateSelected = function (component, ariaInfo, status) {
|
|
set(component.element(), 'aria-selected', status);
|
|
};
|
|
var updateChecked = function (component, ariaInfo, status) {
|
|
set(component.element(), 'aria-checked', status);
|
|
};
|
|
var updateExpanded = function (component, ariaInfo, status) {
|
|
set(component.element(), 'aria-expanded', status);
|
|
};
|
|
|
|
var ToggleSchema = [
|
|
defaulted$1('selected', false),
|
|
option('toggleClass'),
|
|
defaulted$1('toggleOnExecute', true),
|
|
defaultedOf('aria', { mode: 'none' }, choose$1('mode', {
|
|
pressed: [
|
|
defaulted$1('syncWithExpanded', false),
|
|
output('update', updatePressed)
|
|
],
|
|
checked: [output('update', updateChecked)],
|
|
expanded: [output('update', updateExpanded)],
|
|
selected: [output('update', updateSelected)],
|
|
none: [output('update', noop)]
|
|
}))
|
|
];
|
|
|
|
var Toggling = create$1({
|
|
fields: ToggleSchema,
|
|
name: 'toggling',
|
|
active: ActiveToggle,
|
|
apis: ToggleApis,
|
|
state: SetupBehaviourCellState(false)
|
|
});
|
|
|
|
var format = function (command, update) {
|
|
return Receiving.config({
|
|
channels: wrap$1(formatChanged, {
|
|
onReceive: function (button, data) {
|
|
if (data.command === command) {
|
|
update(button, data.state);
|
|
}
|
|
}
|
|
})
|
|
});
|
|
};
|
|
var orientation = function (onReceive) {
|
|
return Receiving.config({ channels: wrap$1(orientationChanged, { onReceive: onReceive }) });
|
|
};
|
|
var receive$1 = function (channel, onReceive) {
|
|
return {
|
|
key: channel,
|
|
value: { onReceive: onReceive }
|
|
};
|
|
};
|
|
|
|
var prefix = 'tinymce-mobile';
|
|
var resolve = function (p) {
|
|
return prefix + '-' + p;
|
|
};
|
|
|
|
var pointerEvents = function () {
|
|
var onClick = function (component, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
emitExecute(component);
|
|
};
|
|
return [
|
|
run(click(), onClick),
|
|
run(tap(), onClick),
|
|
cutter(touchstart()),
|
|
cutter(mousedown())
|
|
];
|
|
};
|
|
var events$2 = function (optAction) {
|
|
var executeHandler = function (action) {
|
|
return runOnExecute(function (component, simulatedEvent) {
|
|
action(component);
|
|
simulatedEvent.stop();
|
|
});
|
|
};
|
|
return derive(flatten([
|
|
optAction.map(executeHandler).toArray(),
|
|
pointerEvents()
|
|
]));
|
|
};
|
|
|
|
var focus$2 = function (component, focusConfig) {
|
|
if (!focusConfig.ignore) {
|
|
focus$1(component.element());
|
|
focusConfig.onFocus(component);
|
|
}
|
|
};
|
|
var blur$1 = function (component, focusConfig) {
|
|
if (!focusConfig.ignore) {
|
|
blur(component.element());
|
|
}
|
|
};
|
|
var isFocused = function (component) {
|
|
return hasFocus(component.element());
|
|
};
|
|
|
|
var FocusApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
focus: focus$2,
|
|
blur: blur$1,
|
|
isFocused: isFocused
|
|
});
|
|
|
|
var exhibit$1 = function (base, focusConfig) {
|
|
var mod = focusConfig.ignore ? {} : { attributes: { tabindex: '-1' } };
|
|
return nu$5(mod);
|
|
};
|
|
var events$3 = function (focusConfig) {
|
|
return derive([run(focus(), function (component, simulatedEvent) {
|
|
focus$2(component, focusConfig);
|
|
simulatedEvent.stop();
|
|
})].concat(focusConfig.stopMousedown ? [run(mousedown(), function (_, simulatedEvent) {
|
|
simulatedEvent.event().prevent();
|
|
})] : []));
|
|
};
|
|
|
|
var ActiveFocus = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit$1,
|
|
events: events$3
|
|
});
|
|
|
|
var FocusSchema = [
|
|
onHandler('onFocus'),
|
|
defaulted$1('stopMousedown', false),
|
|
defaulted$1('ignore', false)
|
|
];
|
|
|
|
var Focusing = create$1({
|
|
fields: FocusSchema,
|
|
name: 'focusing',
|
|
active: ActiveFocus,
|
|
apis: FocusApis
|
|
});
|
|
|
|
var isSupported = function (dom) {
|
|
return dom.style !== undefined && isFunction(dom.style.getPropertyValue);
|
|
};
|
|
|
|
var internalSet = function (dom, property, value) {
|
|
if (!isString(value)) {
|
|
domGlobals.console.error('Invalid call to CSS.set. Property ', property, ':: Value ', value, ':: Element ', dom);
|
|
throw new Error('CSS value must be a string: ' + value);
|
|
}
|
|
if (isSupported(dom)) {
|
|
dom.style.setProperty(property, value);
|
|
}
|
|
};
|
|
var internalRemove = function (dom, property) {
|
|
if (isSupported(dom)) {
|
|
dom.style.removeProperty(property);
|
|
}
|
|
};
|
|
var set$3 = function (element, property, value) {
|
|
var dom = element.dom();
|
|
internalSet(dom, property, value);
|
|
};
|
|
var setAll$1 = function (element, css) {
|
|
var dom = element.dom();
|
|
each(css, function (v, k) {
|
|
internalSet(dom, k, v);
|
|
});
|
|
};
|
|
var get$4 = function (element, property) {
|
|
var dom = element.dom();
|
|
var styles = domGlobals.window.getComputedStyle(dom);
|
|
var r = styles.getPropertyValue(property);
|
|
return r === '' && !inBody(element) ? getUnsafeProperty(dom, property) : r;
|
|
};
|
|
var getUnsafeProperty = function (dom, property) {
|
|
return isSupported(dom) ? dom.style.getPropertyValue(property) : '';
|
|
};
|
|
var getRaw = function (element, property) {
|
|
var dom = element.dom();
|
|
var raw = getUnsafeProperty(dom, property);
|
|
return Option.from(raw).filter(function (r) {
|
|
return r.length > 0;
|
|
});
|
|
};
|
|
var remove$5 = function (element, property) {
|
|
var dom = element.dom();
|
|
internalRemove(dom, property);
|
|
if (getOpt(element, 'style').map(trim).is('')) {
|
|
remove$1(element, 'style');
|
|
}
|
|
};
|
|
var reflow = function (e) {
|
|
return e.dom().offsetWidth;
|
|
};
|
|
|
|
function Dimension (name, getOffset) {
|
|
var set = function (element, h) {
|
|
if (!isNumber(h) && !h.match(/^[0-9]+$/)) {
|
|
throw new Error(name + '.set accepts only positive integer values. Value was ' + h);
|
|
}
|
|
var dom = element.dom();
|
|
if (isSupported(dom)) {
|
|
dom.style[name] = h + 'px';
|
|
}
|
|
};
|
|
var get = function (element) {
|
|
var r = getOffset(element);
|
|
if (r <= 0 || r === null) {
|
|
var css = get$4(element, name);
|
|
return parseFloat(css) || 0;
|
|
}
|
|
return r;
|
|
};
|
|
var getOuter = get;
|
|
var aggregate = function (element, properties) {
|
|
return foldl(properties, function (acc, property) {
|
|
var val = get$4(element, property);
|
|
var value = val === undefined ? 0 : parseInt(val, 10);
|
|
return isNaN(value) ? acc : acc + value;
|
|
}, 0);
|
|
};
|
|
var max = function (element, value, properties) {
|
|
var cumulativeInclusions = aggregate(element, properties);
|
|
var absoluteMax = value > cumulativeInclusions ? value - cumulativeInclusions : 0;
|
|
return absoluteMax;
|
|
};
|
|
return {
|
|
set: set,
|
|
get: get,
|
|
getOuter: getOuter,
|
|
aggregate: aggregate,
|
|
max: max
|
|
};
|
|
}
|
|
|
|
var api = Dimension('height', function (element) {
|
|
var dom = element.dom();
|
|
return inBody(element) ? dom.getBoundingClientRect().height : dom.offsetHeight;
|
|
});
|
|
var get$5 = function (element) {
|
|
return api.get(element);
|
|
};
|
|
|
|
var ancestors = function (scope, predicate, isRoot) {
|
|
return filter$1(parents(scope, isRoot), predicate);
|
|
};
|
|
var siblings$1 = function (scope, predicate) {
|
|
return filter$1(siblings(scope), predicate);
|
|
};
|
|
|
|
var all$2 = function (selector) {
|
|
return all(selector);
|
|
};
|
|
var ancestors$1 = function (scope, selector, isRoot) {
|
|
return ancestors(scope, function (e) {
|
|
return is(e, selector);
|
|
}, isRoot);
|
|
};
|
|
var siblings$2 = function (scope, selector) {
|
|
return siblings$1(scope, function (e) {
|
|
return is(e, selector);
|
|
});
|
|
};
|
|
var descendants = function (scope, selector) {
|
|
return all(selector, scope);
|
|
};
|
|
|
|
var first = function (selector) {
|
|
return one(selector);
|
|
};
|
|
var ancestor$2 = function (scope, selector, isRoot) {
|
|
return ancestor$1(scope, function (e) {
|
|
return is(e, selector);
|
|
}, isRoot);
|
|
};
|
|
var descendant$1 = function (scope, selector) {
|
|
return one(selector, scope);
|
|
};
|
|
var closest$2 = function (scope, selector, isRoot) {
|
|
var is$1 = function (element, selector) {
|
|
return is(element, selector);
|
|
};
|
|
return ClosestOrAncestor(is$1, ancestor$2, scope, selector, isRoot);
|
|
};
|
|
|
|
var BACKSPACE = function () {
|
|
return [8];
|
|
};
|
|
var TAB = function () {
|
|
return [9];
|
|
};
|
|
var ENTER = function () {
|
|
return [13];
|
|
};
|
|
var ESCAPE = function () {
|
|
return [27];
|
|
};
|
|
var SPACE = function () {
|
|
return [32];
|
|
};
|
|
var LEFT = function () {
|
|
return [37];
|
|
};
|
|
var UP = function () {
|
|
return [38];
|
|
};
|
|
var RIGHT = function () {
|
|
return [39];
|
|
};
|
|
var DOWN = function () {
|
|
return [40];
|
|
};
|
|
|
|
var cyclePrev = function (values, index, predicate) {
|
|
var before = reverse(values.slice(0, index));
|
|
var after = reverse(values.slice(index + 1));
|
|
return find$2(before.concat(after), predicate);
|
|
};
|
|
var tryPrev = function (values, index, predicate) {
|
|
var before = reverse(values.slice(0, index));
|
|
return find$2(before, predicate);
|
|
};
|
|
var cycleNext = function (values, index, predicate) {
|
|
var before = values.slice(0, index);
|
|
var after = values.slice(index + 1);
|
|
return find$2(after.concat(before), predicate);
|
|
};
|
|
var tryNext = function (values, index, predicate) {
|
|
var after = values.slice(index + 1);
|
|
return find$2(after, predicate);
|
|
};
|
|
|
|
var inSet = function (keys) {
|
|
return function (event) {
|
|
var raw = event.raw();
|
|
return contains(keys, raw.which);
|
|
};
|
|
};
|
|
var and = function (preds) {
|
|
return function (event) {
|
|
return forall(preds, function (pred) {
|
|
return pred(event);
|
|
});
|
|
};
|
|
};
|
|
var isShift = function (event) {
|
|
var raw = event.raw();
|
|
return raw.shiftKey === true;
|
|
};
|
|
var isControl = function (event) {
|
|
var raw = event.raw();
|
|
return raw.ctrlKey === true;
|
|
};
|
|
var isNotShift = not(isShift);
|
|
|
|
var rule = function (matches, action) {
|
|
return {
|
|
matches: matches,
|
|
classification: action
|
|
};
|
|
};
|
|
var choose$2 = function (transitions, event) {
|
|
var transition = find$2(transitions, function (t) {
|
|
return t.matches(event);
|
|
});
|
|
return transition.map(function (t) {
|
|
return t.classification;
|
|
});
|
|
};
|
|
|
|
var cat = function (arr) {
|
|
var r = [];
|
|
var push = function (x) {
|
|
r.push(x);
|
|
};
|
|
for (var i = 0; i < arr.length; i++) {
|
|
arr[i].each(push);
|
|
}
|
|
return r;
|
|
};
|
|
var sequence = function (arr) {
|
|
var r = [];
|
|
for (var i = 0; i < arr.length; i++) {
|
|
var x = arr[i];
|
|
if (x.isSome()) {
|
|
r.push(x.getOrDie());
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
}
|
|
return Option.some(r);
|
|
};
|
|
var someIf = function (b, a) {
|
|
return b ? Option.some(a) : Option.none();
|
|
};
|
|
|
|
var cycleBy = function (value, delta, min, max) {
|
|
var r = value + delta;
|
|
return r > max ? min : r < min ? max : r;
|
|
};
|
|
var clamp = function (value, min, max) {
|
|
return Math.min(Math.max(value, min), max);
|
|
};
|
|
|
|
var dehighlightAllExcept = function (component, hConfig, hState, skip) {
|
|
var highlighted = descendants(component.element(), '.' + hConfig.highlightClass);
|
|
each$1(highlighted, function (h) {
|
|
if (!exists(skip, function (skipComp) {
|
|
return skipComp.element() === h;
|
|
})) {
|
|
remove$4(h, hConfig.highlightClass);
|
|
component.getSystem().getByDom(h).each(function (target) {
|
|
hConfig.onDehighlight(component, target);
|
|
emit(target, dehighlight());
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var dehighlightAll = function (component, hConfig, hState) {
|
|
return dehighlightAllExcept(component, hConfig, hState, []);
|
|
};
|
|
var dehighlight$1 = function (component, hConfig, hState, target) {
|
|
if (isHighlighted(component, hConfig, hState, target)) {
|
|
remove$4(target.element(), hConfig.highlightClass);
|
|
hConfig.onDehighlight(component, target);
|
|
emit(target, dehighlight());
|
|
}
|
|
};
|
|
var highlight$1 = function (component, hConfig, hState, target) {
|
|
dehighlightAllExcept(component, hConfig, hState, [target]);
|
|
if (!isHighlighted(component, hConfig, hState, target)) {
|
|
add$2(target.element(), hConfig.highlightClass);
|
|
hConfig.onHighlight(component, target);
|
|
emit(target, highlight());
|
|
}
|
|
};
|
|
var highlightFirst = function (component, hConfig, hState) {
|
|
getFirst(component, hConfig).each(function (firstComp) {
|
|
highlight$1(component, hConfig, hState, firstComp);
|
|
});
|
|
};
|
|
var highlightLast = function (component, hConfig, hState) {
|
|
getLast(component, hConfig).each(function (lastComp) {
|
|
highlight$1(component, hConfig, hState, lastComp);
|
|
});
|
|
};
|
|
var highlightAt = function (component, hConfig, hState, index) {
|
|
getByIndex(component, hConfig, hState, index).fold(function (err) {
|
|
throw new Error(err);
|
|
}, function (firstComp) {
|
|
highlight$1(component, hConfig, hState, firstComp);
|
|
});
|
|
};
|
|
var highlightBy = function (component, hConfig, hState, predicate) {
|
|
var candidates = getCandidates(component, hConfig);
|
|
var targetComp = find$2(candidates, predicate);
|
|
targetComp.each(function (c) {
|
|
highlight$1(component, hConfig, hState, c);
|
|
});
|
|
};
|
|
var isHighlighted = function (component, hConfig, hState, queryTarget) {
|
|
return has$2(queryTarget.element(), hConfig.highlightClass);
|
|
};
|
|
var getHighlighted = function (component, hConfig, _hState) {
|
|
return descendant$1(component.element(), '.' + hConfig.highlightClass).bind(function (e) {
|
|
return component.getSystem().getByDom(e).toOption();
|
|
});
|
|
};
|
|
var getByIndex = function (component, hConfig, hState, index) {
|
|
var items = descendants(component.element(), '.' + hConfig.itemClass);
|
|
return Option.from(items[index]).fold(function () {
|
|
return Result.error('No element found with index ' + index);
|
|
}, component.getSystem().getByDom);
|
|
};
|
|
var getFirst = function (component, hConfig, _hState) {
|
|
return descendant$1(component.element(), '.' + hConfig.itemClass).bind(function (e) {
|
|
return component.getSystem().getByDom(e).toOption();
|
|
});
|
|
};
|
|
var getLast = function (component, hConfig, _hState) {
|
|
var items = descendants(component.element(), '.' + hConfig.itemClass);
|
|
var last = items.length > 0 ? Option.some(items[items.length - 1]) : Option.none();
|
|
return last.bind(function (c) {
|
|
return component.getSystem().getByDom(c).toOption();
|
|
});
|
|
};
|
|
var getDelta = function (component, hConfig, hState, delta) {
|
|
var items = descendants(component.element(), '.' + hConfig.itemClass);
|
|
var current = findIndex(items, function (item) {
|
|
return has$2(item, hConfig.highlightClass);
|
|
});
|
|
return current.bind(function (selected) {
|
|
var dest = cycleBy(selected, delta, 0, items.length - 1);
|
|
return component.getSystem().getByDom(items[dest]).toOption();
|
|
});
|
|
};
|
|
var getPrevious = function (component, hConfig, hState) {
|
|
return getDelta(component, hConfig, hState, -1);
|
|
};
|
|
var getNext = function (component, hConfig, hState) {
|
|
return getDelta(component, hConfig, hState, +1);
|
|
};
|
|
var getCandidates = function (component, hConfig, _hState) {
|
|
var items = descendants(component.element(), '.' + hConfig.itemClass);
|
|
return cat(map$1(items, function (i) {
|
|
return component.getSystem().getByDom(i).toOption();
|
|
}));
|
|
};
|
|
|
|
var HighlightApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
dehighlightAll: dehighlightAll,
|
|
dehighlight: dehighlight$1,
|
|
highlight: highlight$1,
|
|
highlightFirst: highlightFirst,
|
|
highlightLast: highlightLast,
|
|
highlightAt: highlightAt,
|
|
highlightBy: highlightBy,
|
|
isHighlighted: isHighlighted,
|
|
getHighlighted: getHighlighted,
|
|
getFirst: getFirst,
|
|
getLast: getLast,
|
|
getPrevious: getPrevious,
|
|
getNext: getNext,
|
|
getCandidates: getCandidates
|
|
});
|
|
|
|
var HighlightSchema = [
|
|
strict$1('highlightClass'),
|
|
strict$1('itemClass'),
|
|
onHandler('onHighlight'),
|
|
onHandler('onDehighlight')
|
|
];
|
|
|
|
var Highlighting = create$1({
|
|
fields: HighlightSchema,
|
|
name: 'highlighting',
|
|
apis: HighlightApis
|
|
});
|
|
|
|
var reportFocusShifting = function (component, prevFocus, newFocus) {
|
|
var noChange = prevFocus.exists(function (p) {
|
|
return newFocus.exists(function (n) {
|
|
return eq(n, p);
|
|
});
|
|
});
|
|
if (!noChange) {
|
|
emitWith(component, focusShifted(), {
|
|
prevFocus: prevFocus,
|
|
newFocus: newFocus
|
|
});
|
|
}
|
|
};
|
|
var dom = function () {
|
|
var get = function (component) {
|
|
return search(component.element());
|
|
};
|
|
var set = function (component, focusee) {
|
|
var prevFocus = get(component);
|
|
component.getSystem().triggerFocus(focusee, component.element());
|
|
var newFocus = get(component);
|
|
reportFocusShifting(component, prevFocus, newFocus);
|
|
};
|
|
return {
|
|
get: get,
|
|
set: set
|
|
};
|
|
};
|
|
var highlights = function () {
|
|
var get = function (component) {
|
|
return Highlighting.getHighlighted(component).map(function (item) {
|
|
return item.element();
|
|
});
|
|
};
|
|
var set = function (component, element) {
|
|
var prevFocus = get(component);
|
|
component.getSystem().getByDom(element).fold(noop, function (item) {
|
|
Highlighting.highlight(component, item);
|
|
});
|
|
var newFocus = get(component);
|
|
reportFocusShifting(component, prevFocus, newFocus);
|
|
};
|
|
return {
|
|
get: get,
|
|
set: set
|
|
};
|
|
};
|
|
|
|
var FocusInsideModes;
|
|
(function (FocusInsideModes) {
|
|
FocusInsideModes['OnFocusMode'] = 'onFocus';
|
|
FocusInsideModes['OnEnterOrSpaceMode'] = 'onEnterOrSpace';
|
|
FocusInsideModes['OnApiMode'] = 'onApi';
|
|
}(FocusInsideModes || (FocusInsideModes = {})));
|
|
|
|
var typical = function (infoSchema, stateInit, getKeydownRules, getKeyupRules, optFocusIn) {
|
|
var schema = function () {
|
|
return infoSchema.concat([
|
|
defaulted$1('focusManager', dom()),
|
|
defaultedOf('focusInside', 'onFocus', valueOf(function (val) {
|
|
return contains([
|
|
'onFocus',
|
|
'onEnterOrSpace',
|
|
'onApi'
|
|
], val) ? Result.value(val) : Result.error('Invalid value for focusInside');
|
|
})),
|
|
output('handler', me),
|
|
output('state', stateInit),
|
|
output('sendFocusIn', optFocusIn)
|
|
]);
|
|
};
|
|
var processKey = function (component, simulatedEvent, getRules, keyingConfig, keyingState) {
|
|
var rules = getRules(component, simulatedEvent, keyingConfig, keyingState);
|
|
return choose$2(rules, simulatedEvent.event()).bind(function (rule) {
|
|
return rule(component, simulatedEvent, keyingConfig, keyingState);
|
|
});
|
|
};
|
|
var toEvents = function (keyingConfig, keyingState) {
|
|
var onFocusHandler = keyingConfig.focusInside !== FocusInsideModes.OnFocusMode ? Option.none() : optFocusIn(keyingConfig).map(function (focusIn) {
|
|
return run(focus(), function (component, simulatedEvent) {
|
|
focusIn(component, keyingConfig, keyingState);
|
|
simulatedEvent.stop();
|
|
});
|
|
});
|
|
var tryGoInsideComponent = function (component, simulatedEvent) {
|
|
var isEnterOrSpace = inSet(SPACE().concat(ENTER()))(simulatedEvent.event());
|
|
if (keyingConfig.focusInside === FocusInsideModes.OnEnterOrSpaceMode && isEnterOrSpace && isSource(component, simulatedEvent)) {
|
|
optFocusIn(keyingConfig).each(function (focusIn) {
|
|
focusIn(component, keyingConfig, keyingState);
|
|
simulatedEvent.stop();
|
|
});
|
|
}
|
|
};
|
|
var keyboardEvents = [
|
|
run(keydown(), function (component, simulatedEvent) {
|
|
processKey(component, simulatedEvent, getKeydownRules, keyingConfig, keyingState).fold(function () {
|
|
tryGoInsideComponent(component, simulatedEvent);
|
|
}, function (_) {
|
|
simulatedEvent.stop();
|
|
});
|
|
}),
|
|
run(keyup(), function (component, simulatedEvent) {
|
|
processKey(component, simulatedEvent, getKeyupRules, keyingConfig, keyingState).each(function (_) {
|
|
simulatedEvent.stop();
|
|
});
|
|
})
|
|
];
|
|
return derive(onFocusHandler.toArray().concat(keyboardEvents));
|
|
};
|
|
var me = {
|
|
schema: schema,
|
|
processKey: processKey,
|
|
toEvents: toEvents
|
|
};
|
|
return me;
|
|
};
|
|
|
|
var create$2 = function (cyclicField) {
|
|
var schema = [
|
|
option('onEscape'),
|
|
option('onEnter'),
|
|
defaulted$1('selector', '[data-alloy-tabstop="true"]:not(:disabled)'),
|
|
defaulted$1('firstTabstop', 0),
|
|
defaulted$1('useTabstopAt', constant(true)),
|
|
option('visibilitySelector')
|
|
].concat([cyclicField]);
|
|
var isVisible = function (tabbingConfig, element) {
|
|
var target = tabbingConfig.visibilitySelector.bind(function (sel) {
|
|
return closest$2(element, sel);
|
|
}).getOr(element);
|
|
return get$5(target) > 0;
|
|
};
|
|
var findInitial = function (component, tabbingConfig) {
|
|
var tabstops = descendants(component.element(), tabbingConfig.selector);
|
|
var visibles = filter$1(tabstops, function (elem) {
|
|
return isVisible(tabbingConfig, elem);
|
|
});
|
|
return Option.from(visibles[tabbingConfig.firstTabstop]);
|
|
};
|
|
var findCurrent = function (component, tabbingConfig) {
|
|
return tabbingConfig.focusManager.get(component).bind(function (elem) {
|
|
return closest$2(elem, tabbingConfig.selector);
|
|
});
|
|
};
|
|
var isTabstop = function (tabbingConfig, element) {
|
|
return isVisible(tabbingConfig, element) && tabbingConfig.useTabstopAt(element);
|
|
};
|
|
var focusIn = function (component, tabbingConfig, _tabbingState) {
|
|
findInitial(component, tabbingConfig).each(function (target) {
|
|
tabbingConfig.focusManager.set(component, target);
|
|
});
|
|
};
|
|
var goFromTabstop = function (component, tabstops, stopIndex, tabbingConfig, cycle) {
|
|
return cycle(tabstops, stopIndex, function (elem) {
|
|
return isTabstop(tabbingConfig, elem);
|
|
}).fold(function () {
|
|
return tabbingConfig.cyclic ? Option.some(true) : Option.none();
|
|
}, function (target) {
|
|
tabbingConfig.focusManager.set(component, target);
|
|
return Option.some(true);
|
|
});
|
|
};
|
|
var go = function (component, _simulatedEvent, tabbingConfig, cycle) {
|
|
var tabstops = descendants(component.element(), tabbingConfig.selector);
|
|
return findCurrent(component, tabbingConfig).bind(function (tabstop) {
|
|
var optStopIndex = findIndex(tabstops, curry(eq, tabstop));
|
|
return optStopIndex.bind(function (stopIndex) {
|
|
return goFromTabstop(component, tabstops, stopIndex, tabbingConfig, cycle);
|
|
});
|
|
});
|
|
};
|
|
var goBackwards = function (component, simulatedEvent, tabbingConfig) {
|
|
var navigate = tabbingConfig.cyclic ? cyclePrev : tryPrev;
|
|
return go(component, simulatedEvent, tabbingConfig, navigate);
|
|
};
|
|
var goForwards = function (component, simulatedEvent, tabbingConfig) {
|
|
var navigate = tabbingConfig.cyclic ? cycleNext : tryNext;
|
|
return go(component, simulatedEvent, tabbingConfig, navigate);
|
|
};
|
|
var execute = function (component, simulatedEvent, tabbingConfig) {
|
|
return tabbingConfig.onEnter.bind(function (f) {
|
|
return f(component, simulatedEvent);
|
|
});
|
|
};
|
|
var exit = function (component, simulatedEvent, tabbingConfig) {
|
|
return tabbingConfig.onEscape.bind(function (f) {
|
|
return f(component, simulatedEvent);
|
|
});
|
|
};
|
|
var getKeydownRules = constant([
|
|
rule(and([
|
|
isShift,
|
|
inSet(TAB())
|
|
]), goBackwards),
|
|
rule(inSet(TAB()), goForwards),
|
|
rule(inSet(ESCAPE()), exit),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(ENTER())
|
|
]), execute)
|
|
]);
|
|
var getKeyupRules = constant([]);
|
|
return typical(schema, NoState.init, getKeydownRules, getKeyupRules, function () {
|
|
return Option.some(focusIn);
|
|
});
|
|
};
|
|
|
|
var AcyclicType = create$2(state$1('cyclic', constant(false)));
|
|
|
|
var CyclicType = create$2(state$1('cyclic', constant(true)));
|
|
|
|
var inside = function (target) {
|
|
return name(target) === 'input' && get$1(target, 'type') !== 'radio' || name(target) === 'textarea';
|
|
};
|
|
|
|
var doDefaultExecute = function (component, _simulatedEvent, focused) {
|
|
dispatch(component, focused, execute());
|
|
return Option.some(true);
|
|
};
|
|
var defaultExecute = function (component, simulatedEvent, focused) {
|
|
var isComplex = inside(focused) && inSet(SPACE())(simulatedEvent.event());
|
|
return isComplex ? Option.none() : doDefaultExecute(component, simulatedEvent, focused);
|
|
};
|
|
var stopEventForFirefox = function (_component, _simulatedEvent) {
|
|
return Option.some(true);
|
|
};
|
|
|
|
var schema$1 = [
|
|
defaulted$1('execute', defaultExecute),
|
|
defaulted$1('useSpace', false),
|
|
defaulted$1('useEnter', true),
|
|
defaulted$1('useControlEnter', false),
|
|
defaulted$1('useDown', false)
|
|
];
|
|
var execute$1 = function (component, simulatedEvent, executeConfig) {
|
|
return executeConfig.execute(component, simulatedEvent, component.element());
|
|
};
|
|
var getKeydownRules = function (component, _simulatedEvent, executeConfig, _executeState) {
|
|
var spaceExec = executeConfig.useSpace && !inside(component.element()) ? SPACE() : [];
|
|
var enterExec = executeConfig.useEnter ? ENTER() : [];
|
|
var downExec = executeConfig.useDown ? DOWN() : [];
|
|
var execKeys = spaceExec.concat(enterExec).concat(downExec);
|
|
return [rule(inSet(execKeys), execute$1)].concat(executeConfig.useControlEnter ? [rule(and([
|
|
isControl,
|
|
inSet(ENTER())
|
|
]), execute$1)] : []);
|
|
};
|
|
var getKeyupRules = function (component, _simulatedEvent, executeConfig, _executeState) {
|
|
return executeConfig.useSpace && !inside(component.element()) ? [rule(inSet(SPACE()), stopEventForFirefox)] : [];
|
|
};
|
|
var ExecutionType = typical(schema$1, NoState.init, getKeydownRules, getKeyupRules, function () {
|
|
return Option.none();
|
|
});
|
|
|
|
var flatgrid = function () {
|
|
var dimensions = Cell(Option.none());
|
|
var setGridSize = function (numRows, numColumns) {
|
|
dimensions.set(Option.some({
|
|
numRows: numRows,
|
|
numColumns: numColumns
|
|
}));
|
|
};
|
|
var getNumRows = function () {
|
|
return dimensions.get().map(function (d) {
|
|
return d.numRows;
|
|
});
|
|
};
|
|
var getNumColumns = function () {
|
|
return dimensions.get().map(function (d) {
|
|
return d.numColumns;
|
|
});
|
|
};
|
|
return nu$6({
|
|
readState: function () {
|
|
return dimensions.get().map(function (d) {
|
|
return {
|
|
numRows: String(d.numRows),
|
|
numColumns: String(d.numColumns)
|
|
};
|
|
}).getOr({
|
|
numRows: '?',
|
|
numColumns: '?'
|
|
});
|
|
},
|
|
setGridSize: setGridSize,
|
|
getNumRows: getNumRows,
|
|
getNumColumns: getNumColumns
|
|
});
|
|
};
|
|
var init = function (spec) {
|
|
return spec.state(spec);
|
|
};
|
|
|
|
var KeyingState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
flatgrid: flatgrid,
|
|
init: init
|
|
});
|
|
|
|
var onDirection = function (isLtr, isRtl) {
|
|
return function (element) {
|
|
return getDirection(element) === 'rtl' ? isRtl : isLtr;
|
|
};
|
|
};
|
|
var getDirection = function (element) {
|
|
return get$4(element, 'direction') === 'rtl' ? 'rtl' : 'ltr';
|
|
};
|
|
|
|
var useH = function (movement) {
|
|
return function (component, simulatedEvent, config, state) {
|
|
var move = movement(component.element());
|
|
return use(move, component, simulatedEvent, config, state);
|
|
};
|
|
};
|
|
var west = function (moveLeft, moveRight) {
|
|
var movement = onDirection(moveLeft, moveRight);
|
|
return useH(movement);
|
|
};
|
|
var east = function (moveLeft, moveRight) {
|
|
var movement = onDirection(moveRight, moveLeft);
|
|
return useH(movement);
|
|
};
|
|
var useV = function (move) {
|
|
return function (component, simulatedEvent, config, state) {
|
|
return use(move, component, simulatedEvent, config, state);
|
|
};
|
|
};
|
|
var use = function (move, component, simulatedEvent, config, state) {
|
|
var outcome = config.focusManager.get(component).bind(function (focused) {
|
|
return move(component.element(), focused, config, state);
|
|
});
|
|
return outcome.map(function (newFocus) {
|
|
config.focusManager.set(component, newFocus);
|
|
return true;
|
|
});
|
|
};
|
|
var north = useV;
|
|
var south = useV;
|
|
var move = useV;
|
|
|
|
var isHidden = function (dom) {
|
|
return dom.offsetWidth <= 0 && dom.offsetHeight <= 0;
|
|
};
|
|
var isVisible = function (element) {
|
|
return !isHidden(element.dom());
|
|
};
|
|
|
|
var locate = function (candidates, predicate) {
|
|
return findIndex(candidates, predicate).map(function (index) {
|
|
return {
|
|
index: constant(index),
|
|
candidates: constant(candidates)
|
|
};
|
|
});
|
|
};
|
|
|
|
var locateVisible = function (container, current, selector) {
|
|
var predicate = function (x) {
|
|
return eq(x, current);
|
|
};
|
|
var candidates = descendants(container, selector);
|
|
var visible = filter$1(candidates, isVisible);
|
|
return locate(visible, predicate);
|
|
};
|
|
var findIndex$1 = function (elements, target) {
|
|
return findIndex(elements, function (elem) {
|
|
return eq(target, elem);
|
|
});
|
|
};
|
|
|
|
var withGrid = function (values, index, numCols, f) {
|
|
var oldRow = Math.floor(index / numCols);
|
|
var oldColumn = index % numCols;
|
|
return f(oldRow, oldColumn).bind(function (address) {
|
|
var newIndex = address.row() * numCols + address.column();
|
|
return newIndex >= 0 && newIndex < values.length ? Option.some(values[newIndex]) : Option.none();
|
|
});
|
|
};
|
|
var cycleHorizontal = function (values, index, numRows, numCols, delta) {
|
|
return withGrid(values, index, numCols, function (oldRow, oldColumn) {
|
|
var onLastRow = oldRow === numRows - 1;
|
|
var colsInRow = onLastRow ? values.length - oldRow * numCols : numCols;
|
|
var newColumn = cycleBy(oldColumn, delta, 0, colsInRow - 1);
|
|
return Option.some({
|
|
row: constant(oldRow),
|
|
column: constant(newColumn)
|
|
});
|
|
});
|
|
};
|
|
var cycleVertical = function (values, index, numRows, numCols, delta) {
|
|
return withGrid(values, index, numCols, function (oldRow, oldColumn) {
|
|
var newRow = cycleBy(oldRow, delta, 0, numRows - 1);
|
|
var onLastRow = newRow === numRows - 1;
|
|
var colsInRow = onLastRow ? values.length - newRow * numCols : numCols;
|
|
var newCol = clamp(oldColumn, 0, colsInRow - 1);
|
|
return Option.some({
|
|
row: constant(newRow),
|
|
column: constant(newCol)
|
|
});
|
|
});
|
|
};
|
|
var cycleRight = function (values, index, numRows, numCols) {
|
|
return cycleHorizontal(values, index, numRows, numCols, +1);
|
|
};
|
|
var cycleLeft = function (values, index, numRows, numCols) {
|
|
return cycleHorizontal(values, index, numRows, numCols, -1);
|
|
};
|
|
var cycleUp = function (values, index, numRows, numCols) {
|
|
return cycleVertical(values, index, numRows, numCols, -1);
|
|
};
|
|
var cycleDown = function (values, index, numRows, numCols) {
|
|
return cycleVertical(values, index, numRows, numCols, +1);
|
|
};
|
|
|
|
var schema$2 = [
|
|
strict$1('selector'),
|
|
defaulted$1('execute', defaultExecute),
|
|
onKeyboardHandler('onEscape'),
|
|
defaulted$1('captureTab', false),
|
|
initSize()
|
|
];
|
|
var focusIn = function (component, gridConfig, _gridState) {
|
|
descendant$1(component.element(), gridConfig.selector).each(function (first) {
|
|
gridConfig.focusManager.set(component, first);
|
|
});
|
|
};
|
|
var findCurrent = function (component, gridConfig) {
|
|
return gridConfig.focusManager.get(component).bind(function (elem) {
|
|
return closest$2(elem, gridConfig.selector);
|
|
});
|
|
};
|
|
var execute$2 = function (component, simulatedEvent, gridConfig, _gridState) {
|
|
return findCurrent(component, gridConfig).bind(function (focused) {
|
|
return gridConfig.execute(component, simulatedEvent, focused);
|
|
});
|
|
};
|
|
var doMove = function (cycle) {
|
|
return function (element, focused, gridConfig, gridState) {
|
|
return locateVisible(element, focused, gridConfig.selector).bind(function (identified) {
|
|
return cycle(identified.candidates(), identified.index(), gridState.getNumRows().getOr(gridConfig.initSize.numRows), gridState.getNumColumns().getOr(gridConfig.initSize.numColumns));
|
|
});
|
|
};
|
|
};
|
|
var handleTab = function (_component, _simulatedEvent, gridConfig) {
|
|
return gridConfig.captureTab ? Option.some(true) : Option.none();
|
|
};
|
|
var doEscape = function (component, simulatedEvent, gridConfig) {
|
|
return gridConfig.onEscape(component, simulatedEvent);
|
|
};
|
|
var moveLeft = doMove(cycleLeft);
|
|
var moveRight = doMove(cycleRight);
|
|
var moveNorth = doMove(cycleUp);
|
|
var moveSouth = doMove(cycleDown);
|
|
var getKeydownRules$1 = constant([
|
|
rule(inSet(LEFT()), west(moveLeft, moveRight)),
|
|
rule(inSet(RIGHT()), east(moveLeft, moveRight)),
|
|
rule(inSet(UP()), north(moveNorth)),
|
|
rule(inSet(DOWN()), south(moveSouth)),
|
|
rule(and([
|
|
isShift,
|
|
inSet(TAB())
|
|
]), handleTab),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(TAB())
|
|
]), handleTab),
|
|
rule(inSet(ESCAPE()), doEscape),
|
|
rule(inSet(SPACE().concat(ENTER())), execute$2)
|
|
]);
|
|
var getKeyupRules$1 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
|
|
var FlatgridType = typical(schema$2, flatgrid, getKeydownRules$1, getKeyupRules$1, function () {
|
|
return Option.some(focusIn);
|
|
});
|
|
|
|
var horizontal = function (container, selector, current, delta) {
|
|
var isDisabledButton = function (candidate) {
|
|
return name(candidate) === 'button' && get$1(candidate, 'disabled') === 'disabled';
|
|
};
|
|
var tryCycle = function (initial, index, candidates) {
|
|
var newIndex = cycleBy(index, delta, 0, candidates.length - 1);
|
|
if (newIndex === initial) {
|
|
return Option.none();
|
|
} else {
|
|
return isDisabledButton(candidates[newIndex]) ? tryCycle(initial, newIndex, candidates) : Option.from(candidates[newIndex]);
|
|
}
|
|
};
|
|
return locateVisible(container, current, selector).bind(function (identified) {
|
|
var index = identified.index();
|
|
var candidates = identified.candidates();
|
|
return tryCycle(index, index, candidates);
|
|
});
|
|
};
|
|
|
|
var schema$3 = [
|
|
strict$1('selector'),
|
|
defaulted$1('getInitial', Option.none),
|
|
defaulted$1('execute', defaultExecute),
|
|
onKeyboardHandler('onEscape'),
|
|
defaulted$1('executeOnMove', false),
|
|
defaulted$1('allowVertical', true)
|
|
];
|
|
var findCurrent$1 = function (component, flowConfig) {
|
|
return flowConfig.focusManager.get(component).bind(function (elem) {
|
|
return closest$2(elem, flowConfig.selector);
|
|
});
|
|
};
|
|
var execute$3 = function (component, simulatedEvent, flowConfig) {
|
|
return findCurrent$1(component, flowConfig).bind(function (focused) {
|
|
return flowConfig.execute(component, simulatedEvent, focused);
|
|
});
|
|
};
|
|
var focusIn$1 = function (component, flowConfig, _state) {
|
|
flowConfig.getInitial(component).orThunk(function () {
|
|
return descendant$1(component.element(), flowConfig.selector);
|
|
}).each(function (first) {
|
|
flowConfig.focusManager.set(component, first);
|
|
});
|
|
};
|
|
var moveLeft$1 = function (element, focused, info) {
|
|
return horizontal(element, info.selector, focused, -1);
|
|
};
|
|
var moveRight$1 = function (element, focused, info) {
|
|
return horizontal(element, info.selector, focused, +1);
|
|
};
|
|
var doMove$1 = function (movement) {
|
|
return function (component, simulatedEvent, flowConfig, flowState) {
|
|
return movement(component, simulatedEvent, flowConfig, flowState).bind(function () {
|
|
return flowConfig.executeOnMove ? execute$3(component, simulatedEvent, flowConfig) : Option.some(true);
|
|
});
|
|
};
|
|
};
|
|
var doEscape$1 = function (component, simulatedEvent, flowConfig) {
|
|
return flowConfig.onEscape(component, simulatedEvent);
|
|
};
|
|
var getKeydownRules$2 = function (_component, _se, flowConfig, _flowState) {
|
|
var westMovers = LEFT().concat(flowConfig.allowVertical ? UP() : []);
|
|
var eastMovers = RIGHT().concat(flowConfig.allowVertical ? DOWN() : []);
|
|
return [
|
|
rule(inSet(westMovers), doMove$1(west(moveLeft$1, moveRight$1))),
|
|
rule(inSet(eastMovers), doMove$1(east(moveLeft$1, moveRight$1))),
|
|
rule(inSet(ENTER()), execute$3),
|
|
rule(inSet(SPACE()), execute$3),
|
|
rule(inSet(ESCAPE()), doEscape$1)
|
|
];
|
|
};
|
|
var getKeyupRules$2 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
|
|
var FlowType = typical(schema$3, NoState.init, getKeydownRules$2, getKeyupRules$2, function () {
|
|
return Option.some(focusIn$1);
|
|
});
|
|
|
|
var toCell = function (matrix, rowIndex, columnIndex) {
|
|
return Option.from(matrix[rowIndex]).bind(function (row) {
|
|
return Option.from(row[columnIndex]).map(function (cell) {
|
|
return {
|
|
rowIndex: rowIndex,
|
|
columnIndex: columnIndex,
|
|
cell: cell
|
|
};
|
|
});
|
|
});
|
|
};
|
|
var cycleHorizontal$1 = function (matrix, rowIndex, startCol, deltaCol) {
|
|
var row = matrix[rowIndex];
|
|
var colsInRow = row.length;
|
|
var newColIndex = cycleBy(startCol, deltaCol, 0, colsInRow - 1);
|
|
return toCell(matrix, rowIndex, newColIndex);
|
|
};
|
|
var cycleVertical$1 = function (matrix, colIndex, startRow, deltaRow) {
|
|
var nextRowIndex = cycleBy(startRow, deltaRow, 0, matrix.length - 1);
|
|
var colsInNextRow = matrix[nextRowIndex].length;
|
|
var nextColIndex = clamp(colIndex, 0, colsInNextRow - 1);
|
|
return toCell(matrix, nextRowIndex, nextColIndex);
|
|
};
|
|
var moveHorizontal = function (matrix, rowIndex, startCol, deltaCol) {
|
|
var row = matrix[rowIndex];
|
|
var colsInRow = row.length;
|
|
var newColIndex = clamp(startCol + deltaCol, 0, colsInRow - 1);
|
|
return toCell(matrix, rowIndex, newColIndex);
|
|
};
|
|
var moveVertical = function (matrix, colIndex, startRow, deltaRow) {
|
|
var nextRowIndex = clamp(startRow + deltaRow, 0, matrix.length - 1);
|
|
var colsInNextRow = matrix[nextRowIndex].length;
|
|
var nextColIndex = clamp(colIndex, 0, colsInNextRow - 1);
|
|
return toCell(matrix, nextRowIndex, nextColIndex);
|
|
};
|
|
var cycleRight$1 = function (matrix, startRow, startCol) {
|
|
return cycleHorizontal$1(matrix, startRow, startCol, +1);
|
|
};
|
|
var cycleLeft$1 = function (matrix, startRow, startCol) {
|
|
return cycleHorizontal$1(matrix, startRow, startCol, -1);
|
|
};
|
|
var cycleUp$1 = function (matrix, startRow, startCol) {
|
|
return cycleVertical$1(matrix, startCol, startRow, -1);
|
|
};
|
|
var cycleDown$1 = function (matrix, startRow, startCol) {
|
|
return cycleVertical$1(matrix, startCol, startRow, +1);
|
|
};
|
|
var moveLeft$2 = function (matrix, startRow, startCol) {
|
|
return moveHorizontal(matrix, startRow, startCol, -1);
|
|
};
|
|
var moveRight$2 = function (matrix, startRow, startCol) {
|
|
return moveHorizontal(matrix, startRow, startCol, +1);
|
|
};
|
|
var moveUp = function (matrix, startRow, startCol) {
|
|
return moveVertical(matrix, startCol, startRow, -1);
|
|
};
|
|
var moveDown = function (matrix, startRow, startCol) {
|
|
return moveVertical(matrix, startCol, startRow, +1);
|
|
};
|
|
|
|
var schema$4 = [
|
|
strictObjOf('selectors', [
|
|
strict$1('row'),
|
|
strict$1('cell')
|
|
]),
|
|
defaulted$1('cycles', true),
|
|
defaulted$1('previousSelector', Option.none),
|
|
defaulted$1('execute', defaultExecute)
|
|
];
|
|
var focusIn$2 = function (component, matrixConfig, _state) {
|
|
var focused = matrixConfig.previousSelector(component).orThunk(function () {
|
|
var selectors = matrixConfig.selectors;
|
|
return descendant$1(component.element(), selectors.cell);
|
|
});
|
|
focused.each(function (cell) {
|
|
matrixConfig.focusManager.set(component, cell);
|
|
});
|
|
};
|
|
var execute$4 = function (component, simulatedEvent, matrixConfig) {
|
|
return search(component.element()).bind(function (focused) {
|
|
return matrixConfig.execute(component, simulatedEvent, focused);
|
|
});
|
|
};
|
|
var toMatrix = function (rows, matrixConfig) {
|
|
return map$1(rows, function (row) {
|
|
return descendants(row, matrixConfig.selectors.cell);
|
|
});
|
|
};
|
|
var doMove$2 = function (ifCycle, ifMove) {
|
|
return function (element, focused, matrixConfig) {
|
|
var move = matrixConfig.cycles ? ifCycle : ifMove;
|
|
return closest$2(focused, matrixConfig.selectors.row).bind(function (inRow) {
|
|
var cellsInRow = descendants(inRow, matrixConfig.selectors.cell);
|
|
return findIndex$1(cellsInRow, focused).bind(function (colIndex) {
|
|
var allRows = descendants(element, matrixConfig.selectors.row);
|
|
return findIndex$1(allRows, inRow).bind(function (rowIndex) {
|
|
var matrix = toMatrix(allRows, matrixConfig);
|
|
return move(matrix, rowIndex, colIndex).map(function (next) {
|
|
return next.cell;
|
|
});
|
|
});
|
|
});
|
|
});
|
|
};
|
|
};
|
|
var moveLeft$3 = doMove$2(cycleLeft$1, moveLeft$2);
|
|
var moveRight$3 = doMove$2(cycleRight$1, moveRight$2);
|
|
var moveNorth$1 = doMove$2(cycleUp$1, moveUp);
|
|
var moveSouth$1 = doMove$2(cycleDown$1, moveDown);
|
|
var getKeydownRules$3 = constant([
|
|
rule(inSet(LEFT()), west(moveLeft$3, moveRight$3)),
|
|
rule(inSet(RIGHT()), east(moveLeft$3, moveRight$3)),
|
|
rule(inSet(UP()), north(moveNorth$1)),
|
|
rule(inSet(DOWN()), south(moveSouth$1)),
|
|
rule(inSet(SPACE().concat(ENTER())), execute$4)
|
|
]);
|
|
var getKeyupRules$3 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
|
|
var MatrixType = typical(schema$4, NoState.init, getKeydownRules$3, getKeyupRules$3, function () {
|
|
return Option.some(focusIn$2);
|
|
});
|
|
|
|
var schema$5 = [
|
|
strict$1('selector'),
|
|
defaulted$1('execute', defaultExecute),
|
|
defaulted$1('moveOnTab', false)
|
|
];
|
|
var execute$5 = function (component, simulatedEvent, menuConfig) {
|
|
return menuConfig.focusManager.get(component).bind(function (focused) {
|
|
return menuConfig.execute(component, simulatedEvent, focused);
|
|
});
|
|
};
|
|
var focusIn$3 = function (component, menuConfig, _state) {
|
|
descendant$1(component.element(), menuConfig.selector).each(function (first) {
|
|
menuConfig.focusManager.set(component, first);
|
|
});
|
|
};
|
|
var moveUp$1 = function (element, focused, info) {
|
|
return horizontal(element, info.selector, focused, -1);
|
|
};
|
|
var moveDown$1 = function (element, focused, info) {
|
|
return horizontal(element, info.selector, focused, +1);
|
|
};
|
|
var fireShiftTab = function (component, simulatedEvent, menuConfig, menuState) {
|
|
return menuConfig.moveOnTab ? move(moveUp$1)(component, simulatedEvent, menuConfig, menuState) : Option.none();
|
|
};
|
|
var fireTab = function (component, simulatedEvent, menuConfig, menuState) {
|
|
return menuConfig.moveOnTab ? move(moveDown$1)(component, simulatedEvent, menuConfig, menuState) : Option.none();
|
|
};
|
|
var getKeydownRules$4 = constant([
|
|
rule(inSet(UP()), move(moveUp$1)),
|
|
rule(inSet(DOWN()), move(moveDown$1)),
|
|
rule(and([
|
|
isShift,
|
|
inSet(TAB())
|
|
]), fireShiftTab),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(TAB())
|
|
]), fireTab),
|
|
rule(inSet(ENTER()), execute$5),
|
|
rule(inSet(SPACE()), execute$5)
|
|
]);
|
|
var getKeyupRules$4 = constant([rule(inSet(SPACE()), stopEventForFirefox)]);
|
|
var MenuType = typical(schema$5, NoState.init, getKeydownRules$4, getKeyupRules$4, function () {
|
|
return Option.some(focusIn$3);
|
|
});
|
|
|
|
var schema$6 = [
|
|
onKeyboardHandler('onSpace'),
|
|
onKeyboardHandler('onEnter'),
|
|
onKeyboardHandler('onShiftEnter'),
|
|
onKeyboardHandler('onLeft'),
|
|
onKeyboardHandler('onRight'),
|
|
onKeyboardHandler('onTab'),
|
|
onKeyboardHandler('onShiftTab'),
|
|
onKeyboardHandler('onUp'),
|
|
onKeyboardHandler('onDown'),
|
|
onKeyboardHandler('onEscape'),
|
|
defaulted$1('stopSpaceKeyup', false),
|
|
option('focusIn')
|
|
];
|
|
var getKeydownRules$5 = function (component, simulatedEvent, specialInfo) {
|
|
return [
|
|
rule(inSet(SPACE()), specialInfo.onSpace),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(ENTER())
|
|
]), specialInfo.onEnter),
|
|
rule(and([
|
|
isShift,
|
|
inSet(ENTER())
|
|
]), specialInfo.onShiftEnter),
|
|
rule(and([
|
|
isShift,
|
|
inSet(TAB())
|
|
]), specialInfo.onShiftTab),
|
|
rule(and([
|
|
isNotShift,
|
|
inSet(TAB())
|
|
]), specialInfo.onTab),
|
|
rule(inSet(UP()), specialInfo.onUp),
|
|
rule(inSet(DOWN()), specialInfo.onDown),
|
|
rule(inSet(LEFT()), specialInfo.onLeft),
|
|
rule(inSet(RIGHT()), specialInfo.onRight),
|
|
rule(inSet(SPACE()), specialInfo.onSpace),
|
|
rule(inSet(ESCAPE()), specialInfo.onEscape)
|
|
];
|
|
};
|
|
var getKeyupRules$5 = function (component, simulatedEvent, specialInfo) {
|
|
return specialInfo.stopSpaceKeyup ? [rule(inSet(SPACE()), stopEventForFirefox)] : [];
|
|
};
|
|
var SpecialType = typical(schema$6, NoState.init, getKeydownRules$5, getKeyupRules$5, function (specialInfo) {
|
|
return specialInfo.focusIn;
|
|
});
|
|
|
|
var acyclic = AcyclicType.schema();
|
|
var cyclic = CyclicType.schema();
|
|
var flow = FlowType.schema();
|
|
var flatgrid$1 = FlatgridType.schema();
|
|
var matrix = MatrixType.schema();
|
|
var execution = ExecutionType.schema();
|
|
var menu = MenuType.schema();
|
|
var special = SpecialType.schema();
|
|
|
|
var KeyboardBranches = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
acyclic: acyclic,
|
|
cyclic: cyclic,
|
|
flow: flow,
|
|
flatgrid: flatgrid$1,
|
|
matrix: matrix,
|
|
execution: execution,
|
|
menu: menu,
|
|
special: special
|
|
});
|
|
|
|
var isFlatgridState = function (keyState) {
|
|
return hasNonNullableKey(keyState, 'setGridSize');
|
|
};
|
|
var Keying = createModes$1({
|
|
branchKey: 'mode',
|
|
branches: KeyboardBranches,
|
|
name: 'keying',
|
|
active: {
|
|
events: function (keyingConfig, keyingState) {
|
|
var handler = keyingConfig.handler;
|
|
return handler.toEvents(keyingConfig, keyingState);
|
|
}
|
|
},
|
|
apis: {
|
|
focusIn: function (component, keyConfig, keyState) {
|
|
keyConfig.sendFocusIn(keyConfig).fold(function () {
|
|
component.getSystem().triggerFocus(component.element(), component.element());
|
|
}, function (sendFocusIn) {
|
|
sendFocusIn(component, keyConfig, keyState);
|
|
});
|
|
},
|
|
setGridSize: function (component, keyConfig, keyState, numRows, numColumns) {
|
|
if (!isFlatgridState(keyState)) {
|
|
domGlobals.console.error('Layout does not support setGridSize');
|
|
} else {
|
|
keyState.setGridSize(numRows, numColumns);
|
|
}
|
|
}
|
|
},
|
|
state: KeyingState
|
|
});
|
|
|
|
var field$1 = function (name, forbidden) {
|
|
return defaultedObjOf(name, {}, map$1(forbidden, function (f) {
|
|
return forbid(f.name(), 'Cannot configure ' + f.name() + ' for ' + name);
|
|
}).concat([state$1('dump', identity)]));
|
|
};
|
|
var get$6 = function (data) {
|
|
return data.dump;
|
|
};
|
|
var augment = function (data, original) {
|
|
return __assign(__assign({}, data.dump), derive$1(original));
|
|
};
|
|
var SketchBehaviours = {
|
|
field: field$1,
|
|
augment: augment,
|
|
get: get$6
|
|
};
|
|
|
|
var _placeholder = 'placeholder';
|
|
var adt$2 = Adt.generate([
|
|
{
|
|
single: [
|
|
'required',
|
|
'valueThunk'
|
|
]
|
|
},
|
|
{
|
|
multiple: [
|
|
'required',
|
|
'valueThunks'
|
|
]
|
|
}
|
|
]);
|
|
var isSubstituted = function (spec) {
|
|
return has(spec, 'uiType');
|
|
};
|
|
var subPlaceholder = function (owner, detail, compSpec, placeholders) {
|
|
if (owner.exists(function (o) {
|
|
return o !== compSpec.owner;
|
|
})) {
|
|
return adt$2.single(true, constant(compSpec));
|
|
}
|
|
return get(placeholders, compSpec.name).fold(function () {
|
|
throw new Error('Unknown placeholder component: ' + compSpec.name + '\nKnown: [' + keys(placeholders) + ']\nNamespace: ' + owner.getOr('none') + '\nSpec: ' + JSON.stringify(compSpec, null, 2));
|
|
}, function (newSpec) {
|
|
return newSpec.replace();
|
|
});
|
|
};
|
|
var scan = function (owner, detail, compSpec, placeholders) {
|
|
if (isSubstituted(compSpec) && compSpec.uiType === _placeholder) {
|
|
return subPlaceholder(owner, detail, compSpec, placeholders);
|
|
} else {
|
|
return adt$2.single(false, constant(compSpec));
|
|
}
|
|
};
|
|
var substitute = function (owner, detail, compSpec, placeholders) {
|
|
var base = scan(owner, detail, compSpec, placeholders);
|
|
return base.fold(function (req, valueThunk) {
|
|
var value = isSubstituted(compSpec) ? valueThunk(detail, compSpec.config, compSpec.validated) : valueThunk(detail);
|
|
var childSpecs = get(value, 'components').getOr([]);
|
|
var substituted = bind(childSpecs, function (c) {
|
|
return substitute(owner, detail, c, placeholders);
|
|
});
|
|
return [__assign(__assign({}, value), { components: substituted })];
|
|
}, function (req, valuesThunk) {
|
|
if (isSubstituted(compSpec)) {
|
|
var values = valuesThunk(detail, compSpec.config, compSpec.validated);
|
|
var preprocessor = compSpec.validated.preprocess.getOr(identity);
|
|
return preprocessor(values);
|
|
} else {
|
|
return valuesThunk(detail);
|
|
}
|
|
});
|
|
};
|
|
var substituteAll = function (owner, detail, components, placeholders) {
|
|
return bind(components, function (c) {
|
|
return substitute(owner, detail, c, placeholders);
|
|
});
|
|
};
|
|
var oneReplace = function (label, replacements) {
|
|
var called = false;
|
|
var used = function () {
|
|
return called;
|
|
};
|
|
var replace = function () {
|
|
if (called) {
|
|
throw new Error('Trying to use the same placeholder more than once: ' + label);
|
|
}
|
|
called = true;
|
|
return replacements;
|
|
};
|
|
var required = function () {
|
|
return replacements.fold(function (req, _) {
|
|
return req;
|
|
}, function (req, _) {
|
|
return req;
|
|
});
|
|
};
|
|
return {
|
|
name: constant(label),
|
|
required: required,
|
|
used: used,
|
|
replace: replace
|
|
};
|
|
};
|
|
var substitutePlaces = function (owner, detail, components, placeholders) {
|
|
var ps = map(placeholders, function (ph, name) {
|
|
return oneReplace(name, ph);
|
|
});
|
|
var outcome = substituteAll(owner, detail, components, ps);
|
|
each(ps, function (p) {
|
|
if (p.used() === false && p.required()) {
|
|
throw new Error('Placeholder: ' + p.name() + ' was not found in components list\nNamespace: ' + owner.getOr('none') + '\nComponents: ' + JSON.stringify(detail.components, null, 2));
|
|
}
|
|
});
|
|
return outcome;
|
|
};
|
|
var single = adt$2.single;
|
|
var multiple = adt$2.multiple;
|
|
var placeholder = constant(_placeholder);
|
|
|
|
var unique = 0;
|
|
var generate$1 = function (prefix) {
|
|
var date = new Date();
|
|
var time = date.getTime();
|
|
var random = Math.floor(Math.random() * 1000000000);
|
|
unique++;
|
|
return prefix + '_' + random + unique + String(time);
|
|
};
|
|
|
|
var adt$3 = Adt.generate([
|
|
{ required: ['data'] },
|
|
{ external: ['data'] },
|
|
{ optional: ['data'] },
|
|
{ group: ['data'] }
|
|
]);
|
|
var fFactory = defaulted$1('factory', { sketch: identity });
|
|
var fSchema = defaulted$1('schema', []);
|
|
var fName = strict$1('name');
|
|
var fPname = field('pname', 'pname', defaultedThunk(function (typeSpec) {
|
|
return '<alloy.' + generate$1(typeSpec.name) + '>';
|
|
}), anyValue$1());
|
|
var fGroupSchema = state$1('schema', function () {
|
|
return [option('preprocess')];
|
|
});
|
|
var fDefaults = defaulted$1('defaults', constant({}));
|
|
var fOverrides = defaulted$1('overrides', constant({}));
|
|
var requiredSpec = objOf([
|
|
fFactory,
|
|
fSchema,
|
|
fName,
|
|
fPname,
|
|
fDefaults,
|
|
fOverrides
|
|
]);
|
|
var externalSpec = objOf([
|
|
fFactory,
|
|
fSchema,
|
|
fName,
|
|
fDefaults,
|
|
fOverrides
|
|
]);
|
|
var optionalSpec = objOf([
|
|
fFactory,
|
|
fSchema,
|
|
fName,
|
|
fPname,
|
|
fDefaults,
|
|
fOverrides
|
|
]);
|
|
var groupSpec = objOf([
|
|
fFactory,
|
|
fGroupSchema,
|
|
fName,
|
|
strict$1('unit'),
|
|
fPname,
|
|
fDefaults,
|
|
fOverrides
|
|
]);
|
|
var asNamedPart = function (part) {
|
|
return part.fold(Option.some, Option.none, Option.some, Option.some);
|
|
};
|
|
var name$1 = function (part) {
|
|
var get = function (data) {
|
|
return data.name;
|
|
};
|
|
return part.fold(get, get, get, get);
|
|
};
|
|
var convert = function (adtConstructor, partSchema) {
|
|
return function (spec) {
|
|
var data = asRawOrDie('Converting part type', partSchema, spec);
|
|
return adtConstructor(data);
|
|
};
|
|
};
|
|
var required = convert(adt$3.required, requiredSpec);
|
|
var external = convert(adt$3.external, externalSpec);
|
|
var optional = convert(adt$3.optional, optionalSpec);
|
|
var group = convert(adt$3.group, groupSpec);
|
|
var original = constant('entirety');
|
|
|
|
var combine = function (detail, data, partSpec, partValidated) {
|
|
return deepMerge(data.defaults(detail, partSpec, partValidated), partSpec, { uid: detail.partUids[data.name] }, data.overrides(detail, partSpec, partValidated));
|
|
};
|
|
var subs = function (owner, detail, parts) {
|
|
var internals = {};
|
|
var externals = {};
|
|
each$1(parts, function (part) {
|
|
part.fold(function (data) {
|
|
internals[data.pname] = single(true, function (detail, partSpec, partValidated) {
|
|
return data.factory.sketch(combine(detail, data, partSpec, partValidated));
|
|
});
|
|
}, function (data) {
|
|
var partSpec = detail.parts[data.name];
|
|
externals[data.name] = constant(data.factory.sketch(combine(detail, data, partSpec[original()]), partSpec));
|
|
}, function (data) {
|
|
internals[data.pname] = single(false, function (detail, partSpec, partValidated) {
|
|
return data.factory.sketch(combine(detail, data, partSpec, partValidated));
|
|
});
|
|
}, function (data) {
|
|
internals[data.pname] = multiple(true, function (detail, _partSpec, _partValidated) {
|
|
var units = detail[data.name];
|
|
return map$1(units, function (u) {
|
|
return data.factory.sketch(deepMerge(data.defaults(detail, u, _partValidated), u, data.overrides(detail, u)));
|
|
});
|
|
});
|
|
});
|
|
});
|
|
return {
|
|
internals: constant(internals),
|
|
externals: constant(externals)
|
|
};
|
|
};
|
|
|
|
var generate$2 = function (owner, parts) {
|
|
var r = {};
|
|
each$1(parts, function (part) {
|
|
asNamedPart(part).each(function (np) {
|
|
var g = doGenerateOne(owner, np.pname);
|
|
r[np.name] = function (config) {
|
|
var validated = asRawOrDie('Part: ' + np.name + ' in ' + owner, objOf(np.schema), config);
|
|
return __assign(__assign({}, g), {
|
|
config: config,
|
|
validated: validated
|
|
});
|
|
};
|
|
});
|
|
});
|
|
return r;
|
|
};
|
|
var doGenerateOne = function (owner, pname) {
|
|
return {
|
|
uiType: placeholder(),
|
|
owner: owner,
|
|
name: pname
|
|
};
|
|
};
|
|
var generateOne = function (owner, pname, config) {
|
|
return {
|
|
uiType: placeholder(),
|
|
owner: owner,
|
|
name: pname,
|
|
config: config,
|
|
validated: {}
|
|
};
|
|
};
|
|
var schemas = function (parts) {
|
|
return bind(parts, function (part) {
|
|
return part.fold(Option.none, Option.some, Option.none, Option.none).map(function (data) {
|
|
return strictObjOf(data.name, data.schema.concat([snapshot(original())]));
|
|
}).toArray();
|
|
});
|
|
};
|
|
var names = function (parts) {
|
|
return map$1(parts, name$1);
|
|
};
|
|
var substitutes = function (owner, detail, parts) {
|
|
return subs(owner, detail, parts);
|
|
};
|
|
var components = function (owner, detail, internals) {
|
|
return substitutePlaces(Option.some(owner), detail, detail.components, internals);
|
|
};
|
|
var getPart = function (component, detail, partKey) {
|
|
var uid = detail.partUids[partKey];
|
|
return component.getSystem().getByUid(uid).toOption();
|
|
};
|
|
var getPartOrDie = function (component, detail, partKey) {
|
|
return getPart(component, detail, partKey).getOrDie('Could not find part: ' + partKey);
|
|
};
|
|
var getAllParts = function (component, detail) {
|
|
var system = component.getSystem();
|
|
return map(detail.partUids, function (pUid, _k) {
|
|
return constant(system.getByUid(pUid));
|
|
});
|
|
};
|
|
var defaultUids = function (baseUid, partTypes) {
|
|
var partNames = names(partTypes);
|
|
return wrapAll$1(map$1(partNames, function (pn) {
|
|
return {
|
|
key: pn,
|
|
value: baseUid + '-' + pn
|
|
};
|
|
}));
|
|
};
|
|
var defaultUidsSchema = function (partTypes) {
|
|
return field('partUids', 'partUids', mergeWithThunk(function (spec) {
|
|
return defaultUids(spec.uid, partTypes);
|
|
}), anyValue$1());
|
|
};
|
|
|
|
var premadeTag = generate$1('alloy-premade');
|
|
var premade = function (comp) {
|
|
return wrap$1(premadeTag, comp);
|
|
};
|
|
var getPremade = function (spec) {
|
|
return get(spec, premadeTag);
|
|
};
|
|
var makeApi = function (f) {
|
|
return markAsSketchApi(function (component) {
|
|
var rest = [];
|
|
for (var _i = 1; _i < arguments.length; _i++) {
|
|
rest[_i - 1] = arguments[_i];
|
|
}
|
|
return f.apply(void 0, __spreadArrays([
|
|
component.getApis(),
|
|
component
|
|
], rest));
|
|
}, f);
|
|
};
|
|
|
|
var prefix$1 = constant('alloy-id-');
|
|
var idAttr = constant('data-alloy-id');
|
|
|
|
var prefix$2 = prefix$1();
|
|
var idAttr$1 = idAttr();
|
|
var write = function (label, elem) {
|
|
var id = generate$1(prefix$2 + label);
|
|
writeOnly(elem, id);
|
|
return id;
|
|
};
|
|
var writeOnly = function (elem, uid) {
|
|
Object.defineProperty(elem.dom(), idAttr$1, {
|
|
value: uid,
|
|
writable: true
|
|
});
|
|
};
|
|
var read$2 = function (elem) {
|
|
var id = isElement(elem) ? elem.dom()[idAttr$1] : null;
|
|
return Option.from(id);
|
|
};
|
|
var generate$3 = function (prefix) {
|
|
return generate$1(prefix);
|
|
};
|
|
|
|
var base = function (partSchemas, partUidsSchemas) {
|
|
var ps = partSchemas.length > 0 ? [strictObjOf('parts', partSchemas)] : [];
|
|
return ps.concat([
|
|
strict$1('uid'),
|
|
defaulted$1('dom', {}),
|
|
defaulted$1('components', []),
|
|
snapshot('originalSpec'),
|
|
defaulted$1('debug.sketcher', {})
|
|
]).concat(partUidsSchemas);
|
|
};
|
|
var asRawOrDie$1 = function (label, schema, spec, partSchemas, partUidsSchemas) {
|
|
var baseS = base(partSchemas, partUidsSchemas);
|
|
return asRawOrDie(label + ' [SpecSchema]', objOfOnly(baseS.concat(schema)), spec);
|
|
};
|
|
|
|
var single$1 = function (owner, schema, factory, spec) {
|
|
var specWithUid = supplyUid(spec);
|
|
var detail = asRawOrDie$1(owner, schema, specWithUid, [], []);
|
|
return factory(detail, specWithUid);
|
|
};
|
|
var composite = function (owner, schema, partTypes, factory, spec) {
|
|
var specWithUid = supplyUid(spec);
|
|
var partSchemas = schemas(partTypes);
|
|
var partUidsSchema = defaultUidsSchema(partTypes);
|
|
var detail = asRawOrDie$1(owner, schema, specWithUid, partSchemas, [partUidsSchema]);
|
|
var subs = substitutes(owner, detail, partTypes);
|
|
var components$1 = components(owner, detail, subs.internals());
|
|
return factory(detail, components$1, specWithUid, subs.externals());
|
|
};
|
|
var hasUid = function (spec) {
|
|
return has(spec, 'uid');
|
|
};
|
|
var supplyUid = function (spec) {
|
|
return hasUid(spec) ? spec : __assign(__assign({}, spec), { uid: generate$3('uid') });
|
|
};
|
|
|
|
function isSketchSpec(spec) {
|
|
return spec.uid !== undefined;
|
|
}
|
|
var singleSchema = objOfOnly([
|
|
strict$1('name'),
|
|
strict$1('factory'),
|
|
strict$1('configFields'),
|
|
defaulted$1('apis', {}),
|
|
defaulted$1('extraApis', {})
|
|
]);
|
|
var compositeSchema = objOfOnly([
|
|
strict$1('name'),
|
|
strict$1('factory'),
|
|
strict$1('configFields'),
|
|
strict$1('partFields'),
|
|
defaulted$1('apis', {}),
|
|
defaulted$1('extraApis', {})
|
|
]);
|
|
var single$2 = function (rawConfig) {
|
|
var config = asRawOrDie('Sketcher for ' + rawConfig.name, singleSchema, rawConfig);
|
|
var sketch = function (spec) {
|
|
return single$1(config.name, config.configFields, config.factory, spec);
|
|
};
|
|
var apis = map(config.apis, makeApi);
|
|
var extraApis = map(config.extraApis, function (f, k) {
|
|
return markAsExtraApi(f, k);
|
|
});
|
|
return __assign(__assign({
|
|
name: constant(config.name),
|
|
configFields: constant(config.configFields),
|
|
sketch: sketch
|
|
}, apis), extraApis);
|
|
};
|
|
var composite$1 = function (rawConfig) {
|
|
var config = asRawOrDie('Sketcher for ' + rawConfig.name, compositeSchema, rawConfig);
|
|
var sketch = function (spec) {
|
|
return composite(config.name, config.configFields, config.partFields, config.factory, spec);
|
|
};
|
|
var parts = generate$2(config.name, config.partFields);
|
|
var apis = map(config.apis, makeApi);
|
|
var extraApis = map(config.extraApis, function (f, k) {
|
|
return markAsExtraApi(f, k);
|
|
});
|
|
return __assign(__assign({
|
|
name: constant(config.name),
|
|
partFields: constant(config.partFields),
|
|
configFields: constant(config.configFields),
|
|
sketch: sketch,
|
|
parts: constant(parts)
|
|
}, apis), extraApis);
|
|
};
|
|
|
|
var factory = function (detail) {
|
|
var events = events$2(detail.action);
|
|
var tag = detail.dom.tag;
|
|
var lookupAttr = function (attr) {
|
|
return get(detail.dom, 'attributes').bind(function (attrs) {
|
|
return get(attrs, attr);
|
|
});
|
|
};
|
|
var getModAttributes = function () {
|
|
if (tag === 'button') {
|
|
var type = lookupAttr('type').getOr('button');
|
|
var roleAttrs = lookupAttr('role').map(function (role) {
|
|
return { role: role };
|
|
}).getOr({});
|
|
return __assign({ type: type }, roleAttrs);
|
|
} else {
|
|
var role = lookupAttr('role').getOr('button');
|
|
return { role: role };
|
|
}
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: detail.components,
|
|
events: events,
|
|
behaviours: SketchBehaviours.augment(detail.buttonBehaviours, [
|
|
Focusing.config({}),
|
|
Keying.config({
|
|
mode: 'execution',
|
|
useSpace: true,
|
|
useEnter: true
|
|
})
|
|
]),
|
|
domModification: { attributes: getModAttributes() },
|
|
eventOrder: detail.eventOrder
|
|
};
|
|
};
|
|
var Button = single$2({
|
|
name: 'Button',
|
|
factory: factory,
|
|
configFields: [
|
|
defaulted$1('uid', undefined),
|
|
strict$1('dom'),
|
|
defaulted$1('components', []),
|
|
SketchBehaviours.field('buttonBehaviours', [
|
|
Focusing,
|
|
Keying
|
|
]),
|
|
option('action'),
|
|
option('role'),
|
|
defaulted$1('eventOrder', {})
|
|
]
|
|
});
|
|
|
|
var exhibit$2 = function () {
|
|
return nu$5({
|
|
styles: {
|
|
'-webkit-user-select': 'none',
|
|
'user-select': 'none',
|
|
'-ms-user-select': 'none',
|
|
'-moz-user-select': '-moz-none'
|
|
},
|
|
attributes: { unselectable: 'on' }
|
|
});
|
|
};
|
|
var events$4 = function () {
|
|
return derive([abort(selectstart(), constant(true))]);
|
|
};
|
|
|
|
var ActiveUnselecting = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$4,
|
|
exhibit: exhibit$2
|
|
});
|
|
|
|
var Unselecting = create$1({
|
|
fields: [],
|
|
name: 'unselecting',
|
|
active: ActiveUnselecting
|
|
});
|
|
|
|
var getAttrs = function (elem) {
|
|
var attributes = elem.dom().attributes !== undefined ? elem.dom().attributes : [];
|
|
return foldl(attributes, function (b, attr) {
|
|
var _a;
|
|
if (attr.name === 'class') {
|
|
return b;
|
|
} else {
|
|
return __assign(__assign({}, b), (_a = {}, _a[attr.name] = attr.value, _a));
|
|
}
|
|
}, {});
|
|
};
|
|
var getClasses = function (elem) {
|
|
return Array.prototype.slice.call(elem.dom().classList, 0);
|
|
};
|
|
var fromHtml$2 = function (html) {
|
|
var elem = Element.fromHtml(html);
|
|
var children$1 = children(elem);
|
|
var attrs = getAttrs(elem);
|
|
var classes = getClasses(elem);
|
|
var contents = children$1.length === 0 ? {} : { innerHtml: get$3(elem) };
|
|
return __assign({
|
|
tag: name(elem),
|
|
classes: classes,
|
|
attributes: attrs
|
|
}, contents);
|
|
};
|
|
|
|
var dom$1 = function (rawHtml) {
|
|
var html = supplant(rawHtml, { prefix: prefix });
|
|
return fromHtml$2(html);
|
|
};
|
|
var spec = function (rawHtml) {
|
|
return { dom: dom$1(rawHtml) };
|
|
};
|
|
|
|
var forToolbarCommand = function (editor, command) {
|
|
return forToolbar(command, function () {
|
|
editor.execCommand(command);
|
|
}, {}, editor);
|
|
};
|
|
var getToggleBehaviours = function (command) {
|
|
return derive$1([
|
|
Toggling.config({
|
|
toggleClass: resolve('toolbar-button-selected'),
|
|
toggleOnExecute: false,
|
|
aria: { mode: 'pressed' }
|
|
}),
|
|
format(command, function (button, status) {
|
|
var toggle = status ? Toggling.on : Toggling.off;
|
|
toggle(button);
|
|
})
|
|
]);
|
|
};
|
|
var forToolbarStateCommand = function (editor, command) {
|
|
var extraBehaviours = getToggleBehaviours(command);
|
|
return forToolbar(command, function () {
|
|
editor.execCommand(command);
|
|
}, extraBehaviours, editor);
|
|
};
|
|
var forToolbarStateAction = function (editor, clazz, command, action) {
|
|
var extraBehaviours = getToggleBehaviours(command);
|
|
return forToolbar(clazz, action, extraBehaviours, editor);
|
|
};
|
|
var getToolbarIconButton = function (clazz, editor) {
|
|
var icons = editor.ui.registry.getAll().icons;
|
|
var optOxideIcon = Option.from(icons[clazz]);
|
|
return optOxideIcon.fold(function () {
|
|
return dom$1('<span class="${prefix}-toolbar-button ${prefix}-toolbar-group-item ${prefix}-icon-' + clazz + ' ${prefix}-icon"></span>');
|
|
}, function (icon) {
|
|
return dom$1('<span class="${prefix}-toolbar-button ${prefix}-toolbar-group-item">' + icon + '</span>');
|
|
});
|
|
};
|
|
var forToolbar = function (clazz, action, extraBehaviours, editor) {
|
|
return Button.sketch({
|
|
dom: getToolbarIconButton(clazz, editor),
|
|
action: action,
|
|
buttonBehaviours: deepMerge(derive$1([Unselecting.config({})]), extraBehaviours)
|
|
});
|
|
};
|
|
|
|
var labelPart = optional({
|
|
schema: [strict$1('dom')],
|
|
name: 'label'
|
|
});
|
|
var edgePart = function (name) {
|
|
return optional({
|
|
name: '' + name + '-edge',
|
|
overrides: function (detail) {
|
|
var action = detail.model.manager.edgeActions[name];
|
|
return action.fold(function () {
|
|
return {};
|
|
}, function (a) {
|
|
return {
|
|
events: derive([
|
|
runActionExtra(touchstart(), function (comp, se, d) {
|
|
return a(comp, d);
|
|
}, [detail]),
|
|
runActionExtra(mousedown(), function (comp, se, d) {
|
|
return a(comp, d);
|
|
}, [detail]),
|
|
runActionExtra(mousemove(), function (comp, se, det) {
|
|
if (det.mouseIsDown.get()) {
|
|
a(comp, det);
|
|
}
|
|
}, [detail])
|
|
])
|
|
};
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var tlEdgePart = edgePart('top-left');
|
|
var tedgePart = edgePart('top');
|
|
var trEdgePart = edgePart('top-right');
|
|
var redgePart = edgePart('right');
|
|
var brEdgePart = edgePart('bottom-right');
|
|
var bedgePart = edgePart('bottom');
|
|
var blEdgePart = edgePart('bottom-left');
|
|
var ledgePart = edgePart('left');
|
|
var thumbPart = required({
|
|
name: 'thumb',
|
|
defaults: constant({ dom: { styles: { position: 'absolute' } } }),
|
|
overrides: function (detail) {
|
|
return {
|
|
events: derive([
|
|
redirectToPart(touchstart(), detail, 'spectrum'),
|
|
redirectToPart(touchmove(), detail, 'spectrum'),
|
|
redirectToPart(touchend(), detail, 'spectrum'),
|
|
redirectToPart(mousedown(), detail, 'spectrum'),
|
|
redirectToPart(mousemove(), detail, 'spectrum'),
|
|
redirectToPart(mouseup(), detail, 'spectrum')
|
|
])
|
|
};
|
|
}
|
|
});
|
|
var spectrumPart = required({
|
|
schema: [state$1('mouseIsDown', function () {
|
|
return Cell(false);
|
|
})],
|
|
name: 'spectrum',
|
|
overrides: function (detail) {
|
|
var modelDetail = detail.model;
|
|
var model = modelDetail.manager;
|
|
var setValueFrom = function (component, simulatedEvent) {
|
|
return model.getValueFromEvent(simulatedEvent).map(function (value) {
|
|
return model.setValueFrom(component, detail, value);
|
|
});
|
|
};
|
|
return {
|
|
behaviours: derive$1([
|
|
Keying.config({
|
|
mode: 'special',
|
|
onLeft: function (spectrum) {
|
|
return model.onLeft(spectrum, detail);
|
|
},
|
|
onRight: function (spectrum) {
|
|
return model.onRight(spectrum, detail);
|
|
},
|
|
onUp: function (spectrum) {
|
|
return model.onUp(spectrum, detail);
|
|
},
|
|
onDown: function (spectrum) {
|
|
return model.onDown(spectrum, detail);
|
|
}
|
|
}),
|
|
Focusing.config({})
|
|
]),
|
|
events: derive([
|
|
run(touchstart(), setValueFrom),
|
|
run(touchmove(), setValueFrom),
|
|
run(mousedown(), setValueFrom),
|
|
run(mousemove(), function (spectrum, se) {
|
|
if (detail.mouseIsDown.get()) {
|
|
setValueFrom(spectrum, se);
|
|
}
|
|
})
|
|
])
|
|
};
|
|
}
|
|
});
|
|
var SliderParts = [
|
|
labelPart,
|
|
ledgePart,
|
|
redgePart,
|
|
tedgePart,
|
|
bedgePart,
|
|
tlEdgePart,
|
|
trEdgePart,
|
|
blEdgePart,
|
|
brEdgePart,
|
|
thumbPart,
|
|
spectrumPart
|
|
];
|
|
|
|
var onLoad$1 = function (component, repConfig, repState) {
|
|
repConfig.store.manager.onLoad(component, repConfig, repState);
|
|
};
|
|
var onUnload = function (component, repConfig, repState) {
|
|
repConfig.store.manager.onUnload(component, repConfig, repState);
|
|
};
|
|
var setValue = function (component, repConfig, repState, data) {
|
|
repConfig.store.manager.setValue(component, repConfig, repState, data);
|
|
};
|
|
var getValue = function (component, repConfig, repState) {
|
|
return repConfig.store.manager.getValue(component, repConfig, repState);
|
|
};
|
|
var getState = function (component, repConfig, repState) {
|
|
return repState;
|
|
};
|
|
|
|
var RepresentApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
onLoad: onLoad$1,
|
|
onUnload: onUnload,
|
|
setValue: setValue,
|
|
getValue: getValue,
|
|
getState: getState
|
|
});
|
|
|
|
var events$5 = function (repConfig, repState) {
|
|
var es = repConfig.resetOnDom ? [
|
|
runOnAttached(function (comp, _se) {
|
|
onLoad$1(comp, repConfig, repState);
|
|
}),
|
|
runOnDetached(function (comp, _se) {
|
|
onUnload(comp, repConfig, repState);
|
|
})
|
|
] : [loadEvent(repConfig, repState, onLoad$1)];
|
|
return derive(es);
|
|
};
|
|
|
|
var ActiveRepresenting = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$5
|
|
});
|
|
|
|
var memory = function () {
|
|
var data = Cell(null);
|
|
var readState = function () {
|
|
return {
|
|
mode: 'memory',
|
|
value: data.get()
|
|
};
|
|
};
|
|
var isNotSet = function () {
|
|
return data.get() === null;
|
|
};
|
|
var clear = function () {
|
|
data.set(null);
|
|
};
|
|
return nu$6({
|
|
set: data.set,
|
|
get: data.get,
|
|
isNotSet: isNotSet,
|
|
clear: clear,
|
|
readState: readState
|
|
});
|
|
};
|
|
var manual = function () {
|
|
var readState = function () {
|
|
};
|
|
return nu$6({ readState: readState });
|
|
};
|
|
var dataset = function () {
|
|
var dataByValue = Cell({});
|
|
var dataByText = Cell({});
|
|
var readState = function () {
|
|
return {
|
|
mode: 'dataset',
|
|
dataByValue: dataByValue.get(),
|
|
dataByText: dataByText.get()
|
|
};
|
|
};
|
|
var clear = function () {
|
|
dataByValue.set({});
|
|
dataByText.set({});
|
|
};
|
|
var lookup = function (itemString) {
|
|
return get(dataByValue.get(), itemString).orThunk(function () {
|
|
return get(dataByText.get(), itemString);
|
|
});
|
|
};
|
|
var update = function (items) {
|
|
var currentDataByValue = dataByValue.get();
|
|
var currentDataByText = dataByText.get();
|
|
var newDataByValue = {};
|
|
var newDataByText = {};
|
|
each$1(items, function (item) {
|
|
newDataByValue[item.value] = item;
|
|
get(item, 'meta').each(function (meta) {
|
|
get(meta, 'text').each(function (text) {
|
|
newDataByText[text] = item;
|
|
});
|
|
});
|
|
});
|
|
dataByValue.set(__assign(__assign({}, currentDataByValue), newDataByValue));
|
|
dataByText.set(__assign(__assign({}, currentDataByText), newDataByText));
|
|
};
|
|
return nu$6({
|
|
readState: readState,
|
|
lookup: lookup,
|
|
update: update,
|
|
clear: clear
|
|
});
|
|
};
|
|
var init$1 = function (spec) {
|
|
return spec.store.manager.state(spec);
|
|
};
|
|
|
|
var RepresentState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
memory: memory,
|
|
dataset: dataset,
|
|
manual: manual,
|
|
init: init$1
|
|
});
|
|
|
|
var setValue$1 = function (component, repConfig, repState, data) {
|
|
var store = repConfig.store;
|
|
repState.update([data]);
|
|
store.setValue(component, data);
|
|
repConfig.onSetValue(component, data);
|
|
};
|
|
var getValue$1 = function (component, repConfig, repState) {
|
|
var store = repConfig.store;
|
|
var key = store.getDataKey(component);
|
|
return repState.lookup(key).fold(function () {
|
|
return store.getFallbackEntry(key);
|
|
}, function (data) {
|
|
return data;
|
|
});
|
|
};
|
|
var onLoad$2 = function (component, repConfig, repState) {
|
|
var store = repConfig.store;
|
|
store.initialValue.each(function (data) {
|
|
setValue$1(component, repConfig, repState, data);
|
|
});
|
|
};
|
|
var onUnload$1 = function (component, repConfig, repState) {
|
|
repState.clear();
|
|
};
|
|
var DatasetStore = [
|
|
option('initialValue'),
|
|
strict$1('getFallbackEntry'),
|
|
strict$1('getDataKey'),
|
|
strict$1('setValue'),
|
|
output('manager', {
|
|
setValue: setValue$1,
|
|
getValue: getValue$1,
|
|
onLoad: onLoad$2,
|
|
onUnload: onUnload$1,
|
|
state: dataset
|
|
})
|
|
];
|
|
|
|
var getValue$2 = function (component, repConfig, _repState) {
|
|
return repConfig.store.getValue(component);
|
|
};
|
|
var setValue$2 = function (component, repConfig, _repState, data) {
|
|
repConfig.store.setValue(component, data);
|
|
repConfig.onSetValue(component, data);
|
|
};
|
|
var onLoad$3 = function (component, repConfig, _repState) {
|
|
repConfig.store.initialValue.each(function (data) {
|
|
repConfig.store.setValue(component, data);
|
|
});
|
|
};
|
|
var ManualStore = [
|
|
strict$1('getValue'),
|
|
defaulted$1('setValue', noop),
|
|
option('initialValue'),
|
|
output('manager', {
|
|
setValue: setValue$2,
|
|
getValue: getValue$2,
|
|
onLoad: onLoad$3,
|
|
onUnload: noop,
|
|
state: NoState.init
|
|
})
|
|
];
|
|
|
|
var setValue$3 = function (component, repConfig, repState, data) {
|
|
repState.set(data);
|
|
repConfig.onSetValue(component, data);
|
|
};
|
|
var getValue$3 = function (component, repConfig, repState) {
|
|
return repState.get();
|
|
};
|
|
var onLoad$4 = function (component, repConfig, repState) {
|
|
repConfig.store.initialValue.each(function (initVal) {
|
|
if (repState.isNotSet()) {
|
|
repState.set(initVal);
|
|
}
|
|
});
|
|
};
|
|
var onUnload$2 = function (component, repConfig, repState) {
|
|
repState.clear();
|
|
};
|
|
var MemoryStore = [
|
|
option('initialValue'),
|
|
output('manager', {
|
|
setValue: setValue$3,
|
|
getValue: getValue$3,
|
|
onLoad: onLoad$4,
|
|
onUnload: onUnload$2,
|
|
state: memory
|
|
})
|
|
];
|
|
|
|
var RepresentSchema = [
|
|
defaultedOf('store', { mode: 'memory' }, choose$1('mode', {
|
|
memory: MemoryStore,
|
|
manual: ManualStore,
|
|
dataset: DatasetStore
|
|
})),
|
|
onHandler('onSetValue'),
|
|
defaulted$1('resetOnDom', false)
|
|
];
|
|
|
|
var Representing = create$1({
|
|
fields: RepresentSchema,
|
|
name: 'representing',
|
|
active: ActiveRepresenting,
|
|
apis: RepresentApis,
|
|
extra: {
|
|
setValueFrom: function (component, source) {
|
|
var value = Representing.getValue(source);
|
|
Representing.setValue(component, value);
|
|
}
|
|
},
|
|
state: RepresentState
|
|
});
|
|
|
|
var api$1 = Dimension('width', function (element) {
|
|
return element.dom().offsetWidth;
|
|
});
|
|
var set$4 = function (element, h) {
|
|
return api$1.set(element, h);
|
|
};
|
|
var get$7 = function (element) {
|
|
return api$1.get(element);
|
|
};
|
|
|
|
var r = function (left, top) {
|
|
var translate = function (x, y) {
|
|
return r(left + x, top + y);
|
|
};
|
|
return {
|
|
left: constant(left),
|
|
top: constant(top),
|
|
translate: translate
|
|
};
|
|
};
|
|
var Position = r;
|
|
|
|
var _sliderChangeEvent = 'slider.change.value';
|
|
var sliderChangeEvent = constant(_sliderChangeEvent);
|
|
var isTouchEvent = function (evt) {
|
|
return evt.type.indexOf('touch') !== -1;
|
|
};
|
|
var getEventSource = function (simulatedEvent) {
|
|
var evt = simulatedEvent.event().raw();
|
|
if (isTouchEvent(evt)) {
|
|
var touchEvent = evt;
|
|
return touchEvent.touches !== undefined && touchEvent.touches.length === 1 ? Option.some(touchEvent.touches[0]).map(function (t) {
|
|
return Position(t.clientX, t.clientY);
|
|
}) : Option.none();
|
|
} else {
|
|
var mouseEvent = evt;
|
|
return mouseEvent.clientX !== undefined ? Option.some(mouseEvent).map(function (me) {
|
|
return Position(me.clientX, me.clientY);
|
|
}) : Option.none();
|
|
}
|
|
};
|
|
|
|
var t = 'top', r$1 = 'right', b = 'bottom', l = 'left';
|
|
var minX = function (detail) {
|
|
return detail.model.minX;
|
|
};
|
|
var minY = function (detail) {
|
|
return detail.model.minY;
|
|
};
|
|
var min1X = function (detail) {
|
|
return detail.model.minX - 1;
|
|
};
|
|
var min1Y = function (detail) {
|
|
return detail.model.minY - 1;
|
|
};
|
|
var maxX = function (detail) {
|
|
return detail.model.maxX;
|
|
};
|
|
var maxY = function (detail) {
|
|
return detail.model.maxY;
|
|
};
|
|
var max1X = function (detail) {
|
|
return detail.model.maxX + 1;
|
|
};
|
|
var max1Y = function (detail) {
|
|
return detail.model.maxY + 1;
|
|
};
|
|
var range = function (detail, max, min) {
|
|
return max(detail) - min(detail);
|
|
};
|
|
var xRange = function (detail) {
|
|
return range(detail, maxX, minX);
|
|
};
|
|
var yRange = function (detail) {
|
|
return range(detail, maxY, minY);
|
|
};
|
|
var halfX = function (detail) {
|
|
return xRange(detail) / 2;
|
|
};
|
|
var halfY = function (detail) {
|
|
return yRange(detail) / 2;
|
|
};
|
|
var step = function (detail) {
|
|
return detail.stepSize;
|
|
};
|
|
var snap = function (detail) {
|
|
return detail.snapToGrid;
|
|
};
|
|
var snapStart = function (detail) {
|
|
return detail.snapStart;
|
|
};
|
|
var rounded = function (detail) {
|
|
return detail.rounded;
|
|
};
|
|
var hasEdge = function (detail, edgeName) {
|
|
return detail[edgeName + '-edge'] !== undefined;
|
|
};
|
|
var hasLEdge = function (detail) {
|
|
return hasEdge(detail, l);
|
|
};
|
|
var hasREdge = function (detail) {
|
|
return hasEdge(detail, r$1);
|
|
};
|
|
var hasTEdge = function (detail) {
|
|
return hasEdge(detail, t);
|
|
};
|
|
var hasBEdge = function (detail) {
|
|
return hasEdge(detail, b);
|
|
};
|
|
var currentValue = function (detail) {
|
|
return detail.model.value.get();
|
|
};
|
|
|
|
var xValue = function (x) {
|
|
return { x: constant(x) };
|
|
};
|
|
var yValue = function (y) {
|
|
return { y: constant(y) };
|
|
};
|
|
var xyValue = function (x, y) {
|
|
return {
|
|
x: constant(x),
|
|
y: constant(y)
|
|
};
|
|
};
|
|
var fireSliderChange = function (component, value) {
|
|
emitWith(component, sliderChangeEvent(), { value: value });
|
|
};
|
|
var setToTLEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(min1X(detail), min1Y(detail)));
|
|
};
|
|
var setToTEdge = function (edge, detail) {
|
|
fireSliderChange(edge, yValue(min1Y(detail)));
|
|
};
|
|
var setToTEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(halfX(detail), min1Y(detail)));
|
|
};
|
|
var setToTREdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(max1X(detail), min1Y(detail)));
|
|
};
|
|
var setToREdge = function (edge, detail) {
|
|
fireSliderChange(edge, xValue(max1X(detail)));
|
|
};
|
|
var setToREdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(max1X(detail), halfY(detail)));
|
|
};
|
|
var setToBREdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(max1X(detail), max1Y(detail)));
|
|
};
|
|
var setToBEdge = function (edge, detail) {
|
|
fireSliderChange(edge, yValue(max1Y(detail)));
|
|
};
|
|
var setToBEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(halfX(detail), max1Y(detail)));
|
|
};
|
|
var setToBLEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(min1X(detail), max1Y(detail)));
|
|
};
|
|
var setToLEdge = function (edge, detail) {
|
|
fireSliderChange(edge, xValue(min1X(detail)));
|
|
};
|
|
var setToLEdgeXY = function (edge, detail) {
|
|
fireSliderChange(edge, xyValue(min1X(detail), halfY(detail)));
|
|
};
|
|
|
|
var reduceBy = function (value, min, max, step) {
|
|
if (value < min) {
|
|
return value;
|
|
} else if (value > max) {
|
|
return max;
|
|
} else if (value === min) {
|
|
return min - 1;
|
|
} else {
|
|
return Math.max(min, value - step);
|
|
}
|
|
};
|
|
var increaseBy = function (value, min, max, step) {
|
|
if (value > max) {
|
|
return value;
|
|
} else if (value < min) {
|
|
return min;
|
|
} else if (value === max) {
|
|
return max + 1;
|
|
} else {
|
|
return Math.min(max, value + step);
|
|
}
|
|
};
|
|
var capValue = function (value, min, max) {
|
|
return Math.max(min, Math.min(max, value));
|
|
};
|
|
var snapValueOf = function (value, min, max, step, snapStart) {
|
|
return snapStart.fold(function () {
|
|
var initValue = value - min;
|
|
var extraValue = Math.round(initValue / step) * step;
|
|
return capValue(min + extraValue, min - 1, max + 1);
|
|
}, function (start) {
|
|
var remainder = (value - start) % step;
|
|
var adjustment = Math.round(remainder / step);
|
|
var rawSteps = Math.floor((value - start) / step);
|
|
var maxSteps = Math.floor((max - start) / step);
|
|
var numSteps = Math.min(maxSteps, rawSteps + adjustment);
|
|
var r = start + numSteps * step;
|
|
return Math.max(start, r);
|
|
});
|
|
};
|
|
var findOffsetOf = function (value, min, max) {
|
|
return Math.min(max, Math.max(value, min)) - min;
|
|
};
|
|
var findValueOf = function (args) {
|
|
var min = args.min, max = args.max, range = args.range, value = args.value, step = args.step, snap = args.snap, snapStart = args.snapStart, rounded = args.rounded, hasMinEdge = args.hasMinEdge, hasMaxEdge = args.hasMaxEdge, minBound = args.minBound, maxBound = args.maxBound, screenRange = args.screenRange;
|
|
var capMin = hasMinEdge ? min - 1 : min;
|
|
var capMax = hasMaxEdge ? max + 1 : max;
|
|
if (value < minBound) {
|
|
return capMin;
|
|
} else if (value > maxBound) {
|
|
return capMax;
|
|
} else {
|
|
var offset = findOffsetOf(value, minBound, maxBound);
|
|
var newValue = capValue(offset / screenRange * range + min, capMin, capMax);
|
|
if (snap && newValue >= min && newValue <= max) {
|
|
return snapValueOf(newValue, min, max, step, snapStart);
|
|
} else if (rounded) {
|
|
return Math.round(newValue);
|
|
} else {
|
|
return newValue;
|
|
}
|
|
}
|
|
};
|
|
var findOffsetOfValue = function (args) {
|
|
var min = args.min, max = args.max, range = args.range, value = args.value, hasMinEdge = args.hasMinEdge, hasMaxEdge = args.hasMaxEdge, maxBound = args.maxBound, maxOffset = args.maxOffset, centerMinEdge = args.centerMinEdge, centerMaxEdge = args.centerMaxEdge;
|
|
if (value < min) {
|
|
return hasMinEdge ? 0 : centerMinEdge;
|
|
} else if (value > max) {
|
|
return hasMaxEdge ? maxBound : centerMaxEdge;
|
|
} else {
|
|
return (value - min) / range * maxOffset;
|
|
}
|
|
};
|
|
|
|
var top = 'top', right = 'right', bottom = 'bottom', left = 'left', width = 'width', height = 'height';
|
|
var getBounds = function (component) {
|
|
return component.element().dom().getBoundingClientRect();
|
|
};
|
|
var getBoundsProperty = function (bounds, property) {
|
|
return bounds[property];
|
|
};
|
|
var getMinXBounds = function (component) {
|
|
var bounds = getBounds(component);
|
|
return getBoundsProperty(bounds, left);
|
|
};
|
|
var getMaxXBounds = function (component) {
|
|
var bounds = getBounds(component);
|
|
return getBoundsProperty(bounds, right);
|
|
};
|
|
var getMinYBounds = function (component) {
|
|
var bounds = getBounds(component);
|
|
return getBoundsProperty(bounds, top);
|
|
};
|
|
var getMaxYBounds = function (component) {
|
|
var bounds = getBounds(component);
|
|
return getBoundsProperty(bounds, bottom);
|
|
};
|
|
var getXScreenRange = function (component) {
|
|
var bounds = getBounds(component);
|
|
return getBoundsProperty(bounds, width);
|
|
};
|
|
var getYScreenRange = function (component) {
|
|
var bounds = getBounds(component);
|
|
return getBoundsProperty(bounds, height);
|
|
};
|
|
var getCenterOffsetOf = function (componentMinEdge, componentMaxEdge, spectrumMinEdge) {
|
|
return (componentMinEdge + componentMaxEdge) / 2 - spectrumMinEdge;
|
|
};
|
|
var getXCenterOffSetOf = function (component, spectrum) {
|
|
var componentBounds = getBounds(component);
|
|
var spectrumBounds = getBounds(spectrum);
|
|
var componentMinEdge = getBoundsProperty(componentBounds, left);
|
|
var componentMaxEdge = getBoundsProperty(componentBounds, right);
|
|
var spectrumMinEdge = getBoundsProperty(spectrumBounds, left);
|
|
return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
|
|
};
|
|
var getYCenterOffSetOf = function (component, spectrum) {
|
|
var componentBounds = getBounds(component);
|
|
var spectrumBounds = getBounds(spectrum);
|
|
var componentMinEdge = getBoundsProperty(componentBounds, top);
|
|
var componentMaxEdge = getBoundsProperty(componentBounds, bottom);
|
|
var spectrumMinEdge = getBoundsProperty(spectrumBounds, top);
|
|
return getCenterOffsetOf(componentMinEdge, componentMaxEdge, spectrumMinEdge);
|
|
};
|
|
|
|
var fireSliderChange$1 = function (spectrum, value) {
|
|
emitWith(spectrum, sliderChangeEvent(), { value: value });
|
|
};
|
|
var sliderValue = function (x) {
|
|
return { x: constant(x) };
|
|
};
|
|
var findValueOfOffset = function (spectrum, detail, left) {
|
|
var args = {
|
|
min: minX(detail),
|
|
max: maxX(detail),
|
|
range: xRange(detail),
|
|
value: left,
|
|
step: step(detail),
|
|
snap: snap(detail),
|
|
snapStart: snapStart(detail),
|
|
rounded: rounded(detail),
|
|
hasMinEdge: hasLEdge(detail),
|
|
hasMaxEdge: hasREdge(detail),
|
|
minBound: getMinXBounds(spectrum),
|
|
maxBound: getMaxXBounds(spectrum),
|
|
screenRange: getXScreenRange(spectrum)
|
|
};
|
|
return findValueOf(args);
|
|
};
|
|
var setValueFrom = function (spectrum, detail, value) {
|
|
var xValue = findValueOfOffset(spectrum, detail, value);
|
|
var sliderVal = sliderValue(xValue);
|
|
fireSliderChange$1(spectrum, sliderVal);
|
|
return xValue;
|
|
};
|
|
var setToMin = function (spectrum, detail) {
|
|
var min = minX(detail);
|
|
fireSliderChange$1(spectrum, sliderValue(min));
|
|
};
|
|
var setToMax = function (spectrum, detail) {
|
|
var max = maxX(detail);
|
|
fireSliderChange$1(spectrum, sliderValue(max));
|
|
};
|
|
var moveBy = function (direction, spectrum, detail) {
|
|
var f = direction > 0 ? increaseBy : reduceBy;
|
|
var xValue = f(currentValue(detail).x(), minX(detail), maxX(detail), step(detail));
|
|
fireSliderChange$1(spectrum, sliderValue(xValue));
|
|
return Option.some(xValue);
|
|
};
|
|
var handleMovement = function (direction) {
|
|
return function (spectrum, detail) {
|
|
return moveBy(direction, spectrum, detail).map(function () {
|
|
return true;
|
|
});
|
|
};
|
|
};
|
|
var getValueFromEvent = function (simulatedEvent) {
|
|
var pos = getEventSource(simulatedEvent);
|
|
return pos.map(function (p) {
|
|
return p.left();
|
|
});
|
|
};
|
|
var findOffsetOfValue$1 = function (spectrum, detail, value, minEdge, maxEdge) {
|
|
var minOffset = 0;
|
|
var maxOffset = getXScreenRange(spectrum);
|
|
var centerMinEdge = minEdge.bind(function (edge) {
|
|
return Option.some(getXCenterOffSetOf(edge, spectrum));
|
|
}).getOr(minOffset);
|
|
var centerMaxEdge = maxEdge.bind(function (edge) {
|
|
return Option.some(getXCenterOffSetOf(edge, spectrum));
|
|
}).getOr(maxOffset);
|
|
var args = {
|
|
min: minX(detail),
|
|
max: maxX(detail),
|
|
range: xRange(detail),
|
|
value: value,
|
|
hasMinEdge: hasLEdge(detail),
|
|
hasMaxEdge: hasREdge(detail),
|
|
minBound: getMinXBounds(spectrum),
|
|
minOffset: minOffset,
|
|
maxBound: getMaxXBounds(spectrum),
|
|
maxOffset: maxOffset,
|
|
centerMinEdge: centerMinEdge,
|
|
centerMaxEdge: centerMaxEdge
|
|
};
|
|
return findOffsetOfValue(args);
|
|
};
|
|
var findPositionOfValue = function (slider, spectrum, value, minEdge, maxEdge, detail) {
|
|
var offset = findOffsetOfValue$1(spectrum, detail, value, minEdge, maxEdge);
|
|
return getMinXBounds(spectrum) - getMinXBounds(slider) + offset;
|
|
};
|
|
var setPositionFromValue = function (slider, thumb, detail, edges) {
|
|
var value = currentValue(detail);
|
|
var pos = findPositionOfValue(slider, edges.getSpectrum(slider), value.x(), edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
|
|
var thumbRadius = get$7(thumb.element()) / 2;
|
|
set$3(thumb.element(), 'left', pos - thumbRadius + 'px');
|
|
};
|
|
var onLeft = handleMovement(-1);
|
|
var onRight = handleMovement(1);
|
|
var onUp = Option.none;
|
|
var onDown = Option.none;
|
|
var edgeActions = {
|
|
'top-left': Option.none(),
|
|
'top': Option.none(),
|
|
'top-right': Option.none(),
|
|
'right': Option.some(setToREdge),
|
|
'bottom-right': Option.none(),
|
|
'bottom': Option.none(),
|
|
'bottom-left': Option.none(),
|
|
'left': Option.some(setToLEdge)
|
|
};
|
|
|
|
var HorizontalModel = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
setValueFrom: setValueFrom,
|
|
setToMin: setToMin,
|
|
setToMax: setToMax,
|
|
findValueOfOffset: findValueOfOffset,
|
|
getValueFromEvent: getValueFromEvent,
|
|
findPositionOfValue: findPositionOfValue,
|
|
setPositionFromValue: setPositionFromValue,
|
|
onLeft: onLeft,
|
|
onRight: onRight,
|
|
onUp: onUp,
|
|
onDown: onDown,
|
|
edgeActions: edgeActions
|
|
});
|
|
|
|
var fireSliderChange$2 = function (spectrum, value) {
|
|
emitWith(spectrum, sliderChangeEvent(), { value: value });
|
|
};
|
|
var sliderValue$1 = function (y) {
|
|
return { y: constant(y) };
|
|
};
|
|
var findValueOfOffset$1 = function (spectrum, detail, top) {
|
|
var args = {
|
|
min: minY(detail),
|
|
max: maxY(detail),
|
|
range: yRange(detail),
|
|
value: top,
|
|
step: step(detail),
|
|
snap: snap(detail),
|
|
snapStart: snapStart(detail),
|
|
rounded: rounded(detail),
|
|
hasMinEdge: hasTEdge(detail),
|
|
hasMaxEdge: hasBEdge(detail),
|
|
minBound: getMinYBounds(spectrum),
|
|
maxBound: getMaxYBounds(spectrum),
|
|
screenRange: getYScreenRange(spectrum)
|
|
};
|
|
return findValueOf(args);
|
|
};
|
|
var setValueFrom$1 = function (spectrum, detail, value) {
|
|
var yValue = findValueOfOffset$1(spectrum, detail, value);
|
|
var sliderVal = sliderValue$1(yValue);
|
|
fireSliderChange$2(spectrum, sliderVal);
|
|
return yValue;
|
|
};
|
|
var setToMin$1 = function (spectrum, detail) {
|
|
var min = minY(detail);
|
|
fireSliderChange$2(spectrum, sliderValue$1(min));
|
|
};
|
|
var setToMax$1 = function (spectrum, detail) {
|
|
var max = maxY(detail);
|
|
fireSliderChange$2(spectrum, sliderValue$1(max));
|
|
};
|
|
var moveBy$1 = function (direction, spectrum, detail) {
|
|
var f = direction > 0 ? increaseBy : reduceBy;
|
|
var yValue = f(currentValue(detail).y(), minY(detail), maxY(detail), step(detail));
|
|
fireSliderChange$2(spectrum, sliderValue$1(yValue));
|
|
return Option.some(yValue);
|
|
};
|
|
var handleMovement$1 = function (direction) {
|
|
return function (spectrum, detail) {
|
|
return moveBy$1(direction, spectrum, detail).map(function () {
|
|
return true;
|
|
});
|
|
};
|
|
};
|
|
var getValueFromEvent$1 = function (simulatedEvent) {
|
|
var pos = getEventSource(simulatedEvent);
|
|
return pos.map(function (p) {
|
|
return p.top();
|
|
});
|
|
};
|
|
var findOffsetOfValue$2 = function (spectrum, detail, value, minEdge, maxEdge) {
|
|
var minOffset = 0;
|
|
var maxOffset = getYScreenRange(spectrum);
|
|
var centerMinEdge = minEdge.bind(function (edge) {
|
|
return Option.some(getYCenterOffSetOf(edge, spectrum));
|
|
}).getOr(minOffset);
|
|
var centerMaxEdge = maxEdge.bind(function (edge) {
|
|
return Option.some(getYCenterOffSetOf(edge, spectrum));
|
|
}).getOr(maxOffset);
|
|
var args = {
|
|
min: minY(detail),
|
|
max: maxY(detail),
|
|
range: yRange(detail),
|
|
value: value,
|
|
hasMinEdge: hasTEdge(detail),
|
|
hasMaxEdge: hasBEdge(detail),
|
|
minBound: getMinYBounds(spectrum),
|
|
minOffset: minOffset,
|
|
maxBound: getMaxYBounds(spectrum),
|
|
maxOffset: maxOffset,
|
|
centerMinEdge: centerMinEdge,
|
|
centerMaxEdge: centerMaxEdge
|
|
};
|
|
return findOffsetOfValue(args);
|
|
};
|
|
var findPositionOfValue$1 = function (slider, spectrum, value, minEdge, maxEdge, detail) {
|
|
var offset = findOffsetOfValue$2(spectrum, detail, value, minEdge, maxEdge);
|
|
return getMinYBounds(spectrum) - getMinYBounds(slider) + offset;
|
|
};
|
|
var setPositionFromValue$1 = function (slider, thumb, detail, edges) {
|
|
var value = currentValue(detail);
|
|
var pos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value.y(), edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
|
|
var thumbRadius = get$5(thumb.element()) / 2;
|
|
set$3(thumb.element(), 'top', pos - thumbRadius + 'px');
|
|
};
|
|
var onLeft$1 = Option.none;
|
|
var onRight$1 = Option.none;
|
|
var onUp$1 = handleMovement$1(-1);
|
|
var onDown$1 = handleMovement$1(1);
|
|
var edgeActions$1 = {
|
|
'top-left': Option.none(),
|
|
'top': Option.some(setToTEdge),
|
|
'top-right': Option.none(),
|
|
'right': Option.none(),
|
|
'bottom-right': Option.none(),
|
|
'bottom': Option.some(setToBEdge),
|
|
'bottom-left': Option.none(),
|
|
'left': Option.none()
|
|
};
|
|
|
|
var VerticalModel = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
setValueFrom: setValueFrom$1,
|
|
setToMin: setToMin$1,
|
|
setToMax: setToMax$1,
|
|
findValueOfOffset: findValueOfOffset$1,
|
|
getValueFromEvent: getValueFromEvent$1,
|
|
findPositionOfValue: findPositionOfValue$1,
|
|
setPositionFromValue: setPositionFromValue$1,
|
|
onLeft: onLeft$1,
|
|
onRight: onRight$1,
|
|
onUp: onUp$1,
|
|
onDown: onDown$1,
|
|
edgeActions: edgeActions$1
|
|
});
|
|
|
|
var fireSliderChange$3 = function (spectrum, value) {
|
|
emitWith(spectrum, sliderChangeEvent(), { value: value });
|
|
};
|
|
var sliderValue$2 = function (x, y) {
|
|
return {
|
|
x: constant(x),
|
|
y: constant(y)
|
|
};
|
|
};
|
|
var setValueFrom$2 = function (spectrum, detail, value) {
|
|
var xValue = findValueOfOffset(spectrum, detail, value.left());
|
|
var yValue = findValueOfOffset$1(spectrum, detail, value.top());
|
|
var val = sliderValue$2(xValue, yValue);
|
|
fireSliderChange$3(spectrum, val);
|
|
return val;
|
|
};
|
|
var moveBy$2 = function (direction, isVerticalMovement, spectrum, detail) {
|
|
var f = direction > 0 ? increaseBy : reduceBy;
|
|
var xValue = isVerticalMovement ? currentValue(detail).x() : f(currentValue(detail).x(), minX(detail), maxX(detail), step(detail));
|
|
var yValue = !isVerticalMovement ? currentValue(detail).y() : f(currentValue(detail).y(), minY(detail), maxY(detail), step(detail));
|
|
fireSliderChange$3(spectrum, sliderValue$2(xValue, yValue));
|
|
return Option.some(xValue);
|
|
};
|
|
var handleMovement$2 = function (direction, isVerticalMovement) {
|
|
return function (spectrum, detail) {
|
|
return moveBy$2(direction, isVerticalMovement, spectrum, detail).map(function () {
|
|
return true;
|
|
});
|
|
};
|
|
};
|
|
var setToMin$2 = function (spectrum, detail) {
|
|
var mX = minX(detail);
|
|
var mY = minY(detail);
|
|
fireSliderChange$3(spectrum, sliderValue$2(mX, mY));
|
|
};
|
|
var setToMax$2 = function (spectrum, detail) {
|
|
var mX = maxX(detail);
|
|
var mY = maxY(detail);
|
|
fireSliderChange$3(spectrum, sliderValue$2(mX, mY));
|
|
};
|
|
var getValueFromEvent$2 = function (simulatedEvent) {
|
|
return getEventSource(simulatedEvent);
|
|
};
|
|
var setPositionFromValue$2 = function (slider, thumb, detail, edges) {
|
|
var value = currentValue(detail);
|
|
var xPos = findPositionOfValue(slider, edges.getSpectrum(slider), value.x(), edges.getLeftEdge(slider), edges.getRightEdge(slider), detail);
|
|
var yPos = findPositionOfValue$1(slider, edges.getSpectrum(slider), value.y(), edges.getTopEdge(slider), edges.getBottomEdge(slider), detail);
|
|
var thumbXRadius = get$7(thumb.element()) / 2;
|
|
var thumbYRadius = get$5(thumb.element()) / 2;
|
|
set$3(thumb.element(), 'left', xPos - thumbXRadius + 'px');
|
|
set$3(thumb.element(), 'top', yPos - thumbYRadius + 'px');
|
|
};
|
|
var onLeft$2 = handleMovement$2(-1, false);
|
|
var onRight$2 = handleMovement$2(1, false);
|
|
var onUp$2 = handleMovement$2(-1, true);
|
|
var onDown$2 = handleMovement$2(1, true);
|
|
var edgeActions$2 = {
|
|
'top-left': Option.some(setToTLEdgeXY),
|
|
'top': Option.some(setToTEdgeXY),
|
|
'top-right': Option.some(setToTREdgeXY),
|
|
'right': Option.some(setToREdgeXY),
|
|
'bottom-right': Option.some(setToBREdgeXY),
|
|
'bottom': Option.some(setToBEdgeXY),
|
|
'bottom-left': Option.some(setToBLEdgeXY),
|
|
'left': Option.some(setToLEdgeXY)
|
|
};
|
|
|
|
var TwoDModel = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
setValueFrom: setValueFrom$2,
|
|
setToMin: setToMin$2,
|
|
setToMax: setToMax$2,
|
|
getValueFromEvent: getValueFromEvent$2,
|
|
setPositionFromValue: setPositionFromValue$2,
|
|
onLeft: onLeft$2,
|
|
onRight: onRight$2,
|
|
onUp: onUp$2,
|
|
onDown: onDown$2,
|
|
edgeActions: edgeActions$2
|
|
});
|
|
|
|
var SliderSchema = [
|
|
defaulted$1('stepSize', 1),
|
|
defaulted$1('onChange', noop),
|
|
defaulted$1('onChoose', noop),
|
|
defaulted$1('onInit', noop),
|
|
defaulted$1('onDragStart', noop),
|
|
defaulted$1('onDragEnd', noop),
|
|
defaulted$1('snapToGrid', false),
|
|
defaulted$1('rounded', true),
|
|
option('snapStart'),
|
|
strictOf('model', choose$1('mode', {
|
|
x: [
|
|
defaulted$1('minX', 0),
|
|
defaulted$1('maxX', 100),
|
|
state$1('value', function (spec) {
|
|
return Cell(spec.mode.minX);
|
|
}),
|
|
strict$1('getInitialValue'),
|
|
output('manager', HorizontalModel)
|
|
],
|
|
y: [
|
|
defaulted$1('minY', 0),
|
|
defaulted$1('maxY', 100),
|
|
state$1('value', function (spec) {
|
|
return Cell(spec.mode.minY);
|
|
}),
|
|
strict$1('getInitialValue'),
|
|
output('manager', VerticalModel)
|
|
],
|
|
xy: [
|
|
defaulted$1('minX', 0),
|
|
defaulted$1('maxX', 100),
|
|
defaulted$1('minY', 0),
|
|
defaulted$1('maxY', 100),
|
|
state$1('value', function (spec) {
|
|
return Cell({
|
|
x: constant(spec.mode.minX),
|
|
y: constant(spec.mode.minY)
|
|
});
|
|
}),
|
|
strict$1('getInitialValue'),
|
|
output('manager', TwoDModel)
|
|
]
|
|
})),
|
|
field$1('sliderBehaviours', [
|
|
Keying,
|
|
Representing
|
|
]),
|
|
state$1('mouseIsDown', function () {
|
|
return Cell(false);
|
|
})
|
|
];
|
|
|
|
var mouseReleased = constant('mouse.released');
|
|
|
|
var sketch = function (detail, components, _spec, _externals) {
|
|
var _a;
|
|
var getThumb = function (component) {
|
|
return getPartOrDie(component, detail, 'thumb');
|
|
};
|
|
var getSpectrum = function (component) {
|
|
return getPartOrDie(component, detail, 'spectrum');
|
|
};
|
|
var getLeftEdge = function (component) {
|
|
return getPart(component, detail, 'left-edge');
|
|
};
|
|
var getRightEdge = function (component) {
|
|
return getPart(component, detail, 'right-edge');
|
|
};
|
|
var getTopEdge = function (component) {
|
|
return getPart(component, detail, 'top-edge');
|
|
};
|
|
var getBottomEdge = function (component) {
|
|
return getPart(component, detail, 'bottom-edge');
|
|
};
|
|
var modelDetail = detail.model;
|
|
var model = modelDetail.manager;
|
|
var refresh = function (slider, thumb) {
|
|
model.setPositionFromValue(slider, thumb, detail, {
|
|
getLeftEdge: getLeftEdge,
|
|
getRightEdge: getRightEdge,
|
|
getTopEdge: getTopEdge,
|
|
getBottomEdge: getBottomEdge,
|
|
getSpectrum: getSpectrum
|
|
});
|
|
};
|
|
var changeValue = function (slider, newValue) {
|
|
modelDetail.value.set(newValue);
|
|
var thumb = getThumb(slider);
|
|
refresh(slider, thumb);
|
|
detail.onChange(slider, thumb, newValue);
|
|
return Option.some(true);
|
|
};
|
|
var resetToMin = function (slider) {
|
|
model.setToMin(slider, detail);
|
|
};
|
|
var resetToMax = function (slider) {
|
|
model.setToMax(slider, detail);
|
|
};
|
|
var choose = function (slider) {
|
|
var fireOnChoose = function () {
|
|
getPart(slider, detail, 'thumb').each(function (thumb) {
|
|
var value = modelDetail.value.get();
|
|
detail.onChoose(slider, thumb, value);
|
|
});
|
|
};
|
|
var wasDown = detail.mouseIsDown.get();
|
|
detail.mouseIsDown.set(false);
|
|
if (wasDown) {
|
|
fireOnChoose();
|
|
}
|
|
};
|
|
var onDragStart = function (slider, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
detail.mouseIsDown.set(true);
|
|
detail.onDragStart(slider, getThumb(slider));
|
|
};
|
|
var onDragEnd = function (slider, simulatedEvent) {
|
|
simulatedEvent.stop();
|
|
detail.onDragEnd(slider, getThumb(slider));
|
|
choose(slider);
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: augment(detail.sliderBehaviours, [
|
|
Keying.config({
|
|
mode: 'special',
|
|
focusIn: function (slider) {
|
|
return getPart(slider, detail, 'spectrum').map(Keying.focusIn).map(constant(true));
|
|
}
|
|
}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (_) {
|
|
return modelDetail.value.get();
|
|
}
|
|
}
|
|
}),
|
|
Receiving.config({ channels: (_a = {}, _a[mouseReleased()] = { onReceive: choose }, _a) })
|
|
]),
|
|
events: derive([
|
|
run(sliderChangeEvent(), function (slider, simulatedEvent) {
|
|
changeValue(slider, simulatedEvent.event().value());
|
|
}),
|
|
runOnAttached(function (slider, _simulatedEvent) {
|
|
var getInitial = modelDetail.getInitialValue();
|
|
modelDetail.value.set(getInitial);
|
|
var thumb = getThumb(slider);
|
|
refresh(slider, thumb);
|
|
var spectrum = getSpectrum(slider);
|
|
detail.onInit(slider, thumb, spectrum, modelDetail.value.get());
|
|
}),
|
|
run(touchstart(), onDragStart),
|
|
run(touchend(), onDragEnd),
|
|
run(mousedown(), onDragStart),
|
|
run(mouseup(), onDragEnd)
|
|
]),
|
|
apis: {
|
|
resetToMin: resetToMin,
|
|
resetToMax: resetToMax,
|
|
changeValue: changeValue,
|
|
refresh: refresh
|
|
},
|
|
domModification: { styles: { position: 'relative' } }
|
|
};
|
|
};
|
|
|
|
var Slider = composite$1({
|
|
name: 'Slider',
|
|
configFields: SliderSchema,
|
|
partFields: SliderParts,
|
|
factory: sketch,
|
|
apis: {
|
|
resetToMin: function (apis, slider) {
|
|
apis.resetToMin(slider);
|
|
},
|
|
resetToMax: function (apis, slider) {
|
|
apis.resetToMax(slider);
|
|
},
|
|
refresh: function (apis, slider) {
|
|
apis.refresh(slider);
|
|
}
|
|
}
|
|
});
|
|
|
|
var button = function (realm, clazz, makeItems, editor) {
|
|
return forToolbar(clazz, function () {
|
|
var items = makeItems();
|
|
realm.setContextToolbar([{
|
|
label: clazz + ' group',
|
|
items: items
|
|
}]);
|
|
}, {}, editor);
|
|
};
|
|
|
|
var BLACK = -1;
|
|
var makeSlider = function (spec$1) {
|
|
var getColor = function (hue) {
|
|
if (hue < 0) {
|
|
return 'black';
|
|
} else if (hue > 360) {
|
|
return 'white';
|
|
} else {
|
|
return 'hsl(' + hue + ', 100%, 50%)';
|
|
}
|
|
};
|
|
var onInit = function (slider, thumb, spectrum, value) {
|
|
var color = getColor(value.x());
|
|
set$3(thumb.element(), 'background-color', color);
|
|
};
|
|
var onChange = function (slider, thumb, value) {
|
|
var color = getColor(value.x());
|
|
set$3(thumb.element(), 'background-color', color);
|
|
spec$1.onChange(slider, thumb, color);
|
|
};
|
|
return Slider.sketch({
|
|
dom: dom$1('<div class="${prefix}-slider ${prefix}-hue-slider-container"></div>'),
|
|
components: [
|
|
Slider.parts()['left-edge'](spec('<div class="${prefix}-hue-slider-black"></div>')),
|
|
Slider.parts().spectrum({
|
|
dom: dom$1('<div class="${prefix}-slider-gradient-container"></div>'),
|
|
components: [spec('<div class="${prefix}-slider-gradient"></div>')],
|
|
behaviours: derive$1([Toggling.config({ toggleClass: resolve('thumb-active') })])
|
|
}),
|
|
Slider.parts()['right-edge'](spec('<div class="${prefix}-hue-slider-white"></div>')),
|
|
Slider.parts().thumb({
|
|
dom: dom$1('<div class="${prefix}-slider-thumb"></div>'),
|
|
behaviours: derive$1([Toggling.config({ toggleClass: resolve('thumb-active') })])
|
|
})
|
|
],
|
|
onChange: onChange,
|
|
onDragStart: function (slider, thumb) {
|
|
Toggling.on(thumb);
|
|
},
|
|
onDragEnd: function (slider, thumb) {
|
|
Toggling.off(thumb);
|
|
},
|
|
onInit: onInit,
|
|
stepSize: 10,
|
|
model: {
|
|
mode: 'x',
|
|
minX: 0,
|
|
maxX: 360,
|
|
getInitialValue: function () {
|
|
return {
|
|
x: function () {
|
|
return spec$1.getInitialValue();
|
|
}
|
|
};
|
|
}
|
|
},
|
|
sliderBehaviours: derive$1([orientation(Slider.refresh)])
|
|
});
|
|
};
|
|
var makeItems = function (spec) {
|
|
return [makeSlider(spec)];
|
|
};
|
|
var sketch$1 = function (realm, editor) {
|
|
var spec = {
|
|
onChange: function (slider, thumb, color) {
|
|
editor.undoManager.transact(function () {
|
|
editor.formatter.apply('forecolor', { value: color });
|
|
editor.nodeChanged();
|
|
});
|
|
},
|
|
getInitialValue: function () {
|
|
return BLACK;
|
|
}
|
|
};
|
|
return button(realm, 'color-levels', function () {
|
|
return makeItems(spec);
|
|
}, editor);
|
|
};
|
|
|
|
var schema$7 = objOfOnly([
|
|
strict$1('getInitialValue'),
|
|
strict$1('onChange'),
|
|
strict$1('category'),
|
|
strict$1('sizes')
|
|
]);
|
|
var sketch$2 = function (rawSpec) {
|
|
var spec$1 = asRawOrDie('SizeSlider', schema$7, rawSpec);
|
|
var isValidValue = function (valueIndex) {
|
|
return valueIndex >= 0 && valueIndex < spec$1.sizes.length;
|
|
};
|
|
var onChange = function (slider, thumb, valueIndex) {
|
|
var index = valueIndex.x();
|
|
if (isValidValue(index)) {
|
|
spec$1.onChange(index);
|
|
}
|
|
};
|
|
return Slider.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [
|
|
resolve('slider-' + spec$1.category + '-size-container'),
|
|
resolve('slider'),
|
|
resolve('slider-size-container')
|
|
]
|
|
},
|
|
onChange: onChange,
|
|
onDragStart: function (slider, thumb) {
|
|
Toggling.on(thumb);
|
|
},
|
|
onDragEnd: function (slider, thumb) {
|
|
Toggling.off(thumb);
|
|
},
|
|
model: {
|
|
mode: 'x',
|
|
minX: 0,
|
|
maxX: spec$1.sizes.length - 1,
|
|
getInitialValue: function () {
|
|
return {
|
|
x: function () {
|
|
return spec$1.getInitialValue();
|
|
}
|
|
};
|
|
}
|
|
},
|
|
stepSize: 1,
|
|
snapToGrid: true,
|
|
sliderBehaviours: derive$1([orientation(Slider.refresh)]),
|
|
components: [
|
|
Slider.parts().spectrum({
|
|
dom: dom$1('<div class="${prefix}-slider-size-container"></div>'),
|
|
components: [spec('<div class="${prefix}-slider-size-line"></div>')]
|
|
}),
|
|
Slider.parts().thumb({
|
|
dom: dom$1('<div class="${prefix}-slider-thumb"></div>'),
|
|
behaviours: derive$1([Toggling.config({ toggleClass: resolve('thumb-active') })])
|
|
})
|
|
]
|
|
});
|
|
};
|
|
|
|
var candidatesArray = [
|
|
'9px',
|
|
'10px',
|
|
'11px',
|
|
'12px',
|
|
'14px',
|
|
'16px',
|
|
'18px',
|
|
'20px',
|
|
'24px',
|
|
'32px',
|
|
'36px'
|
|
];
|
|
var defaultSize = 'medium';
|
|
var defaultIndex = 2;
|
|
var indexToSize = function (index) {
|
|
return Option.from(candidatesArray[index]);
|
|
};
|
|
var sizeToIndex = function (size) {
|
|
return findIndex(candidatesArray, function (v) {
|
|
return v === size;
|
|
});
|
|
};
|
|
var getRawOrComputed = function (isRoot, rawStart) {
|
|
var optStart = isElement(rawStart) ? Option.some(rawStart) : parent(rawStart).filter(isElement);
|
|
return optStart.map(function (start) {
|
|
var inline = closest$1(start, function (elem) {
|
|
return getRaw(elem, 'font-size').isSome();
|
|
}, isRoot).bind(function (elem) {
|
|
return getRaw(elem, 'font-size');
|
|
});
|
|
return inline.getOrThunk(function () {
|
|
return get$4(start, 'font-size');
|
|
});
|
|
}).getOr('');
|
|
};
|
|
var getSize = function (editor) {
|
|
var node = editor.selection.getStart();
|
|
var elem = Element.fromDom(node);
|
|
var root = Element.fromDom(editor.getBody());
|
|
var isRoot = function (e) {
|
|
return eq(root, e);
|
|
};
|
|
var elemSize = getRawOrComputed(isRoot, elem);
|
|
return find$2(candidatesArray, function (size) {
|
|
return elemSize === size;
|
|
}).getOr(defaultSize);
|
|
};
|
|
var applySize = function (editor, value) {
|
|
var currentValue = getSize(editor);
|
|
if (currentValue !== value) {
|
|
editor.execCommand('fontSize', false, value);
|
|
}
|
|
};
|
|
var get$8 = function (editor) {
|
|
var size = getSize(editor);
|
|
return sizeToIndex(size).getOr(defaultIndex);
|
|
};
|
|
var apply$1 = function (editor, index) {
|
|
indexToSize(index).each(function (size) {
|
|
applySize(editor, size);
|
|
});
|
|
};
|
|
var candidates = constant(candidatesArray);
|
|
|
|
var sizes = candidates();
|
|
var makeSlider$1 = function (spec) {
|
|
return sketch$2({
|
|
onChange: spec.onChange,
|
|
sizes: sizes,
|
|
category: 'font',
|
|
getInitialValue: spec.getInitialValue
|
|
});
|
|
};
|
|
var makeItems$1 = function (spec$1) {
|
|
return [
|
|
spec('<span class="${prefix}-toolbar-button ${prefix}-icon-small-font ${prefix}-icon"></span>'),
|
|
makeSlider$1(spec$1),
|
|
spec('<span class="${prefix}-toolbar-button ${prefix}-icon-large-font ${prefix}-icon"></span>')
|
|
];
|
|
};
|
|
var sketch$3 = function (realm, editor) {
|
|
var spec = {
|
|
onChange: function (value) {
|
|
apply$1(editor, value);
|
|
},
|
|
getInitialValue: function () {
|
|
return get$8(editor);
|
|
}
|
|
};
|
|
return button(realm, 'font-size', function () {
|
|
return makeItems$1(spec);
|
|
}, editor);
|
|
};
|
|
|
|
var record = function (spec) {
|
|
var uid = isSketchSpec(spec) && hasNonNullableKey(spec, 'uid') ? spec.uid : generate$3('memento');
|
|
var get = function (anyInSystem) {
|
|
return anyInSystem.getSystem().getByUid(uid).getOrDie();
|
|
};
|
|
var getOpt = function (anyInSystem) {
|
|
return anyInSystem.getSystem().getByUid(uid).toOption();
|
|
};
|
|
var asSpec = function () {
|
|
return __assign(__assign({}, spec), { uid: uid });
|
|
};
|
|
return {
|
|
get: get,
|
|
getOpt: getOpt,
|
|
asSpec: asSpec
|
|
};
|
|
};
|
|
|
|
var promise = function () {
|
|
var Promise = function (fn) {
|
|
if (typeof this !== 'object') {
|
|
throw new TypeError('Promises must be constructed via new');
|
|
}
|
|
if (typeof fn !== 'function') {
|
|
throw new TypeError('not a function');
|
|
}
|
|
this._state = null;
|
|
this._value = null;
|
|
this._deferreds = [];
|
|
doResolve(fn, bind(resolve, this), bind(reject, this));
|
|
};
|
|
var asap = Promise.immediateFn || typeof window.setImmediate === 'function' && window.setImmediate || function (fn) {
|
|
domGlobals.setTimeout(fn, 1);
|
|
};
|
|
function bind(fn, thisArg) {
|
|
return function () {
|
|
return fn.apply(thisArg, arguments);
|
|
};
|
|
}
|
|
var isArray = Array.isArray || function (value) {
|
|
return Object.prototype.toString.call(value) === '[object Array]';
|
|
};
|
|
function handle(deferred) {
|
|
var me = this;
|
|
if (this._state === null) {
|
|
this._deferreds.push(deferred);
|
|
return;
|
|
}
|
|
asap(function () {
|
|
var cb = me._state ? deferred.onFulfilled : deferred.onRejected;
|
|
if (cb === null) {
|
|
(me._state ? deferred.resolve : deferred.reject)(me._value);
|
|
return;
|
|
}
|
|
var ret;
|
|
try {
|
|
ret = cb(me._value);
|
|
} catch (e) {
|
|
deferred.reject(e);
|
|
return;
|
|
}
|
|
deferred.resolve(ret);
|
|
});
|
|
}
|
|
function resolve(newValue) {
|
|
try {
|
|
if (newValue === this) {
|
|
throw new TypeError('A promise cannot be resolved with itself.');
|
|
}
|
|
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
|
|
var then = newValue.then;
|
|
if (typeof then === 'function') {
|
|
doResolve(bind(then, newValue), bind(resolve, this), bind(reject, this));
|
|
return;
|
|
}
|
|
}
|
|
this._state = true;
|
|
this._value = newValue;
|
|
finale.call(this);
|
|
} catch (e) {
|
|
reject.call(this, e);
|
|
}
|
|
}
|
|
function reject(newValue) {
|
|
this._state = false;
|
|
this._value = newValue;
|
|
finale.call(this);
|
|
}
|
|
function finale() {
|
|
for (var _i = 0, _a = this._deferreds; _i < _a.length; _i++) {
|
|
var deferred = _a[_i];
|
|
handle.call(this, deferred);
|
|
}
|
|
this._deferreds = [];
|
|
}
|
|
function Handler(onFulfilled, onRejected, resolve, reject) {
|
|
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
|
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
|
this.resolve = resolve;
|
|
this.reject = reject;
|
|
}
|
|
function doResolve(fn, onFulfilled, onRejected) {
|
|
var done = false;
|
|
try {
|
|
fn(function (value) {
|
|
if (done) {
|
|
return;
|
|
}
|
|
done = true;
|
|
onFulfilled(value);
|
|
}, function (reason) {
|
|
if (done) {
|
|
return;
|
|
}
|
|
done = true;
|
|
onRejected(reason);
|
|
});
|
|
} catch (ex) {
|
|
if (done) {
|
|
return;
|
|
}
|
|
done = true;
|
|
onRejected(ex);
|
|
}
|
|
}
|
|
Promise.prototype.catch = function (onRejected) {
|
|
return this.then(null, onRejected);
|
|
};
|
|
Promise.prototype.then = function (onFulfilled, onRejected) {
|
|
var me = this;
|
|
return new Promise(function (resolve, reject) {
|
|
handle.call(me, new Handler(onFulfilled, onRejected, resolve, reject));
|
|
});
|
|
};
|
|
Promise.all = function () {
|
|
var values = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
values[_i] = arguments[_i];
|
|
}
|
|
var args = Array.prototype.slice.call(values.length === 1 && isArray(values[0]) ? values[0] : values);
|
|
return new Promise(function (resolve, reject) {
|
|
if (args.length === 0) {
|
|
return resolve([]);
|
|
}
|
|
var remaining = args.length;
|
|
function res(i, val) {
|
|
try {
|
|
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
|
var then = val.then;
|
|
if (typeof then === 'function') {
|
|
then.call(val, function (val) {
|
|
res(i, val);
|
|
}, reject);
|
|
return;
|
|
}
|
|
}
|
|
args[i] = val;
|
|
if (--remaining === 0) {
|
|
resolve(args);
|
|
}
|
|
} catch (ex) {
|
|
reject(ex);
|
|
}
|
|
}
|
|
for (var i = 0; i < args.length; i++) {
|
|
res(i, args[i]);
|
|
}
|
|
});
|
|
};
|
|
Promise.resolve = function (value) {
|
|
if (value && typeof value === 'object' && value.constructor === Promise) {
|
|
return value;
|
|
}
|
|
return new Promise(function (resolve) {
|
|
resolve(value);
|
|
});
|
|
};
|
|
Promise.reject = function (reason) {
|
|
return new Promise(function (resolve, reject) {
|
|
reject(reason);
|
|
});
|
|
};
|
|
Promise.race = function (values) {
|
|
return new Promise(function (resolve, reject) {
|
|
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) {
|
|
var value = values_1[_i];
|
|
value.then(resolve, reject);
|
|
}
|
|
});
|
|
};
|
|
return Promise;
|
|
};
|
|
var Promise = window.Promise ? window.Promise : promise();
|
|
|
|
function blobToDataUri(blob) {
|
|
return new Promise(function (resolve) {
|
|
var reader = new domGlobals.FileReader();
|
|
reader.onloadend = function () {
|
|
resolve(reader.result);
|
|
};
|
|
reader.readAsDataURL(blob);
|
|
});
|
|
}
|
|
function blobToBase64(blob) {
|
|
return blobToDataUri(blob).then(function (dataUri) {
|
|
return dataUri.split(',')[1];
|
|
});
|
|
}
|
|
|
|
var blobToBase64$1 = function (blob) {
|
|
return blobToBase64(blob);
|
|
};
|
|
|
|
var addImage = function (editor, blob) {
|
|
blobToBase64$1(blob).then(function (base64) {
|
|
editor.undoManager.transact(function () {
|
|
var cache = editor.editorUpload.blobCache;
|
|
var info = cache.create(generate$1('mceu'), blob, base64);
|
|
cache.add(info);
|
|
var img = editor.dom.createHTML('img', { src: info.blobUri() });
|
|
editor.insertContent(img);
|
|
});
|
|
});
|
|
};
|
|
var extractBlob = function (simulatedEvent) {
|
|
var event = simulatedEvent.event();
|
|
var files = event.raw().target.files || event.raw().dataTransfer.files;
|
|
return Option.from(files[0]);
|
|
};
|
|
var sketch$4 = function (editor) {
|
|
var pickerDom = {
|
|
tag: 'input',
|
|
attributes: {
|
|
accept: 'image/*',
|
|
type: 'file',
|
|
title: ''
|
|
},
|
|
styles: {
|
|
visibility: 'hidden',
|
|
position: 'absolute'
|
|
}
|
|
};
|
|
var memPicker = record({
|
|
dom: pickerDom,
|
|
events: derive([
|
|
cutter(click()),
|
|
run(change(), function (picker, simulatedEvent) {
|
|
extractBlob(simulatedEvent).each(function (blob) {
|
|
addImage(editor, blob);
|
|
});
|
|
})
|
|
])
|
|
});
|
|
return Button.sketch({
|
|
dom: getToolbarIconButton('image', editor),
|
|
components: [memPicker.asSpec()],
|
|
action: function (button) {
|
|
var picker = memPicker.get(button);
|
|
picker.element().dom().click();
|
|
}
|
|
});
|
|
};
|
|
|
|
var get$9 = function (element) {
|
|
return element.dom().textContent;
|
|
};
|
|
var set$5 = function (element, value) {
|
|
return element.dom().textContent = value;
|
|
};
|
|
|
|
var isNotEmpty = function (val) {
|
|
return val.length > 0;
|
|
};
|
|
var defaultToEmpty = function (str) {
|
|
return str === undefined || str === null ? '' : str;
|
|
};
|
|
var noLink = function (editor) {
|
|
var text = editor.selection.getContent({ format: 'text' });
|
|
return {
|
|
url: '',
|
|
text: text,
|
|
title: '',
|
|
target: '',
|
|
link: Option.none()
|
|
};
|
|
};
|
|
var fromLink = function (link) {
|
|
var text = get$9(link);
|
|
var url = get$1(link, 'href');
|
|
var title = get$1(link, 'title');
|
|
var target = get$1(link, 'target');
|
|
return {
|
|
url: defaultToEmpty(url),
|
|
text: text !== url ? defaultToEmpty(text) : '',
|
|
title: defaultToEmpty(title),
|
|
target: defaultToEmpty(target),
|
|
link: Option.some(link)
|
|
};
|
|
};
|
|
var getInfo = function (editor) {
|
|
return query(editor).fold(function () {
|
|
return noLink(editor);
|
|
}, function (link) {
|
|
return fromLink(link);
|
|
});
|
|
};
|
|
var wasSimple = function (link) {
|
|
var prevHref = get$1(link, 'href');
|
|
var prevText = get$9(link);
|
|
return prevHref === prevText;
|
|
};
|
|
var getTextToApply = function (link, url, info) {
|
|
return info.text.toOption().filter(isNotEmpty).fold(function () {
|
|
return wasSimple(link) ? Option.some(url) : Option.none();
|
|
}, Option.some);
|
|
};
|
|
var unlinkIfRequired = function (editor, info) {
|
|
var activeLink = info.link.bind(identity);
|
|
activeLink.each(function (_link) {
|
|
editor.execCommand('unlink');
|
|
});
|
|
};
|
|
var getAttrs$1 = function (url, info) {
|
|
var attrs = {};
|
|
attrs.href = url;
|
|
info.title.toOption().filter(isNotEmpty).each(function (title) {
|
|
attrs.title = title;
|
|
});
|
|
info.target.toOption().filter(isNotEmpty).each(function (target) {
|
|
attrs.target = target;
|
|
});
|
|
return attrs;
|
|
};
|
|
var applyInfo = function (editor, info) {
|
|
info.url.toOption().filter(isNotEmpty).fold(function () {
|
|
unlinkIfRequired(editor, info);
|
|
}, function (url) {
|
|
var attrs = getAttrs$1(url, info);
|
|
var activeLink = info.link.bind(identity);
|
|
activeLink.fold(function () {
|
|
var text = info.text.toOption().filter(isNotEmpty).getOr(url);
|
|
editor.insertContent(editor.dom.createHTML('a', attrs, editor.dom.encode(text)));
|
|
}, function (link) {
|
|
var text = getTextToApply(link, url, info);
|
|
setAll(link, attrs);
|
|
text.each(function (newText) {
|
|
set$5(link, newText);
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var query = function (editor) {
|
|
var start = Element.fromDom(editor.selection.getStart());
|
|
return closest$2(start, 'a');
|
|
};
|
|
|
|
var platform$1 = detect$3();
|
|
var preserve = function (f, editor) {
|
|
var rng = editor.selection.getRng();
|
|
f();
|
|
editor.selection.setRng(rng);
|
|
};
|
|
var forAndroid = function (editor, f) {
|
|
var wrapper = platform$1.os.isAndroid() ? preserve : apply;
|
|
wrapper(f, editor);
|
|
};
|
|
|
|
var events$6 = function (name, eventHandlers) {
|
|
var events = derive(eventHandlers);
|
|
return create$1({
|
|
fields: [strict$1('enabled')],
|
|
name: name,
|
|
active: { events: constant(events) }
|
|
});
|
|
};
|
|
var config = function (name, eventHandlers) {
|
|
var me = events$6(name, eventHandlers);
|
|
return {
|
|
key: name,
|
|
value: {
|
|
config: {},
|
|
me: me,
|
|
configAsRaw: constant({}),
|
|
initialConfig: {},
|
|
state: NoState
|
|
}
|
|
};
|
|
};
|
|
|
|
var getCurrent = function (component, composeConfig, _composeState) {
|
|
return composeConfig.find(component);
|
|
};
|
|
|
|
var ComposeApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
getCurrent: getCurrent
|
|
});
|
|
|
|
var ComposeSchema = [strict$1('find')];
|
|
|
|
var Composing = create$1({
|
|
fields: ComposeSchema,
|
|
name: 'composing',
|
|
apis: ComposeApis
|
|
});
|
|
|
|
var factory$1 = function (detail) {
|
|
var _a = detail.dom, attributes = _a.attributes, domWithoutAttributes = __rest(_a, ['attributes']);
|
|
return {
|
|
uid: detail.uid,
|
|
dom: __assign({
|
|
tag: 'div',
|
|
attributes: __assign({ role: 'presentation' }, attributes)
|
|
}, domWithoutAttributes),
|
|
components: detail.components,
|
|
behaviours: get$6(detail.containerBehaviours),
|
|
events: detail.events,
|
|
domModification: detail.domModification,
|
|
eventOrder: detail.eventOrder
|
|
};
|
|
};
|
|
var Container = single$2({
|
|
name: 'Container',
|
|
factory: factory$1,
|
|
configFields: [
|
|
defaulted$1('components', []),
|
|
field$1('containerBehaviours', []),
|
|
defaulted$1('events', {}),
|
|
defaulted$1('domModification', {}),
|
|
defaulted$1('eventOrder', {})
|
|
]
|
|
});
|
|
|
|
var factory$2 = function (detail) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
behaviours: SketchBehaviours.augment(detail.dataBehaviours, [
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: detail.getInitialValue()
|
|
}
|
|
}),
|
|
Composing.config({ find: Option.some })
|
|
]),
|
|
events: derive([runOnAttached(function (component, _simulatedEvent) {
|
|
Representing.setValue(component, detail.getInitialValue());
|
|
})])
|
|
};
|
|
};
|
|
var DataField = single$2({
|
|
name: 'DataField',
|
|
factory: factory$2,
|
|
configFields: [
|
|
strict$1('uid'),
|
|
strict$1('dom'),
|
|
strict$1('getInitialValue'),
|
|
SketchBehaviours.field('dataBehaviours', [
|
|
Representing,
|
|
Composing
|
|
])
|
|
]
|
|
});
|
|
|
|
var get$a = function (element) {
|
|
return element.dom().value;
|
|
};
|
|
var set$6 = function (element, value) {
|
|
if (value === undefined) {
|
|
throw new Error('Value.set was undefined');
|
|
}
|
|
element.dom().value = value;
|
|
};
|
|
|
|
var schema$8 = constant([
|
|
option('data'),
|
|
defaulted$1('inputAttributes', {}),
|
|
defaulted$1('inputStyles', {}),
|
|
defaulted$1('tag', 'input'),
|
|
defaulted$1('inputClasses', []),
|
|
onHandler('onSetValue'),
|
|
defaulted$1('styles', {}),
|
|
defaulted$1('eventOrder', {}),
|
|
field$1('inputBehaviours', [
|
|
Representing,
|
|
Focusing
|
|
]),
|
|
defaulted$1('selectOnFocus', true)
|
|
]);
|
|
var focusBehaviours = function (detail) {
|
|
return derive$1([Focusing.config({
|
|
onFocus: !detail.selectOnFocus ? noop : function (component) {
|
|
var input = component.element();
|
|
var value = get$a(input);
|
|
input.dom().setSelectionRange(0, value.length);
|
|
}
|
|
})]);
|
|
};
|
|
var behaviours = function (detail) {
|
|
return __assign(__assign({}, focusBehaviours(detail)), augment(detail.inputBehaviours, [Representing.config({
|
|
store: __assign(__assign({ mode: 'manual' }, detail.data.map(function (data) {
|
|
return { initialValue: data };
|
|
}).getOr({})), {
|
|
getValue: function (input) {
|
|
return get$a(input.element());
|
|
},
|
|
setValue: function (input, data) {
|
|
var current = get$a(input.element());
|
|
if (current !== data) {
|
|
set$6(input.element(), data);
|
|
}
|
|
}
|
|
}),
|
|
onSetValue: detail.onSetValue
|
|
})]));
|
|
};
|
|
var dom$2 = function (detail) {
|
|
return {
|
|
tag: detail.tag,
|
|
attributes: __assign({ type: 'text' }, detail.inputAttributes),
|
|
styles: detail.inputStyles,
|
|
classes: detail.inputClasses
|
|
};
|
|
};
|
|
|
|
var factory$3 = function (detail, _spec) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: dom$2(detail),
|
|
components: [],
|
|
behaviours: behaviours(detail),
|
|
eventOrder: detail.eventOrder
|
|
};
|
|
};
|
|
var Input = single$2({
|
|
name: 'Input',
|
|
configFields: schema$8(),
|
|
factory: factory$3
|
|
});
|
|
|
|
var exhibit$3 = function (base, tabConfig) {
|
|
return nu$5({
|
|
attributes: wrapAll$1([{
|
|
key: tabConfig.tabAttr,
|
|
value: 'true'
|
|
}])
|
|
});
|
|
};
|
|
|
|
var ActiveTabstopping = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit$3
|
|
});
|
|
|
|
var TabstopSchema = [defaulted$1('tabAttr', 'data-alloy-tabstop')];
|
|
|
|
var Tabstopping = create$1({
|
|
fields: TabstopSchema,
|
|
name: 'tabstopping',
|
|
active: ActiveTabstopping
|
|
});
|
|
|
|
var global$3 = tinymce.util.Tools.resolve('tinymce.util.I18n');
|
|
|
|
var clearInputBehaviour = 'input-clearing';
|
|
var field$2 = function (name, placeholder) {
|
|
var inputSpec = record(Input.sketch({
|
|
inputAttributes: { placeholder: global$3.translate(placeholder) },
|
|
onSetValue: function (input$1, _data) {
|
|
emit(input$1, input());
|
|
},
|
|
inputBehaviours: derive$1([
|
|
Composing.config({ find: Option.some }),
|
|
Tabstopping.config({}),
|
|
Keying.config({ mode: 'execution' })
|
|
]),
|
|
selectOnFocus: false
|
|
}));
|
|
var buttonSpec = record(Button.sketch({
|
|
dom: dom$1('<button class="${prefix}-input-container-x ${prefix}-icon-cancel-circle ${prefix}-icon"></button>'),
|
|
action: function (button) {
|
|
var input = inputSpec.get(button);
|
|
Representing.setValue(input, '');
|
|
}
|
|
}));
|
|
return {
|
|
name: name,
|
|
spec: Container.sketch({
|
|
dom: dom$1('<div class="${prefix}-input-container"></div>'),
|
|
components: [
|
|
inputSpec.asSpec(),
|
|
buttonSpec.asSpec()
|
|
],
|
|
containerBehaviours: derive$1([
|
|
Toggling.config({ toggleClass: resolve('input-container-empty') }),
|
|
Composing.config({
|
|
find: function (comp) {
|
|
return Option.some(inputSpec.get(comp));
|
|
}
|
|
}),
|
|
config(clearInputBehaviour, [run(input(), function (iContainer) {
|
|
var input = inputSpec.get(iContainer);
|
|
var val = Representing.getValue(input);
|
|
var f = val.length > 0 ? Toggling.off : Toggling.on;
|
|
f(iContainer);
|
|
})])
|
|
])
|
|
})
|
|
};
|
|
};
|
|
var hidden = function (name) {
|
|
return {
|
|
name: name,
|
|
spec: DataField.sketch({
|
|
dom: {
|
|
tag: 'span',
|
|
styles: { display: 'none' }
|
|
},
|
|
getInitialValue: function () {
|
|
return Option.none();
|
|
}
|
|
})
|
|
};
|
|
};
|
|
|
|
var nativeDisabled = [
|
|
'input',
|
|
'button',
|
|
'textarea',
|
|
'select'
|
|
];
|
|
var onLoad$5 = function (component, disableConfig, disableState) {
|
|
var f = disableConfig.disabled() ? disable : enable;
|
|
f(component, disableConfig, disableState);
|
|
};
|
|
var hasNative = function (component, config) {
|
|
return config.useNative === true && contains(nativeDisabled, name(component.element()));
|
|
};
|
|
var nativeIsDisabled = function (component) {
|
|
return has$1(component.element(), 'disabled');
|
|
};
|
|
var nativeDisable = function (component) {
|
|
set(component.element(), 'disabled', 'disabled');
|
|
};
|
|
var nativeEnable = function (component) {
|
|
remove$1(component.element(), 'disabled');
|
|
};
|
|
var ariaIsDisabled = function (component) {
|
|
return get$1(component.element(), 'aria-disabled') === 'true';
|
|
};
|
|
var ariaDisable = function (component) {
|
|
set(component.element(), 'aria-disabled', 'true');
|
|
};
|
|
var ariaEnable = function (component) {
|
|
set(component.element(), 'aria-disabled', 'false');
|
|
};
|
|
var disable = function (component, disableConfig, _disableState) {
|
|
disableConfig.disableClass.each(function (disableClass) {
|
|
add$2(component.element(), disableClass);
|
|
});
|
|
var f = hasNative(component, disableConfig) ? nativeDisable : ariaDisable;
|
|
f(component);
|
|
disableConfig.onDisabled(component);
|
|
};
|
|
var enable = function (component, disableConfig, _disableState) {
|
|
disableConfig.disableClass.each(function (disableClass) {
|
|
remove$4(component.element(), disableClass);
|
|
});
|
|
var f = hasNative(component, disableConfig) ? nativeEnable : ariaEnable;
|
|
f(component);
|
|
disableConfig.onEnabled(component);
|
|
};
|
|
var isDisabled = function (component, disableConfig) {
|
|
return hasNative(component, disableConfig) ? nativeIsDisabled(component) : ariaIsDisabled(component);
|
|
};
|
|
var set$7 = function (component, disableConfig, disableState, disabled) {
|
|
var f = disabled ? disable : enable;
|
|
f(component, disableConfig, disableState);
|
|
};
|
|
|
|
var DisableApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
enable: enable,
|
|
disable: disable,
|
|
isDisabled: isDisabled,
|
|
onLoad: onLoad$5,
|
|
set: set$7
|
|
});
|
|
|
|
var exhibit$4 = function (base, disableConfig) {
|
|
return nu$5({ classes: disableConfig.disabled ? disableConfig.disableClass.map(pure).getOr([]) : [] });
|
|
};
|
|
var events$7 = function (disableConfig, disableState) {
|
|
return derive([
|
|
abort(execute(), function (component, _simulatedEvent) {
|
|
return isDisabled(component, disableConfig);
|
|
}),
|
|
loadEvent(disableConfig, disableState, onLoad$5)
|
|
]);
|
|
};
|
|
|
|
var ActiveDisable = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit$4,
|
|
events: events$7
|
|
});
|
|
|
|
var DisableSchema = [
|
|
defaultedFunction('disabled', never),
|
|
defaulted$1('useNative', true),
|
|
option('disableClass'),
|
|
onHandler('onDisabled'),
|
|
onHandler('onEnabled')
|
|
];
|
|
|
|
var Disabling = create$1({
|
|
fields: DisableSchema,
|
|
name: 'disabling',
|
|
active: ActiveDisable,
|
|
apis: DisableApis
|
|
});
|
|
|
|
var owner$1 = 'form';
|
|
var schema$9 = [field$1('formBehaviours', [Representing])];
|
|
var getPartName = function (name) {
|
|
return '<alloy.field.' + name + '>';
|
|
};
|
|
var sketch$5 = function (fSpec) {
|
|
var parts = function () {
|
|
var record = [];
|
|
var field = function (name, config) {
|
|
record.push(name);
|
|
return generateOne(owner$1, getPartName(name), config);
|
|
};
|
|
return {
|
|
field: field,
|
|
record: function () {
|
|
return record;
|
|
}
|
|
};
|
|
}();
|
|
var spec = fSpec(parts);
|
|
var partNames = parts.record();
|
|
var fieldParts = map$1(partNames, function (n) {
|
|
return required({
|
|
name: n,
|
|
pname: getPartName(n)
|
|
});
|
|
});
|
|
return composite(owner$1, schema$9, fieldParts, make, spec);
|
|
};
|
|
var toResult$1 = function (o, e) {
|
|
return o.fold(function () {
|
|
return Result.error(e);
|
|
}, Result.value);
|
|
};
|
|
var make = function (detail, components) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: augment(detail.formBehaviours, [Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (form) {
|
|
var resPs = getAllParts(form, detail);
|
|
return map(resPs, function (resPThunk, pName) {
|
|
return resPThunk().bind(function (v) {
|
|
var opt = Composing.getCurrent(v);
|
|
return toResult$1(opt, new Error('Cannot find a current component to extract the value from for form part \'' + pName + '\': ' + element(v.element())));
|
|
}).map(Representing.getValue);
|
|
});
|
|
},
|
|
setValue: function (form, values) {
|
|
each(values, function (newValue, key) {
|
|
getPart(form, detail, key).each(function (wrapper) {
|
|
Composing.getCurrent(wrapper).each(function (field) {
|
|
Representing.setValue(field, newValue);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
}
|
|
})]),
|
|
apis: {
|
|
getField: function (form, key) {
|
|
return getPart(form, detail, key).bind(Composing.getCurrent);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
var Form = {
|
|
getField: makeApi(function (apis, component, key) {
|
|
return apis.getField(component, key);
|
|
}),
|
|
sketch: sketch$5
|
|
};
|
|
|
|
var api$2 = function () {
|
|
var subject = Cell(Option.none());
|
|
var revoke = function () {
|
|
subject.get().each(function (s) {
|
|
s.destroy();
|
|
});
|
|
};
|
|
var clear = function () {
|
|
revoke();
|
|
subject.set(Option.none());
|
|
};
|
|
var set = function (s) {
|
|
revoke();
|
|
subject.set(Option.some(s));
|
|
};
|
|
var run = function (f) {
|
|
subject.get().each(f);
|
|
};
|
|
var isSet = function () {
|
|
return subject.get().isSome();
|
|
};
|
|
return {
|
|
clear: clear,
|
|
isSet: isSet,
|
|
set: set,
|
|
run: run
|
|
};
|
|
};
|
|
var value$2 = function () {
|
|
var subject = Cell(Option.none());
|
|
var clear = function () {
|
|
subject.set(Option.none());
|
|
};
|
|
var set = function (s) {
|
|
subject.set(Option.some(s));
|
|
};
|
|
var on = function (f) {
|
|
subject.get().each(f);
|
|
};
|
|
var isSet = function () {
|
|
return subject.get().isSome();
|
|
};
|
|
return {
|
|
clear: clear,
|
|
set: set,
|
|
isSet: isSet,
|
|
on: on
|
|
};
|
|
};
|
|
|
|
var SWIPING_LEFT = 1;
|
|
var SWIPING_RIGHT = -1;
|
|
var SWIPING_NONE = 0;
|
|
var init$2 = function (xValue) {
|
|
return {
|
|
xValue: xValue,
|
|
points: []
|
|
};
|
|
};
|
|
var move$1 = function (model, xValue) {
|
|
if (xValue === model.xValue) {
|
|
return model;
|
|
}
|
|
var currentDirection = xValue - model.xValue > 0 ? SWIPING_LEFT : SWIPING_RIGHT;
|
|
var newPoint = {
|
|
direction: currentDirection,
|
|
xValue: xValue
|
|
};
|
|
var priorPoints = function () {
|
|
if (model.points.length === 0) {
|
|
return [];
|
|
} else {
|
|
var prev = model.points[model.points.length - 1];
|
|
return prev.direction === currentDirection ? model.points.slice(0, model.points.length - 1) : model.points;
|
|
}
|
|
}();
|
|
return {
|
|
xValue: xValue,
|
|
points: priorPoints.concat([newPoint])
|
|
};
|
|
};
|
|
var complete = function (model) {
|
|
if (model.points.length === 0) {
|
|
return SWIPING_NONE;
|
|
} else {
|
|
var firstDirection = model.points[0].direction;
|
|
var lastDirection = model.points[model.points.length - 1].direction;
|
|
return firstDirection === SWIPING_RIGHT && lastDirection === SWIPING_RIGHT ? SWIPING_RIGHT : firstDirection === SWIPING_LEFT && lastDirection === SWIPING_LEFT ? SWIPING_LEFT : SWIPING_NONE;
|
|
}
|
|
};
|
|
|
|
var sketch$6 = function (rawSpec) {
|
|
var navigateEvent = 'navigateEvent';
|
|
var wrapperAdhocEvents = 'serializer-wrapper-events';
|
|
var formAdhocEvents = 'form-events';
|
|
var schema = objOf([
|
|
strict$1('fields'),
|
|
defaulted$1('maxFieldIndex', rawSpec.fields.length - 1),
|
|
strict$1('onExecute'),
|
|
strict$1('getInitialValue'),
|
|
state$1('state', function () {
|
|
return {
|
|
dialogSwipeState: value$2(),
|
|
currentScreen: Cell(0)
|
|
};
|
|
})
|
|
]);
|
|
var spec$1 = asRawOrDie('SerialisedDialog', schema, rawSpec);
|
|
var navigationButton = function (direction, directionName, enabled) {
|
|
return Button.sketch({
|
|
dom: dom$1('<span class="${prefix}-icon-' + directionName + ' ${prefix}-icon"></span>'),
|
|
action: function (button) {
|
|
emitWith(button, navigateEvent, { direction: direction });
|
|
},
|
|
buttonBehaviours: derive$1([Disabling.config({
|
|
disableClass: resolve('toolbar-navigation-disabled'),
|
|
disabled: function () {
|
|
return !enabled;
|
|
}
|
|
})])
|
|
});
|
|
};
|
|
var reposition = function (dialog, message) {
|
|
descendant$1(dialog.element(), '.' + resolve('serialised-dialog-chain')).each(function (parent) {
|
|
set$3(parent, 'left', -spec$1.state.currentScreen.get() * message.width + 'px');
|
|
});
|
|
};
|
|
var navigate = function (dialog, direction) {
|
|
var screens = descendants(dialog.element(), '.' + resolve('serialised-dialog-screen'));
|
|
descendant$1(dialog.element(), '.' + resolve('serialised-dialog-chain')).each(function (parent) {
|
|
if (spec$1.state.currentScreen.get() + direction >= 0 && spec$1.state.currentScreen.get() + direction < screens.length) {
|
|
getRaw(parent, 'left').each(function (left) {
|
|
var currentLeft = parseInt(left, 10);
|
|
var w = get$7(screens[0]);
|
|
set$3(parent, 'left', currentLeft - direction * w + 'px');
|
|
});
|
|
spec$1.state.currentScreen.set(spec$1.state.currentScreen.get() + direction);
|
|
}
|
|
});
|
|
};
|
|
var focusInput = function (dialog) {
|
|
var inputs = descendants(dialog.element(), 'input');
|
|
var optInput = Option.from(inputs[spec$1.state.currentScreen.get()]);
|
|
optInput.each(function (input) {
|
|
dialog.getSystem().getByDom(input).each(function (inputComp) {
|
|
dispatchFocus(dialog, inputComp.element());
|
|
});
|
|
});
|
|
var dotitems = memDots.get(dialog);
|
|
Highlighting.highlightAt(dotitems, spec$1.state.currentScreen.get());
|
|
};
|
|
var resetState = function () {
|
|
spec$1.state.currentScreen.set(0);
|
|
spec$1.state.dialogSwipeState.clear();
|
|
};
|
|
var memForm = record(Form.sketch(function (parts) {
|
|
return {
|
|
dom: dom$1('<div class="${prefix}-serialised-dialog"></div>'),
|
|
components: [Container.sketch({
|
|
dom: dom$1('<div class="${prefix}-serialised-dialog-chain" style="left: 0px; position: absolute;"></div>'),
|
|
components: map$1(spec$1.fields, function (field, i) {
|
|
return i <= spec$1.maxFieldIndex ? Container.sketch({
|
|
dom: dom$1('<div class="${prefix}-serialised-dialog-screen"></div>'),
|
|
components: [
|
|
navigationButton(-1, 'previous', i > 0),
|
|
parts.field(field.name, field.spec),
|
|
navigationButton(+1, 'next', i < spec$1.maxFieldIndex)
|
|
]
|
|
}) : parts.field(field.name, field.spec);
|
|
})
|
|
})],
|
|
formBehaviours: derive$1([
|
|
orientation(function (dialog, message) {
|
|
reposition(dialog, message);
|
|
}),
|
|
Keying.config({
|
|
mode: 'special',
|
|
focusIn: function (dialog, _specialInfo) {
|
|
focusInput(dialog);
|
|
},
|
|
onTab: function (dialog, _specialInfo) {
|
|
navigate(dialog, +1);
|
|
return Option.some(true);
|
|
},
|
|
onShiftTab: function (dialog, _specialInfo) {
|
|
navigate(dialog, -1);
|
|
return Option.some(true);
|
|
}
|
|
}),
|
|
config(formAdhocEvents, [
|
|
runOnAttached(function (dialog, _simulatedEvent) {
|
|
resetState();
|
|
var dotitems = memDots.get(dialog);
|
|
Highlighting.highlightFirst(dotitems);
|
|
spec$1.getInitialValue(dialog).each(function (v) {
|
|
Representing.setValue(dialog, v);
|
|
});
|
|
}),
|
|
runOnExecute(spec$1.onExecute),
|
|
run(transitionend(), function (dialog, simulatedEvent) {
|
|
var event = simulatedEvent.event();
|
|
if (event.raw().propertyName === 'left') {
|
|
focusInput(dialog);
|
|
}
|
|
}),
|
|
run(navigateEvent, function (dialog, simulatedEvent) {
|
|
var event = simulatedEvent.event();
|
|
var direction = event.direction();
|
|
navigate(dialog, direction);
|
|
})
|
|
])
|
|
])
|
|
};
|
|
}));
|
|
var memDots = record({
|
|
dom: dom$1('<div class="${prefix}-dot-container"></div>'),
|
|
behaviours: derive$1([Highlighting.config({
|
|
highlightClass: resolve('dot-active'),
|
|
itemClass: resolve('dot-item')
|
|
})]),
|
|
components: bind(spec$1.fields, function (_f, i) {
|
|
return i <= spec$1.maxFieldIndex ? [spec('<div class="${prefix}-dot-item ${prefix}-icon-full-dot ${prefix}-icon"></div>')] : [];
|
|
})
|
|
});
|
|
return {
|
|
dom: dom$1('<div class="${prefix}-serializer-wrapper"></div>'),
|
|
components: [
|
|
memForm.asSpec(),
|
|
memDots.asSpec()
|
|
],
|
|
behaviours: derive$1([
|
|
Keying.config({
|
|
mode: 'special',
|
|
focusIn: function (wrapper) {
|
|
var form = memForm.get(wrapper);
|
|
Keying.focusIn(form);
|
|
}
|
|
}),
|
|
config(wrapperAdhocEvents, [
|
|
run(touchstart(), function (_wrapper, simulatedEvent) {
|
|
var event = simulatedEvent.event();
|
|
spec$1.state.dialogSwipeState.set(init$2(event.raw().touches[0].clientX));
|
|
}),
|
|
run(touchmove(), function (_wrapper, simulatedEvent) {
|
|
var event = simulatedEvent.event();
|
|
spec$1.state.dialogSwipeState.on(function (state) {
|
|
simulatedEvent.event().prevent();
|
|
spec$1.state.dialogSwipeState.set(move$1(state, event.raw().touches[0].clientX));
|
|
});
|
|
}),
|
|
run(touchend(), function (wrapper, _simulatedEvent) {
|
|
spec$1.state.dialogSwipeState.on(function (state) {
|
|
var dialog = memForm.get(wrapper);
|
|
var direction = -1 * complete(state);
|
|
navigate(dialog, direction);
|
|
});
|
|
})
|
|
])
|
|
])
|
|
};
|
|
};
|
|
|
|
var getGroups = cached(function (realm, editor) {
|
|
return [{
|
|
label: 'the link group',
|
|
items: [sketch$6({
|
|
fields: [
|
|
field$2('url', 'Type or paste URL'),
|
|
field$2('text', 'Link text'),
|
|
field$2('title', 'Link title'),
|
|
field$2('target', 'Link target'),
|
|
hidden('link')
|
|
],
|
|
maxFieldIndex: [
|
|
'url',
|
|
'text',
|
|
'title',
|
|
'target'
|
|
].length - 1,
|
|
getInitialValue: function () {
|
|
return Option.some(getInfo(editor));
|
|
},
|
|
onExecute: function (dialog, _simulatedEvent) {
|
|
var info = Representing.getValue(dialog);
|
|
applyInfo(editor, info);
|
|
realm.restoreToolbar();
|
|
editor.focus();
|
|
}
|
|
})]
|
|
}];
|
|
});
|
|
var sketch$7 = function (realm, editor) {
|
|
return forToolbarStateAction(editor, 'link', 'link', function () {
|
|
var groups = getGroups(realm, editor);
|
|
realm.setContextToolbar(groups);
|
|
forAndroid(editor, function () {
|
|
realm.focusToolbar();
|
|
});
|
|
query(editor).each(function (link) {
|
|
editor.selection.select(link.dom());
|
|
});
|
|
});
|
|
};
|
|
|
|
var DefaultStyleFormats = [
|
|
{
|
|
title: 'Headings',
|
|
items: [
|
|
{
|
|
title: 'Heading 1',
|
|
format: 'h1'
|
|
},
|
|
{
|
|
title: 'Heading 2',
|
|
format: 'h2'
|
|
},
|
|
{
|
|
title: 'Heading 3',
|
|
format: 'h3'
|
|
},
|
|
{
|
|
title: 'Heading 4',
|
|
format: 'h4'
|
|
},
|
|
{
|
|
title: 'Heading 5',
|
|
format: 'h5'
|
|
},
|
|
{
|
|
title: 'Heading 6',
|
|
format: 'h6'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
title: 'Inline',
|
|
items: [
|
|
{
|
|
title: 'Bold',
|
|
icon: 'bold',
|
|
format: 'bold'
|
|
},
|
|
{
|
|
title: 'Italic',
|
|
icon: 'italic',
|
|
format: 'italic'
|
|
},
|
|
{
|
|
title: 'Underline',
|
|
icon: 'underline',
|
|
format: 'underline'
|
|
},
|
|
{
|
|
title: 'Strikethrough',
|
|
icon: 'strikethrough',
|
|
format: 'strikethrough'
|
|
},
|
|
{
|
|
title: 'Superscript',
|
|
icon: 'superscript',
|
|
format: 'superscript'
|
|
},
|
|
{
|
|
title: 'Subscript',
|
|
icon: 'subscript',
|
|
format: 'subscript'
|
|
},
|
|
{
|
|
title: 'Code',
|
|
icon: 'code',
|
|
format: 'code'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
title: 'Blocks',
|
|
items: [
|
|
{
|
|
title: 'Paragraph',
|
|
format: 'p'
|
|
},
|
|
{
|
|
title: 'Blockquote',
|
|
format: 'blockquote'
|
|
},
|
|
{
|
|
title: 'Div',
|
|
format: 'div'
|
|
},
|
|
{
|
|
title: 'Pre',
|
|
format: 'pre'
|
|
}
|
|
]
|
|
},
|
|
{
|
|
title: 'Alignment',
|
|
items: [
|
|
{
|
|
title: 'Left',
|
|
icon: 'alignleft',
|
|
format: 'alignleft'
|
|
},
|
|
{
|
|
title: 'Center',
|
|
icon: 'aligncenter',
|
|
format: 'aligncenter'
|
|
},
|
|
{
|
|
title: 'Right',
|
|
icon: 'alignright',
|
|
format: 'alignright'
|
|
},
|
|
{
|
|
title: 'Justify',
|
|
icon: 'alignjustify',
|
|
format: 'alignjustify'
|
|
}
|
|
]
|
|
}
|
|
];
|
|
|
|
var isRecursive = function (component, originator, target) {
|
|
return eq(originator, component.element()) && !eq(originator, target);
|
|
};
|
|
var events$8 = derive([can(focus(), function (component, simulatedEvent) {
|
|
var originator = simulatedEvent.event().originator();
|
|
var target = simulatedEvent.event().target();
|
|
if (isRecursive(component, originator, target)) {
|
|
domGlobals.console.warn(focus() + ' did not get interpreted by the desired target. ' + '\nOriginator: ' + element(originator) + '\nTarget: ' + element(target) + '\nCheck the ' + focus() + ' event handlers');
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
})]);
|
|
|
|
var DefaultEvents = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$8
|
|
});
|
|
|
|
var make$1 = identity;
|
|
|
|
var NoContextApi = function (getComp) {
|
|
var fail = function (event) {
|
|
return function () {
|
|
throw new Error('The component must be in a context to send: ' + event + (getComp ? '\n' + element(getComp().element()) + ' is not in context.' : ''));
|
|
};
|
|
};
|
|
return {
|
|
debugInfo: constant('fake'),
|
|
triggerEvent: fail('triggerEvent'),
|
|
triggerFocus: fail('triggerFocus'),
|
|
triggerEscape: fail('triggerEscape'),
|
|
build: fail('build'),
|
|
addToWorld: fail('addToWorld'),
|
|
removeFromWorld: fail('removeFromWorld'),
|
|
addToGui: fail('addToGui'),
|
|
removeFromGui: fail('removeFromGui'),
|
|
getByUid: fail('getByUid'),
|
|
getByDom: fail('getByDom'),
|
|
broadcast: fail('broadcast'),
|
|
broadcastOn: fail('broadcastOn'),
|
|
broadcastEvent: fail('broadcastEvent'),
|
|
isConnected: constant(false)
|
|
};
|
|
};
|
|
var singleton = NoContextApi();
|
|
|
|
var generateFrom = function (spec, all) {
|
|
var schema = map$1(all, function (a) {
|
|
return optionObjOf(a.name(), [
|
|
strict$1('config'),
|
|
defaulted$1('state', NoState)
|
|
]);
|
|
});
|
|
var validated = asRaw('component.behaviours', objOf(schema), spec.behaviours).fold(function (errInfo) {
|
|
throw new Error(formatError(errInfo) + '\nComplete spec:\n' + JSON.stringify(spec, null, 2));
|
|
}, function (v) {
|
|
return v;
|
|
});
|
|
return {
|
|
list: all,
|
|
data: map(validated, function (optBlobThunk) {
|
|
var output = optBlobThunk.map(function (blob) {
|
|
return {
|
|
config: blob.config,
|
|
state: blob.state.init(blob.config)
|
|
};
|
|
});
|
|
return function () {
|
|
return output;
|
|
};
|
|
})
|
|
};
|
|
};
|
|
var getBehaviours = function (bData) {
|
|
return bData.list;
|
|
};
|
|
var getData = function (bData) {
|
|
return bData.data;
|
|
};
|
|
|
|
var byInnerKey = function (data, tuple) {
|
|
var r = {};
|
|
each(data, function (detail, key) {
|
|
each(detail, function (value, indexKey) {
|
|
var chain = get(r, indexKey).getOr([]);
|
|
r[indexKey] = chain.concat([tuple(key, value)]);
|
|
});
|
|
});
|
|
return r;
|
|
};
|
|
|
|
var combine$1 = function (info, baseMod, behaviours, base) {
|
|
var modsByBehaviour = __assign({}, baseMod);
|
|
each$1(behaviours, function (behaviour) {
|
|
modsByBehaviour[behaviour.name()] = behaviour.exhibit(info, base);
|
|
});
|
|
var byAspect = byInnerKey(modsByBehaviour, function (name, modification) {
|
|
return {
|
|
name: name,
|
|
modification: modification
|
|
};
|
|
});
|
|
var combineObjects = function (objects) {
|
|
return foldr(objects, function (b, a) {
|
|
return __assign(__assign({}, a.modification), b);
|
|
}, {});
|
|
};
|
|
var combinedClasses = foldr(byAspect.classes, function (b, a) {
|
|
return a.modification.concat(b);
|
|
}, []);
|
|
var combinedAttributes = combineObjects(byAspect.attributes);
|
|
var combinedStyles = combineObjects(byAspect.styles);
|
|
return nu$5({
|
|
classes: combinedClasses,
|
|
attributes: combinedAttributes,
|
|
styles: combinedStyles
|
|
});
|
|
};
|
|
|
|
var sortKeys = function (label, keyName, array, order) {
|
|
try {
|
|
var sorted = sort(array, function (a, b) {
|
|
var aKey = a[keyName]();
|
|
var bKey = b[keyName]();
|
|
var aIndex = order.indexOf(aKey);
|
|
var bIndex = order.indexOf(bKey);
|
|
if (aIndex === -1) {
|
|
throw new Error('The ordering for ' + label + ' does not have an entry for ' + aKey + '.\nOrder specified: ' + JSON.stringify(order, null, 2));
|
|
}
|
|
if (bIndex === -1) {
|
|
throw new Error('The ordering for ' + label + ' does not have an entry for ' + bKey + '.\nOrder specified: ' + JSON.stringify(order, null, 2));
|
|
}
|
|
if (aIndex < bIndex) {
|
|
return -1;
|
|
} else if (bIndex < aIndex) {
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
});
|
|
return Result.value(sorted);
|
|
} catch (err) {
|
|
return Result.error([err]);
|
|
}
|
|
};
|
|
|
|
var uncurried = function (handler, purpose) {
|
|
return {
|
|
handler: handler,
|
|
purpose: constant(purpose)
|
|
};
|
|
};
|
|
var curried = function (handler, purpose) {
|
|
return {
|
|
cHandler: handler,
|
|
purpose: constant(purpose)
|
|
};
|
|
};
|
|
var curryArgs = function (descHandler, extraArgs) {
|
|
return curried(curry.apply(undefined, [descHandler.handler].concat(extraArgs)), descHandler.purpose());
|
|
};
|
|
var getCurried = function (descHandler) {
|
|
return descHandler.cHandler;
|
|
};
|
|
|
|
var behaviourTuple = function (name, handler) {
|
|
return {
|
|
name: constant(name),
|
|
handler: constant(handler)
|
|
};
|
|
};
|
|
var nameToHandlers = function (behaviours, info) {
|
|
var r = {};
|
|
each$1(behaviours, function (behaviour) {
|
|
r[behaviour.name()] = behaviour.handlers(info);
|
|
});
|
|
return r;
|
|
};
|
|
var groupByEvents = function (info, behaviours, base) {
|
|
var behaviourEvents = __assign(__assign({}, base), nameToHandlers(behaviours, info));
|
|
return byInnerKey(behaviourEvents, behaviourTuple);
|
|
};
|
|
var combine$2 = function (info, eventOrder, behaviours, base) {
|
|
var byEventName = groupByEvents(info, behaviours, base);
|
|
return combineGroups(byEventName, eventOrder);
|
|
};
|
|
var assemble = function (rawHandler) {
|
|
var handler = read(rawHandler);
|
|
return function (component, simulatedEvent) {
|
|
var rest = [];
|
|
for (var _i = 2; _i < arguments.length; _i++) {
|
|
rest[_i - 2] = arguments[_i];
|
|
}
|
|
var args = [
|
|
component,
|
|
simulatedEvent
|
|
].concat(rest);
|
|
if (handler.abort.apply(undefined, args)) {
|
|
simulatedEvent.stop();
|
|
} else if (handler.can.apply(undefined, args)) {
|
|
handler.run.apply(undefined, args);
|
|
}
|
|
};
|
|
};
|
|
var missingOrderError = function (eventName, tuples) {
|
|
return Result.error(['The event (' + eventName + ') has more than one behaviour that listens to it.\nWhen this occurs, you must ' + 'specify an event ordering for the behaviours in your spec (e.g. [ "listing", "toggling" ]).\nThe behaviours that ' + 'can trigger it are: ' + JSON.stringify(map$1(tuples, function (c) {
|
|
return c.name();
|
|
}), null, 2)]);
|
|
};
|
|
var fuse$1 = function (tuples, eventOrder, eventName) {
|
|
var order = eventOrder[eventName];
|
|
if (!order) {
|
|
return missingOrderError(eventName, tuples);
|
|
} else {
|
|
return sortKeys('Event: ' + eventName, 'name', tuples, order).map(function (sortedTuples) {
|
|
var handlers = map$1(sortedTuples, function (tuple) {
|
|
return tuple.handler();
|
|
});
|
|
return fuse(handlers);
|
|
});
|
|
}
|
|
};
|
|
var combineGroups = function (byEventName, eventOrder) {
|
|
var r = mapToArray(byEventName, function (tuples, eventName) {
|
|
var combined = tuples.length === 1 ? Result.value(tuples[0].handler()) : fuse$1(tuples, eventOrder, eventName);
|
|
return combined.map(function (handler) {
|
|
var assembled = assemble(handler);
|
|
var purpose = tuples.length > 1 ? filter$1(eventOrder[eventName], function (o) {
|
|
return exists(tuples, function (t) {
|
|
return t.name() === o;
|
|
});
|
|
}).join(' > ') : tuples[0].name();
|
|
return wrap$1(eventName, uncurried(assembled, purpose));
|
|
});
|
|
});
|
|
return consolidate(r, {});
|
|
};
|
|
|
|
var toInfo = function (spec) {
|
|
return asRaw('custom.definition', objOf([
|
|
field('dom', 'dom', strict(), objOf([
|
|
strict$1('tag'),
|
|
defaulted$1('styles', {}),
|
|
defaulted$1('classes', []),
|
|
defaulted$1('attributes', {}),
|
|
option('value'),
|
|
option('innerHtml')
|
|
])),
|
|
strict$1('components'),
|
|
strict$1('uid'),
|
|
defaulted$1('events', {}),
|
|
defaulted$1('apis', {}),
|
|
field('eventOrder', 'eventOrder', mergeWith({
|
|
'alloy.execute': [
|
|
'disabling',
|
|
'alloy.base.behaviour',
|
|
'toggling',
|
|
'typeaheadevents'
|
|
],
|
|
'alloy.focus': [
|
|
'alloy.base.behaviour',
|
|
'focusing',
|
|
'keying'
|
|
],
|
|
'alloy.system.init': [
|
|
'alloy.base.behaviour',
|
|
'disabling',
|
|
'toggling',
|
|
'representing'
|
|
],
|
|
'input': [
|
|
'alloy.base.behaviour',
|
|
'representing',
|
|
'streaming',
|
|
'invalidating'
|
|
],
|
|
'alloy.system.detached': [
|
|
'alloy.base.behaviour',
|
|
'representing',
|
|
'item-events',
|
|
'tooltipping'
|
|
],
|
|
'mousedown': [
|
|
'focusing',
|
|
'alloy.base.behaviour',
|
|
'item-type-events'
|
|
],
|
|
'touchstart': [
|
|
'focusing',
|
|
'alloy.base.behaviour',
|
|
'item-type-events'
|
|
],
|
|
'mouseover': [
|
|
'item-type-events',
|
|
'tooltipping'
|
|
],
|
|
'alloy.receive': [
|
|
'receiving',
|
|
'reflecting',
|
|
'tooltipping'
|
|
]
|
|
}), anyValue$1()),
|
|
option('domModification')
|
|
]), spec);
|
|
};
|
|
var toDefinition = function (detail) {
|
|
return __assign(__assign({}, detail.dom), {
|
|
uid: detail.uid,
|
|
domChildren: map$1(detail.components, function (comp) {
|
|
return comp.element();
|
|
})
|
|
});
|
|
};
|
|
var toModification = function (detail) {
|
|
return detail.domModification.fold(function () {
|
|
return nu$5({});
|
|
}, nu$5);
|
|
};
|
|
var toEvents = function (info) {
|
|
return info.events;
|
|
};
|
|
|
|
var add$3 = function (element, classes) {
|
|
each$1(classes, function (x) {
|
|
add$2(element, x);
|
|
});
|
|
};
|
|
var remove$6 = function (element, classes) {
|
|
each$1(classes, function (x) {
|
|
remove$4(element, x);
|
|
});
|
|
};
|
|
|
|
var renderToDom = function (definition) {
|
|
var subject = Element.fromTag(definition.tag);
|
|
setAll(subject, definition.attributes);
|
|
add$3(subject, definition.classes);
|
|
setAll$1(subject, definition.styles);
|
|
definition.innerHtml.each(function (html) {
|
|
return set$1(subject, html);
|
|
});
|
|
var children = definition.domChildren;
|
|
append$1(subject, children);
|
|
definition.value.each(function (value) {
|
|
set$6(subject, value);
|
|
});
|
|
if (!definition.uid) {
|
|
debugger;
|
|
}
|
|
writeOnly(subject, definition.uid);
|
|
return subject;
|
|
};
|
|
|
|
var getBehaviours$1 = function (spec) {
|
|
var behaviours = get(spec, 'behaviours').getOr({});
|
|
var keys$1 = filter$1(keys(behaviours), function (k) {
|
|
return behaviours[k] !== undefined;
|
|
});
|
|
return map$1(keys$1, function (k) {
|
|
return behaviours[k].me;
|
|
});
|
|
};
|
|
var generateFrom$1 = function (spec, all) {
|
|
return generateFrom(spec, all);
|
|
};
|
|
var generate$4 = function (spec) {
|
|
var all = getBehaviours$1(spec);
|
|
return generateFrom$1(spec, all);
|
|
};
|
|
|
|
var getDomDefinition = function (info, bList, bData) {
|
|
var definition = toDefinition(info);
|
|
var infoModification = toModification(info);
|
|
var baseModification = { 'alloy.base.modification': infoModification };
|
|
var modification = bList.length > 0 ? combine$1(bData, baseModification, bList, definition) : infoModification;
|
|
return merge$1(definition, modification);
|
|
};
|
|
var getEvents = function (info, bList, bData) {
|
|
var baseEvents = { 'alloy.base.behaviour': toEvents(info) };
|
|
return combine$2(bData, info.eventOrder, bList, baseEvents).getOrDie();
|
|
};
|
|
var build = function (spec) {
|
|
var getMe = function () {
|
|
return me;
|
|
};
|
|
var systemApi = Cell(singleton);
|
|
var info = getOrDie(toInfo(spec));
|
|
var bBlob = generate$4(spec);
|
|
var bList = getBehaviours(bBlob);
|
|
var bData = getData(bBlob);
|
|
var modDefinition = getDomDefinition(info, bList, bData);
|
|
var item = renderToDom(modDefinition);
|
|
var events = getEvents(info, bList, bData);
|
|
var subcomponents = Cell(info.components);
|
|
var connect = function (newApi) {
|
|
systemApi.set(newApi);
|
|
};
|
|
var disconnect = function () {
|
|
systemApi.set(NoContextApi(getMe));
|
|
};
|
|
var syncComponents = function () {
|
|
var children$1 = children(item);
|
|
var subs = bind(children$1, function (child) {
|
|
return systemApi.get().getByDom(child).fold(function () {
|
|
return [];
|
|
}, function (c) {
|
|
return [c];
|
|
});
|
|
});
|
|
subcomponents.set(subs);
|
|
};
|
|
var config = function (behaviour) {
|
|
var b = bData;
|
|
var f = isFunction(b[behaviour.name()]) ? b[behaviour.name()] : function () {
|
|
throw new Error('Could not find ' + behaviour.name() + ' in ' + JSON.stringify(spec, null, 2));
|
|
};
|
|
return f();
|
|
};
|
|
var hasConfigured = function (behaviour) {
|
|
return isFunction(bData[behaviour.name()]);
|
|
};
|
|
var getApis = function () {
|
|
return info.apis;
|
|
};
|
|
var readState = function (behaviourName) {
|
|
return bData[behaviourName]().map(function (b) {
|
|
return b.state.readState();
|
|
}).getOr('not enabled');
|
|
};
|
|
var me = {
|
|
getSystem: systemApi.get,
|
|
config: config,
|
|
hasConfigured: hasConfigured,
|
|
spec: constant(spec),
|
|
readState: readState,
|
|
getApis: getApis,
|
|
connect: connect,
|
|
disconnect: disconnect,
|
|
element: constant(item),
|
|
syncComponents: syncComponents,
|
|
components: subcomponents.get,
|
|
events: constant(events)
|
|
};
|
|
return me;
|
|
};
|
|
|
|
var buildSubcomponents = function (spec) {
|
|
var components = get(spec, 'components').getOr([]);
|
|
return map$1(components, build$1);
|
|
};
|
|
var buildFromSpec = function (userSpec) {
|
|
var _a = make$1(userSpec), specEvents = _a.events, spec = __rest(_a, ['events']);
|
|
var components = buildSubcomponents(spec);
|
|
var completeSpec = __assign(__assign({}, spec), {
|
|
events: __assign(__assign({}, DefaultEvents), specEvents),
|
|
components: components
|
|
});
|
|
return Result.value(build(completeSpec));
|
|
};
|
|
var text = function (textContent) {
|
|
var element = Element.fromText(textContent);
|
|
return external$1({ element: element });
|
|
};
|
|
var external$1 = function (spec) {
|
|
var extSpec = asRawOrDie('external.component', objOfOnly([
|
|
strict$1('element'),
|
|
option('uid')
|
|
]), spec);
|
|
var systemApi = Cell(NoContextApi());
|
|
var connect = function (newApi) {
|
|
systemApi.set(newApi);
|
|
};
|
|
var disconnect = function () {
|
|
systemApi.set(NoContextApi(function () {
|
|
return me;
|
|
}));
|
|
};
|
|
extSpec.uid.each(function (uid) {
|
|
writeOnly(extSpec.element, uid);
|
|
});
|
|
var me = {
|
|
getSystem: systemApi.get,
|
|
config: Option.none,
|
|
hasConfigured: constant(false),
|
|
connect: connect,
|
|
disconnect: disconnect,
|
|
getApis: function () {
|
|
return {};
|
|
},
|
|
element: constant(extSpec.element),
|
|
spec: constant(spec),
|
|
readState: constant('No state'),
|
|
syncComponents: noop,
|
|
components: constant([]),
|
|
events: constant({})
|
|
};
|
|
return premade(me);
|
|
};
|
|
var uids = generate$3;
|
|
var build$1 = function (spec) {
|
|
return getPremade(spec).fold(function () {
|
|
var userSpecWithUid = spec.hasOwnProperty('uid') ? spec : __assign({ uid: uids('') }, spec);
|
|
return buildFromSpec(userSpecWithUid).getOrDie();
|
|
}, function (prebuilt) {
|
|
return prebuilt;
|
|
});
|
|
};
|
|
var premade$1 = premade;
|
|
|
|
var hoverEvent = 'alloy.item-hover';
|
|
var focusEvent = 'alloy.item-focus';
|
|
var onHover = function (item) {
|
|
if (search(item.element()).isNone() || Focusing.isFocused(item)) {
|
|
if (!Focusing.isFocused(item)) {
|
|
Focusing.focus(item);
|
|
}
|
|
emitWith(item, hoverEvent, { item: item });
|
|
}
|
|
};
|
|
var onFocus = function (item) {
|
|
emitWith(item, focusEvent, { item: item });
|
|
};
|
|
var hover = constant(hoverEvent);
|
|
var focus$3 = constant(focusEvent);
|
|
|
|
var builder = function (detail) {
|
|
return {
|
|
dom: detail.dom,
|
|
domModification: __assign(__assign({}, detail.domModification), { attributes: __assign(__assign(__assign({ 'role': detail.toggling.isSome() ? 'menuitemcheckbox' : 'menuitem' }, detail.domModification.attributes), { 'aria-haspopup': detail.hasSubmenu }), detail.hasSubmenu ? { 'aria-expanded': false } : {}) }),
|
|
behaviours: SketchBehaviours.augment(detail.itemBehaviours, [
|
|
detail.toggling.fold(Toggling.revoke, function (tConfig) {
|
|
return Toggling.config(__assign({ aria: { mode: 'checked' } }, tConfig));
|
|
}),
|
|
Focusing.config({
|
|
ignore: detail.ignoreFocus,
|
|
stopMousedown: detail.ignoreFocus,
|
|
onFocus: function (component) {
|
|
onFocus(component);
|
|
}
|
|
}),
|
|
Keying.config({ mode: 'execution' }),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: detail.data
|
|
}
|
|
}),
|
|
config('item-type-events', __spreadArrays(pointerEvents(), [
|
|
run(mouseover(), onHover),
|
|
run(focusItem(), Focusing.focus)
|
|
]))
|
|
]),
|
|
components: detail.components,
|
|
eventOrder: detail.eventOrder
|
|
};
|
|
};
|
|
var schema$a = [
|
|
strict$1('data'),
|
|
strict$1('components'),
|
|
strict$1('dom'),
|
|
defaulted$1('hasSubmenu', false),
|
|
option('toggling'),
|
|
SketchBehaviours.field('itemBehaviours', [
|
|
Toggling,
|
|
Focusing,
|
|
Keying,
|
|
Representing
|
|
]),
|
|
defaulted$1('ignoreFocus', false),
|
|
defaulted$1('domModification', {}),
|
|
output('builder', builder),
|
|
defaulted$1('eventOrder', {})
|
|
];
|
|
|
|
var builder$1 = function (detail) {
|
|
return {
|
|
dom: detail.dom,
|
|
components: detail.components,
|
|
events: derive([stopper(focusItem())])
|
|
};
|
|
};
|
|
var schema$b = [
|
|
strict$1('dom'),
|
|
strict$1('components'),
|
|
output('builder', builder$1)
|
|
];
|
|
|
|
var owner$2 = function () {
|
|
return 'item-widget';
|
|
};
|
|
var parts = constant([required({
|
|
name: 'widget',
|
|
overrides: function (detail) {
|
|
return {
|
|
behaviours: derive$1([Representing.config({
|
|
store: {
|
|
mode: 'manual',
|
|
getValue: function (_component) {
|
|
return detail.data;
|
|
},
|
|
setValue: function () {
|
|
}
|
|
}
|
|
})])
|
|
};
|
|
}
|
|
})]);
|
|
|
|
var builder$2 = function (detail) {
|
|
var subs = substitutes(owner$2(), detail, parts());
|
|
var components$1 = components(owner$2(), detail, subs.internals());
|
|
var focusWidget = function (component) {
|
|
return getPart(component, detail, 'widget').map(function (widget) {
|
|
Keying.focusIn(widget);
|
|
return widget;
|
|
});
|
|
};
|
|
var onHorizontalArrow = function (component, simulatedEvent) {
|
|
return inside(simulatedEvent.event().target()) ? Option.none() : function () {
|
|
if (detail.autofocus) {
|
|
simulatedEvent.setSource(component.element());
|
|
return Option.none();
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
}();
|
|
};
|
|
return {
|
|
dom: detail.dom,
|
|
components: components$1,
|
|
domModification: detail.domModification,
|
|
events: derive([
|
|
runOnExecute(function (component, simulatedEvent) {
|
|
focusWidget(component).each(function (_widget) {
|
|
simulatedEvent.stop();
|
|
});
|
|
}),
|
|
run(mouseover(), onHover),
|
|
run(focusItem(), function (component, _simulatedEvent) {
|
|
if (detail.autofocus) {
|
|
focusWidget(component);
|
|
} else {
|
|
Focusing.focus(component);
|
|
}
|
|
})
|
|
]),
|
|
behaviours: SketchBehaviours.augment(detail.widgetBehaviours, [
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: detail.data
|
|
}
|
|
}),
|
|
Focusing.config({
|
|
ignore: detail.ignoreFocus,
|
|
onFocus: function (component) {
|
|
onFocus(component);
|
|
}
|
|
}),
|
|
Keying.config({
|
|
mode: 'special',
|
|
focusIn: detail.autofocus ? function (component) {
|
|
focusWidget(component);
|
|
} : revoke(),
|
|
onLeft: onHorizontalArrow,
|
|
onRight: onHorizontalArrow,
|
|
onEscape: function (component, simulatedEvent) {
|
|
if (!Focusing.isFocused(component) && !detail.autofocus) {
|
|
Focusing.focus(component);
|
|
return Option.some(true);
|
|
} else if (detail.autofocus) {
|
|
simulatedEvent.setSource(component.element());
|
|
return Option.none();
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
}
|
|
})
|
|
])
|
|
};
|
|
};
|
|
var schema$c = [
|
|
strict$1('uid'),
|
|
strict$1('data'),
|
|
strict$1('components'),
|
|
strict$1('dom'),
|
|
defaulted$1('autofocus', false),
|
|
defaulted$1('ignoreFocus', false),
|
|
SketchBehaviours.field('widgetBehaviours', [
|
|
Representing,
|
|
Focusing,
|
|
Keying
|
|
]),
|
|
defaulted$1('domModification', {}),
|
|
defaultUidsSchema(parts()),
|
|
output('builder', builder$2)
|
|
];
|
|
|
|
var itemSchema$1 = choose$1('type', {
|
|
widget: schema$c,
|
|
item: schema$a,
|
|
separator: schema$b
|
|
});
|
|
var configureGrid = function (detail, movementInfo) {
|
|
return {
|
|
mode: 'flatgrid',
|
|
selector: '.' + detail.markers.item,
|
|
initSize: {
|
|
numColumns: movementInfo.initSize.numColumns,
|
|
numRows: movementInfo.initSize.numRows
|
|
},
|
|
focusManager: detail.focusManager
|
|
};
|
|
};
|
|
var configureMatrix = function (detail, movementInfo) {
|
|
return {
|
|
mode: 'matrix',
|
|
selectors: {
|
|
row: movementInfo.rowSelector,
|
|
cell: '.' + detail.markers.item
|
|
},
|
|
focusManager: detail.focusManager
|
|
};
|
|
};
|
|
var configureMenu = function (detail, movementInfo) {
|
|
return {
|
|
mode: 'menu',
|
|
selector: '.' + detail.markers.item,
|
|
moveOnTab: movementInfo.moveOnTab,
|
|
focusManager: detail.focusManager
|
|
};
|
|
};
|
|
var parts$1 = constant([group({
|
|
factory: {
|
|
sketch: function (spec) {
|
|
var itemInfo = asRawOrDie('menu.spec item', itemSchema$1, spec);
|
|
return itemInfo.builder(itemInfo);
|
|
}
|
|
},
|
|
name: 'items',
|
|
unit: 'item',
|
|
defaults: function (detail, u) {
|
|
return u.hasOwnProperty('uid') ? u : __assign(__assign({}, u), { uid: generate$3('item') });
|
|
},
|
|
overrides: function (detail, u) {
|
|
return {
|
|
type: u.type,
|
|
ignoreFocus: detail.fakeFocus,
|
|
domModification: { classes: [detail.markers.item] }
|
|
};
|
|
}
|
|
})]);
|
|
var schema$d = constant([
|
|
strict$1('value'),
|
|
strict$1('items'),
|
|
strict$1('dom'),
|
|
strict$1('components'),
|
|
defaulted$1('eventOrder', {}),
|
|
field$1('menuBehaviours', [
|
|
Highlighting,
|
|
Representing,
|
|
Composing,
|
|
Keying
|
|
]),
|
|
defaultedOf('movement', {
|
|
mode: 'menu',
|
|
moveOnTab: true
|
|
}, choose$1('mode', {
|
|
grid: [
|
|
initSize(),
|
|
output('config', configureGrid)
|
|
],
|
|
matrix: [
|
|
output('config', configureMatrix),
|
|
strict$1('rowSelector')
|
|
],
|
|
menu: [
|
|
defaulted$1('moveOnTab', true),
|
|
output('config', configureMenu)
|
|
]
|
|
})),
|
|
itemMarkers(),
|
|
defaulted$1('fakeFocus', false),
|
|
defaulted$1('focusManager', dom()),
|
|
onHandler('onHighlight')
|
|
]);
|
|
|
|
var focus$4 = constant('alloy.menu-focus');
|
|
|
|
var make$2 = function (detail, components, _spec, _externals) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
markers: detail.markers,
|
|
behaviours: augment(detail.menuBehaviours, [
|
|
Highlighting.config({
|
|
highlightClass: detail.markers.selectedItem,
|
|
itemClass: detail.markers.item,
|
|
onHighlight: detail.onHighlight
|
|
}),
|
|
Representing.config({
|
|
store: {
|
|
mode: 'memory',
|
|
initialValue: detail.value
|
|
}
|
|
}),
|
|
Composing.config({ find: Option.some }),
|
|
Keying.config(detail.movement.config(detail, detail.movement))
|
|
]),
|
|
events: derive([
|
|
run(focus$3(), function (menu, simulatedEvent) {
|
|
var event = simulatedEvent.event();
|
|
menu.getSystem().getByDom(event.target()).each(function (item) {
|
|
Highlighting.highlight(menu, item);
|
|
simulatedEvent.stop();
|
|
emitWith(menu, focus$4(), {
|
|
menu: menu,
|
|
item: item
|
|
});
|
|
});
|
|
}),
|
|
run(hover(), function (menu, simulatedEvent) {
|
|
var item = simulatedEvent.event().item();
|
|
Highlighting.highlight(menu, item);
|
|
})
|
|
]),
|
|
components: components,
|
|
eventOrder: detail.eventOrder,
|
|
domModification: { attributes: { role: 'menu' } }
|
|
};
|
|
};
|
|
|
|
var Menu = composite$1({
|
|
name: 'Menu',
|
|
configFields: schema$d(),
|
|
partFields: parts$1(),
|
|
factory: make$2
|
|
});
|
|
|
|
var preserve$1 = function (f, container) {
|
|
var ownerDoc = owner(container);
|
|
var refocus = active(ownerDoc).bind(function (focused) {
|
|
var hasFocus = function (elem) {
|
|
return eq(focused, elem);
|
|
};
|
|
return hasFocus(container) ? Option.some(container) : descendant(container, hasFocus);
|
|
});
|
|
var result = f(container);
|
|
refocus.each(function (oldFocus) {
|
|
active(ownerDoc).filter(function (newFocus) {
|
|
return eq(newFocus, oldFocus);
|
|
}).fold(function () {
|
|
focus$1(oldFocus);
|
|
}, noop);
|
|
});
|
|
return result;
|
|
};
|
|
|
|
var set$8 = function (component, replaceConfig, replaceState, data) {
|
|
preserve$1(function () {
|
|
var newChildren = map$1(data, component.getSystem().build);
|
|
replaceChildren(component, newChildren);
|
|
}, component.element());
|
|
};
|
|
var insert = function (component, replaceConfig, insertion, childSpec) {
|
|
var child = component.getSystem().build(childSpec);
|
|
attachWith(component, child, insertion);
|
|
};
|
|
var append$2 = function (component, replaceConfig, replaceState, appendee) {
|
|
insert(component, replaceConfig, append, appendee);
|
|
};
|
|
var prepend$1 = function (component, replaceConfig, replaceState, prependee) {
|
|
insert(component, replaceConfig, prepend, prependee);
|
|
};
|
|
var remove$7 = function (component, replaceConfig, replaceState, removee) {
|
|
var children = contents(component);
|
|
var foundChild = find$2(children, function (child) {
|
|
return eq(removee.element(), child.element());
|
|
});
|
|
foundChild.each(detach);
|
|
};
|
|
var contents = function (component, _replaceConfig) {
|
|
return component.components();
|
|
};
|
|
var replaceAt = function (component, replaceConfig, replaceState, replaceeIndex, replacer) {
|
|
var children = contents(component);
|
|
return Option.from(children[replaceeIndex]).map(function (replacee) {
|
|
remove$7(component, replaceConfig, replaceState, replacee);
|
|
replacer.each(function (r) {
|
|
insert(component, replaceConfig, function (p, c) {
|
|
appendAt(p, c, replaceeIndex);
|
|
}, r);
|
|
});
|
|
return replacee;
|
|
});
|
|
};
|
|
var replaceBy = function (component, replaceConfig, replaceState, replaceePred, replacer) {
|
|
var children = contents(component);
|
|
return findIndex(children, replaceePred).bind(function (replaceeIndex) {
|
|
return replaceAt(component, replaceConfig, replaceState, replaceeIndex, replacer);
|
|
});
|
|
};
|
|
|
|
var ReplaceApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
append: append$2,
|
|
prepend: prepend$1,
|
|
remove: remove$7,
|
|
replaceAt: replaceAt,
|
|
replaceBy: replaceBy,
|
|
set: set$8,
|
|
contents: contents
|
|
});
|
|
|
|
var Replacing = create$1({
|
|
fields: [],
|
|
name: 'replacing',
|
|
apis: ReplaceApis
|
|
});
|
|
|
|
var transpose = function (obj) {
|
|
return tupleMap(obj, function (v, k) {
|
|
return {
|
|
k: v,
|
|
v: k
|
|
};
|
|
});
|
|
};
|
|
var trace = function (items, byItem, byMenu, finish) {
|
|
return get(byMenu, finish).bind(function (triggerItem) {
|
|
return get(items, triggerItem).bind(function (triggerMenu) {
|
|
var rest = trace(items, byItem, byMenu, triggerMenu);
|
|
return Option.some([triggerMenu].concat(rest));
|
|
});
|
|
}).getOr([]);
|
|
};
|
|
var generate$5 = function (menus, expansions) {
|
|
var items = {};
|
|
each(menus, function (menuItems, menu) {
|
|
each$1(menuItems, function (item) {
|
|
items[item] = menu;
|
|
});
|
|
});
|
|
var byItem = expansions;
|
|
var byMenu = transpose(expansions);
|
|
var menuPaths = map(byMenu, function (_triggerItem, submenu) {
|
|
return [submenu].concat(trace(items, byItem, byMenu, submenu));
|
|
});
|
|
return map(items, function (menu) {
|
|
return get(menuPaths, menu).getOr([menu]);
|
|
});
|
|
};
|
|
|
|
var init$3 = function () {
|
|
var expansions = Cell({});
|
|
var menus = Cell({});
|
|
var paths = Cell({});
|
|
var primary = Cell(Option.none());
|
|
var directory = Cell({});
|
|
var clear = function () {
|
|
expansions.set({});
|
|
menus.set({});
|
|
paths.set({});
|
|
primary.set(Option.none());
|
|
};
|
|
var isClear = function () {
|
|
return primary.get().isNone();
|
|
};
|
|
var setMenuBuilt = function (menuName, built) {
|
|
var _a;
|
|
menus.set(__assign(__assign({}, menus.get()), (_a = {}, _a[menuName] = {
|
|
type: 'prepared',
|
|
menu: built
|
|
}, _a)));
|
|
};
|
|
var setContents = function (sPrimary, sMenus, sExpansions, dir) {
|
|
primary.set(Option.some(sPrimary));
|
|
expansions.set(sExpansions);
|
|
menus.set(sMenus);
|
|
directory.set(dir);
|
|
var sPaths = generate$5(dir, sExpansions);
|
|
paths.set(sPaths);
|
|
};
|
|
var getTriggeringItem = function (menuValue) {
|
|
return find(expansions.get(), function (v, _k) {
|
|
return v === menuValue;
|
|
});
|
|
};
|
|
var getTriggerData = function (menuValue, getItemByValue, path) {
|
|
return getPreparedMenu(menuValue).bind(function (menu) {
|
|
return getTriggeringItem(menuValue).bind(function (triggeringItemValue) {
|
|
return getItemByValue(triggeringItemValue).map(function (triggeredItem) {
|
|
return {
|
|
triggeredMenu: menu,
|
|
triggeringItem: triggeredItem,
|
|
triggeringPath: path
|
|
};
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var getTriggeringPath = function (itemValue, getItemByValue) {
|
|
var extraPath = filter$1(lookupItem(itemValue).toArray(), function (menuValue) {
|
|
return getPreparedMenu(menuValue).isSome();
|
|
});
|
|
return get(paths.get(), itemValue).bind(function (path) {
|
|
var revPath = reverse(extraPath.concat(path));
|
|
var triggers = bind(revPath, function (menuValue, menuIndex) {
|
|
return getTriggerData(menuValue, getItemByValue, revPath.slice(0, menuIndex + 1)).fold(function () {
|
|
return primary.get().is(menuValue) ? [] : [Option.none()];
|
|
}, function (data) {
|
|
return [Option.some(data)];
|
|
});
|
|
});
|
|
return sequence(triggers);
|
|
});
|
|
};
|
|
var expand = function (itemValue) {
|
|
return get(expansions.get(), itemValue).map(function (menu) {
|
|
var current = get(paths.get(), itemValue).getOr([]);
|
|
return [menu].concat(current);
|
|
});
|
|
};
|
|
var collapse = function (itemValue) {
|
|
return get(paths.get(), itemValue).bind(function (path) {
|
|
return path.length > 1 ? Option.some(path.slice(1)) : Option.none();
|
|
});
|
|
};
|
|
var refresh = function (itemValue) {
|
|
return get(paths.get(), itemValue);
|
|
};
|
|
var getPreparedMenu = function (menuValue) {
|
|
return lookupMenu(menuValue).bind(extractPreparedMenu);
|
|
};
|
|
var lookupMenu = function (menuValue) {
|
|
return get(menus.get(), menuValue);
|
|
};
|
|
var lookupItem = function (itemValue) {
|
|
return get(expansions.get(), itemValue);
|
|
};
|
|
var otherMenus = function (path) {
|
|
var menuValues = directory.get();
|
|
return difference(keys(menuValues), path);
|
|
};
|
|
var getPrimary = function () {
|
|
return primary.get().bind(getPreparedMenu);
|
|
};
|
|
var getMenus = function () {
|
|
return menus.get();
|
|
};
|
|
return {
|
|
setMenuBuilt: setMenuBuilt,
|
|
setContents: setContents,
|
|
expand: expand,
|
|
refresh: refresh,
|
|
collapse: collapse,
|
|
lookupMenu: lookupMenu,
|
|
lookupItem: lookupItem,
|
|
otherMenus: otherMenus,
|
|
getPrimary: getPrimary,
|
|
getMenus: getMenus,
|
|
clear: clear,
|
|
isClear: isClear,
|
|
getTriggeringPath: getTriggeringPath
|
|
};
|
|
};
|
|
var extractPreparedMenu = function (prep) {
|
|
return prep.type === 'prepared' ? Option.some(prep.menu) : Option.none();
|
|
};
|
|
var LayeredState = {
|
|
init: init$3,
|
|
extractPreparedMenu: extractPreparedMenu
|
|
};
|
|
|
|
var make$3 = function (detail, _rawUiSpec) {
|
|
var submenuParentItems = Cell(Option.none());
|
|
var buildMenus = function (container, primaryName, menus) {
|
|
return map(menus, function (spec, name) {
|
|
var makeSketch = function () {
|
|
return Menu.sketch(__assign(__assign({ dom: spec.dom }, spec), {
|
|
value: name,
|
|
items: spec.items,
|
|
markers: detail.markers,
|
|
fakeFocus: detail.fakeFocus,
|
|
onHighlight: detail.onHighlight,
|
|
focusManager: detail.fakeFocus ? highlights() : dom()
|
|
}));
|
|
};
|
|
return name === primaryName ? {
|
|
type: 'prepared',
|
|
menu: container.getSystem().build(makeSketch())
|
|
} : {
|
|
type: 'notbuilt',
|
|
nbMenu: makeSketch
|
|
};
|
|
});
|
|
};
|
|
var layeredState = LayeredState.init();
|
|
var setup = function (container) {
|
|
var componentMap = buildMenus(container, detail.data.primary, detail.data.menus);
|
|
var directory = toDirectory();
|
|
layeredState.setContents(detail.data.primary, componentMap, detail.data.expansions, directory);
|
|
return layeredState.getPrimary();
|
|
};
|
|
var getItemValue = function (item) {
|
|
return Representing.getValue(item).value;
|
|
};
|
|
var getItemByValue = function (_container, menus, itemValue) {
|
|
return findMap(menus, function (menu) {
|
|
if (!menu.getSystem().isConnected()) {
|
|
return Option.none();
|
|
}
|
|
var candidates = Highlighting.getCandidates(menu);
|
|
return find$2(candidates, function (c) {
|
|
return getItemValue(c) === itemValue;
|
|
});
|
|
});
|
|
};
|
|
var toDirectory = function (_container) {
|
|
return map(detail.data.menus, function (data, _menuName) {
|
|
return bind(data.items, function (item) {
|
|
return item.type === 'separator' ? [] : [item.data.value];
|
|
});
|
|
});
|
|
};
|
|
var setActiveMenu = function (container, menu) {
|
|
Highlighting.highlight(container, menu);
|
|
Highlighting.getHighlighted(menu).orThunk(function () {
|
|
return Highlighting.getFirst(menu);
|
|
}).each(function (item) {
|
|
dispatch(container, item.element(), focusItem());
|
|
});
|
|
};
|
|
var getMenus = function (state, menuValues) {
|
|
return cat(map$1(menuValues, function (mv) {
|
|
return state.lookupMenu(mv).bind(function (prep) {
|
|
return prep.type === 'prepared' ? Option.some(prep.menu) : Option.none();
|
|
});
|
|
}));
|
|
};
|
|
var closeOthers = function (container, state, path) {
|
|
var others = getMenus(state, state.otherMenus(path));
|
|
each$1(others, function (o) {
|
|
remove$6(o.element(), [detail.markers.backgroundMenu]);
|
|
if (!detail.stayInDom) {
|
|
Replacing.remove(container, o);
|
|
}
|
|
});
|
|
};
|
|
var getSubmenuParents = function (container) {
|
|
return submenuParentItems.get().getOrThunk(function () {
|
|
var r = {};
|
|
var items = descendants(container.element(), '.' + detail.markers.item);
|
|
var parentItems = filter$1(items, function (i) {
|
|
return get$1(i, 'aria-haspopup') === 'true';
|
|
});
|
|
each$1(parentItems, function (i) {
|
|
container.getSystem().getByDom(i).each(function (itemComp) {
|
|
var key = getItemValue(itemComp);
|
|
r[key] = itemComp;
|
|
});
|
|
});
|
|
submenuParentItems.set(Option.some(r));
|
|
return r;
|
|
});
|
|
};
|
|
var updateAriaExpansions = function (container, path) {
|
|
var parentItems = getSubmenuParents(container);
|
|
each(parentItems, function (v, k) {
|
|
var expanded = contains(path, k);
|
|
set(v.element(), 'aria-expanded', expanded);
|
|
});
|
|
};
|
|
var updateMenuPath = function (container, state, path) {
|
|
return Option.from(path[0]).bind(function (latestMenuName) {
|
|
return state.lookupMenu(latestMenuName).bind(function (menuPrep) {
|
|
if (menuPrep.type === 'notbuilt') {
|
|
return Option.none();
|
|
} else {
|
|
var activeMenu = menuPrep.menu;
|
|
var rest = getMenus(state, path.slice(1));
|
|
each$1(rest, function (r) {
|
|
add$2(r.element(), detail.markers.backgroundMenu);
|
|
});
|
|
if (!inBody(activeMenu.element())) {
|
|
Replacing.append(container, premade$1(activeMenu));
|
|
}
|
|
remove$6(activeMenu.element(), [detail.markers.backgroundMenu]);
|
|
setActiveMenu(container, activeMenu);
|
|
closeOthers(container, state, path);
|
|
return Option.some(activeMenu);
|
|
}
|
|
});
|
|
});
|
|
};
|
|
var ExpandHighlightDecision;
|
|
(function (ExpandHighlightDecision) {
|
|
ExpandHighlightDecision[ExpandHighlightDecision['HighlightSubmenu'] = 0] = 'HighlightSubmenu';
|
|
ExpandHighlightDecision[ExpandHighlightDecision['HighlightParent'] = 1] = 'HighlightParent';
|
|
}(ExpandHighlightDecision || (ExpandHighlightDecision = {})));
|
|
var buildIfRequired = function (container, menuName, menuPrep) {
|
|
if (menuPrep.type === 'notbuilt') {
|
|
var menu = container.getSystem().build(menuPrep.nbMenu());
|
|
layeredState.setMenuBuilt(menuName, menu);
|
|
return menu;
|
|
} else {
|
|
return menuPrep.menu;
|
|
}
|
|
};
|
|
var expandRight = function (container, item, decision) {
|
|
if (decision === void 0) {
|
|
decision = ExpandHighlightDecision.HighlightSubmenu;
|
|
}
|
|
var value = getItemValue(item);
|
|
return layeredState.expand(value).bind(function (path) {
|
|
updateAriaExpansions(container, path);
|
|
return Option.from(path[0]).bind(function (menuName) {
|
|
return layeredState.lookupMenu(menuName).bind(function (activeMenuPrep) {
|
|
var activeMenu = buildIfRequired(container, menuName, activeMenuPrep);
|
|
if (!inBody(activeMenu.element())) {
|
|
Replacing.append(container, premade$1(activeMenu));
|
|
}
|
|
detail.onOpenSubmenu(container, item, activeMenu, reverse(path));
|
|
if (decision === ExpandHighlightDecision.HighlightSubmenu) {
|
|
Highlighting.highlightFirst(activeMenu);
|
|
return updateMenuPath(container, layeredState, path);
|
|
} else {
|
|
Highlighting.dehighlightAll(activeMenu);
|
|
return Option.some(item);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var collapseLeft = function (container, item) {
|
|
var value = getItemValue(item);
|
|
return layeredState.collapse(value).bind(function (path) {
|
|
updateAriaExpansions(container, path);
|
|
return updateMenuPath(container, layeredState, path).map(function (activeMenu) {
|
|
detail.onCollapseMenu(container, item, activeMenu);
|
|
return activeMenu;
|
|
});
|
|
});
|
|
};
|
|
var updateView = function (container, item) {
|
|
var value = getItemValue(item);
|
|
return layeredState.refresh(value).bind(function (path) {
|
|
updateAriaExpansions(container, path);
|
|
return updateMenuPath(container, layeredState, path);
|
|
});
|
|
};
|
|
var onRight = function (container, item) {
|
|
return inside(item.element()) ? Option.none() : expandRight(container, item, ExpandHighlightDecision.HighlightSubmenu);
|
|
};
|
|
var onLeft = function (container, item) {
|
|
return inside(item.element()) ? Option.none() : collapseLeft(container, item);
|
|
};
|
|
var onEscape = function (container, item) {
|
|
return collapseLeft(container, item).orThunk(function () {
|
|
return detail.onEscape(container, item).map(function () {
|
|
return container;
|
|
});
|
|
});
|
|
};
|
|
var keyOnItem = function (f) {
|
|
return function (container, simulatedEvent) {
|
|
return closest$2(simulatedEvent.getSource(), '.' + detail.markers.item).bind(function (target) {
|
|
return container.getSystem().getByDom(target).toOption().bind(function (item) {
|
|
return f(container, item).map(function () {
|
|
return true;
|
|
});
|
|
});
|
|
});
|
|
};
|
|
};
|
|
var events = derive([
|
|
run(focus$4(), function (sandbox, simulatedEvent) {
|
|
var item = simulatedEvent.event().item();
|
|
layeredState.lookupItem(getItemValue(item)).each(function () {
|
|
var menu = simulatedEvent.event().menu();
|
|
Highlighting.highlight(sandbox, menu);
|
|
var value = getItemValue(simulatedEvent.event().item());
|
|
layeredState.refresh(value).each(function (path) {
|
|
return closeOthers(sandbox, layeredState, path);
|
|
});
|
|
});
|
|
}),
|
|
runOnExecute(function (component, simulatedEvent) {
|
|
var target = simulatedEvent.event().target();
|
|
component.getSystem().getByDom(target).each(function (item) {
|
|
var itemValue = getItemValue(item);
|
|
if (itemValue.indexOf('collapse-item') === 0) {
|
|
collapseLeft(component, item);
|
|
}
|
|
expandRight(component, item, ExpandHighlightDecision.HighlightSubmenu).fold(function () {
|
|
detail.onExecute(component, item);
|
|
}, function () {
|
|
});
|
|
});
|
|
}),
|
|
runOnAttached(function (container, _simulatedEvent) {
|
|
setup(container).each(function (primary) {
|
|
Replacing.append(container, premade$1(primary));
|
|
detail.onOpenMenu(container, primary);
|
|
if (detail.highlightImmediately) {
|
|
setActiveMenu(container, primary);
|
|
}
|
|
});
|
|
})
|
|
].concat(detail.navigateOnHover ? [run(hover(), function (sandbox, simulatedEvent) {
|
|
var item = simulatedEvent.event().item();
|
|
updateView(sandbox, item);
|
|
expandRight(sandbox, item, ExpandHighlightDecision.HighlightParent);
|
|
detail.onHover(sandbox, item);
|
|
})] : []));
|
|
var getActiveItem = function (container) {
|
|
return Highlighting.getHighlighted(container).bind(Highlighting.getHighlighted);
|
|
};
|
|
var collapseMenuApi = function (container) {
|
|
getActiveItem(container).each(function (currentItem) {
|
|
collapseLeft(container, currentItem);
|
|
});
|
|
};
|
|
var highlightPrimary = function (container) {
|
|
layeredState.getPrimary().each(function (primary) {
|
|
setActiveMenu(container, primary);
|
|
});
|
|
};
|
|
var extractMenuFromContainer = function (container) {
|
|
return Option.from(container.components()[0]).filter(function (comp) {
|
|
return get$1(comp.element(), 'role') === 'menu';
|
|
});
|
|
};
|
|
var repositionMenus = function (container) {
|
|
var maybeActivePrimary = layeredState.getPrimary().bind(function (primary) {
|
|
return getActiveItem(container).bind(function (currentItem) {
|
|
var itemValue = getItemValue(currentItem);
|
|
var allMenus = values(layeredState.getMenus());
|
|
var preparedMenus = cat(map$1(allMenus, LayeredState.extractPreparedMenu));
|
|
return layeredState.getTriggeringPath(itemValue, function (v) {
|
|
return getItemByValue(container, preparedMenus, v);
|
|
});
|
|
}).map(function (triggeringPath) {
|
|
return {
|
|
primary: primary,
|
|
triggeringPath: triggeringPath
|
|
};
|
|
});
|
|
});
|
|
maybeActivePrimary.fold(function () {
|
|
extractMenuFromContainer(container).each(function (primaryMenu) {
|
|
detail.onRepositionMenu(container, primaryMenu, []);
|
|
});
|
|
}, function (_a) {
|
|
var primary = _a.primary, triggeringPath = _a.triggeringPath;
|
|
detail.onRepositionMenu(container, primary, triggeringPath);
|
|
});
|
|
};
|
|
var apis = {
|
|
collapseMenu: collapseMenuApi,
|
|
highlightPrimary: highlightPrimary,
|
|
repositionMenus: repositionMenus
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
markers: detail.markers,
|
|
behaviours: augment(detail.tmenuBehaviours, [
|
|
Keying.config({
|
|
mode: 'special',
|
|
onRight: keyOnItem(onRight),
|
|
onLeft: keyOnItem(onLeft),
|
|
onEscape: keyOnItem(onEscape),
|
|
focusIn: function (container, _keyInfo) {
|
|
layeredState.getPrimary().each(function (primary) {
|
|
dispatch(container, primary.element(), focusItem());
|
|
});
|
|
}
|
|
}),
|
|
Highlighting.config({
|
|
highlightClass: detail.markers.selectedMenu,
|
|
itemClass: detail.markers.menu
|
|
}),
|
|
Composing.config({
|
|
find: function (container) {
|
|
return Highlighting.getHighlighted(container);
|
|
}
|
|
}),
|
|
Replacing.config({})
|
|
]),
|
|
eventOrder: detail.eventOrder,
|
|
apis: apis,
|
|
events: events
|
|
};
|
|
};
|
|
var collapseItem = constant('collapse-item');
|
|
|
|
var tieredData = function (primary, menus, expansions) {
|
|
return {
|
|
primary: primary,
|
|
menus: menus,
|
|
expansions: expansions
|
|
};
|
|
};
|
|
var singleData = function (name, menu) {
|
|
return {
|
|
primary: name,
|
|
menus: wrap$1(name, menu),
|
|
expansions: {}
|
|
};
|
|
};
|
|
var collapseItem$1 = function (text) {
|
|
return {
|
|
value: generate$1(collapseItem()),
|
|
meta: { text: text }
|
|
};
|
|
};
|
|
var tieredMenu = single$2({
|
|
name: 'TieredMenu',
|
|
configFields: [
|
|
onStrictKeyboardHandler('onExecute'),
|
|
onStrictKeyboardHandler('onEscape'),
|
|
onStrictHandler('onOpenMenu'),
|
|
onStrictHandler('onOpenSubmenu'),
|
|
onHandler('onRepositionMenu'),
|
|
onHandler('onCollapseMenu'),
|
|
defaulted$1('highlightImmediately', true),
|
|
strictObjOf('data', [
|
|
strict$1('primary'),
|
|
strict$1('menus'),
|
|
strict$1('expansions')
|
|
]),
|
|
defaulted$1('fakeFocus', false),
|
|
onHandler('onHighlight'),
|
|
onHandler('onHover'),
|
|
tieredMenuMarkers(),
|
|
strict$1('dom'),
|
|
defaulted$1('navigateOnHover', true),
|
|
defaulted$1('stayInDom', false),
|
|
field$1('tmenuBehaviours', [
|
|
Keying,
|
|
Highlighting,
|
|
Composing,
|
|
Replacing
|
|
]),
|
|
defaulted$1('eventOrder', {})
|
|
],
|
|
apis: {
|
|
collapseMenu: function (apis, tmenu) {
|
|
apis.collapseMenu(tmenu);
|
|
},
|
|
highlightPrimary: function (apis, tmenu) {
|
|
apis.highlightPrimary(tmenu);
|
|
},
|
|
repositionMenus: function (apis, tmenu) {
|
|
apis.repositionMenus(tmenu);
|
|
}
|
|
},
|
|
factory: make$3,
|
|
extraApis: {
|
|
tieredData: tieredData,
|
|
singleData: singleData,
|
|
collapseItem: collapseItem$1
|
|
}
|
|
});
|
|
|
|
var findRoute = function (component, transConfig, transState, route) {
|
|
return get(transConfig.routes, route.start).bind(function (sConfig) {
|
|
return get(sConfig, route.destination);
|
|
});
|
|
};
|
|
var getTransition = function (comp, transConfig, transState) {
|
|
var route = getCurrentRoute(comp, transConfig);
|
|
return route.bind(function (r) {
|
|
return getTransitionOf(comp, transConfig, transState, r);
|
|
});
|
|
};
|
|
var getTransitionOf = function (comp, transConfig, transState, route) {
|
|
return findRoute(comp, transConfig, transState, route).bind(function (r) {
|
|
return r.transition.map(function (t) {
|
|
return {
|
|
transition: t,
|
|
route: r
|
|
};
|
|
});
|
|
});
|
|
};
|
|
var disableTransition = function (comp, transConfig, transState) {
|
|
getTransition(comp, transConfig, transState).each(function (routeTransition) {
|
|
var t = routeTransition.transition;
|
|
remove$4(comp.element(), t.transitionClass);
|
|
remove$1(comp.element(), transConfig.destinationAttr);
|
|
});
|
|
};
|
|
var getNewRoute = function (comp, transConfig, transState, destination) {
|
|
return {
|
|
start: get$1(comp.element(), transConfig.stateAttr),
|
|
destination: destination
|
|
};
|
|
};
|
|
var getCurrentRoute = function (comp, transConfig, _transState) {
|
|
var el = comp.element();
|
|
return getOpt(el, transConfig.destinationAttr).map(function (destination) {
|
|
return {
|
|
start: get$1(comp.element(), transConfig.stateAttr),
|
|
destination: destination
|
|
};
|
|
});
|
|
};
|
|
var jumpTo = function (comp, transConfig, transState, destination) {
|
|
disableTransition(comp, transConfig, transState);
|
|
if (has$1(comp.element(), transConfig.stateAttr) && get$1(comp.element(), transConfig.stateAttr) !== destination) {
|
|
transConfig.onFinish(comp, destination);
|
|
}
|
|
set(comp.element(), transConfig.stateAttr, destination);
|
|
};
|
|
var fasttrack = function (comp, transConfig, _transState, _destination) {
|
|
if (has$1(comp.element(), transConfig.destinationAttr)) {
|
|
getOpt(comp.element(), transConfig.destinationAttr).each(function (destination) {
|
|
set(comp.element(), transConfig.stateAttr, destination);
|
|
});
|
|
remove$1(comp.element(), transConfig.destinationAttr);
|
|
}
|
|
};
|
|
var progressTo = function (comp, transConfig, transState, destination) {
|
|
fasttrack(comp, transConfig);
|
|
var route = getNewRoute(comp, transConfig, transState, destination);
|
|
getTransitionOf(comp, transConfig, transState, route).fold(function () {
|
|
jumpTo(comp, transConfig, transState, destination);
|
|
}, function (routeTransition) {
|
|
disableTransition(comp, transConfig, transState);
|
|
var t = routeTransition.transition;
|
|
add$2(comp.element(), t.transitionClass);
|
|
set(comp.element(), transConfig.destinationAttr, destination);
|
|
});
|
|
};
|
|
var getState$1 = function (comp, transConfig, _transState) {
|
|
return getOpt(comp.element(), transConfig.stateAttr);
|
|
};
|
|
|
|
var TransitionApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
findRoute: findRoute,
|
|
disableTransition: disableTransition,
|
|
getCurrentRoute: getCurrentRoute,
|
|
jumpTo: jumpTo,
|
|
progressTo: progressTo,
|
|
getState: getState$1
|
|
});
|
|
|
|
var events$9 = function (transConfig, transState) {
|
|
return derive([
|
|
run(transitionend(), function (component, simulatedEvent) {
|
|
var raw = simulatedEvent.event().raw();
|
|
getCurrentRoute(component, transConfig).each(function (route) {
|
|
findRoute(component, transConfig, transState, route).each(function (rInfo) {
|
|
rInfo.transition.each(function (rTransition) {
|
|
if (raw.propertyName === rTransition.property) {
|
|
jumpTo(component, transConfig, transState, route.destination);
|
|
transConfig.onTransition(component, route);
|
|
}
|
|
});
|
|
});
|
|
});
|
|
}),
|
|
runOnAttached(function (comp, _se) {
|
|
jumpTo(comp, transConfig, transState, transConfig.initialState);
|
|
})
|
|
]);
|
|
};
|
|
|
|
var ActiveTransitioning = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
events: events$9
|
|
});
|
|
|
|
var TransitionSchema = [
|
|
defaulted$1('destinationAttr', 'data-transitioning-destination'),
|
|
defaulted$1('stateAttr', 'data-transitioning-state'),
|
|
strict$1('initialState'),
|
|
onHandler('onTransition'),
|
|
onHandler('onFinish'),
|
|
strictOf('routes', setOf$1(Result.value, setOf$1(Result.value, objOfOnly([optionObjOfOnly('transition', [
|
|
strict$1('property'),
|
|
strict$1('transitionClass')
|
|
])]))))
|
|
];
|
|
|
|
var createRoutes = function (routes) {
|
|
var r = {};
|
|
each(routes, function (v, k) {
|
|
var waypoints = k.split('<->');
|
|
r[waypoints[0]] = wrap$1(waypoints[1], v);
|
|
r[waypoints[1]] = wrap$1(waypoints[0], v);
|
|
});
|
|
return r;
|
|
};
|
|
var createBistate = function (first, second, transitions) {
|
|
return wrapAll$1([
|
|
{
|
|
key: first,
|
|
value: wrap$1(second, transitions)
|
|
},
|
|
{
|
|
key: second,
|
|
value: wrap$1(first, transitions)
|
|
}
|
|
]);
|
|
};
|
|
var createTristate = function (first, second, third, transitions) {
|
|
return wrapAll$1([
|
|
{
|
|
key: first,
|
|
value: wrapAll$1([
|
|
{
|
|
key: second,
|
|
value: transitions
|
|
},
|
|
{
|
|
key: third,
|
|
value: transitions
|
|
}
|
|
])
|
|
},
|
|
{
|
|
key: second,
|
|
value: wrapAll$1([
|
|
{
|
|
key: first,
|
|
value: transitions
|
|
},
|
|
{
|
|
key: third,
|
|
value: transitions
|
|
}
|
|
])
|
|
},
|
|
{
|
|
key: third,
|
|
value: wrapAll$1([
|
|
{
|
|
key: first,
|
|
value: transitions
|
|
},
|
|
{
|
|
key: second,
|
|
value: transitions
|
|
}
|
|
])
|
|
}
|
|
]);
|
|
};
|
|
var Transitioning = create$1({
|
|
fields: TransitionSchema,
|
|
name: 'transitioning',
|
|
active: ActiveTransitioning,
|
|
apis: TransitionApis,
|
|
extra: {
|
|
createRoutes: createRoutes,
|
|
createBistate: createBistate,
|
|
createTristate: createTristate
|
|
}
|
|
});
|
|
|
|
var scrollableStyle = resolve('scrollable');
|
|
var register = function (element) {
|
|
add$2(element, scrollableStyle);
|
|
};
|
|
var deregister = function (element) {
|
|
remove$4(element, scrollableStyle);
|
|
};
|
|
var scrollable = scrollableStyle;
|
|
|
|
var getValue$4 = function (item) {
|
|
return get(item, 'format').getOr(item.title);
|
|
};
|
|
var convert$1 = function (formats, memMenuThunk) {
|
|
var mainMenu = makeMenu('Styles', [].concat(map$1(formats.items, function (k) {
|
|
return makeItem(getValue$4(k), k.title, k.isSelected(), k.getPreview(), hasNonNullableKey(formats.expansions, getValue$4(k)));
|
|
})), memMenuThunk, false);
|
|
var submenus = map(formats.menus, function (menuItems, menuName) {
|
|
var items = map$1(menuItems, function (item) {
|
|
return makeItem(getValue$4(item), item.title, item.isSelected !== undefined ? item.isSelected() : false, item.getPreview !== undefined ? item.getPreview() : '', hasNonNullableKey(formats.expansions, getValue$4(item)));
|
|
});
|
|
return makeMenu(menuName, items, memMenuThunk, true);
|
|
});
|
|
var menus = deepMerge(submenus, wrap$1('styles', mainMenu));
|
|
var tmenu = tieredMenu.tieredData('styles', menus, formats.expansions);
|
|
return { tmenu: tmenu };
|
|
};
|
|
var makeItem = function (value, text, selected, preview, isMenu) {
|
|
return {
|
|
data: {
|
|
value: value,
|
|
text: text
|
|
},
|
|
type: 'item',
|
|
dom: {
|
|
tag: 'div',
|
|
classes: isMenu ? [resolve('styles-item-is-menu')] : []
|
|
},
|
|
toggling: {
|
|
toggleOnExecute: false,
|
|
toggleClass: resolve('format-matches'),
|
|
selected: selected
|
|
},
|
|
itemBehaviours: derive$1(isMenu ? [] : [format(value, function (comp, status) {
|
|
var toggle = status ? Toggling.on : Toggling.off;
|
|
toggle(comp);
|
|
})]),
|
|
components: [{
|
|
dom: {
|
|
tag: 'div',
|
|
attributes: { style: preview },
|
|
innerHtml: text
|
|
}
|
|
}]
|
|
};
|
|
};
|
|
var makeMenu = function (value, items, memMenuThunk, collapsable) {
|
|
return {
|
|
value: value,
|
|
dom: { tag: 'div' },
|
|
components: [
|
|
Button.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [resolve('styles-collapser')]
|
|
},
|
|
components: collapsable ? [
|
|
{
|
|
dom: {
|
|
tag: 'span',
|
|
classes: [resolve('styles-collapse-icon')]
|
|
}
|
|
},
|
|
text(value)
|
|
] : [text(value)],
|
|
action: function (item) {
|
|
if (collapsable) {
|
|
var comp = memMenuThunk().get(item);
|
|
tieredMenu.collapseMenu(comp);
|
|
}
|
|
}
|
|
}),
|
|
{
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [resolve('styles-menu-items-container')]
|
|
},
|
|
components: [Menu.parts().items({})],
|
|
behaviours: derive$1([config('adhoc-scrollable-menu', [
|
|
runOnAttached(function (component, _simulatedEvent) {
|
|
set$3(component.element(), 'overflow-y', 'auto');
|
|
set$3(component.element(), '-webkit-overflow-scrolling', 'touch');
|
|
register(component.element());
|
|
}),
|
|
runOnDetached(function (component) {
|
|
remove$5(component.element(), 'overflow-y');
|
|
remove$5(component.element(), '-webkit-overflow-scrolling');
|
|
deregister(component.element());
|
|
})
|
|
])])
|
|
}
|
|
],
|
|
items: items,
|
|
menuBehaviours: derive$1([Transitioning.config({
|
|
initialState: 'after',
|
|
routes: Transitioning.createTristate('before', 'current', 'after', {
|
|
transition: {
|
|
property: 'transform',
|
|
transitionClass: 'transitioning'
|
|
}
|
|
})
|
|
})])
|
|
};
|
|
};
|
|
var sketch$8 = function (settings) {
|
|
var dataset = convert$1(settings.formats, function () {
|
|
return memMenu;
|
|
});
|
|
var memMenu = record(tieredMenu.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [resolve('styles-menu')]
|
|
},
|
|
components: [],
|
|
fakeFocus: true,
|
|
stayInDom: true,
|
|
onExecute: function (_tmenu, item) {
|
|
var v = Representing.getValue(item);
|
|
settings.handle(item, v.value);
|
|
return Option.none();
|
|
},
|
|
onEscape: function () {
|
|
return Option.none();
|
|
},
|
|
onOpenMenu: function (container, menu) {
|
|
var w = get$7(container.element());
|
|
set$4(menu.element(), w);
|
|
Transitioning.jumpTo(menu, 'current');
|
|
},
|
|
onOpenSubmenu: function (container, item, submenu) {
|
|
var w = get$7(container.element());
|
|
var menu = ancestor$2(item.element(), '[role="menu"]').getOrDie('hacky');
|
|
var menuComp = container.getSystem().getByDom(menu).getOrDie();
|
|
set$4(submenu.element(), w);
|
|
Transitioning.progressTo(menuComp, 'before');
|
|
Transitioning.jumpTo(submenu, 'after');
|
|
Transitioning.progressTo(submenu, 'current');
|
|
},
|
|
onCollapseMenu: function (container, item, menu) {
|
|
var submenu = ancestor$2(item.element(), '[role="menu"]').getOrDie('hacky');
|
|
var submenuComp = container.getSystem().getByDom(submenu).getOrDie();
|
|
Transitioning.progressTo(submenuComp, 'after');
|
|
Transitioning.progressTo(menu, 'current');
|
|
},
|
|
navigateOnHover: false,
|
|
highlightImmediately: true,
|
|
data: dataset.tmenu,
|
|
markers: {
|
|
backgroundMenu: resolve('styles-background-menu'),
|
|
menu: resolve('styles-menu'),
|
|
selectedMenu: resolve('styles-selected-menu'),
|
|
item: resolve('styles-item'),
|
|
selectedItem: resolve('styles-selected-item')
|
|
}
|
|
}));
|
|
return memMenu.asSpec();
|
|
};
|
|
|
|
var getFromExpandingItem = function (item) {
|
|
var newItem = deepMerge(exclude$1(item, ['items']), { menu: true });
|
|
var rest = expand(item.items);
|
|
var newMenus = deepMerge(rest.menus, wrap$1(item.title, rest.items));
|
|
var newExpansions = deepMerge(rest.expansions, wrap$1(item.title, item.title));
|
|
return {
|
|
item: newItem,
|
|
menus: newMenus,
|
|
expansions: newExpansions
|
|
};
|
|
};
|
|
var getFromItem = function (item) {
|
|
return hasNonNullableKey(item, 'items') ? getFromExpandingItem(item) : {
|
|
item: item,
|
|
menus: {},
|
|
expansions: {}
|
|
};
|
|
};
|
|
var expand = function (items) {
|
|
return foldr(items, function (acc, item) {
|
|
var newData = getFromItem(item);
|
|
return {
|
|
menus: deepMerge(acc.menus, newData.menus),
|
|
items: [newData.item].concat(acc.items),
|
|
expansions: deepMerge(acc.expansions, newData.expansions)
|
|
};
|
|
}, {
|
|
menus: {},
|
|
expansions: {},
|
|
items: []
|
|
});
|
|
};
|
|
|
|
var register$1 = function (editor, settings) {
|
|
var isSelectedFor = function (format) {
|
|
return function () {
|
|
return editor.formatter.match(format);
|
|
};
|
|
};
|
|
var getPreview = function (format) {
|
|
return function () {
|
|
return editor.formatter.getCssText(format);
|
|
};
|
|
};
|
|
var enrichSupported = function (item) {
|
|
return deepMerge(item, {
|
|
isSelected: isSelectedFor(item.format),
|
|
getPreview: getPreview(item.format)
|
|
});
|
|
};
|
|
var enrichMenu = function (item) {
|
|
return deepMerge(item, {
|
|
isSelected: constant(false),
|
|
getPreview: constant('')
|
|
});
|
|
};
|
|
var enrichCustom = function (item) {
|
|
var formatName = generate$1(item.title);
|
|
var newItem = deepMerge(item, {
|
|
format: formatName,
|
|
isSelected: isSelectedFor(formatName),
|
|
getPreview: getPreview(formatName)
|
|
});
|
|
editor.formatter.register(formatName, newItem);
|
|
return newItem;
|
|
};
|
|
var formats = get(settings, 'style_formats').getOr(DefaultStyleFormats);
|
|
var doEnrich = function (items) {
|
|
return map$1(items, function (item) {
|
|
if (hasNonNullableKey(item, 'items')) {
|
|
var newItems = doEnrich(item.items);
|
|
return deepMerge(enrichMenu(item), { items: newItems });
|
|
} else if (hasNonNullableKey(item, 'format')) {
|
|
return enrichSupported(item);
|
|
} else {
|
|
return enrichCustom(item);
|
|
}
|
|
});
|
|
};
|
|
return doEnrich(formats);
|
|
};
|
|
var prune = function (editor, formats) {
|
|
var doPrune = function (items) {
|
|
return bind(items, function (item) {
|
|
if (item.items !== undefined) {
|
|
var newItems = doPrune(item.items);
|
|
return newItems.length > 0 ? [item] : [];
|
|
} else {
|
|
var keep = hasNonNullableKey(item, 'format') ? editor.formatter.canApply(item.format) : true;
|
|
return keep ? [item] : [];
|
|
}
|
|
});
|
|
};
|
|
var prunedItems = doPrune(formats);
|
|
return expand(prunedItems);
|
|
};
|
|
var ui = function (editor, formats, onDone) {
|
|
var pruned = prune(editor, formats);
|
|
return sketch$8({
|
|
formats: pruned,
|
|
handle: function (item, value) {
|
|
editor.undoManager.transact(function () {
|
|
if (Toggling.isOn(item)) {
|
|
editor.formatter.remove(value);
|
|
} else {
|
|
editor.formatter.apply(value);
|
|
}
|
|
});
|
|
onDone();
|
|
}
|
|
});
|
|
};
|
|
|
|
var defaults = [
|
|
'undo',
|
|
'bold',
|
|
'italic',
|
|
'link',
|
|
'image',
|
|
'bullist',
|
|
'styleselect'
|
|
];
|
|
var extract$1 = function (rawToolbar) {
|
|
var toolbar = rawToolbar.replace(/\|/g, ' ').trim();
|
|
return toolbar.length > 0 ? toolbar.split(/\s+/) : [];
|
|
};
|
|
var identifyFromArray = function (toolbar) {
|
|
return bind(toolbar, function (item) {
|
|
return isArray(item) ? identifyFromArray(item) : extract$1(item);
|
|
});
|
|
};
|
|
var identify = function (settings) {
|
|
var toolbar = settings.toolbar !== undefined ? settings.toolbar : defaults;
|
|
return isArray(toolbar) ? identifyFromArray(toolbar) : extract$1(toolbar);
|
|
};
|
|
var setup = function (realm, editor) {
|
|
var commandSketch = function (name) {
|
|
return function () {
|
|
return forToolbarCommand(editor, name);
|
|
};
|
|
};
|
|
var stateCommandSketch = function (name) {
|
|
return function () {
|
|
return forToolbarStateCommand(editor, name);
|
|
};
|
|
};
|
|
var actionSketch = function (name, query, action) {
|
|
return function () {
|
|
return forToolbarStateAction(editor, name, query, action);
|
|
};
|
|
};
|
|
var undo = commandSketch('undo');
|
|
var redo = commandSketch('redo');
|
|
var bold = stateCommandSketch('bold');
|
|
var italic = stateCommandSketch('italic');
|
|
var underline = stateCommandSketch('underline');
|
|
var removeformat = commandSketch('removeformat');
|
|
var link = function () {
|
|
return sketch$7(realm, editor);
|
|
};
|
|
var unlink = actionSketch('unlink', 'link', function () {
|
|
editor.execCommand('unlink', null, false);
|
|
});
|
|
var image = function () {
|
|
return sketch$4(editor);
|
|
};
|
|
var bullist = actionSketch('unordered-list', 'ul', function () {
|
|
editor.execCommand('InsertUnorderedList', null, false);
|
|
});
|
|
var numlist = actionSketch('ordered-list', 'ol', function () {
|
|
editor.execCommand('InsertOrderedList', null, false);
|
|
});
|
|
var fontsizeselect = function () {
|
|
return sketch$3(realm, editor);
|
|
};
|
|
var forecolor = function () {
|
|
return sketch$1(realm, editor);
|
|
};
|
|
var styleFormats = register$1(editor, editor.settings);
|
|
var styleFormatsMenu = function () {
|
|
return ui(editor, styleFormats, function () {
|
|
editor.fire('scrollIntoView');
|
|
});
|
|
};
|
|
var styleselect = function () {
|
|
return forToolbar('style-formats', function (button) {
|
|
editor.fire('toReading');
|
|
realm.dropup().appear(styleFormatsMenu, Toggling.on, button);
|
|
}, derive$1([
|
|
Toggling.config({
|
|
toggleClass: resolve('toolbar-button-selected'),
|
|
toggleOnExecute: false,
|
|
aria: { mode: 'pressed' }
|
|
}),
|
|
Receiving.config({
|
|
channels: wrapAll$1([
|
|
receive$1(orientationChanged, Toggling.off),
|
|
receive$1(dropupDismissed, Toggling.off)
|
|
])
|
|
})
|
|
]), editor);
|
|
};
|
|
var feature = function (prereq, sketch) {
|
|
return {
|
|
isSupported: function () {
|
|
var buttons = editor.ui.registry.getAll().buttons;
|
|
return prereq.forall(function (p) {
|
|
return hasNonNullableKey(buttons, p);
|
|
});
|
|
},
|
|
sketch: sketch
|
|
};
|
|
};
|
|
return {
|
|
undo: feature(Option.none(), undo),
|
|
redo: feature(Option.none(), redo),
|
|
bold: feature(Option.none(), bold),
|
|
italic: feature(Option.none(), italic),
|
|
underline: feature(Option.none(), underline),
|
|
removeformat: feature(Option.none(), removeformat),
|
|
link: feature(Option.none(), link),
|
|
unlink: feature(Option.none(), unlink),
|
|
image: feature(Option.none(), image),
|
|
bullist: feature(Option.some('bullist'), bullist),
|
|
numlist: feature(Option.some('numlist'), numlist),
|
|
fontsizeselect: feature(Option.none(), fontsizeselect),
|
|
forecolor: feature(Option.none(), forecolor),
|
|
styleselect: feature(Option.none(), styleselect)
|
|
};
|
|
};
|
|
var detect$4 = function (settings, features) {
|
|
var itemNames = identify(settings);
|
|
var present = {};
|
|
return bind(itemNames, function (iName) {
|
|
var r = !hasNonNullableKey(present, iName) && hasNonNullableKey(features, iName) && features[iName].isSupported() ? [features[iName].sketch()] : [];
|
|
present[iName] = true;
|
|
return r;
|
|
});
|
|
};
|
|
|
|
var mkEvent = function (target, x, y, stop, prevent, kill, raw) {
|
|
return {
|
|
target: constant(target),
|
|
x: constant(x),
|
|
y: constant(y),
|
|
stop: stop,
|
|
prevent: prevent,
|
|
kill: kill,
|
|
raw: constant(raw)
|
|
};
|
|
};
|
|
var fromRawEvent = function (rawEvent) {
|
|
var target = Element.fromDom(rawEvent.target);
|
|
var stop = function () {
|
|
return rawEvent.stopPropagation();
|
|
};
|
|
var prevent = function () {
|
|
return rawEvent.preventDefault();
|
|
};
|
|
var kill = compose(prevent, stop);
|
|
return mkEvent(target, rawEvent.clientX, rawEvent.clientY, stop, prevent, kill, rawEvent);
|
|
};
|
|
var handle = function (filter, handler) {
|
|
return function (rawEvent) {
|
|
if (filter(rawEvent)) {
|
|
handler(fromRawEvent(rawEvent));
|
|
}
|
|
};
|
|
};
|
|
var binder = function (element, event, filter, handler, useCapture) {
|
|
var wrapped = handle(filter, handler);
|
|
element.dom().addEventListener(event, wrapped, useCapture);
|
|
return { unbind: curry(unbind, element, event, wrapped, useCapture) };
|
|
};
|
|
var bind$2 = function (element, event, filter, handler) {
|
|
return binder(element, event, filter, handler, false);
|
|
};
|
|
var capture = function (element, event, filter, handler) {
|
|
return binder(element, event, filter, handler, true);
|
|
};
|
|
var unbind = function (element, event, handler, useCapture) {
|
|
element.dom().removeEventListener(event, handler, useCapture);
|
|
};
|
|
|
|
var filter$2 = constant(true);
|
|
var bind$3 = function (element, event, handler) {
|
|
return bind$2(element, event, filter$2, handler);
|
|
};
|
|
var capture$1 = function (element, event, handler) {
|
|
return capture(element, event, filter$2, handler);
|
|
};
|
|
|
|
var global$4 = tinymce.util.Tools.resolve('tinymce.util.Delay');
|
|
|
|
var INTERVAL = 50;
|
|
var INSURANCE = 1000 / INTERVAL;
|
|
var get$b = function (outerWindow) {
|
|
var isPortrait = outerWindow.matchMedia('(orientation: portrait)').matches;
|
|
return { isPortrait: constant(isPortrait) };
|
|
};
|
|
var getActualWidth = function (outerWindow) {
|
|
var isIos = detect$3().os.isiOS();
|
|
var isPortrait = get$b(outerWindow).isPortrait();
|
|
return isIos && !isPortrait ? outerWindow.screen.height : outerWindow.screen.width;
|
|
};
|
|
var onChange = function (outerWindow, listeners) {
|
|
var win = Element.fromDom(outerWindow);
|
|
var poller = null;
|
|
var change = function () {
|
|
global$4.clearInterval(poller);
|
|
var orientation = get$b(outerWindow);
|
|
listeners.onChange(orientation);
|
|
onAdjustment(function () {
|
|
listeners.onReady(orientation);
|
|
});
|
|
};
|
|
var orientationHandle = bind$3(win, 'orientationchange', change);
|
|
var onAdjustment = function (f) {
|
|
global$4.clearInterval(poller);
|
|
var flag = outerWindow.innerHeight;
|
|
var insurance = 0;
|
|
poller = global$4.setInterval(function () {
|
|
if (flag !== outerWindow.innerHeight) {
|
|
global$4.clearInterval(poller);
|
|
f(Option.some(outerWindow.innerHeight));
|
|
} else if (insurance > INSURANCE) {
|
|
global$4.clearInterval(poller);
|
|
f(Option.none());
|
|
}
|
|
insurance++;
|
|
}, INTERVAL);
|
|
};
|
|
var destroy = function () {
|
|
orientationHandle.unbind();
|
|
};
|
|
return {
|
|
onAdjustment: onAdjustment,
|
|
destroy: destroy
|
|
};
|
|
};
|
|
|
|
function DelayedFunction (fun, delay) {
|
|
var ref = null;
|
|
var schedule = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
ref = domGlobals.setTimeout(function () {
|
|
fun.apply(null, args);
|
|
ref = null;
|
|
}, delay);
|
|
};
|
|
var cancel = function () {
|
|
if (ref !== null) {
|
|
domGlobals.clearTimeout(ref);
|
|
ref = null;
|
|
}
|
|
};
|
|
return {
|
|
cancel: cancel,
|
|
schedule: schedule
|
|
};
|
|
}
|
|
|
|
var SIGNIFICANT_MOVE = 5;
|
|
var LONGPRESS_DELAY = 400;
|
|
var getTouch = function (event) {
|
|
var raw = event.raw();
|
|
if (raw.touches === undefined || raw.touches.length !== 1) {
|
|
return Option.none();
|
|
}
|
|
return Option.some(raw.touches[0]);
|
|
};
|
|
var isFarEnough = function (touch, data) {
|
|
var distX = Math.abs(touch.clientX - data.x);
|
|
var distY = Math.abs(touch.clientY - data.y);
|
|
return distX > SIGNIFICANT_MOVE || distY > SIGNIFICANT_MOVE;
|
|
};
|
|
var monitor = function (settings) {
|
|
var startData = Cell(Option.none());
|
|
var longpressFired = Cell(false);
|
|
var longpress$1 = DelayedFunction(function (event) {
|
|
settings.triggerEvent(longpress(), event);
|
|
longpressFired.set(true);
|
|
}, LONGPRESS_DELAY);
|
|
var handleTouchstart = function (event) {
|
|
getTouch(event).each(function (touch) {
|
|
longpress$1.cancel();
|
|
var data = {
|
|
x: touch.clientX,
|
|
y: touch.clientY,
|
|
target: event.target()
|
|
};
|
|
longpress$1.schedule(event);
|
|
longpressFired.set(false);
|
|
startData.set(Option.some(data));
|
|
});
|
|
return Option.none();
|
|
};
|
|
var handleTouchmove = function (event) {
|
|
longpress$1.cancel();
|
|
getTouch(event).each(function (touch) {
|
|
startData.get().each(function (data) {
|
|
if (isFarEnough(touch, data)) {
|
|
startData.set(Option.none());
|
|
}
|
|
});
|
|
});
|
|
return Option.none();
|
|
};
|
|
var handleTouchend = function (event) {
|
|
longpress$1.cancel();
|
|
var isSame = function (data) {
|
|
return eq(data.target, event.target());
|
|
};
|
|
return startData.get().filter(isSame).map(function (_data) {
|
|
if (longpressFired.get()) {
|
|
event.prevent();
|
|
return false;
|
|
} else {
|
|
return settings.triggerEvent(tap(), event);
|
|
}
|
|
});
|
|
};
|
|
var handlers = wrapAll$1([
|
|
{
|
|
key: touchstart(),
|
|
value: handleTouchstart
|
|
},
|
|
{
|
|
key: touchmove(),
|
|
value: handleTouchmove
|
|
},
|
|
{
|
|
key: touchend(),
|
|
value: handleTouchend
|
|
}
|
|
]);
|
|
var fireIfReady = function (event, type) {
|
|
return get(handlers, type).bind(function (handler) {
|
|
return handler(event);
|
|
});
|
|
};
|
|
return { fireIfReady: fireIfReady };
|
|
};
|
|
|
|
var monitor$1 = function (editorApi) {
|
|
var tapEvent = monitor({
|
|
triggerEvent: function (type, evt) {
|
|
editorApi.onTapContent(evt);
|
|
}
|
|
});
|
|
var onTouchend = function () {
|
|
return bind$3(editorApi.body(), 'touchend', function (evt) {
|
|
tapEvent.fireIfReady(evt, 'touchend');
|
|
});
|
|
};
|
|
var onTouchmove = function () {
|
|
return bind$3(editorApi.body(), 'touchmove', function (evt) {
|
|
tapEvent.fireIfReady(evt, 'touchmove');
|
|
});
|
|
};
|
|
var fireTouchstart = function (evt) {
|
|
tapEvent.fireIfReady(evt, 'touchstart');
|
|
};
|
|
return {
|
|
fireTouchstart: fireTouchstart,
|
|
onTouchend: onTouchend,
|
|
onTouchmove: onTouchmove
|
|
};
|
|
};
|
|
|
|
var isAndroid6 = detect$3().os.version.major >= 6;
|
|
var initEvents = function (editorApi, toolstrip, alloy) {
|
|
var tapping = monitor$1(editorApi);
|
|
var outerDoc = owner(toolstrip);
|
|
var isRanged = function (sel) {
|
|
return !eq(sel.start(), sel.finish()) || sel.soffset() !== sel.foffset();
|
|
};
|
|
var hasRangeInUi = function () {
|
|
return active(outerDoc).filter(function (input) {
|
|
return name(input) === 'input';
|
|
}).exists(function (input) {
|
|
return input.dom().selectionStart !== input.dom().selectionEnd;
|
|
});
|
|
};
|
|
var updateMargin = function () {
|
|
var rangeInContent = editorApi.doc().dom().hasFocus() && editorApi.getSelection().exists(isRanged);
|
|
alloy.getByDom(toolstrip).each((rangeInContent || hasRangeInUi()) === true ? Toggling.on : Toggling.off);
|
|
};
|
|
var listeners = [
|
|
bind$3(editorApi.body(), 'touchstart', function (evt) {
|
|
editorApi.onTouchContent();
|
|
tapping.fireTouchstart(evt);
|
|
}),
|
|
tapping.onTouchmove(),
|
|
tapping.onTouchend(),
|
|
bind$3(toolstrip, 'touchstart', function (_evt) {
|
|
editorApi.onTouchToolstrip();
|
|
}),
|
|
editorApi.onToReading(function () {
|
|
blur(editorApi.body());
|
|
}),
|
|
editorApi.onToEditing(noop),
|
|
editorApi.onScrollToCursor(function (tinyEvent) {
|
|
tinyEvent.preventDefault();
|
|
editorApi.getCursorBox().each(function (bounds) {
|
|
var cWin = editorApi.win();
|
|
var isOutside = bounds.top() > cWin.innerHeight || bounds.bottom() > cWin.innerHeight;
|
|
var cScrollBy = isOutside ? bounds.bottom() - cWin.innerHeight + 50 : 0;
|
|
if (cScrollBy !== 0) {
|
|
cWin.scrollTo(cWin.pageXOffset, cWin.pageYOffset + cScrollBy);
|
|
}
|
|
});
|
|
})
|
|
].concat(isAndroid6 === true ? [] : [
|
|
bind$3(Element.fromDom(editorApi.win()), 'blur', function () {
|
|
alloy.getByDom(toolstrip).each(Toggling.off);
|
|
}),
|
|
bind$3(outerDoc, 'select', updateMargin),
|
|
bind$3(editorApi.doc(), 'selectionchange', updateMargin)
|
|
]);
|
|
var destroy = function () {
|
|
each$1(listeners, function (l) {
|
|
l.unbind();
|
|
});
|
|
};
|
|
return { destroy: destroy };
|
|
};
|
|
|
|
var safeParse = function (element, attribute) {
|
|
var parsed = parseInt(get$1(element, attribute), 10);
|
|
return isNaN(parsed) ? 0 : parsed;
|
|
};
|
|
|
|
function NodeValue (is, name) {
|
|
var get = function (element) {
|
|
if (!is(element)) {
|
|
throw new Error('Can only get ' + name + ' value of a ' + name + ' node');
|
|
}
|
|
return getOption(element).getOr('');
|
|
};
|
|
var getOption = function (element) {
|
|
return is(element) ? Option.from(element.dom().nodeValue) : Option.none();
|
|
};
|
|
var set = function (element, value) {
|
|
if (!is(element)) {
|
|
throw new Error('Can only set raw ' + name + ' value of a ' + name + ' node');
|
|
}
|
|
element.dom().nodeValue = value;
|
|
};
|
|
return {
|
|
get: get,
|
|
getOption: getOption,
|
|
set: set
|
|
};
|
|
}
|
|
|
|
var api$3 = NodeValue(isText, 'text');
|
|
var getOption = function (element) {
|
|
return api$3.getOption(element);
|
|
};
|
|
|
|
var getEnd = function (element) {
|
|
return name(element) === 'img' ? 1 : getOption(element).fold(function () {
|
|
return children(element).length;
|
|
}, function (v) {
|
|
return v.length;
|
|
});
|
|
};
|
|
|
|
var create$3 = function (start, soffset, finish, foffset) {
|
|
return {
|
|
start: constant(start),
|
|
soffset: constant(soffset),
|
|
finish: constant(finish),
|
|
foffset: constant(foffset)
|
|
};
|
|
};
|
|
var SimRange = { create: create$3 };
|
|
|
|
var adt$4 = Adt.generate([
|
|
{ before: ['element'] },
|
|
{
|
|
on: [
|
|
'element',
|
|
'offset'
|
|
]
|
|
},
|
|
{ after: ['element'] }
|
|
]);
|
|
var cata = function (subject, onBefore, onOn, onAfter) {
|
|
return subject.fold(onBefore, onOn, onAfter);
|
|
};
|
|
var getStart = function (situ) {
|
|
return situ.fold(identity, identity, identity);
|
|
};
|
|
var before$1 = adt$4.before;
|
|
var on$1 = adt$4.on;
|
|
var after$1 = adt$4.after;
|
|
var Situ = {
|
|
before: before$1,
|
|
on: on$1,
|
|
after: after$1,
|
|
cata: cata,
|
|
getStart: getStart
|
|
};
|
|
|
|
var adt$5 = Adt.generate([
|
|
{ domRange: ['rng'] },
|
|
{
|
|
relative: [
|
|
'startSitu',
|
|
'finishSitu'
|
|
]
|
|
},
|
|
{
|
|
exact: [
|
|
'start',
|
|
'soffset',
|
|
'finish',
|
|
'foffset'
|
|
]
|
|
}
|
|
]);
|
|
var exactFromRange = function (simRange) {
|
|
return adt$5.exact(simRange.start(), simRange.soffset(), simRange.finish(), simRange.foffset());
|
|
};
|
|
var getStart$1 = function (selection) {
|
|
return selection.match({
|
|
domRange: function (rng) {
|
|
return Element.fromDom(rng.startContainer);
|
|
},
|
|
relative: function (startSitu, _finishSitu) {
|
|
return Situ.getStart(startSitu);
|
|
},
|
|
exact: function (start, _soffset, _finish, _foffset) {
|
|
return start;
|
|
}
|
|
});
|
|
};
|
|
var domRange = adt$5.domRange;
|
|
var relative = adt$5.relative;
|
|
var exact = adt$5.exact;
|
|
var getWin = function (selection) {
|
|
var start = getStart$1(selection);
|
|
return defaultView(start);
|
|
};
|
|
var range$1 = SimRange.create;
|
|
var Selection = {
|
|
domRange: domRange,
|
|
relative: relative,
|
|
exact: exact,
|
|
exactFromRange: exactFromRange,
|
|
getWin: getWin,
|
|
range: range$1
|
|
};
|
|
|
|
var setStart = function (rng, situ) {
|
|
situ.fold(function (e) {
|
|
rng.setStartBefore(e.dom());
|
|
}, function (e, o) {
|
|
rng.setStart(e.dom(), o);
|
|
}, function (e) {
|
|
rng.setStartAfter(e.dom());
|
|
});
|
|
};
|
|
var setFinish = function (rng, situ) {
|
|
situ.fold(function (e) {
|
|
rng.setEndBefore(e.dom());
|
|
}, function (e, o) {
|
|
rng.setEnd(e.dom(), o);
|
|
}, function (e) {
|
|
rng.setEndAfter(e.dom());
|
|
});
|
|
};
|
|
var relativeToNative = function (win, startSitu, finishSitu) {
|
|
var range = win.document.createRange();
|
|
setStart(range, startSitu);
|
|
setFinish(range, finishSitu);
|
|
return range;
|
|
};
|
|
var exactToNative = function (win, start, soffset, finish, foffset) {
|
|
var rng = win.document.createRange();
|
|
rng.setStart(start.dom(), soffset);
|
|
rng.setEnd(finish.dom(), foffset);
|
|
return rng;
|
|
};
|
|
var toRect = function (rect) {
|
|
return {
|
|
left: constant(rect.left),
|
|
top: constant(rect.top),
|
|
right: constant(rect.right),
|
|
bottom: constant(rect.bottom),
|
|
width: constant(rect.width),
|
|
height: constant(rect.height)
|
|
};
|
|
};
|
|
var getFirstRect = function (rng) {
|
|
var rects = rng.getClientRects();
|
|
var rect = rects.length > 0 ? rects[0] : rng.getBoundingClientRect();
|
|
return rect.width > 0 || rect.height > 0 ? Option.some(rect).map(toRect) : Option.none();
|
|
};
|
|
|
|
var adt$6 = Adt.generate([
|
|
{
|
|
ltr: [
|
|
'start',
|
|
'soffset',
|
|
'finish',
|
|
'foffset'
|
|
]
|
|
},
|
|
{
|
|
rtl: [
|
|
'start',
|
|
'soffset',
|
|
'finish',
|
|
'foffset'
|
|
]
|
|
}
|
|
]);
|
|
var fromRange = function (win, type, range) {
|
|
return type(Element.fromDom(range.startContainer), range.startOffset, Element.fromDom(range.endContainer), range.endOffset);
|
|
};
|
|
var getRanges = function (win, selection) {
|
|
return selection.match({
|
|
domRange: function (rng) {
|
|
return {
|
|
ltr: constant(rng),
|
|
rtl: Option.none
|
|
};
|
|
},
|
|
relative: function (startSitu, finishSitu) {
|
|
return {
|
|
ltr: cached(function () {
|
|
return relativeToNative(win, startSitu, finishSitu);
|
|
}),
|
|
rtl: cached(function () {
|
|
return Option.some(relativeToNative(win, finishSitu, startSitu));
|
|
})
|
|
};
|
|
},
|
|
exact: function (start, soffset, finish, foffset) {
|
|
return {
|
|
ltr: cached(function () {
|
|
return exactToNative(win, start, soffset, finish, foffset);
|
|
}),
|
|
rtl: cached(function () {
|
|
return Option.some(exactToNative(win, finish, foffset, start, soffset));
|
|
})
|
|
};
|
|
}
|
|
});
|
|
};
|
|
var doDiagnose = function (win, ranges) {
|
|
var rng = ranges.ltr();
|
|
if (rng.collapsed) {
|
|
var reversed = ranges.rtl().filter(function (rev) {
|
|
return rev.collapsed === false;
|
|
});
|
|
return reversed.map(function (rev) {
|
|
return adt$6.rtl(Element.fromDom(rev.endContainer), rev.endOffset, Element.fromDom(rev.startContainer), rev.startOffset);
|
|
}).getOrThunk(function () {
|
|
return fromRange(win, adt$6.ltr, rng);
|
|
});
|
|
} else {
|
|
return fromRange(win, adt$6.ltr, rng);
|
|
}
|
|
};
|
|
var diagnose = function (win, selection) {
|
|
var ranges = getRanges(win, selection);
|
|
return doDiagnose(win, ranges);
|
|
};
|
|
var asLtrRange = function (win, selection) {
|
|
var diagnosis = diagnose(win, selection);
|
|
return diagnosis.match({
|
|
ltr: function (start, soffset, finish, foffset) {
|
|
var rng = win.document.createRange();
|
|
rng.setStart(start.dom(), soffset);
|
|
rng.setEnd(finish.dom(), foffset);
|
|
return rng;
|
|
},
|
|
rtl: function (start, soffset, finish, foffset) {
|
|
var rng = win.document.createRange();
|
|
rng.setStart(finish.dom(), foffset);
|
|
rng.setEnd(start.dom(), soffset);
|
|
return rng;
|
|
}
|
|
});
|
|
};
|
|
var ltr = adt$6.ltr;
|
|
var rtl = adt$6.rtl;
|
|
|
|
var beforeSpecial = function (element, offset) {
|
|
var name$1 = name(element);
|
|
if ('input' === name$1) {
|
|
return Situ.after(element);
|
|
} else if (!contains([
|
|
'br',
|
|
'img'
|
|
], name$1)) {
|
|
return Situ.on(element, offset);
|
|
} else {
|
|
return offset === 0 ? Situ.before(element) : Situ.after(element);
|
|
}
|
|
};
|
|
var preprocessExact = function (start, soffset, finish, foffset) {
|
|
var startSitu = beforeSpecial(start, soffset);
|
|
var finishSitu = beforeSpecial(finish, foffset);
|
|
return Selection.relative(startSitu, finishSitu);
|
|
};
|
|
|
|
var makeRange = function (start, soffset, finish, foffset) {
|
|
var doc = owner(start);
|
|
var rng = doc.dom().createRange();
|
|
rng.setStart(start.dom(), soffset);
|
|
rng.setEnd(finish.dom(), foffset);
|
|
return rng;
|
|
};
|
|
var after$2 = function (start, soffset, finish, foffset) {
|
|
var r = makeRange(start, soffset, finish, foffset);
|
|
var same = eq(start, finish) && soffset === foffset;
|
|
return r.collapsed && !same;
|
|
};
|
|
|
|
var doSetNativeRange = function (win, rng) {
|
|
Option.from(win.getSelection()).each(function (selection) {
|
|
selection.removeAllRanges();
|
|
selection.addRange(rng);
|
|
});
|
|
};
|
|
var doSetRange = function (win, start, soffset, finish, foffset) {
|
|
var rng = exactToNative(win, start, soffset, finish, foffset);
|
|
doSetNativeRange(win, rng);
|
|
};
|
|
var setLegacyRtlRange = function (win, selection, start, soffset, finish, foffset) {
|
|
selection.collapse(start.dom(), soffset);
|
|
selection.extend(finish.dom(), foffset);
|
|
};
|
|
var setRangeFromRelative = function (win, relative) {
|
|
return diagnose(win, relative).match({
|
|
ltr: function (start, soffset, finish, foffset) {
|
|
doSetRange(win, start, soffset, finish, foffset);
|
|
},
|
|
rtl: function (start, soffset, finish, foffset) {
|
|
var selection = win.getSelection();
|
|
if (selection.setBaseAndExtent) {
|
|
selection.setBaseAndExtent(start.dom(), soffset, finish.dom(), foffset);
|
|
} else if (selection.extend) {
|
|
try {
|
|
setLegacyRtlRange(win, selection, start, soffset, finish, foffset);
|
|
} catch (e) {
|
|
doSetRange(win, finish, foffset, start, soffset);
|
|
}
|
|
} else {
|
|
doSetRange(win, finish, foffset, start, soffset);
|
|
}
|
|
}
|
|
});
|
|
};
|
|
var setExact = function (win, start, soffset, finish, foffset) {
|
|
var relative = preprocessExact(start, soffset, finish, foffset);
|
|
setRangeFromRelative(win, relative);
|
|
};
|
|
var readRange = function (selection) {
|
|
if (selection.rangeCount > 0) {
|
|
var firstRng = selection.getRangeAt(0);
|
|
var lastRng = selection.getRangeAt(selection.rangeCount - 1);
|
|
return Option.some(SimRange.create(Element.fromDom(firstRng.startContainer), firstRng.startOffset, Element.fromDom(lastRng.endContainer), lastRng.endOffset));
|
|
} else {
|
|
return Option.none();
|
|
}
|
|
};
|
|
var doGetExact = function (selection) {
|
|
var anchor = Element.fromDom(selection.anchorNode);
|
|
var focus = Element.fromDom(selection.focusNode);
|
|
return after$2(anchor, selection.anchorOffset, focus, selection.focusOffset) ? Option.some(SimRange.create(anchor, selection.anchorOffset, focus, selection.focusOffset)) : readRange(selection);
|
|
};
|
|
var getExact = function (win) {
|
|
return Option.from(win.getSelection()).filter(function (sel) {
|
|
return sel.rangeCount > 0;
|
|
}).bind(doGetExact);
|
|
};
|
|
var get$c = function (win) {
|
|
return getExact(win).map(function (range) {
|
|
return Selection.exact(range.start(), range.soffset(), range.finish(), range.foffset());
|
|
});
|
|
};
|
|
var getFirstRect$1 = function (win, selection) {
|
|
var rng = asLtrRange(win, selection);
|
|
return getFirstRect(rng);
|
|
};
|
|
var clear$1 = function (win) {
|
|
var selection = win.getSelection();
|
|
selection.removeAllRanges();
|
|
};
|
|
|
|
var COLLAPSED_WIDTH = 2;
|
|
var collapsedRect = function (rect) {
|
|
return {
|
|
left: rect.left,
|
|
top: rect.top,
|
|
right: rect.right,
|
|
bottom: rect.bottom,
|
|
width: constant(COLLAPSED_WIDTH),
|
|
height: rect.height
|
|
};
|
|
};
|
|
var toRect$1 = function (rawRect) {
|
|
return {
|
|
left: constant(rawRect.left),
|
|
top: constant(rawRect.top),
|
|
right: constant(rawRect.right),
|
|
bottom: constant(rawRect.bottom),
|
|
width: constant(rawRect.width),
|
|
height: constant(rawRect.height)
|
|
};
|
|
};
|
|
var getRectsFromRange = function (range) {
|
|
if (!range.collapsed) {
|
|
return map$1(range.getClientRects(), toRect$1);
|
|
} else {
|
|
var start_1 = Element.fromDom(range.startContainer);
|
|
return parent(start_1).bind(function (parent) {
|
|
var selection = Selection.exact(start_1, range.startOffset, parent, getEnd(parent));
|
|
var optRect = getFirstRect$1(range.startContainer.ownerDocument.defaultView, selection);
|
|
return optRect.map(collapsedRect).map(pure);
|
|
}).getOr([]);
|
|
}
|
|
};
|
|
var getRectangles = function (cWin) {
|
|
var sel = cWin.getSelection();
|
|
return sel !== undefined && sel.rangeCount > 0 ? getRectsFromRange(sel.getRangeAt(0)) : [];
|
|
};
|
|
|
|
var autocompleteHack = function () {
|
|
return function (f) {
|
|
global$4.setTimeout(function () {
|
|
f();
|
|
}, 0);
|
|
};
|
|
};
|
|
var resume = function (cWin) {
|
|
cWin.focus();
|
|
var iBody = Element.fromDom(cWin.document.body);
|
|
var inInput = active().exists(function (elem) {
|
|
return contains([
|
|
'input',
|
|
'textarea'
|
|
], name(elem));
|
|
});
|
|
var transaction = inInput ? autocompleteHack() : apply;
|
|
transaction(function () {
|
|
active().each(blur);
|
|
focus$1(iBody);
|
|
});
|
|
};
|
|
|
|
var EXTRA_SPACING = 50;
|
|
var data = 'data-' + resolve('last-outer-height');
|
|
var setLastHeight = function (cBody, value) {
|
|
set(cBody, data, value);
|
|
};
|
|
var getLastHeight = function (cBody) {
|
|
return safeParse(cBody, data);
|
|
};
|
|
var getBoundsFrom = function (rect) {
|
|
return {
|
|
top: constant(rect.top()),
|
|
bottom: constant(rect.top() + rect.height())
|
|
};
|
|
};
|
|
var getBounds$1 = function (cWin) {
|
|
var rects = getRectangles(cWin);
|
|
return rects.length > 0 ? Option.some(rects[0]).map(getBoundsFrom) : Option.none();
|
|
};
|
|
var findDelta = function (outerWindow, cBody) {
|
|
var last = getLastHeight(cBody);
|
|
var current = outerWindow.innerHeight;
|
|
return last > current ? Option.some(last - current) : Option.none();
|
|
};
|
|
var calculate = function (cWin, bounds, delta) {
|
|
var isOutside = bounds.top() > cWin.innerHeight || bounds.bottom() > cWin.innerHeight;
|
|
return isOutside ? Math.min(delta, bounds.bottom() - cWin.innerHeight + EXTRA_SPACING) : 0;
|
|
};
|
|
var setup$1 = function (outerWindow, cWin) {
|
|
var cBody = Element.fromDom(cWin.document.body);
|
|
var toEditing = function () {
|
|
resume(cWin);
|
|
};
|
|
var onResize = bind$3(Element.fromDom(outerWindow), 'resize', function () {
|
|
findDelta(outerWindow, cBody).each(function (delta) {
|
|
getBounds$1(cWin).each(function (bounds) {
|
|
var cScrollBy = calculate(cWin, bounds, delta);
|
|
if (cScrollBy !== 0) {
|
|
cWin.scrollTo(cWin.pageXOffset, cWin.pageYOffset + cScrollBy);
|
|
}
|
|
});
|
|
});
|
|
setLastHeight(cBody, outerWindow.innerHeight);
|
|
});
|
|
setLastHeight(cBody, outerWindow.innerHeight);
|
|
var destroy = function () {
|
|
onResize.unbind();
|
|
};
|
|
return {
|
|
toEditing: toEditing,
|
|
destroy: destroy
|
|
};
|
|
};
|
|
|
|
var getBodyFromFrame = function (frame) {
|
|
return Option.some(Element.fromDom(frame.dom().contentWindow.document.body));
|
|
};
|
|
var getDocFromFrame = function (frame) {
|
|
return Option.some(Element.fromDom(frame.dom().contentWindow.document));
|
|
};
|
|
var getWinFromFrame = function (frame) {
|
|
return Option.from(frame.dom().contentWindow);
|
|
};
|
|
var getSelectionFromFrame = function (frame) {
|
|
var optWin = getWinFromFrame(frame);
|
|
return optWin.bind(getExact);
|
|
};
|
|
var getFrame = function (editor) {
|
|
return editor.getFrame();
|
|
};
|
|
var getOrDerive = function (name, f) {
|
|
return function (editor) {
|
|
var g = editor[name].getOrThunk(function () {
|
|
var frame = getFrame(editor);
|
|
return function () {
|
|
return f(frame);
|
|
};
|
|
});
|
|
return g();
|
|
};
|
|
};
|
|
var getOrListen = function (editor, doc, name, type) {
|
|
return editor[name].getOrThunk(function () {
|
|
return function (handler) {
|
|
return bind$3(doc, type, handler);
|
|
};
|
|
});
|
|
};
|
|
var toRect$2 = function (rect) {
|
|
return {
|
|
left: constant(rect.left),
|
|
top: constant(rect.top),
|
|
right: constant(rect.right),
|
|
bottom: constant(rect.bottom),
|
|
width: constant(rect.width),
|
|
height: constant(rect.height)
|
|
};
|
|
};
|
|
var getActiveApi = function (editor) {
|
|
var frame = getFrame(editor);
|
|
var tryFallbackBox = function (win) {
|
|
var isCollapsed = function (sel) {
|
|
return eq(sel.start(), sel.finish()) && sel.soffset() === sel.foffset();
|
|
};
|
|
var toStartRect = function (sel) {
|
|
var rect = sel.start().dom().getBoundingClientRect();
|
|
return rect.width > 0 || rect.height > 0 ? Option.some(rect).map(toRect$2) : Option.none();
|
|
};
|
|
return getExact(win).filter(isCollapsed).bind(toStartRect);
|
|
};
|
|
return getBodyFromFrame(frame).bind(function (body) {
|
|
return getDocFromFrame(frame).bind(function (doc) {
|
|
return getWinFromFrame(frame).map(function (win) {
|
|
var html = Element.fromDom(doc.dom().documentElement);
|
|
var getCursorBox = editor.getCursorBox.getOrThunk(function () {
|
|
return function () {
|
|
return get$c(win).bind(function (sel) {
|
|
return getFirstRect$1(win, sel).orThunk(function () {
|
|
return tryFallbackBox(win);
|
|
});
|
|
});
|
|
};
|
|
});
|
|
var setSelection = editor.setSelection.getOrThunk(function () {
|
|
return function (start, soffset, finish, foffset) {
|
|
setExact(win, start, soffset, finish, foffset);
|
|
};
|
|
});
|
|
var clearSelection = editor.clearSelection.getOrThunk(function () {
|
|
return function () {
|
|
clear$1(win);
|
|
};
|
|
});
|
|
return {
|
|
body: constant(body),
|
|
doc: constant(doc),
|
|
win: constant(win),
|
|
html: constant(html),
|
|
getSelection: curry(getSelectionFromFrame, frame),
|
|
setSelection: setSelection,
|
|
clearSelection: clearSelection,
|
|
frame: constant(frame),
|
|
onKeyup: getOrListen(editor, doc, 'onKeyup', 'keyup'),
|
|
onNodeChanged: getOrListen(editor, doc, 'onNodeChanged', 'SelectionChange'),
|
|
onDomChanged: editor.onDomChanged,
|
|
onScrollToCursor: editor.onScrollToCursor,
|
|
onScrollToElement: editor.onScrollToElement,
|
|
onToReading: editor.onToReading,
|
|
onToEditing: editor.onToEditing,
|
|
onToolbarScrollStart: editor.onToolbarScrollStart,
|
|
onTouchContent: editor.onTouchContent,
|
|
onTapContent: editor.onTapContent,
|
|
onTouchToolstrip: editor.onTouchToolstrip,
|
|
getCursorBox: getCursorBox
|
|
};
|
|
});
|
|
});
|
|
});
|
|
};
|
|
var getWin$1 = getOrDerive('getWin', getWinFromFrame);
|
|
|
|
var attr = 'data-ephox-mobile-fullscreen-style';
|
|
var siblingStyles = 'display:none!important;';
|
|
var ancestorPosition = 'position:absolute!important;';
|
|
var ancestorStyles = 'top:0!important;left:0!important;margin:0!important;padding:0!important;width:100%!important;height:100%!important;overflow:visible!important;';
|
|
var bgFallback = 'background-color:rgb(255,255,255)!important;';
|
|
var isAndroid = detect$3().os.isAndroid();
|
|
var matchColor = function (editorBody) {
|
|
var color = get$4(editorBody, 'background-color');
|
|
return color !== undefined && color !== '' ? 'background-color:' + color + '!important' : bgFallback;
|
|
};
|
|
var clobberStyles = function (container, editorBody) {
|
|
var gatherSibilings = function (element) {
|
|
return siblings$2(element, '*');
|
|
};
|
|
var clobber = function (clobberStyle) {
|
|
return function (element) {
|
|
var styles = get$1(element, 'style');
|
|
var backup = styles === undefined ? 'no-styles' : styles.trim();
|
|
if (backup === clobberStyle) {
|
|
return;
|
|
} else {
|
|
set(element, attr, backup);
|
|
set(element, 'style', clobberStyle);
|
|
}
|
|
};
|
|
};
|
|
var ancestors = ancestors$1(container, '*');
|
|
var siblings = bind(ancestors, gatherSibilings);
|
|
var bgColor = matchColor(editorBody);
|
|
each$1(siblings, clobber(siblingStyles));
|
|
each$1(ancestors, clobber(ancestorPosition + ancestorStyles + bgColor));
|
|
var containerStyles = isAndroid === true ? '' : ancestorPosition;
|
|
clobber(containerStyles + ancestorStyles + bgColor)(container);
|
|
};
|
|
var restoreStyles = function () {
|
|
var clobberedEls = all$2('[' + attr + ']');
|
|
each$1(clobberedEls, function (element) {
|
|
var restore = get$1(element, attr);
|
|
if (restore !== 'no-styles') {
|
|
set(element, 'style', restore);
|
|
} else {
|
|
remove$1(element, 'style');
|
|
}
|
|
remove$1(element, attr);
|
|
});
|
|
};
|
|
|
|
var tag = function () {
|
|
var head = first('head').getOrDie();
|
|
var nu = function () {
|
|
var meta = Element.fromTag('meta');
|
|
set(meta, 'name', 'viewport');
|
|
append(head, meta);
|
|
return meta;
|
|
};
|
|
var element = first('meta[name="viewport"]').getOrThunk(nu);
|
|
var backup = get$1(element, 'content');
|
|
var maximize = function () {
|
|
set(element, 'content', 'width=device-width, initial-scale=1.0, user-scalable=no, maximum-scale=1.0');
|
|
};
|
|
var restore = function () {
|
|
if (backup !== undefined && backup !== null && backup.length > 0) {
|
|
set(element, 'content', backup);
|
|
} else {
|
|
set(element, 'content', 'user-scalable=yes');
|
|
}
|
|
};
|
|
return {
|
|
maximize: maximize,
|
|
restore: restore
|
|
};
|
|
};
|
|
|
|
var create$4 = function (platform, mask) {
|
|
var meta = tag();
|
|
var androidApi = api$2();
|
|
var androidEvents = api$2();
|
|
var enter = function () {
|
|
mask.hide();
|
|
add$2(platform.container, resolve('fullscreen-maximized'));
|
|
add$2(platform.container, resolve('android-maximized'));
|
|
meta.maximize();
|
|
add$2(platform.body, resolve('android-scroll-reload'));
|
|
androidApi.set(setup$1(platform.win, getWin$1(platform.editor).getOrDie('no')));
|
|
getActiveApi(platform.editor).each(function (editorApi) {
|
|
clobberStyles(platform.container, editorApi.body());
|
|
androidEvents.set(initEvents(editorApi, platform.toolstrip, platform.alloy));
|
|
});
|
|
};
|
|
var exit = function () {
|
|
meta.restore();
|
|
mask.show();
|
|
remove$4(platform.container, resolve('fullscreen-maximized'));
|
|
remove$4(platform.container, resolve('android-maximized'));
|
|
restoreStyles();
|
|
remove$4(platform.body, resolve('android-scroll-reload'));
|
|
androidEvents.clear();
|
|
androidApi.clear();
|
|
};
|
|
return {
|
|
enter: enter,
|
|
exit: exit
|
|
};
|
|
};
|
|
|
|
var first$1 = function (fn, rate) {
|
|
var timer = null;
|
|
var cancel = function () {
|
|
if (timer !== null) {
|
|
domGlobals.clearTimeout(timer);
|
|
timer = null;
|
|
}
|
|
};
|
|
var throttle = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
if (timer === null) {
|
|
timer = domGlobals.setTimeout(function () {
|
|
fn.apply(null, args);
|
|
timer = null;
|
|
}, rate);
|
|
}
|
|
};
|
|
return {
|
|
cancel: cancel,
|
|
throttle: throttle
|
|
};
|
|
};
|
|
var last = function (fn, rate) {
|
|
var timer = null;
|
|
var cancel = function () {
|
|
if (timer !== null) {
|
|
domGlobals.clearTimeout(timer);
|
|
timer = null;
|
|
}
|
|
};
|
|
var throttle = function () {
|
|
var args = [];
|
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
args[_i] = arguments[_i];
|
|
}
|
|
if (timer !== null) {
|
|
domGlobals.clearTimeout(timer);
|
|
}
|
|
timer = domGlobals.setTimeout(function () {
|
|
fn.apply(null, args);
|
|
timer = null;
|
|
}, rate);
|
|
};
|
|
return {
|
|
cancel: cancel,
|
|
throttle: throttle
|
|
};
|
|
};
|
|
|
|
var sketch$9 = function (onView, _translate) {
|
|
var memIcon = record(Container.sketch({
|
|
dom: dom$1('<div aria-hidden="true" class="${prefix}-mask-tap-icon"></div>'),
|
|
containerBehaviours: derive$1([Toggling.config({
|
|
toggleClass: resolve('mask-tap-icon-selected'),
|
|
toggleOnExecute: false
|
|
})])
|
|
}));
|
|
var onViewThrottle = first$1(onView, 200);
|
|
return Container.sketch({
|
|
dom: dom$1('<div class="${prefix}-disabled-mask"></div>'),
|
|
components: [Container.sketch({
|
|
dom: dom$1('<div class="${prefix}-content-container"></div>'),
|
|
components: [Button.sketch({
|
|
dom: dom$1('<div class="${prefix}-content-tap-section"></div>'),
|
|
components: [memIcon.asSpec()],
|
|
action: function (_button) {
|
|
onViewThrottle.throttle();
|
|
},
|
|
buttonBehaviours: derive$1([Toggling.config({ toggleClass: resolve('mask-tap-icon-selected') })])
|
|
})]
|
|
})]
|
|
});
|
|
};
|
|
|
|
var MobileSchema = objOf([
|
|
strictObjOf('editor', [
|
|
strict$1('getFrame'),
|
|
option('getBody'),
|
|
option('getDoc'),
|
|
option('getWin'),
|
|
option('getSelection'),
|
|
option('setSelection'),
|
|
option('clearSelection'),
|
|
option('cursorSaver'),
|
|
option('onKeyup'),
|
|
option('onNodeChanged'),
|
|
option('getCursorBox'),
|
|
strict$1('onDomChanged'),
|
|
defaulted$1('onTouchContent', noop),
|
|
defaulted$1('onTapContent', noop),
|
|
defaulted$1('onTouchToolstrip', noop),
|
|
defaulted$1('onScrollToCursor', constant({ unbind: noop })),
|
|
defaulted$1('onScrollToElement', constant({ unbind: noop })),
|
|
defaulted$1('onToEditing', constant({ unbind: noop })),
|
|
defaulted$1('onToReading', constant({ unbind: noop })),
|
|
defaulted$1('onToolbarScrollStart', identity)
|
|
]),
|
|
strict$1('socket'),
|
|
strict$1('toolstrip'),
|
|
strict$1('dropup'),
|
|
strict$1('toolbar'),
|
|
strict$1('container'),
|
|
strict$1('alloy'),
|
|
state$1('win', function (spec) {
|
|
return owner(spec.socket).dom().defaultView;
|
|
}),
|
|
state$1('body', function (spec) {
|
|
return Element.fromDom(spec.socket.dom().ownerDocument.body);
|
|
}),
|
|
defaulted$1('translate', identity),
|
|
defaulted$1('setReadOnly', noop),
|
|
defaulted$1('readOnlyOnInit', constant(true))
|
|
]);
|
|
|
|
var produce = function (raw) {
|
|
var mobile = asRawOrDie('Getting AndroidWebapp schema', MobileSchema, raw);
|
|
set$3(mobile.toolstrip, 'width', '100%');
|
|
var onTap = function () {
|
|
mobile.setReadOnly(mobile.readOnlyOnInit());
|
|
mode.enter();
|
|
};
|
|
var mask = build$1(sketch$9(onTap, mobile.translate));
|
|
mobile.alloy.add(mask);
|
|
var maskApi = {
|
|
show: function () {
|
|
mobile.alloy.add(mask);
|
|
},
|
|
hide: function () {
|
|
mobile.alloy.remove(mask);
|
|
}
|
|
};
|
|
append(mobile.container, mask.element());
|
|
var mode = create$4(mobile, maskApi);
|
|
return {
|
|
setReadOnly: mobile.setReadOnly,
|
|
refreshStructure: noop,
|
|
enter: mode.enter,
|
|
exit: mode.exit,
|
|
destroy: noop
|
|
};
|
|
};
|
|
|
|
var schema$e = constant([
|
|
strict$1('dom'),
|
|
defaulted$1('shell', true),
|
|
field$1('toolbarBehaviours', [Replacing])
|
|
]);
|
|
var enhanceGroups = function () {
|
|
return { behaviours: derive$1([Replacing.config({})]) };
|
|
};
|
|
var parts$2 = constant([optional({
|
|
name: 'groups',
|
|
overrides: enhanceGroups
|
|
})]);
|
|
|
|
var factory$4 = function (detail, components, _spec, _externals) {
|
|
var setGroups = function (toolbar, groups) {
|
|
getGroupContainer(toolbar).fold(function () {
|
|
domGlobals.console.error('Toolbar was defined to not be a shell, but no groups container was specified in components');
|
|
throw new Error('Toolbar was defined to not be a shell, but no groups container was specified in components');
|
|
}, function (container) {
|
|
Replacing.set(container, groups);
|
|
});
|
|
};
|
|
var getGroupContainer = function (component) {
|
|
return detail.shell ? Option.some(component) : getPart(component, detail, 'groups');
|
|
};
|
|
var extra = detail.shell ? {
|
|
behaviours: [Replacing.config({})],
|
|
components: []
|
|
} : {
|
|
behaviours: [],
|
|
components: components
|
|
};
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: extra.components,
|
|
behaviours: augment(detail.toolbarBehaviours, extra.behaviours),
|
|
apis: { setGroups: setGroups },
|
|
domModification: { attributes: { role: 'group' } }
|
|
};
|
|
};
|
|
var Toolbar = composite$1({
|
|
name: 'Toolbar',
|
|
configFields: schema$e(),
|
|
partFields: parts$2(),
|
|
factory: factory$4,
|
|
apis: {
|
|
setGroups: function (apis, toolbar, groups) {
|
|
apis.setGroups(toolbar, groups);
|
|
}
|
|
}
|
|
});
|
|
|
|
var schema$f = constant([
|
|
strict$1('items'),
|
|
markers(['itemSelector']),
|
|
field$1('tgroupBehaviours', [Keying])
|
|
]);
|
|
var parts$3 = constant([group({
|
|
name: 'items',
|
|
unit: 'item'
|
|
})]);
|
|
|
|
var factory$5 = function (detail, components, _spec, _externals) {
|
|
return {
|
|
uid: detail.uid,
|
|
dom: detail.dom,
|
|
components: components,
|
|
behaviours: augment(detail.tgroupBehaviours, [Keying.config({
|
|
mode: 'flow',
|
|
selector: detail.markers.itemSelector
|
|
})]),
|
|
domModification: { attributes: { role: 'toolbar' } }
|
|
};
|
|
};
|
|
var ToolbarGroup = composite$1({
|
|
name: 'ToolbarGroup',
|
|
configFields: schema$f(),
|
|
partFields: parts$3(),
|
|
factory: factory$5
|
|
});
|
|
|
|
var dataHorizontal = 'data-' + resolve('horizontal-scroll');
|
|
var canScrollVertically = function (container) {
|
|
container.dom().scrollTop = 1;
|
|
var result = container.dom().scrollTop !== 0;
|
|
container.dom().scrollTop = 0;
|
|
return result;
|
|
};
|
|
var canScrollHorizontally = function (container) {
|
|
container.dom().scrollLeft = 1;
|
|
var result = container.dom().scrollLeft !== 0;
|
|
container.dom().scrollLeft = 0;
|
|
return result;
|
|
};
|
|
var hasVerticalScroll = function (container) {
|
|
return container.dom().scrollTop > 0 || canScrollVertically(container);
|
|
};
|
|
var hasHorizontalScroll = function (container) {
|
|
return container.dom().scrollLeft > 0 || canScrollHorizontally(container);
|
|
};
|
|
var markAsHorizontal = function (container) {
|
|
set(container, dataHorizontal, 'true');
|
|
};
|
|
var hasScroll = function (container) {
|
|
return get$1(container, dataHorizontal) === 'true' ? hasHorizontalScroll(container) : hasVerticalScroll(container);
|
|
};
|
|
var exclusive = function (scope, selector) {
|
|
return bind$3(scope, 'touchmove', function (event) {
|
|
closest$2(event.target(), selector).filter(hasScroll).fold(function () {
|
|
event.raw().preventDefault();
|
|
}, noop);
|
|
});
|
|
};
|
|
|
|
function ScrollingToolbar () {
|
|
var makeGroup = function (gSpec) {
|
|
var scrollClass = gSpec.scrollable === true ? '${prefix}-toolbar-scrollable-group' : '';
|
|
return {
|
|
dom: dom$1('<div aria-label="' + gSpec.label + '" class="${prefix}-toolbar-group ' + scrollClass + '"></div>'),
|
|
tgroupBehaviours: derive$1([config('adhoc-scrollable-toolbar', gSpec.scrollable === true ? [runOnInit(function (component, _simulatedEvent) {
|
|
set$3(component.element(), 'overflow-x', 'auto');
|
|
markAsHorizontal(component.element());
|
|
register(component.element());
|
|
})] : [])]),
|
|
components: [Container.sketch({ components: [ToolbarGroup.parts().items({})] })],
|
|
markers: { itemSelector: '.' + resolve('toolbar-group-item') },
|
|
items: gSpec.items
|
|
};
|
|
};
|
|
var toolbar = build$1(Toolbar.sketch({
|
|
dom: dom$1('<div class="${prefix}-toolbar"></div>'),
|
|
components: [Toolbar.parts().groups({})],
|
|
toolbarBehaviours: derive$1([
|
|
Toggling.config({
|
|
toggleClass: resolve('context-toolbar'),
|
|
toggleOnExecute: false,
|
|
aria: { mode: 'none' }
|
|
}),
|
|
Keying.config({ mode: 'cyclic' })
|
|
]),
|
|
shell: true
|
|
}));
|
|
var wrapper = build$1(Container.sketch({
|
|
dom: { classes: [resolve('toolstrip')] },
|
|
components: [premade$1(toolbar)],
|
|
containerBehaviours: derive$1([Toggling.config({
|
|
toggleClass: resolve('android-selection-context-toolbar'),
|
|
toggleOnExecute: false
|
|
})])
|
|
}));
|
|
var resetGroups = function () {
|
|
Toolbar.setGroups(toolbar, initGroups.get());
|
|
Toggling.off(toolbar);
|
|
};
|
|
var initGroups = Cell([]);
|
|
var setGroups = function (gs) {
|
|
initGroups.set(gs);
|
|
resetGroups();
|
|
};
|
|
var createGroups = function (gs) {
|
|
return map$1(gs, compose(ToolbarGroup.sketch, makeGroup));
|
|
};
|
|
var refresh = function () {
|
|
};
|
|
var setContextToolbar = function (gs) {
|
|
Toggling.on(toolbar);
|
|
Toolbar.setGroups(toolbar, gs);
|
|
};
|
|
var restoreToolbar = function () {
|
|
if (Toggling.isOn(toolbar)) {
|
|
resetGroups();
|
|
}
|
|
};
|
|
var focus = function () {
|
|
Keying.focusIn(toolbar);
|
|
};
|
|
return {
|
|
wrapper: constant(wrapper),
|
|
toolbar: constant(toolbar),
|
|
createGroups: createGroups,
|
|
setGroups: setGroups,
|
|
setContextToolbar: setContextToolbar,
|
|
restoreToolbar: restoreToolbar,
|
|
refresh: refresh,
|
|
focus: focus
|
|
};
|
|
}
|
|
|
|
var makeEditSwitch = function (webapp) {
|
|
return build$1(Button.sketch({
|
|
dom: dom$1('<div class="${prefix}-mask-edit-icon ${prefix}-icon"></div>'),
|
|
action: function () {
|
|
webapp.run(function (w) {
|
|
w.setReadOnly(false);
|
|
});
|
|
}
|
|
}));
|
|
};
|
|
var makeSocket = function () {
|
|
return build$1(Container.sketch({
|
|
dom: dom$1('<div class="${prefix}-editor-socket"></div>'),
|
|
components: [],
|
|
containerBehaviours: derive$1([Replacing.config({})])
|
|
}));
|
|
};
|
|
var showEdit = function (socket, switchToEdit) {
|
|
Replacing.append(socket, premade$1(switchToEdit));
|
|
};
|
|
var hideEdit = function (socket, switchToEdit) {
|
|
Replacing.remove(socket, switchToEdit);
|
|
};
|
|
var updateMode = function (socket, switchToEdit, readOnly, root) {
|
|
var swap = readOnly === true ? Swapping.toAlpha : Swapping.toOmega;
|
|
swap(root);
|
|
var f = readOnly ? showEdit : hideEdit;
|
|
f(socket, switchToEdit);
|
|
};
|
|
|
|
var getAnimationRoot = function (component, slideConfig) {
|
|
return slideConfig.getAnimationRoot.fold(function () {
|
|
return component.element();
|
|
}, function (get) {
|
|
return get(component);
|
|
});
|
|
};
|
|
|
|
var getDimensionProperty = function (slideConfig) {
|
|
return slideConfig.dimension.property;
|
|
};
|
|
var getDimension = function (slideConfig, elem) {
|
|
return slideConfig.dimension.getDimension(elem);
|
|
};
|
|
var disableTransitions = function (component, slideConfig) {
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
remove$6(root, [
|
|
slideConfig.shrinkingClass,
|
|
slideConfig.growingClass
|
|
]);
|
|
};
|
|
var setShrunk = function (component, slideConfig) {
|
|
remove$4(component.element(), slideConfig.openClass);
|
|
add$2(component.element(), slideConfig.closedClass);
|
|
set$3(component.element(), getDimensionProperty(slideConfig), '0px');
|
|
reflow(component.element());
|
|
};
|
|
var setGrown = function (component, slideConfig) {
|
|
remove$4(component.element(), slideConfig.closedClass);
|
|
add$2(component.element(), slideConfig.openClass);
|
|
remove$5(component.element(), getDimensionProperty(slideConfig));
|
|
};
|
|
var doImmediateShrink = function (component, slideConfig, slideState, _calculatedSize) {
|
|
slideState.setCollapsed();
|
|
set$3(component.element(), getDimensionProperty(slideConfig), getDimension(slideConfig, component.element()));
|
|
reflow(component.element());
|
|
disableTransitions(component, slideConfig);
|
|
setShrunk(component, slideConfig);
|
|
slideConfig.onStartShrink(component);
|
|
slideConfig.onShrunk(component);
|
|
};
|
|
var doStartShrink = function (component, slideConfig, slideState, calculatedSize) {
|
|
var size = calculatedSize.getOrThunk(function () {
|
|
return getDimension(slideConfig, component.element());
|
|
});
|
|
slideState.setCollapsed();
|
|
set$3(component.element(), getDimensionProperty(slideConfig), size);
|
|
reflow(component.element());
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
remove$4(root, slideConfig.growingClass);
|
|
add$2(root, slideConfig.shrinkingClass);
|
|
setShrunk(component, slideConfig);
|
|
slideConfig.onStartShrink(component);
|
|
};
|
|
var doStartSmartShrink = function (component, slideConfig, slideState) {
|
|
var size = getDimension(slideConfig, component.element());
|
|
var shrinker = size === '0px' ? doImmediateShrink : doStartShrink;
|
|
shrinker(component, slideConfig, slideState, Option.some(size));
|
|
};
|
|
var doStartGrow = function (component, slideConfig, slideState) {
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
var wasShrinking = has$2(root, slideConfig.shrinkingClass);
|
|
var beforeSize = getDimension(slideConfig, component.element());
|
|
setGrown(component, slideConfig);
|
|
var fullSize = getDimension(slideConfig, component.element());
|
|
var startPartialGrow = function () {
|
|
set$3(component.element(), getDimensionProperty(slideConfig), beforeSize);
|
|
reflow(component.element());
|
|
};
|
|
var startCompleteGrow = function () {
|
|
setShrunk(component, slideConfig);
|
|
};
|
|
var setStartSize = wasShrinking ? startPartialGrow : startCompleteGrow;
|
|
setStartSize();
|
|
remove$4(root, slideConfig.shrinkingClass);
|
|
add$2(root, slideConfig.growingClass);
|
|
setGrown(component, slideConfig);
|
|
set$3(component.element(), getDimensionProperty(slideConfig), fullSize);
|
|
slideState.setExpanded();
|
|
slideConfig.onStartGrow(component);
|
|
};
|
|
var refresh = function (component, slideConfig, slideState) {
|
|
if (slideState.isExpanded()) {
|
|
remove$5(component.element(), getDimensionProperty(slideConfig));
|
|
var fullSize = getDimension(slideConfig, component.element());
|
|
set$3(component.element(), getDimensionProperty(slideConfig), fullSize);
|
|
}
|
|
};
|
|
var grow = function (component, slideConfig, slideState) {
|
|
if (!slideState.isExpanded()) {
|
|
doStartGrow(component, slideConfig, slideState);
|
|
}
|
|
};
|
|
var shrink = function (component, slideConfig, slideState) {
|
|
if (slideState.isExpanded()) {
|
|
doStartSmartShrink(component, slideConfig, slideState);
|
|
}
|
|
};
|
|
var immediateShrink = function (component, slideConfig, slideState) {
|
|
if (slideState.isExpanded()) {
|
|
doImmediateShrink(component, slideConfig, slideState, Option.none());
|
|
}
|
|
};
|
|
var hasGrown = function (component, slideConfig, slideState) {
|
|
return slideState.isExpanded();
|
|
};
|
|
var hasShrunk = function (component, slideConfig, slideState) {
|
|
return slideState.isCollapsed();
|
|
};
|
|
var isGrowing = function (component, slideConfig, _slideState) {
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
return has$2(root, slideConfig.growingClass) === true;
|
|
};
|
|
var isShrinking = function (component, slideConfig, _slideState) {
|
|
var root = getAnimationRoot(component, slideConfig);
|
|
return has$2(root, slideConfig.shrinkingClass) === true;
|
|
};
|
|
var isTransitioning = function (component, slideConfig, slideState) {
|
|
return isGrowing(component, slideConfig) === true || isShrinking(component, slideConfig) === true;
|
|
};
|
|
var toggleGrow = function (component, slideConfig, slideState) {
|
|
var f = slideState.isExpanded() ? doStartSmartShrink : doStartGrow;
|
|
f(component, slideConfig, slideState);
|
|
};
|
|
|
|
var SlidingApis = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
refresh: refresh,
|
|
grow: grow,
|
|
shrink: shrink,
|
|
immediateShrink: immediateShrink,
|
|
hasGrown: hasGrown,
|
|
hasShrunk: hasShrunk,
|
|
isGrowing: isGrowing,
|
|
isShrinking: isShrinking,
|
|
isTransitioning: isTransitioning,
|
|
toggleGrow: toggleGrow,
|
|
disableTransitions: disableTransitions
|
|
});
|
|
|
|
var exhibit$5 = function (base, slideConfig, _slideState) {
|
|
var expanded = slideConfig.expanded;
|
|
return expanded ? nu$5({
|
|
classes: [slideConfig.openClass],
|
|
styles: {}
|
|
}) : nu$5({
|
|
classes: [slideConfig.closedClass],
|
|
styles: wrap$1(slideConfig.dimension.property, '0px')
|
|
});
|
|
};
|
|
var events$a = function (slideConfig, slideState) {
|
|
return derive([runOnSource(transitionend(), function (component, simulatedEvent) {
|
|
var raw = simulatedEvent.event().raw();
|
|
if (raw.propertyName === slideConfig.dimension.property) {
|
|
disableTransitions(component, slideConfig);
|
|
if (slideState.isExpanded()) {
|
|
remove$5(component.element(), slideConfig.dimension.property);
|
|
}
|
|
var notify = slideState.isExpanded() ? slideConfig.onGrown : slideConfig.onShrunk;
|
|
notify(component);
|
|
}
|
|
})]);
|
|
};
|
|
|
|
var ActiveSliding = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
exhibit: exhibit$5,
|
|
events: events$a
|
|
});
|
|
|
|
var SlidingSchema = [
|
|
strict$1('closedClass'),
|
|
strict$1('openClass'),
|
|
strict$1('shrinkingClass'),
|
|
strict$1('growingClass'),
|
|
option('getAnimationRoot'),
|
|
onHandler('onShrunk'),
|
|
onHandler('onStartShrink'),
|
|
onHandler('onGrown'),
|
|
onHandler('onStartGrow'),
|
|
defaulted$1('expanded', false),
|
|
strictOf('dimension', choose$1('property', {
|
|
width: [
|
|
output('property', 'width'),
|
|
output('getDimension', function (elem) {
|
|
return get$7(elem) + 'px';
|
|
})
|
|
],
|
|
height: [
|
|
output('property', 'height'),
|
|
output('getDimension', function (elem) {
|
|
return get$5(elem) + 'px';
|
|
})
|
|
]
|
|
}))
|
|
];
|
|
|
|
var init$4 = function (spec) {
|
|
var state = Cell(spec.expanded);
|
|
var readState = function () {
|
|
return 'expanded: ' + state.get();
|
|
};
|
|
return nu$6({
|
|
isExpanded: function () {
|
|
return state.get() === true;
|
|
},
|
|
isCollapsed: function () {
|
|
return state.get() === false;
|
|
},
|
|
setCollapsed: curry(state.set, false),
|
|
setExpanded: curry(state.set, true),
|
|
readState: readState
|
|
});
|
|
};
|
|
|
|
var SlidingState = /*#__PURE__*/Object.freeze({
|
|
__proto__: null,
|
|
init: init$4
|
|
});
|
|
|
|
var Sliding = create$1({
|
|
fields: SlidingSchema,
|
|
name: 'sliding',
|
|
active: ActiveSliding,
|
|
apis: SlidingApis,
|
|
state: SlidingState
|
|
});
|
|
|
|
var build$2 = function (refresh, scrollIntoView) {
|
|
var dropup = build$1(Container.sketch({
|
|
dom: {
|
|
tag: 'div',
|
|
classes: [resolve('dropup')]
|
|
},
|
|
components: [],
|
|
containerBehaviours: derive$1([
|
|
Replacing.config({}),
|
|
Sliding.config({
|
|
closedClass: resolve('dropup-closed'),
|
|
openClass: resolve('dropup-open'),
|
|
shrinkingClass: resolve('dropup-shrinking'),
|
|
growingClass: resolve('dropup-growing'),
|
|
dimension: { property: 'height' },
|
|
onShrunk: function (component) {
|
|
refresh();
|
|
scrollIntoView();
|
|
Replacing.set(component, []);
|
|
},
|
|
onGrown: function (_component) {
|
|
refresh();
|
|
scrollIntoView();
|
|
}
|
|
}),
|
|
orientation(function (_component, _data) {
|
|
disappear(noop);
|
|
})
|
|
])
|
|
}));
|
|
var appear = function (menu, update, component) {
|
|
if (Sliding.hasShrunk(dropup) === true && Sliding.isTransitioning(dropup) === false) {
|
|
domGlobals.window.requestAnimationFrame(function () {
|
|
update(component);
|
|
Replacing.set(dropup, [menu()]);
|
|
Sliding.grow(dropup);
|
|
});
|
|
}
|
|
};
|
|
var disappear = function (onReadyToShrink) {
|
|
domGlobals.window.requestAnimationFrame(function () {
|
|
onReadyToShrink();
|
|
Sliding.shrink(dropup);
|
|
});
|
|
};
|
|
return {
|
|
appear: appear,
|
|
disappear: disappear,
|
|
component: constant(dropup),
|
|
element: dropup.element
|
|
};
|
|
};
|
|
|
|
var closest$3 = function (scope, selector, isRoot) {
|
|
return closest$2(scope, selector, isRoot).isSome();
|
|
};
|
|
|
|
var isDangerous = function (event) {
|
|
var keyEv = event.raw();
|
|
return keyEv.which === BACKSPACE()[0] && !contains([
|
|
'input',
|
|
'textarea'
|
|
], name(event.target())) && !closest$3(event.target(), '[contenteditable="true"]');
|
|
};
|
|
var isFirefox = function () {
|
|
return detect$3().browser.isFirefox();
|
|
};
|
|
var settingsSchema = objOfOnly([
|
|
strictFunction('triggerEvent'),
|
|
defaulted$1('stopBackspace', true)
|
|
]);
|
|
var bindFocus = function (container, handler) {
|
|
if (isFirefox()) {
|
|
return capture$1(container, 'focus', handler);
|
|
} else {
|
|
return bind$3(container, 'focusin', handler);
|
|
}
|
|
};
|
|
var bindBlur = function (container, handler) {
|
|
if (isFirefox()) {
|
|
return capture$1(container, 'blur', handler);
|
|
} else {
|
|
return bind$3(container, 'focusout', handler);
|
|
}
|
|
};
|
|
var setup$2 = function (container, rawSettings) {
|
|
var settings = asRawOrDie('Getting GUI events settings', settingsSchema, rawSettings);
|
|
var pointerEvents = [
|
|
'touchstart',
|
|
'touchmove',
|
|
'touchend',
|
|
'touchcancel',
|
|
'gesturestart',
|
|
'mousedown',
|
|
'mouseup',
|
|
'mouseover',
|
|
'mousemove',
|
|
'mouseout',
|
|
'click'
|
|
];
|
|
var tapEvent = monitor(settings);
|
|
var simpleEvents = map$1(pointerEvents.concat([
|
|
'selectstart',
|
|
'input',
|
|
'contextmenu',
|
|
'change',
|
|
'transitionend',
|
|
'drag',
|
|
'dragstart',
|
|
'dragend',
|
|
'dragenter',
|
|
'dragleave',
|
|
'dragover',
|
|
'drop',
|
|
'keyup'
|
|
]), function (type) {
|
|
return bind$3(container, type, function (event) {
|
|
tapEvent.fireIfReady(event, type).each(function (tapStopped) {
|
|
if (tapStopped) {
|
|
event.kill();
|
|
}
|
|
});
|
|
var stopped = settings.triggerEvent(type, event);
|
|
if (stopped) {
|
|
event.kill();
|
|
}
|
|
});
|
|
});
|
|
var pasteTimeout = Cell(Option.none());
|
|
var onPaste = bind$3(container, 'paste', function (event) {
|
|
tapEvent.fireIfReady(event, 'paste').each(function (tapStopped) {
|
|
if (tapStopped) {
|
|
event.kill();
|
|
}
|
|
});
|
|
var stopped = settings.triggerEvent('paste', event);
|
|
if (stopped) {
|
|
event.kill();
|
|
}
|
|
pasteTimeout.set(Option.some(domGlobals.setTimeout(function () {
|
|
settings.triggerEvent(postPaste(), event);
|
|
}, 0)));
|
|
});
|
|
var onKeydown = bind$3(container, 'keydown', function (event) {
|
|
var stopped = settings.triggerEvent('keydown', event);
|
|
if (stopped) {
|
|
event.kill();
|
|
} else if (settings.stopBackspace === true && isDangerous(event)) {
|
|
event.prevent();
|
|
}
|
|
});
|
|
var onFocusIn = bindFocus(container, function (event) {
|
|
var stopped = settings.triggerEvent('focusin', event);
|
|
if (stopped) {
|
|
event.kill();
|
|
}
|
|
});
|
|
var focusoutTimeout = Cell(Option.none());
|
|
var onFocusOut = bindBlur(container, function (event) {
|
|
var stopped = settings.triggerEvent('focusout', event);
|
|
if (stopped) {
|
|
event.kill();
|
|
}
|
|
focusoutTimeout.set(Option.some(domGlobals.setTimeout(function () {
|
|
settings.triggerEvent(postBlur(), event);
|
|
}, 0)));
|
|
});
|
|
var unbind = function () {
|
|
each$1(simpleEvents, function (e) {
|
|
e.unbind();
|
|
});
|
|
onKeydown.unbind();
|
|
onFocusIn.unbind();
|
|
onFocusOut.unbind();
|
|
onPaste.unbind();
|
|
pasteTimeout.get().each(domGlobals.clearTimeout);
|
|
focusoutTimeout.get().each(domGlobals.clearTimeout);
|
|
};
|
|
return { unbind: unbind };
|
|
};
|
|
|
|
var derive$2 = function (rawEvent, rawTarget) {
|
|
var source = get(rawEvent, 'target').map(function (getTarget) {
|
|
return getTarget();
|
|
}).getOr(rawTarget);
|
|
return Cell(source);
|
|
};
|
|
|
|
var fromSource = function (event, source) {
|
|
var stopper = Cell(false);
|
|
var cutter = Cell(false);
|
|
var stop = function () {
|
|
stopper.set(true);
|
|
};
|
|
var cut = function () {
|
|
cutter.set(true);
|
|
};
|
|
return {
|
|
stop: stop,
|
|
cut: cut,
|
|
isStopped: stopper.get,
|
|
isCut: cutter.get,
|
|
event: constant(event),
|
|
setSource: source.set,
|
|
getSource: source.get
|
|
};
|
|
};
|
|
var fromExternal = function (event) {
|
|
var stopper = Cell(false);
|
|
var stop = function () {
|
|
stopper.set(true);
|
|
};
|
|
return {
|
|
stop: stop,
|
|
cut: noop,
|
|
isStopped: stopper.get,
|
|
isCut: constant(false),
|
|
event: constant(event),
|
|
setSource: die('Cannot set source of a broadcasted event'),
|
|
getSource: die('Cannot get source of a broadcasted event')
|
|
};
|
|
};
|
|
|
|
var adt$7 = Adt.generate([
|
|
{ stopped: [] },
|
|
{ resume: ['element'] },
|
|
{ complete: [] }
|
|
]);
|
|
var doTriggerHandler = function (lookup, eventType, rawEvent, target, source, logger) {
|
|
var handler = lookup(eventType, target);
|
|
var simulatedEvent = fromSource(rawEvent, source);
|
|
return handler.fold(function () {
|
|
logger.logEventNoHandlers(eventType, target);
|
|
return adt$7.complete();
|
|
}, function (handlerInfo) {
|
|
var descHandler = handlerInfo.descHandler;
|
|
var eventHandler = getCurried(descHandler);
|
|
eventHandler(simulatedEvent);
|
|
if (simulatedEvent.isStopped()) {
|
|
logger.logEventStopped(eventType, handlerInfo.element, descHandler.purpose());
|
|
return adt$7.stopped();
|
|
} else if (simulatedEvent.isCut()) {
|
|
logger.logEventCut(eventType, handlerInfo.element, descHandler.purpose());
|
|
return adt$7.complete();
|
|
} else {
|
|
return parent(handlerInfo.element).fold(function () {
|
|
logger.logNoParent(eventType, handlerInfo.element, descHandler.purpose());
|
|
return adt$7.complete();
|
|
}, function (parent) {
|
|
logger.logEventResponse(eventType, handlerInfo.element, descHandler.purpose());
|
|
return adt$7.resume(parent);
|
|
});
|
|
}
|
|
});
|
|
};
|
|
var doTriggerOnUntilStopped = function (lookup, eventType, rawEvent, rawTarget, source, logger) {
|
|
return doTriggerHandler(lookup, eventType, rawEvent, rawTarget, source, logger).fold(function () {
|
|
return true;
|
|
}, function (parent) {
|
|
return doTriggerOnUntilStopped(lookup, eventType, rawEvent, parent, source, logger);
|
|
}, function () {
|
|
return false;
|
|
});
|
|
};
|
|
var triggerHandler = function (lookup, eventType, rawEvent, target, logger) {
|
|
var source = derive$2(rawEvent, target);
|
|
return doTriggerHandler(lookup, eventType, rawEvent, target, source, logger);
|
|
};
|
|
var broadcast = function (listeners, rawEvent, _logger) {
|
|
var simulatedEvent = fromExternal(rawEvent);
|
|
each$1(listeners, function (listener) {
|
|
var descHandler = listener.descHandler();
|
|
var handler = getCurried(descHandler);
|
|
handler(simulatedEvent);
|
|
});
|
|
return simulatedEvent.isStopped();
|
|
};
|
|
var triggerUntilStopped = function (lookup, eventType, rawEvent, logger) {
|
|
var rawTarget = rawEvent.target();
|
|
return triggerOnUntilStopped(lookup, eventType, rawEvent, rawTarget, logger);
|
|
};
|
|
var triggerOnUntilStopped = function (lookup, eventType, rawEvent, rawTarget, logger) {
|
|
var source = derive$2(rawEvent, rawTarget);
|
|
return doTriggerOnUntilStopped(lookup, eventType, rawEvent, rawTarget, source, logger);
|
|
};
|
|
|
|
var eventHandler = function (element, descHandler) {
|
|
return {
|
|
element: element,
|
|
descHandler: descHandler
|
|
};
|
|
};
|
|
var broadcastHandler = function (id, handler) {
|
|
return {
|
|
id: constant(id),
|
|
descHandler: constant(handler)
|
|
};
|
|
};
|
|
function EventRegistry () {
|
|
var registry = {};
|
|
var registerId = function (extraArgs, id, events) {
|
|
each(events, function (v, k) {
|
|
var handlers = registry[k] !== undefined ? registry[k] : {};
|
|
handlers[id] = curryArgs(v, extraArgs);
|
|
registry[k] = handlers;
|
|
});
|
|
};
|
|
var findHandler = function (handlers, elem) {
|
|
return read$2(elem).fold(function () {
|
|
return Option.none();
|
|
}, function (id) {
|
|
return handlers.bind(function (h) {
|
|
return get(h, id);
|
|
}).map(function (descHandler) {
|
|
return eventHandler(elem, descHandler);
|
|
});
|
|
});
|
|
};
|
|
var filterByType = function (type) {
|
|
return get(registry, type).map(function (handlers) {
|
|
return mapToArray(handlers, function (f, id) {
|
|
return broadcastHandler(id, f);
|
|
});
|
|
}).getOr([]);
|
|
};
|
|
var find = function (isAboveRoot, type, target) {
|
|
var handlers = get(registry, type);
|
|
return closest(target, function (elem) {
|
|
return findHandler(handlers, elem);
|
|
}, isAboveRoot);
|
|
};
|
|
var unregisterId = function (id) {
|
|
each(registry, function (handlersById, _eventName) {
|
|
if (handlersById.hasOwnProperty(id)) {
|
|
delete handlersById[id];
|
|
}
|
|
});
|
|
};
|
|
return {
|
|
registerId: registerId,
|
|
unregisterId: unregisterId,
|
|
filterByType: filterByType,
|
|
find: find
|
|
};
|
|
}
|
|
|
|
function Registry () {
|
|
var events = EventRegistry();
|
|
var components = {};
|
|
var readOrTag = function (component) {
|
|
var elem = component.element();
|
|
return read$2(elem).fold(function () {
|
|
return write('uid-', component.element());
|
|
}, function (uid) {
|
|
return uid;
|
|
});
|
|
};
|
|
var failOnDuplicate = function (component, tagId) {
|
|
var conflict = components[tagId];
|
|
if (conflict === component) {
|
|
unregister(component);
|
|
} else {
|
|
throw new Error('The tagId "' + tagId + '" is already used by: ' + element(conflict.element()) + '\nCannot use it for: ' + element(component.element()) + '\n' + 'The conflicting element is' + (inBody(conflict.element()) ? ' ' : ' not ') + 'already in the DOM');
|
|
}
|
|
};
|
|
var register = function (component) {
|
|
var tagId = readOrTag(component);
|
|
if (hasNonNullableKey(components, tagId)) {
|
|
failOnDuplicate(component, tagId);
|
|
}
|
|
var extraArgs = [component];
|
|
events.registerId(extraArgs, tagId, component.events());
|
|
components[tagId] = component;
|
|
};
|
|
var unregister = function (component) {
|
|
read$2(component.element()).each(function (tagId) {
|
|
delete components[tagId];
|
|
events.unregisterId(tagId);
|
|
});
|
|
};
|
|
var filter = function (type) {
|
|
return events.filterByType(type);
|
|
};
|
|
var find = function (isAboveRoot, type, target) {
|
|
return events.find(isAboveRoot, type, target);
|
|
};
|
|
var getById = function (id) {
|
|
return get(components, id);
|
|
};
|
|
return {
|
|
find: find,
|
|
filter: filter,
|
|
register: register,
|
|
unregister: unregister,
|
|
getById: getById
|
|
};
|
|
}
|
|
|
|
var takeover = function (root) {
|
|
var isAboveRoot = function (el) {
|
|
return parent(root.element()).fold(function () {
|
|
return true;
|
|
}, function (parent) {
|
|
return eq(el, parent);
|
|
});
|
|
};
|
|
var registry = Registry();
|
|
var lookup = function (eventName, target) {
|
|
return registry.find(isAboveRoot, eventName, target);
|
|
};
|
|
var domEvents = setup$2(root.element(), {
|
|
triggerEvent: function (eventName, event) {
|
|
return monitorEvent(eventName, event.target(), function (logger) {
|
|
return triggerUntilStopped(lookup, eventName, event, logger);
|
|
});
|
|
}
|
|
});
|
|
var systemApi = {
|
|
debugInfo: constant('real'),
|
|
triggerEvent: function (eventName, target, data) {
|
|
monitorEvent(eventName, target, function (logger) {
|
|
return triggerOnUntilStopped(lookup, eventName, data, target, logger);
|
|
});
|
|
},
|
|
triggerFocus: function (target, originator) {
|
|
read$2(target).fold(function () {
|
|
focus$1(target);
|
|
}, function (_alloyId) {
|
|
monitorEvent(focus(), target, function (logger) {
|
|
triggerHandler(lookup, focus(), {
|
|
originator: constant(originator),
|
|
kill: noop,
|
|
prevent: noop,
|
|
target: constant(target)
|
|
}, target, logger);
|
|
return false;
|
|
});
|
|
});
|
|
},
|
|
triggerEscape: function (comp, simulatedEvent) {
|
|
systemApi.triggerEvent('keydown', comp.element(), simulatedEvent.event());
|
|
},
|
|
getByUid: function (uid) {
|
|
return getByUid(uid);
|
|
},
|
|
getByDom: function (elem) {
|
|
return getByDom(elem);
|
|
},
|
|
build: build$1,
|
|
addToGui: function (c) {
|
|
add(c);
|
|
},
|
|
removeFromGui: function (c) {
|
|
remove$1(c);
|
|
},
|
|
addToWorld: function (c) {
|
|
addToWorld(c);
|
|
},
|
|
removeFromWorld: function (c) {
|
|
removeFromWorld(c);
|
|
},
|
|
broadcast: function (message) {
|
|
broadcast$1(message);
|
|
},
|
|
broadcastOn: function (channels, message) {
|
|
broadcastOn(channels, message);
|
|
},
|
|
broadcastEvent: function (eventName, event) {
|
|
broadcastEvent(eventName, event);
|
|
},
|
|
isConnected: constant(true)
|
|
};
|
|
var addToWorld = function (component) {
|
|
component.connect(systemApi);
|
|
if (!isText(component.element())) {
|
|
registry.register(component);
|
|
each$1(component.components(), addToWorld);
|
|
systemApi.triggerEvent(systemInit(), component.element(), { target: constant(component.element()) });
|
|
}
|
|
};
|
|
var removeFromWorld = function (component) {
|
|
if (!isText(component.element())) {
|
|
each$1(component.components(), removeFromWorld);
|
|
registry.unregister(component);
|
|
}
|
|
component.disconnect();
|
|
};
|
|
var add = function (component) {
|
|
attach$1(root, component);
|
|
};
|
|
var remove$1 = function (component) {
|
|
detach(component);
|
|
};
|
|
var destroy = function () {
|
|
domEvents.unbind();
|
|
remove(root.element());
|
|
};
|
|
var broadcastData = function (data) {
|
|
var receivers = registry.filter(receive());
|
|
each$1(receivers, function (receiver) {
|
|
var descHandler = receiver.descHandler();
|
|
var handler = getCurried(descHandler);
|
|
handler(data);
|
|
});
|
|
};
|
|
var broadcast$1 = function (message) {
|
|
broadcastData({
|
|
universal: constant(true),
|
|
data: constant(message)
|
|
});
|
|
};
|
|
var broadcastOn = function (channels, message) {
|
|
broadcastData({
|
|
universal: constant(false),
|
|
channels: constant(channels),
|
|
data: constant(message)
|
|
});
|
|
};
|
|
var broadcastEvent = function (eventName, event) {
|
|
var listeners = registry.filter(eventName);
|
|
return broadcast(listeners, event);
|
|
};
|
|
var getByUid = function (uid) {
|
|
return registry.getById(uid).fold(function () {
|
|
return Result.error(new Error('Could not find component with uid: "' + uid + '" in system.'));
|
|
}, Result.value);
|
|
};
|
|
var getByDom = function (elem) {
|
|
var uid = read$2(elem).getOr('not found');
|
|
return getByUid(uid);
|
|
};
|
|
addToWorld(root);
|
|
return {
|
|
root: constant(root),
|
|
element: root.element,
|
|
destroy: destroy,
|
|
add: add,
|
|
remove: remove$1,
|
|
getByUid: getByUid,
|
|
getByDom: getByDom,
|
|
addToWorld: addToWorld,
|
|
removeFromWorld: removeFromWorld,
|
|
broadcast: broadcast$1,
|
|
broadcastOn: broadcastOn,
|
|
broadcastEvent: broadcastEvent
|
|
};
|
|
};
|
|
|
|
var READ_ONLY_MODE_CLASS = resolve('readonly-mode');
|
|
var EDIT_MODE_CLASS = resolve('edit-mode');
|
|
function OuterContainer (spec) {
|
|
var root = build$1(Container.sketch({
|
|
dom: { classes: [resolve('outer-container')].concat(spec.classes) },
|
|
containerBehaviours: derive$1([Swapping.config({
|
|
alpha: READ_ONLY_MODE_CLASS,
|
|
omega: EDIT_MODE_CLASS
|
|
})])
|
|
}));
|
|
return takeover(root);
|
|
}
|
|
|
|
function AndroidRealm (scrollIntoView) {
|
|
var alloy = OuterContainer({ classes: [resolve('android-container')] });
|
|
var toolbar = ScrollingToolbar();
|
|
var webapp = api$2();
|
|
var switchToEdit = makeEditSwitch(webapp);
|
|
var socket = makeSocket();
|
|
var dropup = build$2(noop, scrollIntoView);
|
|
alloy.add(toolbar.wrapper());
|
|
alloy.add(socket);
|
|
alloy.add(dropup.component());
|
|
var setToolbarGroups = function (rawGroups) {
|
|
var groups = toolbar.createGroups(rawGroups);
|
|
toolbar.setGroups(groups);
|
|
};
|
|
var setContextToolbar = function (rawGroups) {
|
|
var groups = toolbar.createGroups(rawGroups);
|
|
toolbar.setContextToolbar(groups);
|
|
};
|
|
var focusToolbar = function () {
|
|
toolbar.focus();
|
|
};
|
|
var restoreToolbar = function () {
|
|
toolbar.restoreToolbar();
|
|
};
|
|
var init = function (spec) {
|
|
webapp.set(produce(spec));
|
|
};
|
|
var exit = function () {
|
|
webapp.run(function (w) {
|
|
w.exit();
|
|
Replacing.remove(socket, switchToEdit);
|
|
});
|
|
};
|
|
var updateMode$1 = function (readOnly) {
|
|
updateMode(socket, switchToEdit, readOnly, alloy.root());
|
|
};
|
|
return {
|
|
system: constant(alloy),
|
|
element: alloy.element,
|
|
init: init,
|
|
exit: exit,
|
|
setToolbarGroups: setToolbarGroups,
|
|
setContextToolbar: setContextToolbar,
|
|
focusToolbar: focusToolbar,
|
|
restoreToolbar: restoreToolbar,
|
|
updateMode: updateMode$1,
|
|
socket: constant(socket),
|
|
dropup: constant(dropup)
|
|
};
|
|
}
|
|
|
|
var input$1 = function (parent, operation) {
|
|
var input = Element.fromTag('input');
|
|
setAll$1(input, {
|
|
opacity: '0',
|
|
position: 'absolute',
|
|
top: '-1000px',
|
|
left: '-1000px'
|
|
});
|
|
append(parent, input);
|
|
focus$1(input);
|
|
operation(input);
|
|
remove(input);
|
|
};
|
|
|
|
var refresh$1 = function (winScope) {
|
|
var sel = winScope.getSelection();
|
|
if (sel.rangeCount > 0) {
|
|
var br = sel.getRangeAt(0);
|
|
var r = winScope.document.createRange();
|
|
r.setStart(br.startContainer, br.startOffset);
|
|
r.setEnd(br.endContainer, br.endOffset);
|
|
sel.removeAllRanges();
|
|
sel.addRange(r);
|
|
}
|
|
};
|
|
|
|
var resume$1 = function (cWin, frame) {
|
|
active().each(function (active) {
|
|
if (!eq(active, frame)) {
|
|
blur(active);
|
|
}
|
|
});
|
|
cWin.focus();
|
|
focus$1(Element.fromDom(cWin.document.body));
|
|
refresh$1(cWin);
|
|
};
|
|
|
|
var stubborn = function (outerBody, cWin, page, frame) {
|
|
var toEditing = function () {
|
|
resume$1(cWin, frame);
|
|
};
|
|
var toReading = function () {
|
|
input$1(outerBody, blur);
|
|
};
|
|
var captureInput = bind$3(page, 'keydown', function (evt) {
|
|
if (!contains([
|
|
'input',
|
|
'textarea'
|
|
], name(evt.target()))) {
|
|
toEditing();
|
|
}
|
|
});
|
|
var onToolbarTouch = function () {
|
|
};
|
|
var destroy = function () {
|
|
captureInput.unbind();
|
|
};
|
|
return {
|
|
toReading: toReading,
|
|
toEditing: toEditing,
|
|
onToolbarTouch: onToolbarTouch,
|
|
destroy: destroy
|
|
};
|
|
};
|
|
|
|
var initEvents$1 = function (editorApi, iosApi, toolstrip, socket, _dropup) {
|
|
var saveSelectionFirst = function () {
|
|
iosApi.run(function (api) {
|
|
api.highlightSelection();
|
|
});
|
|
};
|
|
var refreshIosSelection = function () {
|
|
iosApi.run(function (api) {
|
|
api.refreshSelection();
|
|
});
|
|
};
|
|
var scrollToY = function (yTop, height) {
|
|
var y = yTop - socket.dom().scrollTop;
|
|
iosApi.run(function (api) {
|
|
api.scrollIntoView(y, y + height);
|
|
});
|
|
};
|
|
var scrollToElement = function (_target) {
|
|
scrollToY(iosApi, socket);
|
|
};
|
|
var scrollToCursor = function () {
|
|
editorApi.getCursorBox().each(function (box) {
|
|
scrollToY(box.top(), box.height());
|
|
});
|
|
};
|
|
var clearSelection = function () {
|
|
iosApi.run(function (api) {
|
|
api.clearSelection();
|
|
});
|
|
};
|
|
var clearAndRefresh = function () {
|
|
clearSelection();
|
|
refreshThrottle.throttle();
|
|
};
|
|
var refreshView = function () {
|
|
scrollToCursor();
|
|
iosApi.run(function (api) {
|
|
api.syncHeight();
|
|
});
|
|
};
|
|
var reposition = function () {
|
|
var toolbarHeight = get$5(toolstrip);
|
|
iosApi.run(function (api) {
|
|
api.setViewportOffset(toolbarHeight);
|
|
});
|
|
refreshIosSelection();
|
|
refreshView();
|
|
};
|
|
var toEditing = function () {
|
|
iosApi.run(function (api) {
|
|
api.toEditing();
|
|
});
|
|
};
|
|
var toReading = function () {
|
|
iosApi.run(function (api) {
|
|
api.toReading();
|
|
});
|
|
};
|
|
var onToolbarTouch = function (event) {
|
|
iosApi.run(function (api) {
|
|
api.onToolbarTouch(event);
|
|
});
|
|
};
|
|
var tapping = monitor$1(editorApi);
|
|
var refreshThrottle = last(refreshView, 300);
|
|
var listeners = [
|
|
editorApi.onKeyup(clearAndRefresh),
|
|
editorApi.onNodeChanged(refreshIosSelection),
|
|
editorApi.onDomChanged(refreshThrottle.throttle),
|
|
editorApi.onDomChanged(refreshIosSelection),
|
|
editorApi.onScrollToCursor(function (tinyEvent) {
|
|
tinyEvent.preventDefault();
|
|
refreshThrottle.throttle();
|
|
}),
|
|
editorApi.onScrollToElement(function (event) {
|
|
scrollToElement(event.element());
|
|
}),
|
|
editorApi.onToEditing(toEditing),
|
|
editorApi.onToReading(toReading),
|
|
bind$3(editorApi.doc(), 'touchend', function (touchEvent) {
|
|
if (eq(editorApi.html(), touchEvent.target()) || eq(editorApi.body(), touchEvent.target())) ;
|
|
}),
|
|
bind$3(toolstrip, 'transitionend', function (transitionEvent) {
|
|
if (transitionEvent.raw().propertyName === 'height') {
|
|
reposition();
|
|
}
|
|
}),
|
|
capture$1(toolstrip, 'touchstart', function (touchEvent) {
|
|
saveSelectionFirst();
|
|
onToolbarTouch(touchEvent);
|
|
editorApi.onTouchToolstrip();
|
|
}),
|
|
bind$3(editorApi.body(), 'touchstart', function (evt) {
|
|
clearSelection();
|
|
editorApi.onTouchContent();
|
|
tapping.fireTouchstart(evt);
|
|
}),
|
|
tapping.onTouchmove(),
|
|
tapping.onTouchend(),
|
|
bind$3(editorApi.body(), 'click', function (event) {
|
|
event.kill();
|
|
}),
|
|
bind$3(toolstrip, 'touchmove', function () {
|
|
editorApi.onToolbarScrollStart();
|
|
})
|
|
];
|
|
var destroy = function () {
|
|
each$1(listeners, function (l) {
|
|
l.unbind();
|
|
});
|
|
};
|
|
return { destroy: destroy };
|
|
};
|
|
|
|
function FakeSelection (win, frame) {
|
|
var doc = win.document;
|
|
var container = Element.fromTag('div');
|
|
add$2(container, resolve('unfocused-selections'));
|
|
append(Element.fromDom(doc.documentElement), container);
|
|
var onTouch = bind$3(container, 'touchstart', function (event) {
|
|
event.prevent();
|
|
resume$1(win, frame);
|
|
clear();
|
|
});
|
|
var make = function (rectangle) {
|
|
var span = Element.fromTag('span');
|
|
add$3(span, [
|
|
resolve('layer-editor'),
|
|
resolve('unfocused-selection')
|
|
]);
|
|
setAll$1(span, {
|
|
left: rectangle.left() + 'px',
|
|
top: rectangle.top() + 'px',
|
|
width: rectangle.width() + 'px',
|
|
height: rectangle.height() + 'px'
|
|
});
|
|
return span;
|
|
};
|
|
var update = function () {
|
|
clear();
|
|
var rectangles = getRectangles(win);
|
|
var spans = map$1(rectangles, make);
|
|
append$1(container, spans);
|
|
};
|
|
var clear = function () {
|
|
empty(container);
|
|
};
|
|
var destroy = function () {
|
|
onTouch.unbind();
|
|
remove(container);
|
|
};
|
|
var isActive = function () {
|
|
return children(container).length > 0;
|
|
};
|
|
return {
|
|
update: update,
|
|
isActive: isActive,
|
|
destroy: destroy,
|
|
clear: clear
|
|
};
|
|
}
|
|
|
|
var exports$1 = {}, module = { exports: exports$1 };
|
|
(function (define, exports, module, require) {
|
|
(function (f) {
|
|
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
module.exports = f();
|
|
} else if (typeof define === 'function' && define.amd) {
|
|
define([], f);
|
|
} else {
|
|
var g;
|
|
if (typeof window !== 'undefined') {
|
|
g = window;
|
|
} else if (typeof global !== 'undefined') {
|
|
g = global;
|
|
} else if (typeof self !== 'undefined') {
|
|
g = self;
|
|
} else {
|
|
g = this;
|
|
}
|
|
g.EphoxContactWrapper = f();
|
|
}
|
|
}(function () {
|
|
return function () {
|
|
function r(e, n, t) {
|
|
function o(i, f) {
|
|
if (!n[i]) {
|
|
if (!e[i]) {
|
|
var c = 'function' == typeof require && require;
|
|
if (!f && c)
|
|
return c(i, !0);
|
|
if (u)
|
|
return u(i, !0);
|
|
var a = new Error('Cannot find module \'' + i + '\'');
|
|
throw a.code = 'MODULE_NOT_FOUND', a;
|
|
}
|
|
var p = n[i] = { exports: {} };
|
|
e[i][0].call(p.exports, function (r) {
|
|
var n = e[i][1][r];
|
|
return o(n || r);
|
|
}, p, p.exports, r, e, n, t);
|
|
}
|
|
return n[i].exports;
|
|
}
|
|
for (var u = 'function' == typeof require && require, i = 0; i < t.length; i++)
|
|
o(t[i]);
|
|
return o;
|
|
}
|
|
return r;
|
|
}()({
|
|
1: [
|
|
function (require, module, exports) {
|
|
var process = module.exports = {};
|
|
var cachedSetTimeout;
|
|
var cachedClearTimeout;
|
|
function defaultSetTimout() {
|
|
throw new Error('setTimeout has not been defined');
|
|
}
|
|
function defaultClearTimeout() {
|
|
throw new Error('clearTimeout has not been defined');
|
|
}
|
|
(function () {
|
|
try {
|
|
if (typeof setTimeout === 'function') {
|
|
cachedSetTimeout = setTimeout;
|
|
} else {
|
|
cachedSetTimeout = defaultSetTimout;
|
|
}
|
|
} catch (e) {
|
|
cachedSetTimeout = defaultSetTimout;
|
|
}
|
|
try {
|
|
if (typeof clearTimeout === 'function') {
|
|
cachedClearTimeout = clearTimeout;
|
|
} else {
|
|
cachedClearTimeout = defaultClearTimeout;
|
|
}
|
|
} catch (e) {
|
|
cachedClearTimeout = defaultClearTimeout;
|
|
}
|
|
}());
|
|
function runTimeout(fun) {
|
|
if (cachedSetTimeout === setTimeout) {
|
|
return setTimeout(fun, 0);
|
|
}
|
|
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
|
cachedSetTimeout = setTimeout;
|
|
return setTimeout(fun, 0);
|
|
}
|
|
try {
|
|
return cachedSetTimeout(fun, 0);
|
|
} catch (e) {
|
|
try {
|
|
return cachedSetTimeout.call(null, fun, 0);
|
|
} catch (e) {
|
|
return cachedSetTimeout.call(this, fun, 0);
|
|
}
|
|
}
|
|
}
|
|
function runClearTimeout(marker) {
|
|
if (cachedClearTimeout === clearTimeout) {
|
|
return clearTimeout(marker);
|
|
}
|
|
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
|
cachedClearTimeout = clearTimeout;
|
|
return clearTimeout(marker);
|
|
}
|
|
try {
|
|
return cachedClearTimeout(marker);
|
|
} catch (e) {
|
|
try {
|
|
return cachedClearTimeout.call(null, marker);
|
|
} catch (e) {
|
|
return cachedClearTimeout.call(this, marker);
|
|
}
|
|
}
|
|
}
|
|
var queue = [];
|
|
var draining = false;
|
|
var currentQueue;
|
|
var queueIndex = -1;
|
|
function cleanUpNextTick() {
|
|
if (!draining || !currentQueue) {
|
|
return;
|
|
}
|
|
draining = false;
|
|
if (currentQueue.length) {
|
|
queue = currentQueue.concat(queue);
|
|
} else {
|
|
queueIndex = -1;
|
|
}
|
|
if (queue.length) {
|
|
drainQueue();
|
|
}
|
|
}
|
|
function drainQueue() {
|
|
if (draining) {
|
|
return;
|
|
}
|
|
var timeout = runTimeout(cleanUpNextTick);
|
|
draining = true;
|
|
var len = queue.length;
|
|
while (len) {
|
|
currentQueue = queue;
|
|
queue = [];
|
|
while (++queueIndex < len) {
|
|
if (currentQueue) {
|
|
currentQueue[queueIndex].run();
|
|
}
|
|
}
|
|
queueIndex = -1;
|
|
len = queue.length;
|
|
}
|
|
currentQueue = null;
|
|
draining = false;
|
|
runClearTimeout(timeout);
|
|
}
|
|
process.nextTick = function (fun) {
|
|
var args = new Array(arguments.length - 1);
|
|
if (arguments.length > 1) {
|
|
for (var i = 1; i < arguments.length; i++) {
|
|
args[i - 1] = arguments[i];
|
|
}
|
|
}
|
|
queue.push(new Item(fun, args));
|
|
if (queue.length === 1 && !draining) {
|
|
runTimeout(drainQueue);
|
|
}
|
|
};
|
|
function Item(fun, array) {
|
|
this.fun = fun;
|
|
this.array = array;
|
|
}
|
|
Item.prototype.run = function () {
|
|
this.fun.apply(null, this.array);
|
|
};
|
|
process.title = 'browser';
|
|
process.browser = true;
|
|
process.env = {};
|
|
process.argv = [];
|
|
process.version = '';
|
|
process.versions = {};
|
|
function noop() {
|
|
}
|
|
process.on = noop;
|
|
process.addListener = noop;
|
|
process.once = noop;
|
|
process.off = noop;
|
|
process.removeListener = noop;
|
|
process.removeAllListeners = noop;
|
|
process.emit = noop;
|
|
process.prependListener = noop;
|
|
process.prependOnceListener = noop;
|
|
process.listeners = function (name) {
|
|
return [];
|
|
};
|
|
process.binding = function (name) {
|
|
throw new Error('process.binding is not supported');
|
|
};
|
|
process.cwd = function () {
|
|
return '/';
|
|
};
|
|
process.chdir = function (dir) {
|
|
throw new Error('process.chdir is not supported');
|
|
};
|
|
process.umask = function () {
|
|
return 0;
|
|
};
|
|
},
|
|
{}
|
|
],
|
|
2: [
|
|
function (require, module, exports) {
|
|
(function (setImmediate) {
|
|
(function (root) {
|
|
var setTimeoutFunc = setTimeout;
|
|
function noop() {
|
|
}
|
|
function bind(fn, thisArg) {
|
|
return function () {
|
|
fn.apply(thisArg, arguments);
|
|
};
|
|
}
|
|
function Promise(fn) {
|
|
if (typeof this !== 'object')
|
|
throw new TypeError('Promises must be constructed via new');
|
|
if (typeof fn !== 'function')
|
|
throw new TypeError('not a function');
|
|
this._state = 0;
|
|
this._handled = false;
|
|
this._value = undefined;
|
|
this._deferreds = [];
|
|
doResolve(fn, this);
|
|
}
|
|
function handle(self, deferred) {
|
|
while (self._state === 3) {
|
|
self = self._value;
|
|
}
|
|
if (self._state === 0) {
|
|
self._deferreds.push(deferred);
|
|
return;
|
|
}
|
|
self._handled = true;
|
|
Promise._immediateFn(function () {
|
|
var cb = self._state === 1 ? deferred.onFulfilled : deferred.onRejected;
|
|
if (cb === null) {
|
|
(self._state === 1 ? resolve : reject)(deferred.promise, self._value);
|
|
return;
|
|
}
|
|
var ret;
|
|
try {
|
|
ret = cb(self._value);
|
|
} catch (e) {
|
|
reject(deferred.promise, e);
|
|
return;
|
|
}
|
|
resolve(deferred.promise, ret);
|
|
});
|
|
}
|
|
function resolve(self, newValue) {
|
|
try {
|
|
if (newValue === self)
|
|
throw new TypeError('A promise cannot be resolved with itself.');
|
|
if (newValue && (typeof newValue === 'object' || typeof newValue === 'function')) {
|
|
var then = newValue.then;
|
|
if (newValue instanceof Promise) {
|
|
self._state = 3;
|
|
self._value = newValue;
|
|
finale(self);
|
|
return;
|
|
} else if (typeof then === 'function') {
|
|
doResolve(bind(then, newValue), self);
|
|
return;
|
|
}
|
|
}
|
|
self._state = 1;
|
|
self._value = newValue;
|
|
finale(self);
|
|
} catch (e) {
|
|
reject(self, e);
|
|
}
|
|
}
|
|
function reject(self, newValue) {
|
|
self._state = 2;
|
|
self._value = newValue;
|
|
finale(self);
|
|
}
|
|
function finale(self) {
|
|
if (self._state === 2 && self._deferreds.length === 0) {
|
|
Promise._immediateFn(function () {
|
|
if (!self._handled) {
|
|
Promise._unhandledRejectionFn(self._value);
|
|
}
|
|
});
|
|
}
|
|
for (var i = 0, len = self._deferreds.length; i < len; i++) {
|
|
handle(self, self._deferreds[i]);
|
|
}
|
|
self._deferreds = null;
|
|
}
|
|
function Handler(onFulfilled, onRejected, promise) {
|
|
this.onFulfilled = typeof onFulfilled === 'function' ? onFulfilled : null;
|
|
this.onRejected = typeof onRejected === 'function' ? onRejected : null;
|
|
this.promise = promise;
|
|
}
|
|
function doResolve(fn, self) {
|
|
var done = false;
|
|
try {
|
|
fn(function (value) {
|
|
if (done)
|
|
return;
|
|
done = true;
|
|
resolve(self, value);
|
|
}, function (reason) {
|
|
if (done)
|
|
return;
|
|
done = true;
|
|
reject(self, reason);
|
|
});
|
|
} catch (ex) {
|
|
if (done)
|
|
return;
|
|
done = true;
|
|
reject(self, ex);
|
|
}
|
|
}
|
|
Promise.prototype['catch'] = function (onRejected) {
|
|
return this.then(null, onRejected);
|
|
};
|
|
Promise.prototype.then = function (onFulfilled, onRejected) {
|
|
var prom = new this.constructor(noop);
|
|
handle(this, new Handler(onFulfilled, onRejected, prom));
|
|
return prom;
|
|
};
|
|
Promise.all = function (arr) {
|
|
var args = Array.prototype.slice.call(arr);
|
|
return new Promise(function (resolve, reject) {
|
|
if (args.length === 0)
|
|
return resolve([]);
|
|
var remaining = args.length;
|
|
function res(i, val) {
|
|
try {
|
|
if (val && (typeof val === 'object' || typeof val === 'function')) {
|
|
var then = val.then;
|
|
if (typeof then === 'function') {
|
|
then.call(val, function (val) {
|
|
res(i, val);
|
|
}, reject);
|
|
return;
|
|
}
|
|
}
|
|
args[i] = val;
|
|
if (--remaining === 0) {
|
|
resolve(args);
|
|
}
|
|
} catch (ex) {
|
|
reject(ex);
|
|
}
|
|
}
|
|
for (var i = 0; i < args.length; i++) {
|
|
res(i, args[i]);
|
|
}
|
|
});
|
|
};
|
|
Promise.resolve = function (value) {
|
|
if (value && typeof value === 'object' && value.constructor === Promise) {
|
|
return value;
|
|
}
|
|
return new Promise(function (resolve) {
|
|
resolve(value);
|
|
});
|
|
};
|
|
Promise.reject = function (value) {
|
|
return new Promise(function (resolve, reject) {
|
|
reject(value);
|
|
});
|
|
};
|
|
Promise.race = function (values) {
|
|
return new Promise(function (resolve, reject) {
|
|
for (var i = 0, len = values.length; i < len; i++) {
|
|
values[i].then(resolve, reject);
|
|
}
|
|
});
|
|
};
|
|
Promise._immediateFn = typeof setImmediate === 'function' ? function (fn) {
|
|
setImmediate(fn);
|
|
} : function (fn) {
|
|
setTimeoutFunc(fn, 0);
|
|
};
|
|
Promise._unhandledRejectionFn = function _unhandledRejectionFn(err) {
|
|
if (typeof console !== 'undefined' && console) {
|
|
console.warn('Possible Unhandled Promise Rejection:', err);
|
|
}
|
|
};
|
|
Promise._setImmediateFn = function _setImmediateFn(fn) {
|
|
Promise._immediateFn = fn;
|
|
};
|
|
Promise._setUnhandledRejectionFn = function _setUnhandledRejectionFn(fn) {
|
|
Promise._unhandledRejectionFn = fn;
|
|
};
|
|
if (typeof module !== 'undefined' && module.exports) {
|
|
module.exports = Promise;
|
|
} else if (!root.Promise) {
|
|
root.Promise = Promise;
|
|
}
|
|
}(this));
|
|
}.call(this, require('timers').setImmediate));
|
|
},
|
|
{ 'timers': 3 }
|
|
],
|
|
3: [
|
|
function (require, module, exports) {
|
|
(function (setImmediate, clearImmediate) {
|
|
var nextTick = require('process/browser.js').nextTick;
|
|
var apply = Function.prototype.apply;
|
|
var slice = Array.prototype.slice;
|
|
var immediateIds = {};
|
|
var nextImmediateId = 0;
|
|
exports.setTimeout = function () {
|
|
return new Timeout(apply.call(setTimeout, window, arguments), clearTimeout);
|
|
};
|
|
exports.setInterval = function () {
|
|
return new Timeout(apply.call(setInterval, window, arguments), clearInterval);
|
|
};
|
|
exports.clearTimeout = exports.clearInterval = function (timeout) {
|
|
timeout.close();
|
|
};
|
|
function Timeout(id, clearFn) {
|
|
this._id = id;
|
|
this._clearFn = clearFn;
|
|
}
|
|
Timeout.prototype.unref = Timeout.prototype.ref = function () {
|
|
};
|
|
Timeout.prototype.close = function () {
|
|
this._clearFn.call(window, this._id);
|
|
};
|
|
exports.enroll = function (item, msecs) {
|
|
clearTimeout(item._idleTimeoutId);
|
|
item._idleTimeout = msecs;
|
|
};
|
|
exports.unenroll = function (item) {
|
|
clearTimeout(item._idleTimeoutId);
|
|
item._idleTimeout = -1;
|
|
};
|
|
exports._unrefActive = exports.active = function (item) {
|
|
clearTimeout(item._idleTimeoutId);
|
|
var msecs = item._idleTimeout;
|
|
if (msecs >= 0) {
|
|
item._idleTimeoutId = setTimeout(function onTimeout() {
|
|
if (item._onTimeout)
|
|
item._onTimeout();
|
|
}, msecs);
|
|
}
|
|
};
|
|
exports.setImmediate = typeof setImmediate === 'function' ? setImmediate : function (fn) {
|
|
var id = nextImmediateId++;
|
|
var args = arguments.length < 2 ? false : slice.call(arguments, 1);
|
|
immediateIds[id] = true;
|
|
nextTick(function onNextTick() {
|
|
if (immediateIds[id]) {
|
|
if (args) {
|
|
fn.apply(null, args);
|
|
} else {
|
|
fn.call(null);
|
|
}
|
|
exports.clearImmediate(id);
|
|
}
|
|
});
|
|
return id;
|
|
};
|
|
exports.clearImmediate = typeof clearImmediate === 'function' ? clearImmediate : function (id) {
|
|
delete immediateIds[id];
|
|
};
|
|
}.call(this, require('timers').setImmediate, require('timers').clearImmediate));
|
|
},
|
|
{
|
|
'process/browser.js': 1,
|
|
'timers': 3
|
|
}
|
|
],
|
|
4: [
|
|
function (require, module, exports) {
|
|
var promisePolyfill = require('promise-polyfill');
|
|
var Global = function () {
|
|
if (typeof window !== 'undefined') {
|
|
return window;
|
|
} else {
|
|
return Function('return this;')();
|
|
}
|
|
}();
|
|
module.exports = { boltExport: Global.Promise || promisePolyfill };
|
|
},
|
|
{ 'promise-polyfill': 2 }
|
|
]
|
|
}, {}, [4])(4);
|
|
}));
|
|
}(undefined, exports$1, module, undefined));
|
|
var Promise$1 = module.exports.boltExport;
|
|
|
|
var nu$7 = function (baseFn) {
|
|
var data = Option.none();
|
|
var callbacks = [];
|
|
var map = function (f) {
|
|
return nu$7(function (nCallback) {
|
|
get(function (data) {
|
|
nCallback(f(data));
|
|
});
|
|
});
|
|
};
|
|
var get = function (nCallback) {
|
|
if (isReady()) {
|
|
call(nCallback);
|
|
} else {
|
|
callbacks.push(nCallback);
|
|
}
|
|
};
|
|
var set = function (x) {
|
|
data = Option.some(x);
|
|
run(callbacks);
|
|
callbacks = [];
|
|
};
|
|
var isReady = function () {
|
|
return data.isSome();
|
|
};
|
|
var run = function (cbs) {
|
|
each$1(cbs, call);
|
|
};
|
|
var call = function (cb) {
|
|
data.each(function (x) {
|
|
domGlobals.setTimeout(function () {
|
|
cb(x);
|
|
}, 0);
|
|
});
|
|
};
|
|
baseFn(set);
|
|
return {
|
|
get: get,
|
|
map: map,
|
|
isReady: isReady
|
|
};
|
|
};
|
|
var pure$1 = function (a) {
|
|
return nu$7(function (callback) {
|
|
callback(a);
|
|
});
|
|
};
|
|
var LazyValue = {
|
|
nu: nu$7,
|
|
pure: pure$1
|
|
};
|
|
|
|
var errorReporter = function (err) {
|
|
domGlobals.setTimeout(function () {
|
|
throw err;
|
|
}, 0);
|
|
};
|
|
var make$4 = function (run) {
|
|
var get = function (callback) {
|
|
run().then(callback, errorReporter);
|
|
};
|
|
var map = function (fab) {
|
|
return make$4(function () {
|
|
return run().then(fab);
|
|
});
|
|
};
|
|
var bind = function (aFutureB) {
|
|
return make$4(function () {
|
|
return run().then(function (v) {
|
|
return aFutureB(v).toPromise();
|
|
});
|
|
});
|
|
};
|
|
var anonBind = function (futureB) {
|
|
return make$4(function () {
|
|
return run().then(function () {
|
|
return futureB.toPromise();
|
|
});
|
|
});
|
|
};
|
|
var toLazy = function () {
|
|
return LazyValue.nu(get);
|
|
};
|
|
var toCached = function () {
|
|
var cache = null;
|
|
return make$4(function () {
|
|
if (cache === null) {
|
|
cache = run();
|
|
}
|
|
return cache;
|
|
});
|
|
};
|
|
var toPromise = run;
|
|
return {
|
|
map: map,
|
|
bind: bind,
|
|
anonBind: anonBind,
|
|
toLazy: toLazy,
|
|
toCached: toCached,
|
|
toPromise: toPromise,
|
|
get: get
|
|
};
|
|
};
|
|
var nu$8 = function (baseFn) {
|
|
return make$4(function () {
|
|
return new Promise$1(baseFn);
|
|
});
|
|
};
|
|
var pure$2 = function (a) {
|
|
return make$4(function () {
|
|
return Promise$1.resolve(a);
|
|
});
|
|
};
|
|
var Future = {
|
|
nu: nu$8,
|
|
pure: pure$2
|
|
};
|
|
|
|
var adjust = function (value, destination, amount) {
|
|
if (Math.abs(value - destination) <= amount) {
|
|
return Option.none();
|
|
} else if (value < destination) {
|
|
return Option.some(value + amount);
|
|
} else {
|
|
return Option.some(value - amount);
|
|
}
|
|
};
|
|
var create$5 = function () {
|
|
var interval = null;
|
|
var animate = function (getCurrent, destination, amount, increment, doFinish, rate) {
|
|
var finished = false;
|
|
var finish = function (v) {
|
|
finished = true;
|
|
doFinish(v);
|
|
};
|
|
global$4.clearInterval(interval);
|
|
var abort = function (v) {
|
|
global$4.clearInterval(interval);
|
|
finish(v);
|
|
};
|
|
interval = global$4.setInterval(function () {
|
|
var value = getCurrent();
|
|
adjust(value, destination, amount).fold(function () {
|
|
global$4.clearInterval(interval);
|
|
finish(destination);
|
|
}, function (s) {
|
|
increment(s, abort);
|
|
if (!finished) {
|
|
var newValue = getCurrent();
|
|
if (newValue !== s || Math.abs(newValue - destination) > Math.abs(value - destination)) {
|
|
global$4.clearInterval(interval);
|
|
finish(destination);
|
|
}
|
|
}
|
|
});
|
|
}, rate);
|
|
};
|
|
return { animate: animate };
|
|
};
|
|
|
|
var findDevice = function (deviceWidth, deviceHeight) {
|
|
var devices = [
|
|
{
|
|
width: 320,
|
|
height: 480,
|
|
keyboard: {
|
|
portrait: 300,
|
|
landscape: 240
|
|
}
|
|
},
|
|
{
|
|
width: 320,
|
|
height: 568,
|
|
keyboard: {
|
|
portrait: 300,
|
|
landscape: 240
|
|
}
|
|
},
|
|
{
|
|
width: 375,
|
|
height: 667,
|
|
keyboard: {
|
|
portrait: 305,
|
|
landscape: 240
|
|
}
|
|
},
|
|
{
|
|
width: 414,
|
|
height: 736,
|
|
keyboard: {
|
|
portrait: 320,
|
|
landscape: 240
|
|
}
|
|
},
|
|
{
|
|
width: 768,
|
|
height: 1024,
|
|
keyboard: {
|
|
portrait: 320,
|
|
landscape: 400
|
|
}
|
|
},
|
|
{
|
|
width: 1024,
|
|
height: 1366,
|
|
keyboard: {
|
|
portrait: 380,
|
|
landscape: 460
|
|
}
|
|
}
|
|
];
|
|
return findMap(devices, function (device) {
|
|
return someIf(deviceWidth <= device.width && deviceHeight <= device.height, device.keyboard);
|
|
}).getOr({
|
|
portrait: deviceHeight / 5,
|
|
landscape: deviceWidth / 4
|
|
});
|
|
};
|
|
|
|
var softKeyboardLimits = function (outerWindow) {
|
|
return findDevice(outerWindow.screen.width, outerWindow.screen.height);
|
|
};
|
|
var accountableKeyboardHeight = function (outerWindow) {
|
|
var portrait = get$b(outerWindow).isPortrait();
|
|
var limits = softKeyboardLimits(outerWindow);
|
|
var keyboard = portrait ? limits.portrait : limits.landscape;
|
|
var visualScreenHeight = portrait ? outerWindow.screen.height : outerWindow.screen.width;
|
|
return visualScreenHeight - outerWindow.innerHeight > keyboard ? 0 : keyboard;
|
|
};
|
|
var getGreenzone = function (socket, dropup) {
|
|
var outerWindow = owner(socket).dom().defaultView;
|
|
var viewportHeight = get$5(socket) + get$5(dropup);
|
|
var acc = accountableKeyboardHeight(outerWindow);
|
|
return viewportHeight - acc;
|
|
};
|
|
var updatePadding = function (contentBody, socket, dropup) {
|
|
var greenzoneHeight = getGreenzone(socket, dropup);
|
|
var deltaHeight = get$5(socket) + get$5(dropup) - greenzoneHeight;
|
|
set$3(contentBody, 'padding-bottom', deltaHeight + 'px');
|
|
};
|
|
|
|
var fixture = Adt.generate([
|
|
{
|
|
fixed: [
|
|
'element',
|
|
'property',
|
|
'offsetY'
|
|
]
|
|
},
|
|
{
|
|
scroller: [
|
|
'element',
|
|
'offsetY'
|
|
]
|
|
}
|
|
]);
|
|
var yFixedData = 'data-' + resolve('position-y-fixed');
|
|
var yFixedProperty = 'data-' + resolve('y-property');
|
|
var yScrollingData = 'data-' + resolve('scrolling');
|
|
var windowSizeData = 'data-' + resolve('last-window-height');
|
|
var getYFixedData = function (element) {
|
|
return safeParse(element, yFixedData);
|
|
};
|
|
var getYFixedProperty = function (element) {
|
|
return get$1(element, yFixedProperty);
|
|
};
|
|
var getLastWindowSize = function (element) {
|
|
return safeParse(element, windowSizeData);
|
|
};
|
|
var classifyFixed = function (element, offsetY) {
|
|
var prop = getYFixedProperty(element);
|
|
return fixture.fixed(element, prop, offsetY);
|
|
};
|
|
var classifyScrolling = function (element, offsetY) {
|
|
return fixture.scroller(element, offsetY);
|
|
};
|
|
var classify = function (element) {
|
|
var offsetY = getYFixedData(element);
|
|
var classifier = get$1(element, yScrollingData) === 'true' ? classifyScrolling : classifyFixed;
|
|
return classifier(element, offsetY);
|
|
};
|
|
var findFixtures = function (container) {
|
|
var candidates = descendants(container, '[' + yFixedData + ']');
|
|
return map$1(candidates, classify);
|
|
};
|
|
var takeoverToolbar = function (toolbar) {
|
|
var oldToolbarStyle = get$1(toolbar, 'style');
|
|
setAll$1(toolbar, {
|
|
position: 'absolute',
|
|
top: '0px'
|
|
});
|
|
set(toolbar, yFixedData, '0px');
|
|
set(toolbar, yFixedProperty, 'top');
|
|
var restore = function () {
|
|
set(toolbar, 'style', oldToolbarStyle || '');
|
|
remove$1(toolbar, yFixedData);
|
|
remove$1(toolbar, yFixedProperty);
|
|
};
|
|
return { restore: restore };
|
|
};
|
|
var takeoverViewport = function (toolbarHeight, height, viewport) {
|
|
var oldViewportStyle = get$1(viewport, 'style');
|
|
register(viewport);
|
|
setAll$1(viewport, {
|
|
position: 'absolute',
|
|
height: height + 'px',
|
|
width: '100%',
|
|
top: toolbarHeight + 'px'
|
|
});
|
|
set(viewport, yFixedData, toolbarHeight + 'px');
|
|
set(viewport, yScrollingData, 'true');
|
|
set(viewport, yFixedProperty, 'top');
|
|
var restore = function () {
|
|
deregister(viewport);
|
|
set(viewport, 'style', oldViewportStyle || '');
|
|
remove$1(viewport, yFixedData);
|
|
remove$1(viewport, yScrollingData);
|
|
remove$1(viewport, yFixedProperty);
|
|
};
|
|
return { restore: restore };
|
|
};
|
|
var takeoverDropup = function (dropup) {
|
|
var oldDropupStyle = get$1(dropup, 'style');
|
|
setAll$1(dropup, {
|
|
position: 'absolute',
|
|
bottom: '0px'
|
|
});
|
|
set(dropup, yFixedData, '0px');
|
|
set(dropup, yFixedProperty, 'bottom');
|
|
var restore = function () {
|
|
set(dropup, 'style', oldDropupStyle || '');
|
|
remove$1(dropup, yFixedData);
|
|
remove$1(dropup, yFixedProperty);
|
|
};
|
|
return { restore: restore };
|
|
};
|
|
var deriveViewportHeight = function (viewport, toolbarHeight, dropupHeight) {
|
|
var outerWindow = owner(viewport).dom().defaultView;
|
|
var winH = outerWindow.innerHeight;
|
|
set(viewport, windowSizeData, winH + 'px');
|
|
return winH - toolbarHeight - dropupHeight;
|
|
};
|
|
var takeover$1 = function (viewport, contentBody, toolbar, dropup) {
|
|
var outerWindow = owner(viewport).dom().defaultView;
|
|
var toolbarSetup = takeoverToolbar(toolbar);
|
|
var toolbarHeight = get$5(toolbar);
|
|
var dropupHeight = get$5(dropup);
|
|
var viewportHeight = deriveViewportHeight(viewport, toolbarHeight, dropupHeight);
|
|
var viewportSetup = takeoverViewport(toolbarHeight, viewportHeight, viewport);
|
|
var dropupSetup = takeoverDropup(dropup);
|
|
var isActive = true;
|
|
var restore = function () {
|
|
isActive = false;
|
|
toolbarSetup.restore();
|
|
viewportSetup.restore();
|
|
dropupSetup.restore();
|
|
};
|
|
var isExpanding = function () {
|
|
var currentWinHeight = outerWindow.innerHeight;
|
|
var lastWinHeight = getLastWindowSize(viewport);
|
|
return currentWinHeight > lastWinHeight;
|
|
};
|
|
var refresh = function () {
|
|
if (isActive) {
|
|
var newToolbarHeight = get$5(toolbar);
|
|
var dropupHeight_1 = get$5(dropup);
|
|
var newHeight = deriveViewportHeight(viewport, newToolbarHeight, dropupHeight_1);
|
|
set(viewport, yFixedData, newToolbarHeight + 'px');
|
|
set$3(viewport, 'height', newHeight + 'px');
|
|
updatePadding(contentBody, viewport, dropup);
|
|
}
|
|
};
|
|
var setViewportOffset = function (newYOffset) {
|
|
var offsetPx = newYOffset + 'px';
|
|
set(viewport, yFixedData, offsetPx);
|
|
refresh();
|
|
};
|
|
updatePadding(contentBody, viewport, dropup);
|
|
return {
|
|
setViewportOffset: setViewportOffset,
|
|
isExpanding: isExpanding,
|
|
isShrinking: not(isExpanding),
|
|
refresh: refresh,
|
|
restore: restore
|
|
};
|
|
};
|
|
|
|
var animator = create$5();
|
|
var ANIMATION_STEP = 15;
|
|
var NUM_TOP_ANIMATION_FRAMES = 10;
|
|
var ANIMATION_RATE = 10;
|
|
var lastScroll = 'data-' + resolve('last-scroll-top');
|
|
var getTop = function (element) {
|
|
var raw = getRaw(element, 'top').getOr('0');
|
|
return parseInt(raw, 10);
|
|
};
|
|
var getScrollTop = function (element) {
|
|
return parseInt(element.dom().scrollTop, 10);
|
|
};
|
|
var moveScrollAndTop = function (element, destination, finalTop) {
|
|
return Future.nu(function (callback) {
|
|
var getCurrent = curry(getScrollTop, element);
|
|
var update = function (newScroll) {
|
|
element.dom().scrollTop = newScroll;
|
|
set$3(element, 'top', getTop(element) + ANIMATION_STEP + 'px');
|
|
};
|
|
var finish = function () {
|
|
element.dom().scrollTop = destination;
|
|
set$3(element, 'top', finalTop + 'px');
|
|
callback(destination);
|
|
};
|
|
animator.animate(getCurrent, destination, ANIMATION_STEP, update, finish, ANIMATION_RATE);
|
|
});
|
|
};
|
|
var moveOnlyScroll = function (element, destination) {
|
|
return Future.nu(function (callback) {
|
|
var getCurrent = curry(getScrollTop, element);
|
|
set(element, lastScroll, getCurrent());
|
|
var update = function (newScroll, abort) {
|
|
var previous = safeParse(element, lastScroll);
|
|
if (previous !== element.dom().scrollTop) {
|
|
abort(element.dom().scrollTop);
|
|
} else {
|
|
element.dom().scrollTop = newScroll;
|
|
set(element, lastScroll, newScroll);
|
|
}
|
|
};
|
|
var finish = function () {
|
|
element.dom().scrollTop = destination;
|
|
set(element, lastScroll, destination);
|
|
callback(destination);
|
|
};
|
|
var distance = Math.abs(destination - getCurrent());
|
|
var step = Math.ceil(distance / NUM_TOP_ANIMATION_FRAMES);
|
|
animator.animate(getCurrent, destination, step, update, finish, ANIMATION_RATE);
|
|
});
|
|
};
|
|
var moveOnlyTop = function (element, destination) {
|
|
return Future.nu(function (callback) {
|
|
var getCurrent = curry(getTop, element);
|
|
var update = function (newTop) {
|
|
set$3(element, 'top', newTop + 'px');
|
|
};
|
|
var finish = function () {
|
|
update(destination);
|
|
callback(destination);
|
|
};
|
|
var distance = Math.abs(destination - getCurrent());
|
|
var step = Math.ceil(distance / NUM_TOP_ANIMATION_FRAMES);
|
|
animator.animate(getCurrent, destination, step, update, finish, ANIMATION_RATE);
|
|
});
|
|
};
|
|
var updateTop = function (element, amount) {
|
|
var newTop = amount + getYFixedData(element) + 'px';
|
|
set$3(element, 'top', newTop);
|
|
};
|
|
var moveWindowScroll = function (toolbar, viewport, destY) {
|
|
var outerWindow = owner(toolbar).dom().defaultView;
|
|
return Future.nu(function (callback) {
|
|
updateTop(toolbar, destY);
|
|
updateTop(viewport, destY);
|
|
outerWindow.scrollTo(0, destY);
|
|
callback(destY);
|
|
});
|
|
};
|
|
|
|
function BackgroundActivity (doAction) {
|
|
var action = Cell(LazyValue.pure({}));
|
|
var start = function (value) {
|
|
var future = LazyValue.nu(function (callback) {
|
|
return doAction(value).get(callback);
|
|
});
|
|
action.set(future);
|
|
};
|
|
var idle = function (g) {
|
|
action.get().get(function () {
|
|
g();
|
|
});
|
|
};
|
|
return {
|
|
start: start,
|
|
idle: idle
|
|
};
|
|
}
|
|
|
|
var scrollIntoView = function (cWin, socket, dropup, top, bottom) {
|
|
var greenzone = getGreenzone(socket, dropup);
|
|
var refreshCursor = curry(refresh$1, cWin);
|
|
if (top > greenzone || bottom > greenzone) {
|
|
moveOnlyScroll(socket, socket.dom().scrollTop - greenzone + bottom).get(refreshCursor);
|
|
} else if (top < 0) {
|
|
moveOnlyScroll(socket, socket.dom().scrollTop + top).get(refreshCursor);
|
|
}
|
|
};
|
|
|
|
var par = function (asyncValues, nu) {
|
|
return nu(function (callback) {
|
|
var r = [];
|
|
var count = 0;
|
|
var cb = function (i) {
|
|
return function (value) {
|
|
r[i] = value;
|
|
count++;
|
|
if (count >= asyncValues.length) {
|
|
callback(r);
|
|
}
|
|
};
|
|
};
|
|
if (asyncValues.length === 0) {
|
|
callback([]);
|
|
} else {
|
|
each$1(asyncValues, function (asyncValue, i) {
|
|
asyncValue.get(cb(i));
|
|
});
|
|
}
|
|
});
|
|
};
|
|
|
|
var par$1 = function (futures) {
|
|
return par(futures, Future.nu);
|
|
};
|
|
|
|
var updateFixed = function (element, property, winY, offsetY) {
|
|
var destination = winY + offsetY;
|
|
set$3(element, property, destination + 'px');
|
|
return Future.pure(offsetY);
|
|
};
|
|
var updateScrollingFixed = function (element, winY, offsetY) {
|
|
var destTop = winY + offsetY;
|
|
var oldProp = getRaw(element, 'top').getOr(offsetY);
|
|
var delta = destTop - parseInt(oldProp, 10);
|
|
var destScroll = element.dom().scrollTop + delta;
|
|
return moveScrollAndTop(element, destScroll, destTop);
|
|
};
|
|
var updateFixture = function (fixture, winY) {
|
|
return fixture.fold(function (element, property, offsetY) {
|
|
return updateFixed(element, property, winY, offsetY);
|
|
}, function (element, offsetY) {
|
|
return updateScrollingFixed(element, winY, offsetY);
|
|
});
|
|
};
|
|
var updatePositions = function (container, winY) {
|
|
var fixtures = findFixtures(container);
|
|
var updates = map$1(fixtures, function (fixture) {
|
|
return updateFixture(fixture, winY);
|
|
});
|
|
return par$1(updates);
|
|
};
|
|
|
|
var VIEW_MARGIN = 5;
|
|
var register$2 = function (toolstrip, socket, container, outerWindow, structure, cWin) {
|
|
var scroller = BackgroundActivity(function (y) {
|
|
return moveWindowScroll(toolstrip, socket, y);
|
|
});
|
|
var scrollBounds = function () {
|
|
var rects = getRectangles(cWin);
|
|
return Option.from(rects[0]).bind(function (rect) {
|
|
var viewTop = rect.top() - socket.dom().scrollTop;
|
|
var outside = viewTop > outerWindow.innerHeight + VIEW_MARGIN || viewTop < -VIEW_MARGIN;
|
|
return outside ? Option.some({
|
|
top: constant(viewTop),
|
|
bottom: constant(viewTop + rect.height())
|
|
}) : Option.none();
|
|
});
|
|
};
|
|
var scrollThrottle = last(function () {
|
|
scroller.idle(function () {
|
|
updatePositions(container, outerWindow.pageYOffset).get(function () {
|
|
var extraScroll = scrollBounds();
|
|
extraScroll.each(function (extra) {
|
|
socket.dom().scrollTop = socket.dom().scrollTop + extra.top();
|
|
});
|
|
scroller.start(0);
|
|
structure.refresh();
|
|
});
|
|
});
|
|
}, 1000);
|
|
var onScroll = bind$3(Element.fromDom(outerWindow), 'scroll', function () {
|
|
if (outerWindow.pageYOffset < 0) {
|
|
return;
|
|
}
|
|
scrollThrottle.throttle();
|
|
});
|
|
updatePositions(container, outerWindow.pageYOffset).get(identity);
|
|
return { unbind: onScroll.unbind };
|
|
};
|
|
var setup$3 = function (bag) {
|
|
var cWin = bag.cWin;
|
|
var ceBody = bag.ceBody;
|
|
var socket = bag.socket;
|
|
var toolstrip = bag.toolstrip;
|
|
var contentElement = bag.contentElement;
|
|
var keyboardType = bag.keyboardType;
|
|
var outerWindow = bag.outerWindow;
|
|
var dropup = bag.dropup;
|
|
var outerBody = bag.outerBody;
|
|
var structure = takeover$1(socket, ceBody, toolstrip, dropup);
|
|
var keyboardModel = keyboardType(outerBody, cWin, body(), contentElement);
|
|
var toEditing = function () {
|
|
keyboardModel.toEditing();
|
|
clearSelection();
|
|
};
|
|
var toReading = function () {
|
|
keyboardModel.toReading();
|
|
};
|
|
var onToolbarTouch = function (_event) {
|
|
keyboardModel.onToolbarTouch();
|
|
};
|
|
var onOrientation = onChange(outerWindow, {
|
|
onChange: noop,
|
|
onReady: structure.refresh
|
|
});
|
|
onOrientation.onAdjustment(function () {
|
|
structure.refresh();
|
|
});
|
|
var onResize = bind$3(Element.fromDom(outerWindow), 'resize', function () {
|
|
if (structure.isExpanding()) {
|
|
structure.refresh();
|
|
}
|
|
});
|
|
var onScroll = register$2(toolstrip, socket, outerBody, outerWindow, structure, cWin);
|
|
var unfocusedSelection = FakeSelection(cWin, contentElement);
|
|
var refreshSelection = function () {
|
|
if (unfocusedSelection.isActive()) {
|
|
unfocusedSelection.update();
|
|
}
|
|
};
|
|
var highlightSelection = function () {
|
|
unfocusedSelection.update();
|
|
};
|
|
var clearSelection = function () {
|
|
unfocusedSelection.clear();
|
|
};
|
|
var scrollIntoView$1 = function (top, bottom) {
|
|
scrollIntoView(cWin, socket, dropup, top, bottom);
|
|
};
|
|
var syncHeight = function () {
|
|
set$3(contentElement, 'height', contentElement.dom().contentWindow.document.body.scrollHeight + 'px');
|
|
};
|
|
var setViewportOffset = function (newYOffset) {
|
|
structure.setViewportOffset(newYOffset);
|
|
moveOnlyTop(socket, newYOffset).get(identity);
|
|
};
|
|
var destroy = function () {
|
|
structure.restore();
|
|
onOrientation.destroy();
|
|
onScroll.unbind();
|
|
onResize.unbind();
|
|
keyboardModel.destroy();
|
|
unfocusedSelection.destroy();
|
|
input$1(body(), blur);
|
|
};
|
|
return {
|
|
toEditing: toEditing,
|
|
toReading: toReading,
|
|
onToolbarTouch: onToolbarTouch,
|
|
refreshSelection: refreshSelection,
|
|
clearSelection: clearSelection,
|
|
highlightSelection: highlightSelection,
|
|
scrollIntoView: scrollIntoView$1,
|
|
updateToolbarPadding: noop,
|
|
setViewportOffset: setViewportOffset,
|
|
syncHeight: syncHeight,
|
|
refreshStructure: structure.refresh,
|
|
destroy: destroy
|
|
};
|
|
};
|
|
|
|
var create$6 = function (platform, mask) {
|
|
var meta = tag();
|
|
var priorState = value$2();
|
|
var scrollEvents = value$2();
|
|
var iosApi = api$2();
|
|
var iosEvents = api$2();
|
|
var enter = function () {
|
|
mask.hide();
|
|
var doc = Element.fromDom(domGlobals.document);
|
|
getActiveApi(platform.editor).each(function (editorApi) {
|
|
priorState.set({
|
|
socketHeight: getRaw(platform.socket, 'height'),
|
|
iframeHeight: getRaw(editorApi.frame(), 'height'),
|
|
outerScroll: domGlobals.document.body.scrollTop
|
|
});
|
|
scrollEvents.set({ exclusives: exclusive(doc, '.' + scrollable) });
|
|
add$2(platform.container, resolve('fullscreen-maximized'));
|
|
clobberStyles(platform.container, editorApi.body());
|
|
meta.maximize();
|
|
set$3(platform.socket, 'overflow', 'scroll');
|
|
set$3(platform.socket, '-webkit-overflow-scrolling', 'touch');
|
|
focus$1(editorApi.body());
|
|
iosApi.set(setup$3({
|
|
cWin: editorApi.win(),
|
|
ceBody: editorApi.body(),
|
|
socket: platform.socket,
|
|
toolstrip: platform.toolstrip,
|
|
dropup: platform.dropup.element(),
|
|
contentElement: editorApi.frame(),
|
|
outerBody: platform.body,
|
|
outerWindow: platform.win,
|
|
keyboardType: stubborn
|
|
}));
|
|
iosApi.run(function (api) {
|
|
api.syncHeight();
|
|
});
|
|
iosEvents.set(initEvents$1(editorApi, iosApi, platform.toolstrip, platform.socket, platform.dropup));
|
|
});
|
|
};
|
|
var exit = function () {
|
|
meta.restore();
|
|
iosEvents.clear();
|
|
iosApi.clear();
|
|
mask.show();
|
|
priorState.on(function (s) {
|
|
s.socketHeight.each(function (h) {
|
|
set$3(platform.socket, 'height', h);
|
|
});
|
|
s.iframeHeight.each(function (h) {
|
|
set$3(platform.editor.getFrame(), 'height', h);
|
|
});
|
|
domGlobals.document.body.scrollTop = s.scrollTop;
|
|
});
|
|
priorState.clear();
|
|
scrollEvents.on(function (s) {
|
|
s.exclusives.unbind();
|
|
});
|
|
scrollEvents.clear();
|
|
remove$4(platform.container, resolve('fullscreen-maximized'));
|
|
restoreStyles();
|
|
deregister(platform.toolbar);
|
|
remove$5(platform.socket, 'overflow');
|
|
remove$5(platform.socket, '-webkit-overflow-scrolling');
|
|
blur(platform.editor.getFrame());
|
|
getActiveApi(platform.editor).each(function (editorApi) {
|
|
editorApi.clearSelection();
|
|
});
|
|
};
|
|
var refreshStructure = function () {
|
|
iosApi.run(function (api) {
|
|
api.refreshStructure();
|
|
});
|
|
};
|
|
return {
|
|
enter: enter,
|
|
refreshStructure: refreshStructure,
|
|
exit: exit
|
|
};
|
|
};
|
|
|
|
var produce$1 = function (raw) {
|
|
var mobile = asRawOrDie('Getting IosWebapp schema', MobileSchema, raw);
|
|
set$3(mobile.toolstrip, 'width', '100%');
|
|
set$3(mobile.container, 'position', 'relative');
|
|
var onView = function () {
|
|
mobile.setReadOnly(mobile.readOnlyOnInit());
|
|
mode.enter();
|
|
};
|
|
var mask = build$1(sketch$9(onView, mobile.translate));
|
|
mobile.alloy.add(mask);
|
|
var maskApi = {
|
|
show: function () {
|
|
mobile.alloy.add(mask);
|
|
},
|
|
hide: function () {
|
|
mobile.alloy.remove(mask);
|
|
}
|
|
};
|
|
var mode = create$6(mobile, maskApi);
|
|
return {
|
|
setReadOnly: mobile.setReadOnly,
|
|
refreshStructure: mode.refreshStructure,
|
|
enter: mode.enter,
|
|
exit: mode.exit,
|
|
destroy: noop
|
|
};
|
|
};
|
|
|
|
function IosRealm (scrollIntoView) {
|
|
var alloy = OuterContainer({ classes: [resolve('ios-container')] });
|
|
var toolbar = ScrollingToolbar();
|
|
var webapp = api$2();
|
|
var switchToEdit = makeEditSwitch(webapp);
|
|
var socket = makeSocket();
|
|
var dropup = build$2(function () {
|
|
webapp.run(function (w) {
|
|
w.refreshStructure();
|
|
});
|
|
}, scrollIntoView);
|
|
alloy.add(toolbar.wrapper());
|
|
alloy.add(socket);
|
|
alloy.add(dropup.component());
|
|
var setToolbarGroups = function (rawGroups) {
|
|
var groups = toolbar.createGroups(rawGroups);
|
|
toolbar.setGroups(groups);
|
|
};
|
|
var setContextToolbar = function (rawGroups) {
|
|
var groups = toolbar.createGroups(rawGroups);
|
|
toolbar.setContextToolbar(groups);
|
|
};
|
|
var focusToolbar = function () {
|
|
toolbar.focus();
|
|
};
|
|
var restoreToolbar = function () {
|
|
toolbar.restoreToolbar();
|
|
};
|
|
var init = function (spec) {
|
|
webapp.set(produce$1(spec));
|
|
};
|
|
var exit = function () {
|
|
webapp.run(function (w) {
|
|
Replacing.remove(socket, switchToEdit);
|
|
w.exit();
|
|
});
|
|
};
|
|
var updateMode$1 = function (readOnly) {
|
|
updateMode(socket, switchToEdit, readOnly, alloy.root());
|
|
};
|
|
return {
|
|
system: constant(alloy),
|
|
element: alloy.element,
|
|
init: init,
|
|
exit: exit,
|
|
setToolbarGroups: setToolbarGroups,
|
|
setContextToolbar: setContextToolbar,
|
|
focusToolbar: focusToolbar,
|
|
restoreToolbar: restoreToolbar,
|
|
updateMode: updateMode$1,
|
|
socket: constant(socket),
|
|
dropup: constant(dropup)
|
|
};
|
|
}
|
|
|
|
var global$5 = tinymce.util.Tools.resolve('tinymce.EditorManager');
|
|
|
|
var derive$3 = function (editor) {
|
|
var base = get(editor.settings, 'skin_url').fold(function () {
|
|
return global$5.baseURL + '/skins/ui/oxide';
|
|
}, function (url) {
|
|
return url;
|
|
});
|
|
return {
|
|
content: base + '/content.mobile.min.css',
|
|
ui: base + '/skin.mobile.min.css'
|
|
};
|
|
};
|
|
|
|
var fireChange = function (realm, command, state) {
|
|
realm.system().broadcastOn([formatChanged], {
|
|
command: command,
|
|
state: state
|
|
});
|
|
};
|
|
var init$5 = function (realm, editor) {
|
|
var allFormats = keys(editor.formatter.get());
|
|
each$1(allFormats, function (command) {
|
|
editor.formatter.formatChanged(command, function (state) {
|
|
fireChange(realm, command, state);
|
|
});
|
|
});
|
|
each$1([
|
|
'ul',
|
|
'ol'
|
|
], function (command) {
|
|
editor.selection.selectorChanged(command, function (state, _data) {
|
|
fireChange(realm, command, state);
|
|
});
|
|
});
|
|
};
|
|
|
|
var fireSkinLoaded = function (editor) {
|
|
return function () {
|
|
var done = function () {
|
|
editor._skinLoaded = true;
|
|
editor.fire('SkinLoaded');
|
|
};
|
|
if (editor.initialized) {
|
|
done();
|
|
} else {
|
|
editor.on('init', done);
|
|
}
|
|
};
|
|
};
|
|
|
|
var READING = 'toReading';
|
|
var EDITING = 'toEditing';
|
|
var renderMobileTheme = function (editor) {
|
|
var renderUI = function () {
|
|
var targetNode = editor.getElement();
|
|
var cssUrls = derive$3(editor);
|
|
if (isSkinDisabled(editor) === false) {
|
|
editor.contentCSS.push(cssUrls.content);
|
|
global$1.DOM.styleSheetLoader.load(cssUrls.ui, fireSkinLoaded(editor));
|
|
} else {
|
|
fireSkinLoaded(editor)();
|
|
}
|
|
var doScrollIntoView = function () {
|
|
editor.fire('ScrollIntoView');
|
|
};
|
|
var realm = detect$3().os.isAndroid() ? AndroidRealm(doScrollIntoView) : IosRealm(doScrollIntoView);
|
|
var original = Element.fromDom(targetNode);
|
|
attachSystemAfter(original, realm.system());
|
|
var findFocusIn = function (elem) {
|
|
return search(elem).bind(function (focused) {
|
|
return realm.system().getByDom(focused).toOption();
|
|
});
|
|
};
|
|
var outerWindow = targetNode.ownerDocument.defaultView;
|
|
var orientation = onChange(outerWindow, {
|
|
onChange: function () {
|
|
var alloy = realm.system();
|
|
alloy.broadcastOn([orientationChanged], { width: getActualWidth(outerWindow) });
|
|
},
|
|
onReady: noop
|
|
});
|
|
var setReadOnly = function (dynamicGroup, readOnlyGroups, mainGroups, ro) {
|
|
if (ro === false) {
|
|
editor.selection.collapse();
|
|
}
|
|
var toolbars = configureToolbar(dynamicGroup, readOnlyGroups, mainGroups);
|
|
realm.setToolbarGroups(ro === true ? toolbars.readOnly : toolbars.main);
|
|
editor.setMode(ro === true ? 'readonly' : 'design');
|
|
editor.fire(ro === true ? READING : EDITING);
|
|
realm.updateMode(ro);
|
|
};
|
|
var configureToolbar = function (dynamicGroup, readOnlyGroups, mainGroups) {
|
|
var dynamic = dynamicGroup.get();
|
|
var toolbars = {
|
|
readOnly: dynamic.backToMask.concat(readOnlyGroups.get()),
|
|
main: dynamic.backToMask.concat(mainGroups.get())
|
|
};
|
|
return toolbars;
|
|
};
|
|
var bindHandler = function (label, handler) {
|
|
editor.on(label, handler);
|
|
return {
|
|
unbind: function () {
|
|
editor.off(label);
|
|
}
|
|
};
|
|
};
|
|
editor.on('init', function () {
|
|
realm.init({
|
|
editor: {
|
|
getFrame: function () {
|
|
return Element.fromDom(editor.contentAreaContainer.querySelector('iframe'));
|
|
},
|
|
onDomChanged: function () {
|
|
return { unbind: noop };
|
|
},
|
|
onToReading: function (handler) {
|
|
return bindHandler(READING, handler);
|
|
},
|
|
onToEditing: function (handler) {
|
|
return bindHandler(EDITING, handler);
|
|
},
|
|
onScrollToCursor: function (handler) {
|
|
editor.on('ScrollIntoView', function (tinyEvent) {
|
|
handler(tinyEvent);
|
|
});
|
|
var unbind = function () {
|
|
editor.off('ScrollIntoView');
|
|
orientation.destroy();
|
|
};
|
|
return { unbind: unbind };
|
|
},
|
|
onTouchToolstrip: function () {
|
|
hideDropup();
|
|
},
|
|
onTouchContent: function () {
|
|
var toolbar = Element.fromDom(editor.editorContainer.querySelector('.' + resolve('toolbar')));
|
|
findFocusIn(toolbar).each(emitExecute);
|
|
realm.restoreToolbar();
|
|
hideDropup();
|
|
},
|
|
onTapContent: function (evt) {
|
|
var target = evt.target();
|
|
if (name(target) === 'img') {
|
|
editor.selection.select(target.dom());
|
|
evt.kill();
|
|
} else if (name(target) === 'a') {
|
|
var component = realm.system().getByDom(Element.fromDom(editor.editorContainer));
|
|
component.each(function (container) {
|
|
if (Swapping.isAlpha(container)) {
|
|
openLink(target.dom());
|
|
}
|
|
});
|
|
}
|
|
}
|
|
},
|
|
container: Element.fromDom(editor.editorContainer),
|
|
socket: Element.fromDom(editor.contentAreaContainer),
|
|
toolstrip: Element.fromDom(editor.editorContainer.querySelector('.' + resolve('toolstrip'))),
|
|
toolbar: Element.fromDom(editor.editorContainer.querySelector('.' + resolve('toolbar'))),
|
|
dropup: realm.dropup(),
|
|
alloy: realm.system(),
|
|
translate: noop,
|
|
setReadOnly: function (ro) {
|
|
setReadOnly(dynamicGroup, readOnlyGroups, mainGroups, ro);
|
|
},
|
|
readOnlyOnInit: function () {
|
|
return readOnlyOnInit();
|
|
}
|
|
});
|
|
var hideDropup = function () {
|
|
realm.dropup().disappear(function () {
|
|
realm.system().broadcastOn([dropupDismissed], {});
|
|
});
|
|
};
|
|
var backToMaskGroup = {
|
|
label: 'The first group',
|
|
scrollable: false,
|
|
items: [forToolbar('back', function () {
|
|
editor.selection.collapse();
|
|
realm.exit();
|
|
}, {}, editor)]
|
|
};
|
|
var backToReadOnlyGroup = {
|
|
label: 'Back to read only',
|
|
scrollable: false,
|
|
items: [forToolbar('readonly-back', function () {
|
|
setReadOnly(dynamicGroup, readOnlyGroups, mainGroups, true);
|
|
}, {}, editor)]
|
|
};
|
|
var readOnlyGroup = {
|
|
label: 'The read only mode group',
|
|
scrollable: true,
|
|
items: []
|
|
};
|
|
var features = setup(realm, editor);
|
|
var items = detect$4(editor.settings, features);
|
|
var actionGroup = {
|
|
label: 'the action group',
|
|
scrollable: true,
|
|
items: items
|
|
};
|
|
var extraGroup = {
|
|
label: 'The extra group',
|
|
scrollable: false,
|
|
items: []
|
|
};
|
|
var mainGroups = Cell([
|
|
actionGroup,
|
|
extraGroup
|
|
]);
|
|
var readOnlyGroups = Cell([
|
|
readOnlyGroup,
|
|
extraGroup
|
|
]);
|
|
var dynamicGroup = Cell({
|
|
backToMask: [backToMaskGroup],
|
|
backToReadOnly: [backToReadOnlyGroup]
|
|
});
|
|
init$5(realm, editor);
|
|
});
|
|
editor.on('remove', function () {
|
|
realm.exit();
|
|
});
|
|
editor.on('detach', function () {
|
|
detachSystem(realm.system());
|
|
realm.system().destroy();
|
|
});
|
|
return {
|
|
iframeContainer: realm.socket().element().dom(),
|
|
editorContainer: realm.element().dom()
|
|
};
|
|
};
|
|
return {
|
|
getNotificationManagerImpl: function () {
|
|
return {
|
|
open: constant({
|
|
progressBar: { value: noop },
|
|
close: noop,
|
|
text: noop,
|
|
getEl: constant(null),
|
|
moveTo: noop,
|
|
moveRel: noop,
|
|
settings: {}
|
|
}),
|
|
close: noop,
|
|
reposition: noop,
|
|
getArgs: constant({})
|
|
};
|
|
},
|
|
renderUI: renderUI
|
|
};
|
|
};
|
|
function Theme () {
|
|
global$2.add('mobile', renderMobileTheme);
|
|
}
|
|
|
|
Theme();
|
|
|
|
}(window));
|