@stackflow/plugin-history-sync
Advanced tools
Comparing version 0.4.1-alpha.4 to 0.4.1-alpha.7
@@ -1,2 +0,2 @@ | ||
var $=Object.create;var w=Object.defineProperty,L=Object.defineProperties,O=Object.getOwnPropertyDescriptor,M=Object.getOwnPropertyDescriptors,j=Object.getOwnPropertyNames,E=Object.getOwnPropertySymbols,C=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty,D=Object.prototype.propertyIsEnumerable;var N=(t,e,n)=>e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,o=(t,e)=>{for(var n in e||(e={}))b.call(e,n)&&N(t,n,e[n]);if(E)for(var n of E(e))D.call(e,n)&&N(t,n,e[n]);return t},k=(t,e)=>L(t,M(e));var q=(t,e)=>{for(var n in e)w(t,n,{get:e[n],enumerable:!0})},H=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of j(e))!b.call(t,a)&&a!==n&&w(t,a,{get:()=>e[a],enumerable:!(r=O(e,a))||r.enumerable});return t};var F=(t,e,n)=>(n=t!=null?$(C(t)):{},H(e||!t||!t.__esModule?w(n,"default",{value:t,enumerable:!0}):n,t)),K=t=>H(w({},"__esModule",{value:!0}),t);var Z={};q(Z,{historySyncPlugin:()=>Y});module.exports=K(Z);var m=require("@stackflow/core");var I=F(require("url-pattern"));function z(t){return new URL(t,"file://")}function Q(t){let e={};return t.forEach((n,r)=>{e[r]=n}),e}function V(t){return t.endsWith("/")?t:`${t}/`}function W(t){return t.toString().length>0?`?${t}`:t}function y(t){let e=new I.default(`${t}(/)`);return{fill(n){var f;let r=e.stringify(n),a=(f=e.match(r))!=null?f:{},i=o({},n);Object.keys(a).forEach(u=>{delete i[u]});let c=new URLSearchParams(i);return V(r)+W(c)},parse(n){let r=z(n),a=e.match(r.pathname),i=Q(r.searchParams);return a?o(o({},i),a):null}}}var g="@stackflow/plugin-history-sync@0.4.0",J=1e3,B=60*J;function x(){return typeof window=="undefined"?null:window.history.state}function h(t){return typeof t=="string"?[t]:t}function R(t){let e=t;return typeof e=="object"&&e!==null&&"_TAG"in e&&typeof e._TAG=="string"&&e._TAG===g?t:null}function X({state:t,url:e,useHash:n}){if(typeof window=="undefined")return;let r=n?`${window.location.pathname}#${e}`:e;window.history.pushState(t,"",r)}function G({state:t,url:e,useHash:n}){if(typeof window=="undefined")return;let r=n?`${window.location.pathname}#${e}`:e;window.history.replaceState(t,"",r)}function Y(t){return({context:e})=>{let n=!1,r=null;return{key:"historySync",initialPushedEvent(){var d,s,P;let a=R(x()),i=(d=e==null?void 0:e.req)!=null&&d.path?e.req.path:typeof window!="undefined"?window.location.pathname+window.location.search:null,c=(s=t.experimental_initialPreloadRef)==null?void 0:s.call(t,{context:e,path:i});if(a)return k(o(o({},a.activity.pushedBy),c?{preloadRef:c}:null),{name:"Pushed"});if(!i)return null;let f=Object.keys(t.routes);for(let p=0;p<f.length;p+=1){let S=f[p],_=h(t.routes[S]);for(let T=0;T<_.length;T+=1){let U=_[T],A=y(U).parse(i);if(!!A)return(0,m.makeEvent)("Pushed",o({activityId:(0,m.id)(),activityName:S,params:o({},A),eventDate:new Date().getTime()-B},c?{preloadRef:c}:null))}}let u=t.fallbackActivity({context:e}),v=h(t.routes[u]),l=(P=t.experimental_initialPreloadRef)==null?void 0:P.call(t,{context:e,path:v[0]});return(0,m.makeEvent)("Pushed",o({activityId:(0,m.id)(),activityName:u,params:{},eventDate:new Date().getTime()-B},l?{preloadRef:l}:null))},onInit({actions:{getStack:a,dispatchEvent:i}}){let c=a().activities[0],f=y(h(t.routes[c.name])[0]);G({url:f.fill(c.params),state:{_TAG:g,activity:c},useHash:t.useHash});let u=v=>{let l=R(v.state);if(!l)return;let{activities:d}=a(),s=d.find(S=>S.id===l.activity.pushedBy.activityId),P=!s&&l.activity.pushedBy.activityId<d[0].id||(s==null?void 0:s.transitionState)==="enter-active"||(s==null?void 0:s.transitionState)==="enter-done",p=!s&&l.activity.pushedBy.activityId>d[d.length-1].id||(s==null?void 0:s.transitionState)==="exit-active"||(s==null?void 0:s.transitionState)==="exit-done";P&&(i("Popped",{}),s||(n=!0,i("Pushed",o({},l.activity.pushedBy)))),p&&(n=!0,i("Pushed",{activityId:l.activity.pushedBy.activityId,activityName:l.activity.pushedBy.activityName,params:l.activity.pushedBy.params}))};r==null||r(),typeof window!="undefined"&&window.addEventListener("popstate",u),r=()=>{typeof window!="undefined"&&window.removeEventListener("popstate",u)}},onPushed({effect:{activity:a}}){if(n){n=!1;return}let i=y(h(t.routes[a.name])[0]);X({url:i.fill(a.params),state:{_TAG:g,activity:a},useHash:t.useHash})},onReplaced({effect:{activity:a}}){let i=y(h(t.routes[a.name])[0]);G({url:i.fill(a.params),state:{_TAG:g,activity:a},useHash:t.useHash})},onBeforePush({params:a,actions:{overrideParams:i}}){var u;let f=y(h(t.routes[a.activityName])[0]).fill(a.params);i(k(o({},a),{preloadRef:(u=t.experimental_preloadRef)==null?void 0:u.call(t,{context:e,path:f})}))},onBeforePop({actions:{preventDefault:a}}){a();do typeof window!="undefined"&&window.history.back();while(!R(x()))}}}} | ||
var L=Object.create;var P=Object.defineProperty,O=Object.defineProperties,M=Object.getOwnPropertyDescriptor,j=Object.getOwnPropertyDescriptors,C=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols,D=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var E=(t,e,a)=>e in t?P(t,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):t[e]=a,l=(t,e)=>{for(var a in e||(e={}))b.call(e,a)&&E(t,a,e[a]);if(_)for(var a of _(e))q.call(e,a)&&E(t,a,e[a]);return t},H=(t,e)=>O(t,j(e));var F=(t,e)=>{for(var a in e)P(t,a,{get:e[a],enumerable:!0})},I=(t,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let u of C(e))!b.call(t,u)&&u!==a&&P(t,u,{get:()=>e[u],enumerable:!(i=M(e,u))||i.enumerable});return t};var K=(t,e,a)=>(a=t!=null?L(D(t)):{},I(e||!t||!t.__esModule?P(a,"default",{value:t,enumerable:!0}):a,t)),z=t=>I(P({},"__esModule",{value:!0}),t);var tt={};F(tt,{historySyncPlugin:()=>Z});module.exports=z(tt);var v=require("@stackflow/core");var B=K(require("url-pattern"));function Q(t){return new URL(t,"file://")}function V(t){let e={};return t.forEach((a,i)=>{e[i]=a}),e}function W(t){return t.endsWith("/")?t:`${t}/`}function J(t){return t.toString().length>0?`?${t}`:t}function h(t){let e=new B.default(`${t}(/)`);return{fill(a){var c;let i=e.stringify(a),u=(c=e.match(i))!=null?c:{},n=l({},a);Object.keys(u).forEach(d=>{delete n[d]});let s=new URLSearchParams(n);return W(i)+J(s)},parse(a){let i=Q(a),u=e.match(i.pathname),n=V(i.searchParams);return u?l(l({},n),u):null}}}var S="@stackflow/plugin-history-sync@0.4.0",X=1e3,x=60*X;function G(){return typeof window=="undefined"?null:window.history.state}function p(t){return typeof t=="string"?[t]:t}function R(t){let e=t;return typeof e=="object"&&e!==null&&"_TAG"in e&&typeof e._TAG=="string"&&e._TAG===S?t:null}function Y({state:t,url:e,useHash:a}){if(typeof window=="undefined")return;let i=a?`${window.location.pathname}#${e}`:e;window.history.pushState(t,"",i)}function U({state:t,url:e,useHash:a}){if(typeof window=="undefined")return;let i=a?`${window.location.pathname}#${e}`:e;window.history.replaceState(t,"",i)}function Z(t){return({context:e})=>{let a=!1,i=null;function u({activityName:n,activityParams:s}){var y;let d=h(p(t.routes[n])[0]).fill(s);return(y=t.experimental_preloadRef)==null?void 0:y.call(t,{context:e,path:d})}return{key:"historySync",initialPushedEvent(){var m,r,g;let n=R(G()),s=(m=e==null?void 0:e.req)!=null&&m.path?e.req.path:typeof window!="undefined"?window.location.pathname+window.location.search:null,c=(r=t.experimental_initialPreloadRef)==null?void 0:r.call(t,{context:e,path:s});if(n)return H(l(l({},n.activity.pushedBy),c?{preloadRef:c}:null),{name:"Pushed"});if(!s)return null;let d=Object.keys(t.routes);for(let w=0;w<d.length;w+=1){let f=d[w],N=p(t.routes[f]);for(let k=0;k<N.length;k+=1){let $=N[k],A=h($).parse(s);if(!!A)return(0,v.makeEvent)("Pushed",l({activityId:(0,v.id)(),activityName:f,params:l({},A),eventDate:new Date().getTime()-x},c?{preloadRef:c}:null))}}let y=t.fallbackActivity({context:e}),T=p(t.routes[y]),o=(g=t.experimental_initialPreloadRef)==null?void 0:g.call(t,{context:e,path:T[0]});return(0,v.makeEvent)("Pushed",l({activityId:(0,v.id)(),activityName:y,params:{},eventDate:new Date().getTime()-x},o?{preloadRef:o}:null))},onInit({actions:{getStack:n,dispatchEvent:s}}){let c=n().activities[0],d=h(p(t.routes[c.name])[0]);U({url:d.fill(c.params),state:{_TAG:S,activity:c},useHash:t.useHash});let y=T=>{let o=R(T.state);if(!o)return;let{activities:m}=n(),r=m.find(f=>f.id===o.activity.pushedBy.activityId),g=!r&&o.activity.pushedBy.activityId<m[0].id||(r==null?void 0:r.transitionState)==="enter-active"||(r==null?void 0:r.transitionState)==="enter-done",w=!r&&o.activity.pushedBy.activityId>m[m.length-1].id||(r==null?void 0:r.transitionState)==="exit-active"||(r==null?void 0:r.transitionState)==="exit-done";if(g&&(s("Popped",{}),!r)){a=!0;let f=u({activityName:o.activity.name,activityParams:o.activity.params});s("Pushed",l(l({},o.activity.pushedBy),f?{preloadRef:f}:null))}if(w){a=!0;let f=u({activityName:o.activity.name,activityParams:o.activity.params});s("Pushed",l({activityId:o.activity.pushedBy.activityId,activityName:o.activity.pushedBy.activityName,params:o.activity.pushedBy.params},f?{preloadRef:f}:null))}};i==null||i(),typeof window!="undefined"&&window.addEventListener("popstate",y),i=()=>{typeof window!="undefined"&&window.removeEventListener("popstate",y)}},onPushed({effect:{activity:n}}){if(a){a=!1;return}let s=h(p(t.routes[n.name])[0]);Y({url:s.fill(n.params),state:{_TAG:S,activity:n},useHash:t.useHash})},onReplaced({effect:{activity:n}}){let s=h(p(t.routes[n.name])[0]);U({url:s.fill(n.params),state:{_TAG:S,activity:n},useHash:t.useHash})},onBeforePush({params:n,actions:{overrideParams:s}}){let c=u({activityName:n.activityName,activityParams:n.params});s(l(l({},n),c?{preloadRef:c}:null))},onBeforePop({actions:{preventDefault:n}}){n();do typeof window!="undefined"&&window.history.back();while(!R(G()))}}}} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@stackflow/plugin-history-sync", | ||
"version": "0.4.1-alpha.4+823f630", | ||
"version": "0.4.1-alpha.7+3fddba2", | ||
"license": "Apache-2.0", | ||
@@ -52,3 +52,3 @@ "exports": { | ||
}, | ||
"gitHead": "823f630296324cdd4db22bcd5352f152c81033ce" | ||
"gitHead": "3fddba2b58bfa39b04b594242d70f7a00d042c40" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
64095
410