diff --git a/build/amd/senna/src/app/version-min.js b/build/amd/senna/src/app/version-min.js index b378cb0..b2217d4 100644 --- a/build/amd/senna/src/app/version-min.js +++ b/build/amd/senna/src/app/version-min.js @@ -1 +1 @@ -define(["exports"],function(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t="3.0.0-milestone.2";e["default"]=t}); \ No newline at end of file +define(["exports"],function(e){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var t="3.0.0-milestone.6";e["default"]=t}); \ No newline at end of file diff --git a/build/amd/senna/src/app/version.js b/build/amd/senna/src/app/version.js index f09c07a..d2d88d3 100644 --- a/build/amd/senna/src/app/version.js +++ b/build/amd/senna/src/app/version.js @@ -8,7 +8,7 @@ define(['exports'], function (exports) { * @returns String containing the current senna version */ - var version = '3.0.0-milestone.2'; + var version = '3.0.0-milestone.6'; exports.default = version; }); diff --git a/build/globals/senna-debug.js b/build/globals/senna-debug.js index fc7f176..37a9d3f 100644 --- a/build/globals/senna-debug.js +++ b/build/globals/senna-debug.js @@ -1,7 +1,7 @@ /** * Senna.js - A blazing-fast Single Page Application engine * @author Liferay, Inc. - * @version v3.0.0-milestone.2 + * @version v3.0.0-milestone.6 * @link http://sennajs.com * @license BSD-3-Clause */ @@ -10554,7 +10554,7 @@ globals.document.addEventListener('DOMContentLoaded', function () { * @returns String containing the current senna version */ -var version = '3.0.0-milestone.2'; +var version = '3.0.0-milestone.6'; exports['default'] = App$1; exports.dataAttributeHandler = dataAttributeHandler; diff --git a/build/globals/senna-min.js b/build/globals/senna-min.js index 36c75c1..bceaf17 100644 --- a/build/globals/senna-min.js +++ b/build/globals/senna-min.js @@ -1,10 +1,10 @@ /** * Senna.js - A blazing-fast Single Page Application engine * @author Liferay, Inc. - * @version v3.0.0-milestone.2 + * @version v3.0.0-milestone.6 * @link http://sennajs.com * @license BSD-3-Clause */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.senna={})}(this,function(e){"use strict";function t(e){return void 0!==e}function n(e){return t(e)&&!a(e)}function r(e){return e&&"object"===("undefined"==typeof e?"undefined":Le(e))&&9===e.nodeType}function i(e){return"function"==typeof e}function a(e){return null===e}function o(e){var t="undefined"==typeof e?"undefined":Le(e);return"object"===t&&null!==e||"function"===t}function u(e){return"string"==typeof e||e instanceof String}function s(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{checkEnv:!0},t="undefined"!=typeof process&&!process.browser;return t&&e.checkEnv&&(t="undefined"!=typeof process.env&&"test"!==process.env.NODE_ENV),t}function l(e){return e=e||[],Array.isArray(e)?e:[e]}function c(e,t){if(o(e)&&u(t)){e.length||(e=[e]);for(var n=0;n"+e,t.removeChild(t.firstChild);for(var n=document.createDocumentFragment();t.firstChild;)n.appendChild(t.firstChild);return n}function k(e,t){return r(e)?e.documentElement.contains(t):e.contains(t)}function E(e,t,n,r,i){var a=Xe[t];return a&&a.delegate&&(t=a.originalEvent,r=a.handler.bind(a,r)),i&&(r=r.bind(),r.defaultListener_=!0),y(e,t),u(n)?v(e,t,n,r):d(n,t,r),new Qe(u(n)?e:n,t,r,u(n)?n:null)}function S(e,t,n){if(n&&"click"===t&&2===n.button)return!1;var r=["BUTTON","INPUT","SELECT","TEXTAREA","FIELDSET"];return!("click"===t&&r.indexOf(e.tagName)>-1)||!(e.disabled||R(e,"fieldset[disabled]"))}function b(e){return n(e)&&"number"==typeof e.length&&"function"==typeof e.item}function P(e){e&&e.parentNode&&e.parentNode.removeChild(e)}function w(e){T(e);var t=!0,n=e.currentTarget,r=[];return t&=q(n,e,r),t&=j(r,e),e.delegateTarget=null,e[$e]=n,t}function A(e,t){if(!e||1!==e.nodeType)return!1;var n=Element.prototype,r=n.matches||n.webkitMatchesSelector||n.mozMatchesSelector||n.msMatchesSelector||n.oMatchesSelector;return r?r.call(e,t):L(e,t)}function L(e,t){var n=e.parentNode;if(n)for(var r=n.querySelectorAll(t),i=0;i0&&void 0!==arguments[0]?arguments[0]:{};et=e}function Y(){return"undefined"!=typeof window&&window.__METAL_COMPATIBILITY__&&$(window.__METAL_COMPATIBILITY__),et}function K(e,t){return e||t}function G(e){if(!e.name){var t=e.toString();e.name=t.substring(9,t.indexOf("("))}return e.name}function J(e,t){var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:K,r=t+"_MERGED";if(!e.hasOwnProperty(r)){var i=e.hasOwnProperty(t)?e[t]:null;e.__proto__&&!e.__proto__.isPrototypeOf(Function)&&(i=n(i,J(e.__proto__,t,n))),e[r]=i}return e[r]}function Z(e,t){if(e){var n=e[nt];return t&&!e.hasOwnProperty(nt)&&(n=null),n||(e[nt]=tt++)}return tt++}function ee(e){return e}function te(e){return"boolean"==typeof e}function ne(e){return void 0!==e}function re(e){return ne(e)&&!se(e)}function ie(e){return e&&"object"===("undefined"==typeof e?"undefined":Le(e))&&9===e.nodeType}function ae(e){return e&&"object"===("undefined"==typeof e?"undefined":Le(e))&&11===e.nodeType}function oe(e){return e&&"object"===("undefined"==typeof e?"undefined":Le(e))&&1===e.nodeType}function ue(e){return"function"==typeof e}function se(e){return null===e}function le(e){return"number"==typeof e}function ce(e){return null!==e&&e===e.window}function he(e){var t="undefined"==typeof e?"undefined":Le(e);return"object"===t&&null!==e||"function"===t}function fe(e){return e&&"object"===("undefined"==typeof e?"undefined":Le(e))&&"function"==typeof e.then}function de(e){return"string"==typeof e||e instanceof String}function ve(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{checkEnv:!0},t="undefined"!=typeof process&&!process.browser;return t&&e.checkEnv&&(t="undefined"!=typeof process.env&&"test"!==process.env.NODE_ENV),t}function pe(){}function ye(e){var t=document.createElement("a");if(t.href=e,":"===t.protocol||!/:/.test(t.href))throw new TypeError(e+" is not a valid URL");return{hash:t.hash,hostname:t.hostname,password:t.password,pathname:"/"===t.pathname[0]?t.pathname:"/"+t.pathname,port:t.port,protocol:t.protocol,search:t.search,username:t.username}}function me(e){if(ue(URL)&&URL.length){var t=new URL(e);if(t.port&&t.href.indexOf(t.port)===-1)throw new TypeError(e+" is not a valid URL");return t}return ye(e)}function ge(e){return e=e||[],Array.isArray(e)?e:[e]}function _e(e){return{match:e[0],prefix:e[1],name:e[2],paramPattern:e[3],unnamedPattern:e[4],modifier:e[5]}}function ke(e){for(var t="",n=0;n1&&void 0!==arguments[1]?arguments[1]:[],r=0;r=0)&&e.removeAt(t,r),i}},{key:"removeAt",value:function(e,t){return 1===Array.prototype.splice.call(e,t,1).length}},{key:"slice",value:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=[],i=t;i1?r-1:0),a=1;a1&&void 0!==arguments[1]?arguments[1]:window,n=e.split(".");return n.reduce(function(e,t){return e[t]},t)}},{key:"map",value:function(e,t){for(var n={},r=Object.keys(e),i=0;i0?n:null}},{key:"removeListener",value:function(){return this.off.apply(this,arguments)}},{key:"runListenerHandlers_",value:function(e){var t=this.listenerHandlers_;if(t){t=l(t);for(var n=0;n>>0),rt=Object.freeze({UID_PROPERTY:nt,abstractMethod:z,disableCompatibilityMode:X,enableCompatibilityMode:$,getCompatibilityModeData:Y,getFunctionName:G,getStaticProperty:J,getUid:Z,identityFunction:ee,isBoolean:te,isDef:ne,isDefAndNotNull:re,isDocument:ie,isDocumentFragment:ae,isElement:oe,isFunction:ue,isNull:se,isNumber:le,isWindow:ce,isObject:he,isPromise:fe,isString:de,isServerSide:ve,nullFunction:pe}),it=function(){function e(){Te(this,e)}return Ce(e,null,[{key:"equal",value:function(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:[],r=0;r=0)&&e.removeAt(t,r),i}},{key:"removeAt",value:function(e,t){return 1===Array.prototype.splice.call(e,t,1).length}},{key:"slice",value:function(e,t){for(var n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.length,r=[],i=t;i1?r-1:0),a=1;a1&&void 0!==arguments[1]?arguments[1]:window,n=e.split(".");return n.reduce(function(e,t){return e[t]},t)}},{key:"map",value:function(e,t){for(var n={},r=Object.keys(e),i=0;i0&&void 0!==arguments[0]?arguments[0]:"";Te(this,e),this.url=e.parse(this.maybeAddProtocolAndHostname_(t))}return Ce(e,[{key:"addParametersFromMultiMap",value:function(e){var t=this;return e.names().forEach(function(n){e.getAll(n).forEach(function(e){t.addParameterValue(n,e)})}),this}},{key:"addParameterValue",value:function(e,t){return this.ensureQueryInitialized_(),ne(t)&&(t=String(t)),this.query.add(e,t),this}},{key:"addParameterValues",value:function(e,t){var n=this;return t.forEach(function(t){return n.addParameterValue(e,t)}),this}},{key:"ensureQueryInitialized_",value:function(){var t=this;if(!this.query){this.query=new ct;var n=this.url.search;n&&n.substring(1).split("&").forEach(function(n){var r=n.split("="),i=He(r,2),a=i[0],o=i[1];ne(o)&&(o=e.urlDecode(o)),t.addParameterValue(a,o)})}}},{key:"getHash",value:function(){return this.url.hash||""}},{key:"getHost",value:function(){var e=this.getHostname();if(e){var t=this.getPort();t&&"80"!==t&&(e+=":"+t)}return e}},{key:"getHostname",value:function(){var t=this.url.hostname;return t===e.HOSTNAME_PLACEHOLDER?"":t}},{key:"getOrigin",value:function(){var e=this.getHost();return e?this.getProtocol()+"//"+e:""}},{key:"getParameterValue",value:function(e){return this.ensureQueryInitialized_(),this.query.get(e)}},{key:"getParameterValues",value:function(e){return this.ensureQueryInitialized_(),this.query.getAll(e)}},{key:"getParameterNames",value:function(){return this.ensureQueryInitialized_(),this.query.names()}},{key:"getPathname",value:function(){return this.url.pathname}},{key:"getPort",value:function(){return this.url.port}},{key:"getProtocol",value:function(){return this.url.protocol}},{key:"getSearch",value:function(){var e=this,t="",n="";return this.getParameterNames().forEach(function(t){e.getParameterValues(t).forEach(function(e){n+=t,ne(e)&&(n+="="+encodeURIComponent(e)),n+="&"})}),n=n.slice(0,-1),n&&(t+="?"+n),t}},{key:"hasParameter",value:function(e){return this.ensureQueryInitialized_(),this.query.contains(e)}},{key:"makeUnique",value:function(){return this.setParameterValue(e.RANDOM_PARAM,st.getRandomString()),this}},{key:"maybeAddProtocolAndHostname_",value:function(t){var n=t;if(t.indexOf("://")===-1&&0!==t.indexOf("javascript:"))switch(n=e.DEFAULT_PROTOCOL,"/"===t[0]&&"/"===t[1]||(n+="//"),t.charAt(0)){case".":case"?":case"#":n+=e.HOSTNAME_PLACEHOLDER,n+="/",n+=t;break;case"":case"/":"/"!==t[1]&&(n+=e.HOSTNAME_PLACEHOLDER),n+=t;break;default:n+=t}return n}},{key:"removeParameter",value:function(e){return this.ensureQueryInitialized_(),this.query.remove(e),this}},{key:"removeUnique",value:function(){return this.removeParameter(e.RANDOM_PARAM),this}},{key:"setHash",value:function(e){return this.url.hash=e,this}},{key:"setHostname",value:function(e){return this.url.hostname=e,this}},{key:"setParameterValue",value:function(e,t){return this.removeParameter(e),this.addParameterValue(e,t),this}},{key:"setParameterValues",value:function(e,t){var n=this;return this.removeParameter(e),t.forEach(function(t){return n.addParameterValue(e,t)}),this}},{key:"setPathname",value:function(e){return this.url.pathname=e,this}},{key:"setPort",value:function(e){return this.url.port=e,this}},{key:"setProtocol",value:function(e){return this.url.protocol=e,":"!==this.url.protocol[this.url.protocol.length-1]&&(this.url.protocol+=":"),this}},{key:"toString",value:function(){var e="",t=this.getHost();return t&&(e+=this.getProtocol()+"//"),e+=t+this.getPathname()+this.getSearch()+this.getHash()}}],[{key:"getParseFn",value:function(){return dt}},{key:"parse",value:function(e){return dt(e)}},{key:"setParseFn",value:function(e){dt=e}},{key:"joinPaths",value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;r1&&"/"===e[t-1]&&(e=e.substr(0,t-1)),e}},{key:"setElementWithRandomHref",value:function(e){return e.href=e.href+"?q="+Math.random(),e}},{key:"setReferrer",value:function(e){Object.defineProperty(Ze.document,"referrer",{configurable:!0,get:function(){return e}})}}]),e}(),mt={basePath:"data-senna-base-path",linkSelector:"data-senna-link-selector",loadingCssClass:"data-senna-loading-css-class",senna:"data-senna",dispatch:"data-senna-dispatch",surface:"data-senna-surface",updateScrollPosition:"data-senna-update-scroll-position"},gt=function(e){function t(e,n,r){Te(this,t);var i=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return i.emitter_=e,i.event_=n,i.listener_=r,i}return Re(t,e),Ce(t,[{key:"disposeInternal",value:function(){this.removeListener(),this.emitter_=null,this.listener_=null}},{key:"removeListener",value:function(){this.emitter_.isDisposed()||this.emitter_.removeListener(this.event_,this.listener_)}}]),t}(ot),_t=[0],kt=function(e){function t(){Te(this,t);var e=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.events_=null,e.listenerHandlers_=null,e.shouldUseFacade_=!1,e}return Re(t,e),Ce(t,[{key:"addHandler_",value:function(e,t){return e?(Array.isArray(e)||(e=[e]),e.push(t)):e=t,e}},{key:"addListener",value:function(e,t,n){this.validateListener_(t);for(var r=this.toEventsArray_(e),i=0;i0?n:null}},{key:"removeListener",value:function(){return this.off.apply(this,arguments)}},{key:"runListenerHandlers_",value:function(e){var t=this.listenerHandlers_;if(t){t=ge(t);for(var n=0;n-1)}}]),e}(),Pt=function(e){function t(){Te(this,t);var e=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.cache=null,e.cacheable=!1,e}return Re(t,e),Ce(t,[{key:"addCache",value:function(e){return this.cacheable&&(this.cache=e),this}},{key:"clearCache",value:function(){return this.cache=null,this}},{key:"disposeInternal",value:function(){this.clearCache()}},{key:"getCache",value:function(){return this.cache}},{key:"isCacheable",value:function(){return this.cacheable}},{key:"setCacheable",value:function(e){e||this.clearCache(),this.cacheable=e}}]),t}(ot),wt=function(e){function t(){Te(this,t);var e=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.id=e.makeId_(Z()),e.metas=null,e.title=null,e}return Re(t,e),Ce(t,[{key:"activate",value:function(){}},{key:"beforeActivate",value:function(){}},{key:"beforeDeactivate",value:function(){}},{key:"beforeUpdateHistoryPath",value:function(e){return e}},{key:"beforeUpdateHistoryState",value:function(e){return e}},{key:"deactivate",value:function(){}},{key:"disposeInternal",value:function(){Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"disposeInternal",this).call(this)}},{key:"evaluateScripts",value:function(e){var t=[];return Object.keys(e).forEach(function(n){e[n].activeChild&&t.push(new Promise(function(t){Ge.runScriptsInElement(e[n].activeChild,function(){return t()})}))}),Promise.all(t)}},{key:"evaluateStyles",value:function(){return Promise.resolve()}},{key:"flip",value:function(e){var t=this,n=[];return Object.keys(e).forEach(function(r){var i=e[r],a=i.show(t.id);n.push(a)}),Promise.all(n)}},{key:"getId",value:function(){return this.id}},{key:"getMetas",value:function(){return this.metas}},{key:"getSurfaceContent",value:function(){}},{key:"getTitle",value:function(){return this.title}},{key:"load",value:function(){return Promise.resolve()}},{key:"makeId_",value:function(e){return"screen_"+e}},{key:"setId",value:function(e){this.id=e}},{key:"setMetas",value:function(e){this.metas=e}},{key:"setTitle",value:function(e){this.title=e}},{key:"toString",value:function(){return this.id}}]),t}(Pt);wt.isImplementedBy=function(e){return e instanceof wt};var At=function(e){function t(e){Te(this,t);var n=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));if(!e)throw new Error("Surface element id not specified. A surface element requires a valid id.");return n.activeChild=null,n.defaultChild=null,n.element=null,n.id=e,n.transitionFn=null,n.defaultChild=n.getChild(t.DEFAULT),n.maybeWrapContentAsDefault_(),n.activeChild=n.defaultChild,n}return Re(t,e),Ce(t,[{key:"addContent",value:function(e,t){var n=this.defaultChild;re(t)&&(n=this.getChild(e),n?H(n):(n=this.createChild(e),this.transition(n,null)),g(n,t));var r=this.getElement();return r&&n&&g(r,n),n}},{key:"createChild",value:function(e){var t=Ze.document.createElement("div");return t.setAttribute("id",this.makeId_(e)),t}},{key:"getChild",value:function(e){return Ze.document.getElementById(this.makeId_(e))}},{key:"getElement",value:function(){return this.element?this.element:(this.element=Ze.document.getElementById(this.id),this.element)}},{key:"getId",value:function(){return this.id}},{key:"getTransitionFn",value:function(){return this.transitionFn}},{key:"makeId_",value:function(e){return this.id+"-"+e}},{key:"maybeWrapContentAsDefault_",value:function(){var e=this.getElement();if(e&&!this.defaultChild){for(var n=Ze.document.createDocumentFragment();e.firstChild;)n.appendChild(e.firstChild);this.defaultChild=this.addContent(t.DEFAULT,n),this.transition(null,this.defaultChild)}}},{key:"setId",value:function(e){this.id=e}},{key:"setTransitionFn",value:function(e){this.transitionFn=e}},{key:"show",value:function(e){var t=this.activeChild,n=this.getChild(e);n||(n=this.defaultChild),this.activeChild=n;var r=function(){t&&t!==n&&P(t)};return this.transition(t,n).then(r)["catch"](r)}},{key:"remove",value:function(e){var t=this.getChild(e);t&&P(t)}},{key:"toString",value:function(){return this.id}},{key:"transition",value:function(e,n){var r=this.transitionFn||t.defaultTransition;return Promise.resolve(r.call(this,e,n))}}]),t}(ot);At.DEFAULT="default",At.defaultTransition=function(e,t){e&&(e.style.display="none",e.classList.remove("flipped")),t&&(t.style.display="block",t.classList.add("flipped"))};var Lt={IMMEDIATE:"immediate",SCHEDULE_LAST:"scheduleLast"},Tt=function(e){function t(){Te(this,t);var e=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.activeScreen=null,e.activePath=null,e.allowPreventNavigate=!0,e.basePath="",e.browserPathBeforeNavigate=yt.getCurrentBrowserPathWithoutHash(),e.captureScrollPositionFromScrollEvent=!0,e.defaultTitle=Ze.document.title,e.formSelector='form[enctype="multipart/form-data"]:not([data-senna-off])',e.ignoreQueryStringFromRoutePath=!1,e.linkSelector='a:not([data-senna-off]):not([target="_blank"])',e.loadingCssClass="senna-loading",e.nativeScrollRestorationSupported="scrollRestoration"in Ze.window.history,e.navigationStrategy=Lt.IMMEDIATE,e.isNavigationPending=!1,e.pendingNavigate=null,e.popstateScrollLeft=0,e.popstateScrollTop=0,e.redirectPath=null,e.routes=[],e.scheduledNavigationQueue=[],e.screens={},e.skipLoadPopstate=!1,e.surfaces={},e.updateScrollPosition=!0,e.appEventHandlers_=new Et,e.appEventHandlers_.add(C(Ze.window,"scroll",yt.debounce(e.onScroll_.bind(e),100)),C(Ze.window,"load",e.onLoad_.bind(e)),C(Ze.window,"popstate",e.onPopstate_.bind(e))),e.on("startNavigate",e.onStartNavigate_),e.on("beforeNavigate",e.onBeforeNavigate_),e.on("beforeNavigate",e.onBeforeNavigateDefault_,!0),e.on("beforeUnload",e.onBeforeUnloadDefault_),e.setLinkSelector(e.linkSelector),e.setFormSelector(e.formSelector),e.maybeOverloadBeforeUnload_(),e}return Re(t,e),Ce(t,[{key:"addRoutes",value:function(e){var t=this;return Array.isArray(e)||(e=[e]),e.forEach(function(e){e instanceof bt||(e=new bt(e.path,e.handler)),t.routes.push(e)}),this}},{key:"addSurfaces",value:function(e){var t=this;return Array.isArray(e)||(e=[e]),e.forEach(function(e){de(e)&&(e=new At(e)),t.surfaces[e.getId()]=e}),this}},{key:"canNavigate",value:function(e){var t=yt.isWebUri(e);if(!t)return!1;var n=yt.getUrlPath(e);return!!this.isLinkSameOrigin_(t.getHost())&&(!!this.isSameBasePath_(n)&&((!t.getHash()||!yt.isCurrentBrowserPath(n))&&!!this.findRoute(n)))}},{key:"clearScreensCache",value:function(){var e=this;Object.keys(this.screens).forEach(function(t){t===e.activePath?e.activeScreen.clearCache():e.isNavigationPending&&e.pendingNavigate.path===t||e.removeScreen(t)})}},{key:"createScreenInstance",value:function(e,t){if(!this.pendingNavigate&&e===this.activePath)return this.activeScreen;var n=this.screens[e];if(!n){var r=t.getHandler();n=r===wt||wt.isImplementedBy(r.prototype)?new r:r(t)||new wt}return n}},{key:"disposeInternal",value:function(){this.activeScreen&&this.removeScreen(this.activePath),this.clearScreensCache(),this.formEventHandler_.removeListener(),this.linkEventHandler_.removeListener(),this.appEventHandlers_.removeAllListeners(),Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"disposeInternal",this).call(this)}},{key:"dispatch",value:function(){return this.navigate(yt.getCurrentBrowserPath(),!0)}},{key:"doNavigate_",value:function(e,t){var n=this,r=this.findRoute(e);if(!r)return this.pendingNavigate=Promise.reject(new Error("No route for "+e)),this.pendingNavigate;this.stopPendingNavigate_(),this.isNavigationPending=!0;var i=this.createScreenInstance(e,r),a=function(){if(n.navigationStrategy=Lt.IMMEDIATE,n.scheduledNavigationQueue.length){var e=n.scheduledNavigationQueue.shift();n.maybeNavigate_(e.href,e)}};return this.maybePreventDeactivate_().then(function(){return n.maybePreventActivate_(i)}).then(function(){return i.load(e)}).then(function(){n.navigationStrategy=Lt.SCHEDULE_LAST,n.activeScreen&&n.activeScreen.deactivate(),n.prepareNavigateHistory_(e,i,t),n.prepareNavigateSurfaces_(i,n.surfaces,n.extractParams(r,e))}).then(function(){return i.evaluateStyles(n.surfaces)}).then(function(){return i.flip(n.surfaces)}).then(function(){return i.evaluateScripts(n.surfaces)}).then(function(){return n.maybeUpdateScrollPositionState_()}).then(function(){return n.syncScrollPositionSyncThenAsync_()}).then(function(){return n.finalizeNavigate_(e,i)}).then(function(){return n.maybeOverloadBeforeUnload_()}).then(function(){a()})["catch"](function(t){throw n.isNavigationPending=!1,n.handleNavigateError_(e,i,t),a(),t})}},{key:"extractParams",value:function(e,t){return e.extractParams(this.getRoutePath(t))}},{key:"finalizeNavigate_",value:function(e,t){t.activate(),this.activeScreen&&!this.activeScreen.isCacheable()&&this.activeScreen!==t&&this.removeScreen(this.activePath),this.activePath=e,this.activeScreen=t,this.browserPathBeforeNavigate=yt.getCurrentBrowserPathWithoutHash(),this.screens[e]=t,this.isNavigationPending=!1,this.pendingNavigate=null,Ze.capturedFormElement=null,Ze.capturedFormButtonElement=null}},{key:"findRoute",value:function(e){e=this.getRoutePath(e);for(var t=0;t0}},{key:"isLinkSameOrigin_",value:function(e){var t=new vt(e),n=new vt(Ze.window.location.host);return t.getPort()===n.getPort()&&t.getHostname()===n.getHostname()}},{key:"isSameBasePath_",value:function(e){return 0===e.indexOf(this.basePath)}},{key:"lockHistoryScrollPosition_",value:function(){var e=Ze.window.history.state;if(e){var t=!1,n=function r(){Ze.document.removeEventListener("scroll",r,!1),t||(Ze.window.scrollTo(e.scrollLeft,e.scrollTop),t=!0)};at.nextTick(n),Ze.document.addEventListener("scroll",n,!1)}}},{key:"maybeDisableNativeScrollRestoration",value:function(){this.nativeScrollRestorationSupported&&(this.nativeScrollRestoration_=Ze.window.history.scrollRestoration,Ze.window.history.scrollRestoration="manual")}},{key:"maybeScheduleNavigation_",value:function(e,t){return!(!this.isNavigationPending||this.navigationStrategy!==Lt.SCHEDULE_LAST)&&(this.scheduledNavigationQueue=[ut.mixin({href:e,isScheduledNavigation:!0},t)],!0)}},{key:"maybeNavigate_",value:function(e,t){if(this.canNavigate(e)){var n=this.maybeScheduleNavigation_(e,t);if(n)return void t.preventDefault();var r=!1;try{this.navigate(yt.getUrlPath(e),!1,t)}catch(i){r=!0}r||t.isScheduledNavigation||t.preventDefault()}}},{key:"maybeOverloadBeforeUnload_",value:function(){var e=this;"function"==typeof window.onbeforeunload&&(window._onbeforeunload=window.onbeforeunload,window.onbeforeunload=function(t){if(e.emit("beforeUnload",t),t&&t.defaultPrevented)return!0},window.onbeforeunload._overloaded=!0)}},{key:"maybePreventActivate_",value:function(e){var t=this;return Promise.resolve().then(function(){return e.beforeActivate()}).then(function(e){if(e)return t.pendingNavigate=Promise.reject("Cancelled by next screen"),t.pendingNavigate})}},{key:"maybePreventDeactivate_",value:function(){var e=this;return Promise.resolve().then(function(){if(e.activeScreen)return e.activeScreen.beforeDeactivate()}).then(function(t){if(t)return e.pendingNavigate=Promise.reject(new Error("Cancelled by active screen")),e.pendingNavigate})}},{key:"maybeRepositionScrollToHashedAnchor",value:function(){var e=Ze.window.location.hash;if(e){var t=Ze.document.getElementById(e.substring(1));if(t){var n=yt.getNodeOffset(t),r=n.offsetLeft,i=n.offsetTop;Ze.window.scrollTo(r,i)}}}},{key:"maybeRestoreNativeScrollRestoration",value:function(){this.nativeScrollRestorationSupported&&this.nativeScrollRestoration_&&(Ze.window.history.scrollRestoration=this.nativeScrollRestoration_)}},{key:"maybeRestoreRedirectPathHash_",value:function(e,t,n){return t===yt.getUrlPathWithoutHash(e)?t+n:t}},{key:"maybeUpdateScrollPositionState_",value:function(){var e=Ze.window.location.hash,t=Ze.document.getElementById(e.substring(1));if(t){var n=yt.getNodeOffset(t),r=n.offsetLeft,i=n.offsetTop;this.saveHistoryCurrentPageScrollPosition_(i,r)}}},{key:"navigate",value:function(e,t,n){if(!yt.isHtml5HistorySupported())throw new Error("HTML5 History is not supported. Senna will not intercept navigation.");return n&&(Ze.capturedFormElement=n.capturedFormElement,Ze.capturedFormButtonElement=n.capturedFormButtonElement),e===this.activePath&&(t=!0),this.emit("beforeNavigate",{event:n,path:e,replaceHistory:!!t}),this.pendingNavigate}},{key:"onBeforeNavigate_",value:function(e){Ze.capturedFormElement&&(e.form=Ze.capturedFormElement)}},{key:"onBeforeNavigateDefault_",value:function(e){(!this.pendingNavigate||this.pendingNavigate.path!==e.path&&this.navigationStrategy!==Lt.SCHEDULE_LAST)&&(this.emit("beforeUnload",e),this.emit("startNavigate",{form:e.form,path:e.path,replaceHistory:e.replaceHistory}))}},{key:"onBeforeUnloadDefault_",value:function(e){var t=window._onbeforeunload;t&&!t._overloaded&&t()&&e.preventDefault()}},{key:"onDocClickDelegate_",value:function(e){e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||e.button||this.maybeNavigate_(e.delegateTarget.href,e)}},{key:"onDocSubmitDelegate_",value:function(e){var t=e.delegateTarget;if("get"!==t.method){e.capturedFormElement=t;var n="button:not([type]),button[type=submit],input[type=submit]";A(Ze.document.activeElement,n)?e.capturedFormButtonElement=Ze.document.activeElement:e.capturedFormButtonElement=t.querySelector(n),this.maybeNavigate_(t.action,e)}}},{key:"onLoad_",value:function(){var e=this;this.skipLoadPopstate=!0,setTimeout(function(){e.skipLoadPopstate=!1},0),this.maybeRepositionScrollToHashedAnchor()}},{key:"onPopstate_",value:function(e){if(!this.skipLoadPopstate){if(yt.isCurrentBrowserPath(this.browserPathBeforeNavigate))return void this.maybeRepositionScrollToHashedAnchor();var t=e.state;if(!t)return void(Ze.window.location.hash?(this.redirectPath&&!yt.isCurrentBrowserPath(this.redirectPath)&&this.reloadPage(),this.maybeRepositionScrollToHashedAnchor()):this.reloadPage());if(t.senna){this.popstateScrollTop=t.scrollTop,this.popstateScrollLeft=t.scrollLeft,this.nativeScrollRestorationSupported||this.lockHistoryScrollPosition_(),this.once("endNavigate",function(){t.referrer&&yt.setReferrer(t.referrer)});var n=new vt(t.path);n.setHostname(Ze.window.location.hostname),n.setPort(Ze.window.location.port);var r=this.maybeScheduleNavigation_(n.toString(),{});if(r)return;this.navigate(t.path,!0)}}}},{key:"onScroll_",value:function(){this.captureScrollPositionFromScrollEvent&&this.saveHistoryCurrentPageScrollPosition_(Ze.window.pageYOffset,Ze.window.pageXOffset); -}},{key:"onStartNavigate_",value:function(e){var t=this;this.maybeDisableNativeScrollRestoration(),this.captureScrollPositionFromScrollEvent=!1,c(Ze.document.documentElement,this.loadingCssClass);var n={form:e.form,path:e.path},r=function(e){t.pendingNavigate||t.scheduledNavigationQueue.length||(I(Ze.document.documentElement,t.loadingCssClass),t.maybeRestoreNativeScrollRestoration(),t.captureScrollPositionFromScrollEvent=!0),t.emit("endNavigate",e)};this.pendingNavigate=this.doNavigate_(e.path,e.replaceHistory).then(function(){r(n)})["catch"](function(e){throw n.error=e,r(n),e}),this.pendingNavigate.path=e.path}},{key:"prefetch",value:function(e){var t=this,n=this.findRoute(e);if(!n)return Promise.reject(new Error("No route for "+e));var r=this.createScreenInstance(e,n);return r.load(e).then(function(){return t.screens[e]=r})["catch"](function(n){throw t.handleNavigateError_(e,r,n),n})}},{key:"prepareNavigateHistory_",value:function(e,t,n){var r=t.getTitle();de(r)||(r=this.getDefaultTitle());var i=t.beforeUpdateHistoryPath(e),a=new vt(e).getHash();i=this.maybeRestoreRedirectPathHash_(e,i,a);var o={form:re(Ze.capturedFormElement),path:e,redirectPath:i,scrollLeft:0,scrollTop:0,senna:!0};n&&(o.scrollTop=this.popstateScrollTop,o.scrollLeft=this.popstateScrollLeft),this.updateHistory_(r,i,t.beforeUpdateHistoryState(o),n),this.redirectPath=i}},{key:"prepareNavigateSurfaces_",value:function(e,t,n){Object.keys(t).forEach(function(r){var i=e.getSurfaceContent(r,n);t[r].addContent(e.getId(),i)})}},{key:"reloadPage",value:function(){Ze.window.location.reload()}},{key:"removeRoute",value:function(e){return it.remove(this.routes,e)}},{key:"removeScreen",value:function(e){var t=this,n=this.screens[e];n&&(Object.keys(this.surfaces).forEach(function(e){return t.surfaces[e].remove(n.getId())}),n.dispose(),delete this.screens[e])}},{key:"saveHistoryCurrentPageScrollPosition_",value:function(e,t){var n=Ze.window.history.state;if(n&&n.senna){var r=[e,t];n.scrollTop=r[0],n.scrollLeft=r[1],Ze.window.history.replaceState(n,null,null)}}},{key:"setAllowPreventNavigate",value:function(e){this.allowPreventNavigate=e}},{key:"setBasePath",value:function(e){this.basePath=yt.removePathTrailingSlash(e)}},{key:"setDefaultTitle",value:function(e){this.defaultTitle=e}},{key:"setFormSelector",value:function(e){this.formSelector=e,this.formEventHandler_&&this.formEventHandler_.removeListener(),this.formEventHandler_=E(document,"submit",this.formSelector,this.onDocSubmitDelegate_.bind(this),this.allowPreventNavigate)}},{key:"setIgnoreQueryStringFromRoutePath",value:function(e){this.ignoreQueryStringFromRoutePath=e}},{key:"setLinkSelector",value:function(e){this.linkSelector=e,this.linkEventHandler_&&this.linkEventHandler_.removeListener(),this.linkEventHandler_=E(document,"click",this.linkSelector,this.onDocClickDelegate_.bind(this),this.allowPreventNavigate)}},{key:"setLoadingCssClass",value:function(e){this.loadingCssClass=e}},{key:"setUpdateScrollPosition",value:function(e){this.updateScrollPosition=e}},{key:"stopPendingNavigate_",value:function(){this.pendingNavigate=null}},{key:"syncScrollPositionSyncThenAsync_",value:function(){var e=this,t=Ze.window.history.state;if(t){var n=t.scrollTop,r=t.scrollLeft,i=function(){e.updateScrollPosition&&Ze.window.scrollTo(r,n)};return new Promise(function(e){i(),setTimeout(function(){i(),e()},0)})}}},{key:"updateHistory_",value:function(e,t,n,r){var i=Ze.window.location.href;n&&(n.referrer=i),r?Ze.window.history.replaceState(n,e,t):Ze.window.history.pushState(n,e,t),yt.setReferrer(i);var a=Ze.document.querySelector("title");a?a.innerHTML=e:Ze.document.title=e}}]),t}(kt),Ct=function Ut(){Te(this,Ut)};Ct.INVALID_STATUS="Invalid status code",Ct.REQUEST_ERROR="Request error",Ct.REQUEST_TIMEOUT="Request timeout",Ct.REQUEST_PREMATURE_TERMINATION="Request terminated prematurely";var Ot=function(e){function t(){Te(this,t);var e=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.cacheable=!0,e.httpHeaders={"X-PJAX":"true","X-Requested-With":"XMLHttpRequest"},e.httpMethod=t.GET,e.request=null,e.timeout=3e4,e}return Re(t,e),Ce(t,[{key:"assertValidResponseStatusCode",value:function(e){if(!this.isValidResponseStatusCode(e)){var t=new Error(Ct.INVALID_STATUS);throw t.invalidStatus=!0,t.statusCode=e,t}}},{key:"beforeUpdateHistoryPath",value:function(e){var t=this.getRequestPath();return t&&t!==e?t:e}},{key:"beforeUpdateHistoryState",value:function(e){return e.senna&&e.form&&e.redirectPath===e.path?null:e}},{key:"formatLoadPath",value:function(e){var n=new vt(e);return n.setHostname(Ze.window.location.hostname),n.setProtocol(Ze.window.location.protocol),Ze.window.location.port&&n.setPort(Ze.window.location.port),yt.isIeOrEdge()&&this.httpMethod===t.GET?n.makeUnique().toString():n.toString()}},{key:"getHttpHeaders",value:function(){return this.httpHeaders}},{key:"getHttpMethod",value:function(){return this.httpMethod}},{key:"getRequestPath",value:function(){var e=this.getRequest();if(e){var n=e.url,r=this.maybeExtractResponseUrlFromRequest(e);return r&&(n=r),yt.isIeOrEdge()&&this.httpMethod===t.GET&&(n=new vt(n).removeUnique().toString()),yt.getUrlPath(n)}return null}},{key:"getRequest",value:function(){return this.request}},{key:"getTimeout",value:function(){return this.timeout}},{key:"isValidResponseStatusCode",value:function(e){return e>=200&&e<=399}},{key:"getFormData",value:function(e,t){var n=new FormData(e);return this.maybeAppendSubmitButtonValue_(n,t),n}},{key:"load",value:function(e){var n=this,r=this.getCache();if(re(r))return Promise.resolve(r);var i=null,a=this.httpMethod,o=new Headers;Object.keys(this.httpHeaders).forEach(function(e){o.set(e,n.httpHeaders[e])}),Ze.capturedFormElement&&(this.addSafariXHRPolyfill(),i=this.getFormData(Ze.capturedFormElement,Ze.capturedFormButtonElement),a=t.POST,yt.isIeOrEdge()&&o.append("If-None-Match",'"0"'));var u=this.formatLoadPath(e),s=new Request(u,{body:i,credentials:"include",headers:o,method:a,mode:"cors",redirect:"follow",referrer:"client"});return this.setRequest(s),Promise.race([fetch(s).then(function(e){return n.removeSafariXHRPolyfill(),n.assertValidResponseStatusCode(e.status),e.clone().text()}).then(function(e){return a===t.GET&&n.isCacheable()&&n.addCache(e),e}),new Promise(function(e,t){setTimeout(function(){return t(new Error(Ct.REQUEST_TIMEOUT))},n.timeout)})])["catch"](function(e){switch(n.removeSafariXHRPolyfill(),e.message){case Ct.REQUEST_TIMEOUT:e.timeout=!0;break;case Ct.REQUEST_ERROR:e.requestError=!0;break;case Ct.REQUEST_PREMATURE_TERMINATION:e.requestError=!0,e.requestPrematureTermination=!0}throw e})}},{key:"maybeAppendSubmitButtonValue_",value:function(e,t){t&&t.name&&e.append(t.name,t.value)}},{key:"maybeExtractResponseUrlFromRequest",value:function(e){return e.headers.get(t.X_REQUEST_URL_HEADER)}},{key:"addSafariXHRPolyfill",value:function(){if(Ze.capturedFormElement&&yt.isSafari())for(var e=Ze.capturedFormElement.querySelectorAll('input[type="file"]:not([disabled])'),t=0;t0)return;n.setAttribute("data-safari-temp-disabled","true"),n.setAttribute("disabled","")}}},{key:"removeSafariXHRPolyfill",value:function(){if(Ze.capturedFormElement&&yt.isSafari())for(var e=Ze.capturedFormElement.querySelectorAll('input[type="file"][data-safari-temp-disabled]'),t=0;t/gi,"/senna>");var n=void 0;if(yt.isIe()){var r=Ze.document.createRange().createContextualFragment(e);n=r.querySelector("senna")}else t.innerHTML=e,n=t.querySelector("senna");n&&(yt.clearNodeAttributes(t),yt.copyNodeAttributes(n,t))}},{key:"disposeInternal",value:function(){this.disposePendingStyles(),Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"disposeInternal",this).call(this)}},{key:"disposePendingStyles",value:function(){this.pendingStyles&&yt.removeElementsFromDocument(this.pendingStyles)}},{key:"evaluateScripts",value:function(e){var n=this,r=this.evaluateTrackedResources_(Ge.runScriptsInElement,t.selectors.scripts,t.selectors.scriptsTemporary,t.selectors.scriptsPermanent);return r.then(function(){return Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"evaluateScripts",n).call(n,e)})}},{key:"evaluateStyles",value:function(e){var n=this;this.pendingStyles=[];var r=this.evaluateTrackedResources_(Je.runStylesInElement,t.selectors.styles,t.selectors.stylesTemporary,t.selectors.stylesPermanent,this.appendStyleIntoDocument_.bind(this));return r.then(function(){return Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"evaluateStyles",n).call(n,e)})}},{key:"evaluateFavicon_",value:function(){var e=this,n=this.virtualQuerySelectorAll_(t.selectors.favicon),r=this.querySelectorAll_(t.selectors.favicon);return new Promise(function(t){yt.removeElementsFromDocument(r),e.runFaviconInElement_(n).then(function(){return t()})})}},{key:"evaluateTrackedResources_",value:function(e,n,r,i,a){var o=this,u=this.virtualQuerySelectorAll_(n),s=this.querySelectorAll_(r),l=this.querySelectorAll_(i);l.forEach(function(e){var n=o.getResourceKey_(e);n&&(t.permanentResourcesInDoc[n]=!0)});var c=_();return u.forEach(function(e){var n=o.getResourceKey_(e);t.permanentResourcesInDoc[n]||c.appendChild(e),n&&A(e,i)&&(t.permanentResourcesInDoc[n]=!0)}),new Promise(function(t){e(c,function(){yt.removeElementsFromDocument(s),t()},a)})}},{key:"flip",value:function(e){var n=this;return Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"flip",this).call(this,e).then(function(){yt.clearNodeAttributes(Ze.document.documentElement),yt.copyNodeAttributes(n.virtualDocument,Ze.document.documentElement),n.evaluateFavicon_(),n.updateMetaTags_()})}},{key:"updateMetaTags_",value:function(){var e=this.querySelectorAll_("meta"),t=this.metas;e&&(yt.removeElementsFromDocument(e),t&&t.forEach(function(e){return Ze.document.head.appendChild(e)}))}},{key:"getResourceKey_",value:function(e){return e.id||e.href||e.src||""}},{key:"getSurfaceContent",value:function(e){var t=this.virtualDocument.querySelector("#"+e);if(t){var n=t.querySelector("#"+e+"-"+At.DEFAULT);return n?n.innerHTML:t.innerHTML}}},{key:"getTitleSelector",value:function(){return this.titleSelector}},{key:"load",value:function(e){var n=this;return Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"load",this).call(this,e).then(function(e){return n.allocateVirtualDocumentForContent(e),n.resolveTitleFromVirtualDocument(),n.resolveMetaTagsFromVirtualDocument(),n.assertSameBodyIdInVirtualDocument(),yt.isIe()&&n.makeTemporaryStylesHrefsUnique_(),e})}},{key:"makeTemporaryStylesHrefsUnique_",value:function(){var e=this,n=this.virtualQuerySelectorAll_(t.selectors.stylesTemporary);n.forEach(function(t){return e.replaceStyleAndMakeUnique_(t)})}},{key:"replaceStyleAndMakeUnique_",value:function(e){if(e.href){var t=Ze.document.createElement(e.tagName);e.href=new vt(e.href).makeUnique().toString(),yt.copyNodeAttributes(e,t),e.parentNode.replaceChild(t,e),e.disabled=!0}}},{key:"runFaviconInElement_",value:function(e){return new Promise(function(t){e.forEach(function(e){return document.head.appendChild(yt.isIe()?e:yt.setElementWithRandomHref(e))}),t()})}},{key:"virtualQuerySelectorAll_",value:function(e){return Array.prototype.slice.call(this.virtualDocument.querySelectorAll(e))}},{key:"querySelectorAll_",value:function(e){return Array.prototype.slice.call(Ze.document.querySelectorAll(e))}},{key:"releaseVirtualDocument",value:function(){this.virtualDocument=null}},{key:"resolveTitleFromVirtualDocument",value:function(){var e=this.virtualDocument.querySelector(this.titleSelector);e&&this.setTitle(e.textContent.trim())}},{key:"resolveMetaTagsFromVirtualDocument",value:function(){var e=this.virtualQuerySelectorAll_(this.metaTagsSelector);e&&this.setMetas(e)}},{key:"setTitleSelector",value:function(e){this.titleSelector=e}}]),t}(Ot),Nt=':not([rel="Shortcut Icon"]):not([rel="shortcut icon"]):not([rel="icon"]):not([href$="favicon.icon"])';Rt.selectors={favicon:'link[rel="Shortcut Icon"],link[rel="shortcut icon"],link[rel="icon"],link[href$="favicon.icon"]',scripts:"script[data-senna-track]",scriptsPermanent:'script[data-senna-track="permanent"]',scriptsTemporary:'script[data-senna-track="temporary"]',styles:"style[data-senna-track],link[data-senna-track]"+Nt,stylesPermanent:'style[data-senna-track="permanent"],link[data-senna-track="permanent"]'+Nt,stylesTemporary:'style[data-senna-track="temporary"],link[data-senna-track="temporary"]'+Nt},Rt.permanentResourcesInDoc={};var Ht=function(e){function t(){Te(this,t);var e=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.app=null,e.baseElement=null,e}return Re(t,e),Ce(t,[{key:"handle",value:function(){if(!oe(this.baseElement))throw new Error("Senna data attribute handler base element not set or invalid, try setting a valid element that contains a `data-senna` attribute.");if(this.baseElement.hasAttribute(mt.senna)){if(this.app)throw new Error("Senna app was already initialized.");this.app=new Tt,this.maybeAddRoutes_(),this.maybeAddSurfaces_(),this.maybeSetBasePath_(),this.maybeSetLinkSelector_(),this.maybeSetLoadingCssClass_(),this.maybeSetUpdateScrollPosition_(),this.maybeDispatch_()}}},{key:"disposeInternal",value:function(){this.app&&this.app.dispose()}},{key:"getApp",value:function(){return this.app}},{key:"getBaseElement",value:function(){return this.baseElement}},{key:"maybeAddRoutes_",value:function(){var e=this,t='link[rel="senna-route"]';this.querySelectorAllAsArray_(t).forEach(function(t){return e.maybeParseLinkRoute_(t)}),this.app.hasRoutes()||this.app.addRoutes(new bt(/.*/,Rt))}},{key:"maybeAddSurfaces_",value:function(){var e=this,t="["+mt.surface+"]";this.querySelectorAllAsArray_(t).forEach(function(t){e.updateElementIdIfSpecialSurface_(t),e.app.addSurfaces(t.id)})}},{key:"maybeDispatch_",value:function(){this.baseElement.hasAttribute(mt.dispatch)&&this.app.dispatch()}},{key:"maybeParseLinkRoute_",value:function(e){var t=new bt(this.maybeParseLinkRoutePath_(e),this.maybeParseLinkRouteHandler_(e));this.app.addRoutes(t)}},{key:"maybeParseLinkRouteHandler_",value:function(e){var t=e.getAttribute("type");return re(t)&&(t=ut.getObjectByName(t)),t}},{key:"maybeParseLinkRoutePath_",value:function(e){var t=e.getAttribute("href");return re(t)&&0===t.indexOf("regex:")&&(t=new RegExp(t.substring(6))),t}},{key:"maybeSetBasePath_",value:function(){var e=this.baseElement.getAttribute(mt.basePath);re(e)&&this.app.setBasePath(e)}},{key:"maybeSetLinkSelector_",value:function(){var e=this.baseElement.getAttribute(mt.linkSelector);re(e)&&this.app.setLinkSelector(e)}},{key:"maybeSetLoadingCssClass_",value:function(){var e=this.baseElement.getAttribute(mt.loadingCssClass);re(e)&&this.app.setLoadingCssClass(e)}},{key:"maybeSetUpdateScrollPosition_",value:function(){var e=this.baseElement.getAttribute(mt.updateScrollPosition);re(e)&&("false"===e?this.app.setUpdateScrollPosition(!1):this.app.setUpdateScrollPosition(!0))}},{key:"querySelectorAllAsArray_",value:function(e){return Array.prototype.slice.call(Ze.document.querySelectorAll(e))}},{key:"updateElementIdIfSpecialSurface_",value:function(e){e.id||e!==Ze.document.body||(e.id="senna_surface_"+Z())}},{key:"setBaseElement",value:function(e){this.baseElement=e}}]),t}(ot),It=new Ht;Ze.document.addEventListener("DOMContentLoaded",function(){It.setBaseElement(Ze.document.body),It.handle()});var xt="3.0.0-milestone.2";e["default"]=Tt,e.dataAttributeHandler=It,e.utils=yt,e.App=Tt,e.HtmlScreen=Rt,e.Route=bt,e.RequestScreen=Ot,e.Screen=wt,e.version=xt,Object.defineProperty(e,"__esModule",{value:!0})}); \ No newline at end of file +}},{key:"onStartNavigate_",value:function(e){var t=this;this.maybeDisableNativeScrollRestoration(),this.captureScrollPositionFromScrollEvent=!1,c(Ze.document.documentElement,this.loadingCssClass);var n={form:e.form,path:e.path},r=function(e){t.pendingNavigate||t.scheduledNavigationQueue.length||(I(Ze.document.documentElement,t.loadingCssClass),t.maybeRestoreNativeScrollRestoration(),t.captureScrollPositionFromScrollEvent=!0),t.emit("endNavigate",e)};this.pendingNavigate=this.doNavigate_(e.path,e.replaceHistory).then(function(){r(n)})["catch"](function(e){throw n.error=e,r(n),e}),this.pendingNavigate.path=e.path}},{key:"prefetch",value:function(e){var t=this,n=this.findRoute(e);if(!n)return Promise.reject(new Error("No route for "+e));var r=this.createScreenInstance(e,n);return r.load(e).then(function(){return t.screens[e]=r})["catch"](function(n){throw t.handleNavigateError_(e,r,n),n})}},{key:"prepareNavigateHistory_",value:function(e,t,n){var r=t.getTitle();de(r)||(r=this.getDefaultTitle());var i=t.beforeUpdateHistoryPath(e),a=new vt(e).getHash();i=this.maybeRestoreRedirectPathHash_(e,i,a);var o={form:re(Ze.capturedFormElement),path:e,redirectPath:i,scrollLeft:0,scrollTop:0,senna:!0};n&&(o.scrollTop=this.popstateScrollTop,o.scrollLeft=this.popstateScrollLeft),this.updateHistory_(r,i,t.beforeUpdateHistoryState(o),n),this.redirectPath=i}},{key:"prepareNavigateSurfaces_",value:function(e,t,n){Object.keys(t).forEach(function(r){var i=e.getSurfaceContent(r,n);t[r].addContent(e.getId(),i)})}},{key:"reloadPage",value:function(){Ze.window.location.reload()}},{key:"removeRoute",value:function(e){return it.remove(this.routes,e)}},{key:"removeScreen",value:function(e){var t=this,n=this.screens[e];n&&(Object.keys(this.surfaces).forEach(function(e){return t.surfaces[e].remove(n.getId())}),n.dispose(),delete this.screens[e])}},{key:"saveHistoryCurrentPageScrollPosition_",value:function(e,t){var n=Ze.window.history.state;if(n&&n.senna){var r=[e,t];n.scrollTop=r[0],n.scrollLeft=r[1],Ze.window.history.replaceState(n,null,null)}}},{key:"setAllowPreventNavigate",value:function(e){this.allowPreventNavigate=e}},{key:"setBasePath",value:function(e){this.basePath=yt.removePathTrailingSlash(e)}},{key:"setDefaultTitle",value:function(e){this.defaultTitle=e}},{key:"setFormSelector",value:function(e){this.formSelector=e,this.formEventHandler_&&this.formEventHandler_.removeListener(),this.formEventHandler_=E(document,"submit",this.formSelector,this.onDocSubmitDelegate_.bind(this),this.allowPreventNavigate)}},{key:"setIgnoreQueryStringFromRoutePath",value:function(e){this.ignoreQueryStringFromRoutePath=e}},{key:"setLinkSelector",value:function(e){this.linkSelector=e,this.linkEventHandler_&&this.linkEventHandler_.removeListener(),this.linkEventHandler_=E(document,"click",this.linkSelector,this.onDocClickDelegate_.bind(this),this.allowPreventNavigate)}},{key:"setLoadingCssClass",value:function(e){this.loadingCssClass=e}},{key:"setUpdateScrollPosition",value:function(e){this.updateScrollPosition=e}},{key:"stopPendingNavigate_",value:function(){this.pendingNavigate=null}},{key:"syncScrollPositionSyncThenAsync_",value:function(){var e=this,t=Ze.window.history.state;if(t){var n=t.scrollTop,r=t.scrollLeft,i=function(){e.updateScrollPosition&&Ze.window.scrollTo(r,n)};return new Promise(function(e){i(),setTimeout(function(){i(),e()},0)})}}},{key:"updateHistory_",value:function(e,t,n,r){var i=Ze.window.location.href;n&&(n.referrer=i),r?Ze.window.history.replaceState(n,e,t):Ze.window.history.pushState(n,e,t),yt.setReferrer(i);var a=Ze.document.querySelector("title");a?a.innerHTML=e:Ze.document.title=e}}]),t}(kt),Ct=function Ut(){Te(this,Ut)};Ct.INVALID_STATUS="Invalid status code",Ct.REQUEST_ERROR="Request error",Ct.REQUEST_TIMEOUT="Request timeout",Ct.REQUEST_PREMATURE_TERMINATION="Request terminated prematurely";var Ot=function(e){function t(){Te(this,t);var e=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.cacheable=!0,e.httpHeaders={"X-PJAX":"true","X-Requested-With":"XMLHttpRequest"},e.httpMethod=t.GET,e.request=null,e.timeout=3e4,e}return Re(t,e),Ce(t,[{key:"assertValidResponseStatusCode",value:function(e){if(!this.isValidResponseStatusCode(e)){var t=new Error(Ct.INVALID_STATUS);throw t.invalidStatus=!0,t.statusCode=e,t}}},{key:"beforeUpdateHistoryPath",value:function(e){var t=this.getRequestPath();return t&&t!==e?t:e}},{key:"beforeUpdateHistoryState",value:function(e){return e.senna&&e.form&&e.redirectPath===e.path?null:e}},{key:"formatLoadPath",value:function(e){var n=new vt(e);return n.setHostname(Ze.window.location.hostname),n.setProtocol(Ze.window.location.protocol),Ze.window.location.port&&n.setPort(Ze.window.location.port),yt.isIeOrEdge()&&this.httpMethod===t.GET?n.makeUnique().toString():n.toString()}},{key:"getHttpHeaders",value:function(){return this.httpHeaders}},{key:"getHttpMethod",value:function(){return this.httpMethod}},{key:"getRequestPath",value:function(){var e=this.getRequest();if(e){var n=e.url,r=this.maybeExtractResponseUrlFromRequest(e);return r&&(n=r),yt.isIeOrEdge()&&this.httpMethod===t.GET&&(n=new vt(n).removeUnique().toString()),yt.getUrlPath(n)}return null}},{key:"getRequest",value:function(){return this.request}},{key:"getTimeout",value:function(){return this.timeout}},{key:"isValidResponseStatusCode",value:function(e){return e>=200&&e<=399}},{key:"getFormData",value:function(e,t){var n=new FormData(e);return this.maybeAppendSubmitButtonValue_(n,t),n}},{key:"load",value:function(e){var n=this,r=this.getCache();if(re(r))return Promise.resolve(r);var i=null,a=this.httpMethod,o=new Headers;Object.keys(this.httpHeaders).forEach(function(e){o.set(e,n.httpHeaders[e])}),Ze.capturedFormElement&&(this.addSafariXHRPolyfill(),i=this.getFormData(Ze.capturedFormElement,Ze.capturedFormButtonElement),a=t.POST,yt.isIeOrEdge()&&o.append("If-None-Match",'"0"'));var u=this.formatLoadPath(e),s=new Request(u,{body:i,credentials:"include",headers:o,method:a,mode:"cors",redirect:"follow",referrer:"client"});return this.setRequest(s),Promise.race([fetch(s).then(function(e){return n.removeSafariXHRPolyfill(),n.assertValidResponseStatusCode(e.status),e.clone().text()}).then(function(e){return a===t.GET&&n.isCacheable()&&n.addCache(e),e}),new Promise(function(e,t){setTimeout(function(){return t(new Error(Ct.REQUEST_TIMEOUT))},n.timeout)})])["catch"](function(e){switch(n.removeSafariXHRPolyfill(),e.message){case Ct.REQUEST_TIMEOUT:e.timeout=!0;break;case Ct.REQUEST_ERROR:e.requestError=!0;break;case Ct.REQUEST_PREMATURE_TERMINATION:e.requestError=!0,e.requestPrematureTermination=!0}throw e})}},{key:"maybeAppendSubmitButtonValue_",value:function(e,t){t&&t.name&&e.append(t.name,t.value)}},{key:"maybeExtractResponseUrlFromRequest",value:function(e){return e.headers.get(t.X_REQUEST_URL_HEADER)}},{key:"addSafariXHRPolyfill",value:function(){if(Ze.capturedFormElement&&yt.isSafari())for(var e=Ze.capturedFormElement.querySelectorAll('input[type="file"]:not([disabled])'),t=0;t0)return;n.setAttribute("data-safari-temp-disabled","true"),n.setAttribute("disabled","")}}},{key:"removeSafariXHRPolyfill",value:function(){if(Ze.capturedFormElement&&yt.isSafari())for(var e=Ze.capturedFormElement.querySelectorAll('input[type="file"][data-safari-temp-disabled]'),t=0;t/gi,"/senna>");var n=void 0;if(yt.isIe()){var r=Ze.document.createRange().createContextualFragment(e);n=r.querySelector("senna")}else t.innerHTML=e,n=t.querySelector("senna");n&&(yt.clearNodeAttributes(t),yt.copyNodeAttributes(n,t))}},{key:"disposeInternal",value:function(){this.disposePendingStyles(),Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"disposeInternal",this).call(this)}},{key:"disposePendingStyles",value:function(){this.pendingStyles&&yt.removeElementsFromDocument(this.pendingStyles)}},{key:"evaluateScripts",value:function(e){var n=this,r=this.evaluateTrackedResources_(Ge.runScriptsInElement,t.selectors.scripts,t.selectors.scriptsTemporary,t.selectors.scriptsPermanent);return r.then(function(){return Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"evaluateScripts",n).call(n,e)})}},{key:"evaluateStyles",value:function(e){var n=this;this.pendingStyles=[];var r=this.evaluateTrackedResources_(Je.runStylesInElement,t.selectors.styles,t.selectors.stylesTemporary,t.selectors.stylesPermanent,this.appendStyleIntoDocument_.bind(this));return r.then(function(){return Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"evaluateStyles",n).call(n,e)})}},{key:"evaluateFavicon_",value:function(){var e=this,n=this.virtualQuerySelectorAll_(t.selectors.favicon),r=this.querySelectorAll_(t.selectors.favicon);return new Promise(function(t){yt.removeElementsFromDocument(r),e.runFaviconInElement_(n).then(function(){return t()})})}},{key:"evaluateTrackedResources_",value:function(e,n,r,i,a){var o=this,u=this.virtualQuerySelectorAll_(n),s=this.querySelectorAll_(r),l=this.querySelectorAll_(i);l.forEach(function(e){var n=o.getResourceKey_(e);n&&(t.permanentResourcesInDoc[n]=!0)});var c=_();return u.forEach(function(e){var n=o.getResourceKey_(e);t.permanentResourcesInDoc[n]||c.appendChild(e),n&&A(e,i)&&(t.permanentResourcesInDoc[n]=!0)}),new Promise(function(t){e(c,function(){yt.removeElementsFromDocument(s),t()},a)})}},{key:"flip",value:function(e){var n=this;return Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"flip",this).call(this,e).then(function(){yt.clearNodeAttributes(Ze.document.documentElement),yt.copyNodeAttributes(n.virtualDocument,Ze.document.documentElement),n.evaluateFavicon_(),n.updateMetaTags_()})}},{key:"updateMetaTags_",value:function(){var e=this.querySelectorAll_("meta"),t=this.metas;e&&(yt.removeElementsFromDocument(e),t&&t.forEach(function(e){return Ze.document.head.appendChild(e)}))}},{key:"getResourceKey_",value:function(e){return e.id||e.href||e.src||""}},{key:"getSurfaceContent",value:function(e){var t=this.virtualDocument.querySelector("#"+e);if(t){var n=t.querySelector("#"+e+"-"+At.DEFAULT);return n?n.innerHTML:t.innerHTML}}},{key:"getTitleSelector",value:function(){return this.titleSelector}},{key:"load",value:function(e){var n=this;return Oe(t.prototype.__proto__||Object.getPrototypeOf(t.prototype),"load",this).call(this,e).then(function(e){return n.allocateVirtualDocumentForContent(e),n.resolveTitleFromVirtualDocument(),n.resolveMetaTagsFromVirtualDocument(),n.assertSameBodyIdInVirtualDocument(),yt.isIe()&&n.makeTemporaryStylesHrefsUnique_(),e})}},{key:"makeTemporaryStylesHrefsUnique_",value:function(){var e=this,n=this.virtualQuerySelectorAll_(t.selectors.stylesTemporary);n.forEach(function(t){return e.replaceStyleAndMakeUnique_(t)})}},{key:"replaceStyleAndMakeUnique_",value:function(e){if(e.href){var t=Ze.document.createElement(e.tagName);e.href=new vt(e.href).makeUnique().toString(),yt.copyNodeAttributes(e,t),e.parentNode.replaceChild(t,e),e.disabled=!0}}},{key:"runFaviconInElement_",value:function(e){return new Promise(function(t){e.forEach(function(e){return document.head.appendChild(yt.isIe()?e:yt.setElementWithRandomHref(e))}),t()})}},{key:"virtualQuerySelectorAll_",value:function(e){return Array.prototype.slice.call(this.virtualDocument.querySelectorAll(e))}},{key:"querySelectorAll_",value:function(e){return Array.prototype.slice.call(Ze.document.querySelectorAll(e))}},{key:"releaseVirtualDocument",value:function(){this.virtualDocument=null}},{key:"resolveTitleFromVirtualDocument",value:function(){var e=this.virtualDocument.querySelector(this.titleSelector);e&&this.setTitle(e.textContent.trim())}},{key:"resolveMetaTagsFromVirtualDocument",value:function(){var e=this.virtualQuerySelectorAll_(this.metaTagsSelector);e&&this.setMetas(e)}},{key:"setTitleSelector",value:function(e){this.titleSelector=e}}]),t}(Ot),Nt=':not([rel="Shortcut Icon"]):not([rel="shortcut icon"]):not([rel="icon"]):not([href$="favicon.icon"])';Rt.selectors={favicon:'link[rel="Shortcut Icon"],link[rel="shortcut icon"],link[rel="icon"],link[href$="favicon.icon"]',scripts:"script[data-senna-track]",scriptsPermanent:'script[data-senna-track="permanent"]',scriptsTemporary:'script[data-senna-track="temporary"]',styles:"style[data-senna-track],link[data-senna-track]"+Nt,stylesPermanent:'style[data-senna-track="permanent"],link[data-senna-track="permanent"]'+Nt,stylesTemporary:'style[data-senna-track="temporary"],link[data-senna-track="temporary"]'+Nt},Rt.permanentResourcesInDoc={};var Ht=function(e){function t(){Te(this,t);var e=Ne(this,(t.__proto__||Object.getPrototypeOf(t)).call(this));return e.app=null,e.baseElement=null,e}return Re(t,e),Ce(t,[{key:"handle",value:function(){if(!oe(this.baseElement))throw new Error("Senna data attribute handler base element not set or invalid, try setting a valid element that contains a `data-senna` attribute.");if(this.baseElement.hasAttribute(mt.senna)){if(this.app)throw new Error("Senna app was already initialized.");this.app=new Tt,this.maybeAddRoutes_(),this.maybeAddSurfaces_(),this.maybeSetBasePath_(),this.maybeSetLinkSelector_(),this.maybeSetLoadingCssClass_(),this.maybeSetUpdateScrollPosition_(),this.maybeDispatch_()}}},{key:"disposeInternal",value:function(){this.app&&this.app.dispose()}},{key:"getApp",value:function(){return this.app}},{key:"getBaseElement",value:function(){return this.baseElement}},{key:"maybeAddRoutes_",value:function(){var e=this,t='link[rel="senna-route"]';this.querySelectorAllAsArray_(t).forEach(function(t){return e.maybeParseLinkRoute_(t)}),this.app.hasRoutes()||this.app.addRoutes(new bt(/.*/,Rt))}},{key:"maybeAddSurfaces_",value:function(){var e=this,t="["+mt.surface+"]";this.querySelectorAllAsArray_(t).forEach(function(t){e.updateElementIdIfSpecialSurface_(t),e.app.addSurfaces(t.id)})}},{key:"maybeDispatch_",value:function(){this.baseElement.hasAttribute(mt.dispatch)&&this.app.dispatch()}},{key:"maybeParseLinkRoute_",value:function(e){var t=new bt(this.maybeParseLinkRoutePath_(e),this.maybeParseLinkRouteHandler_(e));this.app.addRoutes(t)}},{key:"maybeParseLinkRouteHandler_",value:function(e){var t=e.getAttribute("type");return re(t)&&(t=ut.getObjectByName(t)),t}},{key:"maybeParseLinkRoutePath_",value:function(e){var t=e.getAttribute("href");return re(t)&&0===t.indexOf("regex:")&&(t=new RegExp(t.substring(6))),t}},{key:"maybeSetBasePath_",value:function(){var e=this.baseElement.getAttribute(mt.basePath);re(e)&&this.app.setBasePath(e)}},{key:"maybeSetLinkSelector_",value:function(){var e=this.baseElement.getAttribute(mt.linkSelector);re(e)&&this.app.setLinkSelector(e)}},{key:"maybeSetLoadingCssClass_",value:function(){var e=this.baseElement.getAttribute(mt.loadingCssClass);re(e)&&this.app.setLoadingCssClass(e)}},{key:"maybeSetUpdateScrollPosition_",value:function(){var e=this.baseElement.getAttribute(mt.updateScrollPosition);re(e)&&("false"===e?this.app.setUpdateScrollPosition(!1):this.app.setUpdateScrollPosition(!0))}},{key:"querySelectorAllAsArray_",value:function(e){return Array.prototype.slice.call(Ze.document.querySelectorAll(e))}},{key:"updateElementIdIfSpecialSurface_",value:function(e){e.id||e!==Ze.document.body||(e.id="senna_surface_"+Z())}},{key:"setBaseElement",value:function(e){this.baseElement=e}}]),t}(ot),It=new Ht;Ze.document.addEventListener("DOMContentLoaded",function(){It.setBaseElement(Ze.document.body),It.handle()});var xt="3.0.0-milestone.6";e["default"]=Tt,e.dataAttributeHandler=It,e.utils=yt,e.App=Tt,e.HtmlScreen=Rt,e.Route=bt,e.RequestScreen=Ot,e.Screen=wt,e.version=xt,Object.defineProperty(e,"__esModule",{value:!0})}); \ No newline at end of file diff --git a/build/globals/senna.js b/build/globals/senna.js index 0cce7d6..e5f1475 100644 --- a/build/globals/senna.js +++ b/build/globals/senna.js @@ -1,7 +1,7 @@ /** * Senna.js - A blazing-fast Single Page Application engine * @author Liferay, Inc. - * @version v3.0.0-milestone.2 + * @version v3.0.0-milestone.6 * @link http://sennajs.com * @license BSD-3-Clause */ @@ -10554,7 +10554,7 @@ globals.document.addEventListener('DOMContentLoaded', function () { * @returns String containing the current senna version */ -var version = '3.0.0-milestone.2'; +var version = '3.0.0-milestone.6'; exports['default'] = App$1; exports.dataAttributeHandler = dataAttributeHandler; diff --git a/package-lock.json b/package-lock.json index 3b0d370..90e9ccc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "senna", - "version": "3.0.0-milestone.2", + "version": "3.0.0-milestone.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e637a75..d3f17a3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "senna", - "version": "3.0.0-milestone.2", + "version": "3.0.0-milestone.6", "description": "A blazing-fast Single Page Application engine", "license": "BSD-3-Clause", "repository": "liferay/senna.js",