From f697052aa283b1d3e11090222a907d5184c70b46 Mon Sep 17 00:00:00 2001 From: monokee Date: Thu, 29 Oct 2020 13:31:05 +0100 Subject: [PATCH] 6.1.2 - Release Candidate [Router] - when route passed to Router.navigate() starts with 'http' we do a redirect via window.location.href - this way routes are treated just like beforeRoute filter returns. --- build/cue.js | 4 ++++ build/cue.min.js | 2 +- build/cue.module.js | 4 ++++ src/modules/router.js | 4 ++++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/build/cue.js b/build/cue.js index ca28a96..a9a194b 100644 --- a/build/cue.js +++ b/build/cue.js @@ -1927,6 +1927,10 @@ const Router = { navigate(route, options = {}) { + if (route.lastIndexOf('http', 0) === 0) { + return window.location.href = route; + } + const { hash, query, rel } = getRouteParts(route); options = Object.assign({}, DEFAULT_TRIGGER_OPTIONS, options); diff --git a/build/cue.min.js b/build/cue.min.js index 1bcae29..c914f3e 100644 --- a/build/cue.min.js +++ b/build/cue.min.js @@ -1 +1 @@ -!function(e){const t=()=>{};function n(e,t){if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){if(e.constructor!==t.constructor)return!1;let r;if(Array.isArray(e)){if(e.length!==t.length)return!1;for(r=e.length;0!=r--;)if(!n(e[r],t[r]))return!1;return!0}const o=Object.keys(e),s=o.length;if(s!==Object.keys(t).length)return!1;for(r=s;0!=r--;)if(!Object.prototype.hasOwnProperty.call(t,o[r]))return!1;for(r=s;0!=r--;){const s=o[r];if(!n(e[s],t[s]))return!1}return!0}return e!=e&&t!=t}function r(e){if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){const t=[];for(let n=0;n{clearTimeout(h);for(let e=0;e{h=setTimeout(()=>{for(let e=0;enew Promise((r,i)=>{d();const a=o(e),c=function(e){const t=s.getItem(e+"::ts");return null===t?u:Number(t){t>0&&function(e,t,n){const r=Date.now()+1e3*n;"object"==typeof t&&(t=JSON.stringify(t));const o=e+"::ts";s.setItem(e,t),s.setItem(o,""+r);let i=s.getItem(l);null===i?i=`${e},${o},`:-1===i.indexOf(e+",")&&(i=`${i}${e},${o},`);s.setItem(l,i)}(a,e,t),r(e)}).catch(e=>{i(e)}).finally(f):(f(),r(c))}),post:(e,t,n)=>new Promise((r,o)=>{d(),m(e,"POST",n,t).then(e=>r(e)).catch(e=>o(e)).finally(f)}),put:(e,t,n)=>new Promise((r,o)=>{d(),m(e,"PUT",n,t).then(e=>r(e)).catch(e=>o(e)).finally(f)}),delete:(e,t,n)=>new Promise((r,o)=>{d(),m(e,"DELETE",n,t).then(e=>r(e)).catch(e=>o(e)).finally(f)}),clearCache(e){g(o(e))},onRequestStart(e){if(a.indexOf(e)>-1)throw new Error("[Cue.js] Server.onRequestStart(handler) - the provided handler is already registered.");return a.push(e),{unsubscribe(){a.splice(a.indexOf(e),1)}}},onRequestStop(e){if(c.indexOf(e)>-1)throw new Error("[Cue.js] Server.onRequestStop(handler) - the provided handler is already registered.");return c.push(e),{unsubscribe(){c.splice(c.indexOf(e),1)}}}};function g(e){if(e){if(null!==s.getItem(e)){const t=e+"::ts";s.removeItem(e),s.removeItem(t);const n=s.getItem(l);if(null!==n){const r=n.split(",");r.splice(r.indexOf(e),1),r.splice(r.indexOf(t),1),s.setItem(l,r.join(",")+",")}}}else{const e=s.getItem(l);if(null!==e){const t=e.split(",");for(let e=0;e{fetch(e,{method:t,mode:"cors",cache:"no-store",credentials:"same-origin",headers:o,redirect:"follow",referrer:"no-referrer",body:"GET"===t?null:"string"==typeof r?r:JSON.stringify(r)}).then(e=>{e.ok?204===e.status?n({}):e.json().then(e=>n(e)):e.json().then(e=>s(e))}).catch(e=>{s(e)}).finally(()=>{i.delete(e)})})),i.get(e)}}const y=new Map,b=new Map,v=new Map,w=new Map,C=[];let S=null;const O={cueEvent(e,t){y.set(e,t)},cueCallback(e,t){b.set(e,t)},cueComputations(e,t,n,r){const o=e.get(n),s=[e,t,r];for(let e=0;e0;){for(t of v.entries())r=t[0],-1===C.indexOf(r)&&(o=t[1],i=o[0],s=o[1],r.needsUpdate=!0,a=r.value(o[2]),!0===r.hasChanged&&(s[r.ownPropertyName]&&b.set(s[r.ownPropertyName],a),w.set(r,o)),C.push(r));for(t of(v.clear(),w.entries()))if(r=t[0],o=t[1],n=o[0].get(r.ownPropertyName),n)for(e=0;e0;)C.pop()}const E=(e,t)=>e+"."+t+"::CueStore",j=(e,t)=>void 0===t?null:t,P=new Map,k=Symbol("Cue.Store.internals"),I=Symbol("Cue.Store"),T=Symbol("Cue.Store.set"),R=Symbol("Cue.Store.get"),A=Symbol("Cue.Store.dispatch");class M{constructor(e,t){this.id=I,this.store=e,this.key=t}get(e=!1){return!0===e?r(this.store[k].data[this.key]):this.store[k].data[this.key]}set(e){this.store[k].data[this.key]=e,this.store[A](this.key,e)}}class _{constructor(e,t,n){const o=this[k]={name:e,defaultData:r(t),events:new Map,bindings:new Map,storage:n};if(null===n)o.usesStorage=!1,o.data=r(t);else{o.usesStorage=!0;const r=o.storageKeys={};for(const s in t){const t=E(e,s);r[s]=t,null===n.getItem(t)&&n.setItem(t,JSON.stringify(o.defaultData[s],j))}o.data=new Proxy({},{get:(t,o)=>JSON.parse(n.getItem(r[o]||E(e,o))),set:(t,o,s)=>(n.setItem(r[o]||E(e,o),JSON.stringify(s,j)),!0),has:(t,o)=>null!==n.getItem(r[o]||E(e,o)),deleteProperty:(t,o)=>(n.removeItem(r[o]||E(e,o)),!0)})}}[R](e){return this[k].data[e]}[T](e,t){this[k].data[e]=t,this[A](e,t)}[A](e,t){const n=this[k].events.get(e);if(n){for(let e=0;e{const n=r.events.get(e);n.splice(n.indexOf(t),1)}}}}const $={create(e,t,n=null){if(P.has(e))throw new Error('Can not create Store "'+e+'". A store with the same name already exists.');const r=new _(e,t,n);return P.set(e,r),r},destroy(e){if(!P.has(e))throw new Error('Can not destroy Store "'+e+'". Store does not exist.');const t=P.get(e);t.clear(!0),t[k].events.clear(),P.delete(e)}},q={computedProperty:null,computedProperties:null};let L=null,N=[];class D{constructor(e,t,n=[]){this.ownPropertyName=e,this.computation=t,this.sourceProperties=n,this.intermediate=void 0,this._value=void 0,this._type=-1,this.needsUpdate=!0,this.hasChanged=!1}value(e){return!0===this.needsUpdate&&(this.intermediate=this.computation.call(e,e,this._value),Array.isArray(this.intermediate)?(this.hasChanged=1!==this._type||!function(e,t){if(e.length!==t.length)return!1;for(let n=0;n ")}`);-1===N.indexOf(e)&&z(e,t,n)}n.has(e)||n.set(e,r)}}const J=/(\$self(?=[\\040,{.:#[>+~]))|\$self\b/g,B=[" ",".",":","#","[",">","+","~"];let G=-1;const Q=Symbol("Component Data"),F=document.createElement("div"),K={compiler:document.getElementById("cue::compiler")||Object.assign(document.head.appendChild(document.createElement("style")),{id:"cue::compiler"}),components:document.getElementById("cue::components")||Object.assign(document.head.appendChild(document.createElement("style")),{id:"cue::components"})},Y={define(e,o){let s=!1,i=!1;const a={initialize:t,connected:t,disconnected:t},c={static:{},computed:new Map,bindings:{},reactions:{}},l=document.createElement("template");l.innerHTML=o.element||"";const u=function e(t,n){for(let r,o,s,i,a=0;a+~]))|\\"+e+"\b","g"),n[e]);K.compiler.innerHTML=t;const r=K.compiler.sheet;let o="",s="";for(let t,n=0;n0&&(c.computed=U(e,c.computed))}const e=this[Q];if(!1===e.initialized){e.initialized=!0;const t=e._data=Object.assign(r(c.static),e._data),n=e.computedProperties;e.data=new Proxy(t,{set:Z,get:(t,o)=>c.bindings[o]?c.bindings[o].get(!0):n.has(o)?n.get(o).value(e.data):r(t[o])});for(const e of c.computed.entries()){const t=e[1];n.set(e[0],new D(t.ownPropertyName,t.computation,t.sourceProperties))}e.dependencyGraph=function(e){const t=new Map;let n,r,o;for(n of e.values())for(r=0;r{c.reactions[t](e.refs,n,e.data)};0===this.innerHTML.length&&(this.innerHTML=l.innerHTML);for(const t in u){const n=this.querySelector(u[t]);n&&(n[Q]||(n[Q]={},n.renderEach=ee),e.refs[t]=n)}if(e.refs.$self=this,this.hasAttribute("data")){const t=JSON.parse(this.getAttribute("data"));this.removeAttribute("data"),Object.assign(e._data,t)}for(const t in e.reactions)O.cueCallback(e.reactions[t],e.data[t]);O.react(),requestAnimationFrame(()=>{a.initialize.call(this,e.refs),a.connected.call(this,e.refs)})}else a.connected.call(this,e.refs);for(const t in c.bindings)e.dependencyGraph.has(t)&&e.subscriptions.push(c.bindings[t].store.subscribe(c.bindings[t].key,()=>O.cueComputations(e.dependencyGraph,e.reactions,t,e.data))),e.reactions[t]&&e.subscriptions.push(c.bindings[t].store.subscribe(c.bindings[t].key,e.reactions[t]))}disconnectedCallback(){const e=this[Q],t=e.subscriptions;for(;t.length;)t.pop().unsubscribe();a.disconnected.call(this,e.refs)}getData(e){if(!e){const e=this[Q],t={};let n;for(n in c.bindings)t[n]=c.bindings[n].get(!0);for(n in e._data)t[n]=r(e._data[n]);return t}return this[Q].data[e]}setData(e,t){if("object"==typeof e)for(const t in e)this.setData(t,e[t]);if(c.computed.has(e))throw new Error(`You can not set property "${e}" because it is a computed property.`);const o=this[Q];c.bindings[e]&&!n(c.bindings[e].get(!1),t)?(o.dataEvent.detail.key=e,o.dataEvent.detail.value=r(t),this.dispatchEvent(o.dataEvent),c.bindings[e].set(t)):n(o._data[e],t)||(o._data[e]=t,o.dataEvent.detail.key=e,o.dataEvent.detail.value=r(t),this.dispatchEvent(o.dataEvent),o.reactions[e]&&O.cueCallback(o.reactions[e],t),o.dependencyGraph.has(e)&&O.cueComputations(o.dependencyGraph,o.reactions,e,o.data),O.react())}};for(const e in o)"function"==typeof o[e]&&"initialize"!==e&&(h.prototype[e]=o[e]);h.prototype.renderEach=ee,customElements.define(e,h);const d="<"+e,f="";return e=>{let t,n,r=d;for(t in e)n=e[t],n=n&&"object"==typeof n?JSON.stringify(n):n,r+=` ${t}='${n}'`;return r+=">"+l.innerHTML+f,r}},create(e,t){if("string"!=typeof(e=(e="function"==typeof e?e():e).trim())||"<"!==e[0])throw new Error('[Cue.js] - Component.create(node) -> argument "node" is not valid HTML: "'+e+'"');F.innerHTML=e;const n=F.children[0];if(t){console.warn("[Cue.js] - Component.create(...) [data] parameter will be deprecated in a future version. Pass data object as an attribute to the components factory function instead.");const e=n[Q];e?Object.assign(e._data,r(t)):console.warn("[Cue.js] - Component.create(...) [data] parameter passed to non-cue element will be ignored.")}return n}};function V(e,t,n=""){4===t.type?n+="@media "+t.media.mediaText+" {":n+="@supports "+t.conditionText+" {";let r="";for(let o,s=0;s-1){const r=e.selectorText.split(","),o=[];for(let e,n=0;n-1}function Z(e,t,n){throw new Error(`Can not change data in reactions: this.${t} = ${n} has been ignored.`)}function ee(e,n,r=t){e=Array.isArray(e)?e:Object.values(e||{});const o=this[Q].childData||[];if(this[Q].childData=e,0===e.length)this.innerHTML="";else if(0===o.length)for(let t=0;t0&&n[u-1]<=i)a=u-1;else{for(;u-l>1;)t=Math.floor((l+u)/2),n[t]>i?u=t:l=t;a=l}-1!==a&&(o[s]=r[a]),a===c?(c++,n[c]=i,r[c]=s):i=0;s=o[s],c--)n[c]=s;return n}(y,l),O=[];let x=f;for(v=c;v<=h;v++)O[v]=x,x=x.nextSibling;for(v=0;v=l;v--)S[j]===v?(a=O[y[S[j]]],o(a,n[v]),j--):(-1===y[v]?E=r(n[v],v,n):(E=O[y[v]],o(E,n[v])),e.insertBefore(E,a),a=E)}(this,o,e,n,r)}const te=e.location.origin+e.location.pathname,ne=[te,e.location.hostname,e.location.hostname+"/",e.location.origin];"/"!==te[te.length-1]&&ne.push(te+"/"),e.location.pathname&&"/"!==e.location.pathname&&ne.push(e.location.pathname);const re=["/","#","/#","/#/",...ne],oe=new URL(te),se=Se(te),ie=new Map,ae=new Set,ce=[];let le=null;const ue={},he={params:{},keepQuery:!0,forceReload:!1,history:"pushState"};let de=!1,fe={},pe=["/"];e.location.hash&&pe.push(...e.location.hash.split("/"));const ge={before(e,t){if(me(),"*"===e)null!==le&&console.warn("[Cue.js] - Router.before(*, filter) - overwriting previously registered wildcard filter (*)"),le=t;else{const{hash:n}=ve(e);if(ie.has(n))throw new Error("[Cue.js] Router.beforeRoute() already has a filter for "+("#"===n?e+" (root url)":e));ie.set(n,t)}},on(e,t){if(me(),"*"===e)-1===ce.indexOf(t)&&ce.push(t);else{const{hash:n}=ve(e);if(ae.has(n))throw new Error('[Cue.js] Router.onRoute() already has a action for "'+n=="#"?e+" (root url)":e+'".');ae.add(n),function(e,t){const n=ue["/"]||(ue["/"]={action:void 0,children:{}});if("#"===e)n.action=t;else{const r=e.split("/"),o=r[r.length-1];r.reduce((e,n)=>e[n]?(n===o&&(e[n].action=t),e[n].children):(e[n]={action:n===o?t:void 0,children:{}}).children,n.children)}}(n,t)}},hasFilter(e){if("*"===e)return null!==le;{const{hash:t}=ve(e);return ie.has(t)}},hasAction(e){if("*"===e)return ce.length>0;{const{hash:t}=ve(e);return ae.has(t)}},navigate(t,n={}){const{hash:r,query:o,rel:s}=ve(t);!0===(n=Object.assign({},he,n)).keepQuery?Object.assign(fe,Oe(o)):fe=Oe(o),le&&le(s,fe,e=>{if(e!==s)return be(e)}),ie.has(r)&&ie.get(r)(s,fe,e=>{if(e!==s)return be(e)}),function(t,n,r,o){(function(e){const t=se+(e="#"===e?"":e);for(let e=0;en.length&&r.push(...function(e,t){const n=[];for(let r=e.length;re?fe[e]:Object.assign({},fe),addQueryParameters(e,t){if(void 0===t&&"object"==typeof e)for(const t in e)fe[t]=e[t];else fe[e]=t;ye()},setQueryParameters(e){fe=r(e),ye()},removeQueryParameters(e){e?Array.isArray(e)?e.forEach(e=>{fe[e]&&delete fe[e]}):fe[e]&&delete fe[e]:fe={},ye()}};function me(){de||(de=!0,e.addEventListener("popstate",()=>{ge.navigate(e.location.href,{history:"replaceState",forceReload:!1})}))}function ye(){oe.search=xe(fe),e.history.replaceState(null,document.title,oe.toString())}function be(t){return 0===t.lastIndexOf("http",0)?e.location.href=t:ge.navigate(t,{history:"replaceState",forceReload:!1})}function ve(e){if(re.indexOf(e)>-1)return{rel:"/",abs:te,hash:"#",query:""};if("?"===e[0]||"#"===e[0]){const{hash:t,query:n}=we(e);return{rel:Ce(t),abs:te+t,hash:t||"#",query:n}}if("?"!==(e=function(e){const t=(r=e,o=re,o.filter(e=>0===r.lastIndexOf(e,0)).sort((e,t)=>t.length-e.length)[0]),n=t?e.substr(t.length):e;var r,o;return 0===n.lastIndexOf("/",0)?n.substr(1):n}(e))[0]&&"#"!==e[0])throw new Error('Invalid Route: "'+e+'". Non-root paths must start with ? query or # hash.');const{hash:t,query:n}=we(e);return{rel:Ce(t),abs:te+t,hash:t||"#",query:n}}function we(e){const t=e.indexOf("#"),n=e.indexOf("?");if(-1===t)return{hash:"",query:Se(new URL(e,te).search)};if(-1===n)return{hash:Se(new URL(e,te).hash),query:""};const r=new URL(e,te);if(n1){const n=e.substring(1).replace(/\+/g," ").replace(/;/g,"&").split("&");for(let e,r,o=0;o1)||decodeURIComponent(e[1]))}return t}function xe(e){let t="?";for(const n in e)t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n])+"&";return"?"===t?t="":"&"===t[t.length-1]&&(t=t.substring(0,t.length-1)),t}const Ee={Component:Y,Store:$,Server:p,Router:ge};"object"==typeof module&&"object"==typeof module.exports?module.exports=Ee:"function"==typeof define&&define.amd?define("Cue",[],(function(){return Ee})):e.Cue=Ee}(window||this); \ No newline at end of file +!function(e){const t=()=>{};function n(e,t){if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){if(e.constructor!==t.constructor)return!1;let r;if(Array.isArray(e)){if(e.length!==t.length)return!1;for(r=e.length;0!=r--;)if(!n(e[r],t[r]))return!1;return!0}const o=Object.keys(e),s=o.length;if(s!==Object.keys(t).length)return!1;for(r=s;0!=r--;)if(!Object.prototype.hasOwnProperty.call(t,o[r]))return!1;for(r=s;0!=r--;){const s=o[r];if(!n(e[s],t[s]))return!1}return!0}return e!=e&&t!=t}function r(e){if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){const t=[];for(let n=0;n{clearTimeout(h);for(let e=0;e{h=setTimeout(()=>{for(let e=0;enew Promise((r,i)=>{d();const a=o(e),c=function(e){const t=s.getItem(e+"::ts");return null===t?u:Number(t){t>0&&function(e,t,n){const r=Date.now()+1e3*n;"object"==typeof t&&(t=JSON.stringify(t));const o=e+"::ts";s.setItem(e,t),s.setItem(o,""+r);let i=s.getItem(l);null===i?i=`${e},${o},`:-1===i.indexOf(e+",")&&(i=`${i}${e},${o},`);s.setItem(l,i)}(a,e,t),r(e)}).catch(e=>{i(e)}).finally(f):(f(),r(c))}),post:(e,t,n)=>new Promise((r,o)=>{d(),m(e,"POST",n,t).then(e=>r(e)).catch(e=>o(e)).finally(f)}),put:(e,t,n)=>new Promise((r,o)=>{d(),m(e,"PUT",n,t).then(e=>r(e)).catch(e=>o(e)).finally(f)}),delete:(e,t,n)=>new Promise((r,o)=>{d(),m(e,"DELETE",n,t).then(e=>r(e)).catch(e=>o(e)).finally(f)}),clearCache(e){g(o(e))},onRequestStart(e){if(a.indexOf(e)>-1)throw new Error("[Cue.js] Server.onRequestStart(handler) - the provided handler is already registered.");return a.push(e),{unsubscribe(){a.splice(a.indexOf(e),1)}}},onRequestStop(e){if(c.indexOf(e)>-1)throw new Error("[Cue.js] Server.onRequestStop(handler) - the provided handler is already registered.");return c.push(e),{unsubscribe(){c.splice(c.indexOf(e),1)}}}};function g(e){if(e){if(null!==s.getItem(e)){const t=e+"::ts";s.removeItem(e),s.removeItem(t);const n=s.getItem(l);if(null!==n){const r=n.split(",");r.splice(r.indexOf(e),1),r.splice(r.indexOf(t),1),s.setItem(l,r.join(",")+",")}}}else{const e=s.getItem(l);if(null!==e){const t=e.split(",");for(let e=0;e{fetch(e,{method:t,mode:"cors",cache:"no-store",credentials:"same-origin",headers:o,redirect:"follow",referrer:"no-referrer",body:"GET"===t?null:"string"==typeof r?r:JSON.stringify(r)}).then(e=>{e.ok?204===e.status?n({}):e.json().then(e=>n(e)):e.json().then(e=>s(e))}).catch(e=>{s(e)}).finally(()=>{i.delete(e)})})),i.get(e)}}const y=new Map,b=new Map,v=new Map,w=new Map,C=[];let S=null;const O={cueEvent(e,t){y.set(e,t)},cueCallback(e,t){b.set(e,t)},cueComputations(e,t,n,r){const o=e.get(n),s=[e,t,r];for(let e=0;e0;){for(t of v.entries())r=t[0],-1===C.indexOf(r)&&(o=t[1],i=o[0],s=o[1],r.needsUpdate=!0,a=r.value(o[2]),!0===r.hasChanged&&(s[r.ownPropertyName]&&b.set(s[r.ownPropertyName],a),w.set(r,o)),C.push(r));for(t of(v.clear(),w.entries()))if(r=t[0],o=t[1],n=o[0].get(r.ownPropertyName),n)for(e=0;e0;)C.pop()}const E=(e,t)=>e+"."+t+"::CueStore",j=(e,t)=>void 0===t?null:t,P=new Map,k=Symbol("Cue.Store.internals"),I=Symbol("Cue.Store"),T=Symbol("Cue.Store.set"),R=Symbol("Cue.Store.get"),A=Symbol("Cue.Store.dispatch");class M{constructor(e,t){this.id=I,this.store=e,this.key=t}get(e=!1){return!0===e?r(this.store[k].data[this.key]):this.store[k].data[this.key]}set(e){this.store[k].data[this.key]=e,this.store[A](this.key,e)}}class _{constructor(e,t,n){const o=this[k]={name:e,defaultData:r(t),events:new Map,bindings:new Map,storage:n};if(null===n)o.usesStorage=!1,o.data=r(t);else{o.usesStorage=!0;const r=o.storageKeys={};for(const s in t){const t=E(e,s);r[s]=t,null===n.getItem(t)&&n.setItem(t,JSON.stringify(o.defaultData[s],j))}o.data=new Proxy({},{get:(t,o)=>JSON.parse(n.getItem(r[o]||E(e,o))),set:(t,o,s)=>(n.setItem(r[o]||E(e,o),JSON.stringify(s,j)),!0),has:(t,o)=>null!==n.getItem(r[o]||E(e,o)),deleteProperty:(t,o)=>(n.removeItem(r[o]||E(e,o)),!0)})}}[R](e){return this[k].data[e]}[T](e,t){this[k].data[e]=t,this[A](e,t)}[A](e,t){const n=this[k].events.get(e);if(n){for(let e=0;e{const n=r.events.get(e);n.splice(n.indexOf(t),1)}}}}const $={create(e,t,n=null){if(P.has(e))throw new Error('Can not create Store "'+e+'". A store with the same name already exists.');const r=new _(e,t,n);return P.set(e,r),r},destroy(e){if(!P.has(e))throw new Error('Can not destroy Store "'+e+'". Store does not exist.');const t=P.get(e);t.clear(!0),t[k].events.clear(),P.delete(e)}},q={computedProperty:null,computedProperties:null};let L=null,N=[];class D{constructor(e,t,n=[]){this.ownPropertyName=e,this.computation=t,this.sourceProperties=n,this.intermediate=void 0,this._value=void 0,this._type=-1,this.needsUpdate=!0,this.hasChanged=!1}value(e){return!0===this.needsUpdate&&(this.intermediate=this.computation.call(e,e,this._value),Array.isArray(this.intermediate)?(this.hasChanged=1!==this._type||!function(e,t){if(e.length!==t.length)return!1;for(let n=0;n ")}`);-1===N.indexOf(e)&&z(e,t,n)}n.has(e)||n.set(e,r)}}const J=/(\$self(?=[\\040,{.:#[>+~]))|\$self\b/g,B=[" ",".",":","#","[",">","+","~"];let G=-1;const Q=Symbol("Component Data"),F=document.createElement("div"),K={compiler:document.getElementById("cue::compiler")||Object.assign(document.head.appendChild(document.createElement("style")),{id:"cue::compiler"}),components:document.getElementById("cue::components")||Object.assign(document.head.appendChild(document.createElement("style")),{id:"cue::components"})},Y={define(e,o){let s=!1,i=!1;const a={initialize:t,connected:t,disconnected:t},c={static:{},computed:new Map,bindings:{},reactions:{}},l=document.createElement("template");l.innerHTML=o.element||"";const u=function e(t,n){for(let r,o,s,i,a=0;a+~]))|\\"+e+"\b","g"),n[e]);K.compiler.innerHTML=t;const r=K.compiler.sheet;let o="",s="";for(let t,n=0;n0&&(c.computed=U(e,c.computed))}const e=this[Q];if(!1===e.initialized){e.initialized=!0;const t=e._data=Object.assign(r(c.static),e._data),n=e.computedProperties;e.data=new Proxy(t,{set:Z,get:(t,o)=>c.bindings[o]?c.bindings[o].get(!0):n.has(o)?n.get(o).value(e.data):r(t[o])});for(const e of c.computed.entries()){const t=e[1];n.set(e[0],new D(t.ownPropertyName,t.computation,t.sourceProperties))}e.dependencyGraph=function(e){const t=new Map;let n,r,o;for(n of e.values())for(r=0;r{c.reactions[t](e.refs,n,e.data)};0===this.innerHTML.length&&(this.innerHTML=l.innerHTML);for(const t in u){const n=this.querySelector(u[t]);n&&(n[Q]||(n[Q]={},n.renderEach=ee),e.refs[t]=n)}if(e.refs.$self=this,this.hasAttribute("data")){const t=JSON.parse(this.getAttribute("data"));this.removeAttribute("data"),Object.assign(e._data,t)}for(const t in e.reactions)O.cueCallback(e.reactions[t],e.data[t]);O.react(),requestAnimationFrame(()=>{a.initialize.call(this,e.refs),a.connected.call(this,e.refs)})}else a.connected.call(this,e.refs);for(const t in c.bindings)e.dependencyGraph.has(t)&&e.subscriptions.push(c.bindings[t].store.subscribe(c.bindings[t].key,()=>O.cueComputations(e.dependencyGraph,e.reactions,t,e.data))),e.reactions[t]&&e.subscriptions.push(c.bindings[t].store.subscribe(c.bindings[t].key,e.reactions[t]))}disconnectedCallback(){const e=this[Q],t=e.subscriptions;for(;t.length;)t.pop().unsubscribe();a.disconnected.call(this,e.refs)}getData(e){if(!e){const e=this[Q],t={};let n;for(n in c.bindings)t[n]=c.bindings[n].get(!0);for(n in e._data)t[n]=r(e._data[n]);return t}return this[Q].data[e]}setData(e,t){if("object"==typeof e)for(const t in e)this.setData(t,e[t]);if(c.computed.has(e))throw new Error(`You can not set property "${e}" because it is a computed property.`);const o=this[Q];c.bindings[e]&&!n(c.bindings[e].get(!1),t)?(o.dataEvent.detail.key=e,o.dataEvent.detail.value=r(t),this.dispatchEvent(o.dataEvent),c.bindings[e].set(t)):n(o._data[e],t)||(o._data[e]=t,o.dataEvent.detail.key=e,o.dataEvent.detail.value=r(t),this.dispatchEvent(o.dataEvent),o.reactions[e]&&O.cueCallback(o.reactions[e],t),o.dependencyGraph.has(e)&&O.cueComputations(o.dependencyGraph,o.reactions,e,o.data),O.react())}};for(const e in o)"function"==typeof o[e]&&"initialize"!==e&&(h.prototype[e]=o[e]);h.prototype.renderEach=ee,customElements.define(e,h);const d="<"+e,f="";return e=>{let t,n,r=d;for(t in e)n=e[t],n=n&&"object"==typeof n?JSON.stringify(n):n,r+=` ${t}='${n}'`;return r+=">"+l.innerHTML+f,r}},create(e,t){if("string"!=typeof(e=(e="function"==typeof e?e():e).trim())||"<"!==e[0])throw new Error('[Cue.js] - Component.create(node) -> argument "node" is not valid HTML: "'+e+'"');F.innerHTML=e;const n=F.children[0];if(t){console.warn("[Cue.js] - Component.create(...) [data] parameter will be deprecated in a future version. Pass data object as an attribute to the components factory function instead.");const e=n[Q];e?Object.assign(e._data,r(t)):console.warn("[Cue.js] - Component.create(...) [data] parameter passed to non-cue element will be ignored.")}return n}};function V(e,t,n=""){4===t.type?n+="@media "+t.media.mediaText+" {":n+="@supports "+t.conditionText+" {";let r="";for(let o,s=0;s-1){const r=e.selectorText.split(","),o=[];for(let e,n=0;n-1}function Z(e,t,n){throw new Error(`Can not change data in reactions: this.${t} = ${n} has been ignored.`)}function ee(e,n,r=t){e=Array.isArray(e)?e:Object.values(e||{});const o=this[Q].childData||[];if(this[Q].childData=e,0===e.length)this.innerHTML="";else if(0===o.length)for(let t=0;t0&&n[u-1]<=i)a=u-1;else{for(;u-l>1;)t=Math.floor((l+u)/2),n[t]>i?u=t:l=t;a=l}-1!==a&&(o[s]=r[a]),a===c?(c++,n[c]=i,r[c]=s):i=0;s=o[s],c--)n[c]=s;return n}(y,l),O=[];let x=f;for(v=c;v<=h;v++)O[v]=x,x=x.nextSibling;for(v=0;v=l;v--)S[j]===v?(a=O[y[S[j]]],o(a,n[v]),j--):(-1===y[v]?E=r(n[v],v,n):(E=O[y[v]],o(E,n[v])),e.insertBefore(E,a),a=E)}(this,o,e,n,r)}const te=e.location.origin+e.location.pathname,ne=[te,e.location.hostname,e.location.hostname+"/",e.location.origin];"/"!==te[te.length-1]&&ne.push(te+"/"),e.location.pathname&&"/"!==e.location.pathname&&ne.push(e.location.pathname);const re=["/","#","/#","/#/",...ne],oe=new URL(te),se=Se(te),ie=new Map,ae=new Set,ce=[];let le=null;const ue={},he={params:{},keepQuery:!0,forceReload:!1,history:"pushState"};let de=!1,fe={},pe=["/"];e.location.hash&&pe.push(...e.location.hash.split("/"));const ge={before(e,t){if(me(),"*"===e)null!==le&&console.warn("[Cue.js] - Router.before(*, filter) - overwriting previously registered wildcard filter (*)"),le=t;else{const{hash:n}=ve(e);if(ie.has(n))throw new Error("[Cue.js] Router.beforeRoute() already has a filter for "+("#"===n?e+" (root url)":e));ie.set(n,t)}},on(e,t){if(me(),"*"===e)-1===ce.indexOf(t)&&ce.push(t);else{const{hash:n}=ve(e);if(ae.has(n))throw new Error('[Cue.js] Router.onRoute() already has a action for "'+n=="#"?e+" (root url)":e+'".');ae.add(n),function(e,t){const n=ue["/"]||(ue["/"]={action:void 0,children:{}});if("#"===e)n.action=t;else{const r=e.split("/"),o=r[r.length-1];r.reduce((e,n)=>e[n]?(n===o&&(e[n].action=t),e[n].children):(e[n]={action:n===o?t:void 0,children:{}}).children,n.children)}}(n,t)}},hasFilter(e){if("*"===e)return null!==le;{const{hash:t}=ve(e);return ie.has(t)}},hasAction(e){if("*"===e)return ce.length>0;{const{hash:t}=ve(e);return ae.has(t)}},navigate(t,n={}){if(0===t.lastIndexOf("http",0))return e.location.href=t;const{hash:r,query:o,rel:s}=ve(t);!0===(n=Object.assign({},he,n)).keepQuery?Object.assign(fe,Oe(o)):fe=Oe(o),le&&le(s,fe,e=>{if(e!==s)return be(e)}),ie.has(r)&&ie.get(r)(s,fe,e=>{if(e!==s)return be(e)}),function(t,n,r,o){(function(e){const t=se+(e="#"===e?"":e);for(let e=0;en.length&&r.push(...function(e,t){const n=[];for(let r=e.length;re?fe[e]:Object.assign({},fe),addQueryParameters(e,t){if(void 0===t&&"object"==typeof e)for(const t in e)fe[t]=e[t];else fe[e]=t;ye()},setQueryParameters(e){fe=r(e),ye()},removeQueryParameters(e){e?Array.isArray(e)?e.forEach(e=>{fe[e]&&delete fe[e]}):fe[e]&&delete fe[e]:fe={},ye()}};function me(){de||(de=!0,e.addEventListener("popstate",()=>{ge.navigate(e.location.href,{history:"replaceState",forceReload:!1})}))}function ye(){oe.search=xe(fe),e.history.replaceState(null,document.title,oe.toString())}function be(t){return 0===t.lastIndexOf("http",0)?e.location.href=t:ge.navigate(t,{history:"replaceState",forceReload:!1})}function ve(e){if(re.indexOf(e)>-1)return{rel:"/",abs:te,hash:"#",query:""};if("?"===e[0]||"#"===e[0]){const{hash:t,query:n}=we(e);return{rel:Ce(t),abs:te+t,hash:t||"#",query:n}}if("?"!==(e=function(e){const t=(r=e,o=re,o.filter(e=>0===r.lastIndexOf(e,0)).sort((e,t)=>t.length-e.length)[0]),n=t?e.substr(t.length):e;var r,o;return 0===n.lastIndexOf("/",0)?n.substr(1):n}(e))[0]&&"#"!==e[0])throw new Error('Invalid Route: "'+e+'". Non-root paths must start with ? query or # hash.');const{hash:t,query:n}=we(e);return{rel:Ce(t),abs:te+t,hash:t||"#",query:n}}function we(e){const t=e.indexOf("#"),n=e.indexOf("?");if(-1===t)return{hash:"",query:Se(new URL(e,te).search)};if(-1===n)return{hash:Se(new URL(e,te).hash),query:""};const r=new URL(e,te);if(n1){const n=e.substring(1).replace(/\+/g," ").replace(/;/g,"&").split("&");for(let e,r,o=0;o1)||decodeURIComponent(e[1]))}return t}function xe(e){let t="?";for(const n in e)t+=encodeURIComponent(n)+"="+encodeURIComponent(e[n])+"&";return"?"===t?t="":"&"===t[t.length-1]&&(t=t.substring(0,t.length-1)),t}const Ee={Component:Y,Store:$,Server:p,Router:ge};"object"==typeof module&&"object"==typeof module.exports?module.exports=Ee:"function"==typeof define&&define.amd?define("Cue",[],(function(){return Ee})):e.Cue=Ee}(window||this); \ No newline at end of file diff --git a/build/cue.module.js b/build/cue.module.js index c7f1ebb..71bb479 100644 --- a/build/cue.module.js +++ b/build/cue.module.js @@ -1926,6 +1926,10 @@ const Router = { navigate(route, options = {}) { + if (route.lastIndexOf('http', 0) === 0) { + return window.location.href = route; + } + const { hash, query, rel } = getRouteParts(route); options = Object.assign({}, DEFAULT_TRIGGER_OPTIONS, options); diff --git a/src/modules/router.js b/src/modules/router.js index 2c7d453..365faf7 100644 --- a/src/modules/router.js +++ b/src/modules/router.js @@ -103,6 +103,10 @@ export const Router = { navigate(route, options = {}) { + if (route.lastIndexOf('http', 0) === 0) { + return window.location.href = route; + } + const { hash, query, rel } = getRouteParts(route); options = Object.assign({}, DEFAULT_TRIGGER_OPTIONS, options);