@stackflow/plugin-history-sync
Advanced tools
Comparing version 0.4.1-alpha.2 to 0.4.1-alpha.3
@@ -12,4 +12,10 @@ import { StackflowReactPlugin } from "@stackflow/react"; | ||
useHash?: boolean; | ||
experimental_initialPreloadRef?: (path: string) => any; | ||
experimental_preloadRef?: (path: string) => any; | ||
experimental_initialPreloadRef?: (args: { | ||
context: any; | ||
path: string; | ||
}) => any; | ||
experimental_preloadRef?: (args: { | ||
context: any; | ||
path: string; | ||
}) => any; | ||
}; | ||
@@ -16,0 +22,0 @@ export declare function historySyncPlugin<T extends { |
@@ -1,2 +0,2 @@ | ||
var G=Object.create;var w=Object.defineProperty,U=Object.defineProperties,$=Object.getOwnPropertyDescriptor,L=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols,M=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var A=(t,e,n)=>e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,f=(t,e)=>{for(var n in e||(e={}))E.call(e,n)&&A(t,n,e[n]);if(_)for(var n of _(e))j.call(e,n)&&A(t,n,e[n]);return t},T=(t,e)=>U(t,L(e));var C=(t,e)=>{for(var n in e)w(t,n,{get:e[n],enumerable:!0})},N=(t,e,n,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of O(e))!E.call(t,a)&&a!==n&&w(t,a,{get:()=>e[a],enumerable:!(i=$(e,a))||i.enumerable});return t};var D=(t,e,n)=>(n=t!=null?G(M(t)):{},N(e||!t||!t.__esModule?w(n,"default",{value:t,enumerable:!0}):n,t)),q=t=>N(w({},"__esModule",{value:!0}),t);var X={};C(X,{historySyncPlugin:()=>J});module.exports=q(X);var m=require("@stackflow/core");var H=D(require("url-pattern"));function F(t){return new URL(t,"file://")}function K(t){let e={};return t.forEach((n,i)=>{e[i]=n}),e}function z(t){return t.endsWith("/")?t:`${t}/`}function Q(t){return t.toString().length>0?`?${t}`:t}function y(t){let e=new H.default(`${t}(/)`);return{fill(n){var u;let i=e.stringify(n),a=(u=e.match(i))!=null?u:{},s=f({},n);Object.keys(a).forEach(l=>{delete s[l]});let c=new URLSearchParams(s);return z(i)+Q(c)},parse(n){let i=F(n),a=e.match(i.pathname),s=K(i.searchParams);return a?f(f({},s),a):null}}}var g="@stackflow/plugin-history-sync@0.4.0",V=1e3,I=60*V;function b(){return typeof window=="undefined"?null:window.history.state}function h(t){return typeof t=="string"?[t]:t}function k(t){let e=t;return typeof e=="object"&&e!==null&&"_TAG"in e&&typeof e._TAG=="string"&&e._TAG===g?t:null}function W({state:t,url:e,useHash:n}){if(typeof window=="undefined")return;let i=n?`${window.location.pathname}#${e}`:e;window.history.pushState(t,"",i)}function x({state:t,url:e,useHash:n}){if(typeof window=="undefined")return;let i=n?`${window.location.pathname}#${e}`:e;window.history.replaceState(t,"",i)}function J(t){return({context:e})=>{let n=!1,i=null;return{key:"historySync",initialPushedEvent(){var S,o,d;let a=k(b());if(a)return T(f({},a.activity.pushedBy),{name:"Pushed"});let s=(S=e==null?void 0:e.req)!=null&&S.path?e.req.path:typeof window!="undefined"?window.location.pathname+window.location.search:null;if(!s)return null;let c=Object.keys(t.routes);for(let r=0;r<c.length;r+=1){let v=c[r],P=h(t.routes[v]);for(let p=0;p<P.length;p+=1){let B=P[p],R=y(B).parse(s);if(!!R)return(0,m.makeEvent)("Pushed",{activityId:(0,m.id)(),activityName:v,params:f({},R),preloadRef:(o=t.experimental_initialPreloadRef)==null?void 0:o.call(t,s),eventDate:new Date().getTime()-I})}}let u=t.fallbackActivity({context:e}),l=h(t.routes[u]);return(0,m.makeEvent)("Pushed",{activityId:(0,m.id)(),activityName:u,params:{},preloadRef:(d=t.experimental_initialPreloadRef)==null?void 0:d.call(t,l[0]),eventDate:new Date().getTime()-I})},onInit({actions:{getStack:a,dispatchEvent:s}}){let c=a().activities[0],u=y(h(t.routes[c.name])[0]);x({url:u.fill(c.params),state:{_TAG:g,activity:c},useHash:t.useHash});let l=S=>{let o=k(S.state);if(!o)return;let{activities:d}=a(),r=d.find(p=>p.id===o.activity.pushedBy.activityId),v=!r&&o.activity.pushedBy.activityId<d[0].id||(r==null?void 0:r.transitionState)==="enter-active"||(r==null?void 0:r.transitionState)==="enter-done",P=!r&&o.activity.pushedBy.activityId>d[d.length-1].id||(r==null?void 0:r.transitionState)==="exit-active"||(r==null?void 0:r.transitionState)==="exit-done";v&&(s("Popped",{}),r||(n=!0,s("Pushed",f({},o.activity.pushedBy)))),P&&(n=!0,s("Pushed",{activityId:o.activity.pushedBy.activityId,activityName:o.activity.pushedBy.activityName,params:o.activity.pushedBy.params}))};i==null||i(),typeof window!="undefined"&&window.addEventListener("popstate",l),i=()=>{typeof window!="undefined"&&window.removeEventListener("popstate",l)}},onPushed({effect:{activity:a}}){if(n){n=!1;return}let s=y(h(t.routes[a.name])[0]);W({url:s.fill(a.params),state:{_TAG:g,activity:a},useHash:t.useHash})},onReplaced({effect:{activity:a}}){let s=y(h(t.routes[a.name])[0]);x({url:s.fill(a.params),state:{_TAG:g,activity:a},useHash:t.useHash})},onBeforePush({params:a,actions:{overrideParams:s}}){var l;let u=y(h(t.routes[a.activityName])[0]).fill(a.params);s(T(f({},a),{preloadRef:(l=t.experimental_preloadRef)==null?void 0:l.call(t,u)}))},onBeforePop({actions:{preventDefault:a}}){a();do typeof window!="undefined"&&window.history.back();while(!k(b()))}}}} | ||
var G=Object.create;var w=Object.defineProperty,U=Object.defineProperties,$=Object.getOwnPropertyDescriptor,L=Object.getOwnPropertyDescriptors,O=Object.getOwnPropertyNames,_=Object.getOwnPropertySymbols,M=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty,j=Object.prototype.propertyIsEnumerable;var A=(t,e,n)=>e in t?w(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,f=(t,e)=>{for(var n in e||(e={}))E.call(e,n)&&A(t,n,e[n]);if(_)for(var n of _(e))j.call(e,n)&&A(t,n,e[n]);return t},T=(t,e)=>U(t,L(e));var C=(t,e)=>{for(var n in e)w(t,n,{get:e[n],enumerable:!0})},N=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of O(e))!E.call(t,a)&&a!==n&&w(t,a,{get:()=>e[a],enumerable:!(r=$(e,a))||r.enumerable});return t};var D=(t,e,n)=>(n=t!=null?G(M(t)):{},N(e||!t||!t.__esModule?w(n,"default",{value:t,enumerable:!0}):n,t)),q=t=>N(w({},"__esModule",{value:!0}),t);var X={};C(X,{historySyncPlugin:()=>J});module.exports=q(X);var m=require("@stackflow/core");var H=D(require("url-pattern"));function F(t){return new URL(t,"file://")}function K(t){let e={};return t.forEach((n,r)=>{e[r]=n}),e}function z(t){return t.endsWith("/")?t:`${t}/`}function Q(t){return t.toString().length>0?`?${t}`:t}function y(t){let e=new H.default(`${t}(/)`);return{fill(n){var u;let r=e.stringify(n),a=(u=e.match(r))!=null?u:{},s=f({},n);Object.keys(a).forEach(l=>{delete s[l]});let c=new URLSearchParams(s);return z(r)+Q(c)},parse(n){let r=F(n),a=e.match(r.pathname),s=K(r.searchParams);return a?f(f({},s),a):null}}}var P="@stackflow/plugin-history-sync@0.4.0",V=1e3,I=60*V;function b(){return typeof window=="undefined"?null:window.history.state}function h(t){return typeof t=="string"?[t]:t}function k(t){let e=t;return typeof e=="object"&&e!==null&&"_TAG"in e&&typeof e._TAG=="string"&&e._TAG===P?t:null}function W({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 B({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 J(t){return({context:e})=>{let n=!1,r=null;return{key:"historySync",initialPushedEvent(){var S,o,d;let a=k(b());if(a)return T(f({},a.activity.pushedBy),{name:"Pushed"});let s=(S=e==null?void 0:e.req)!=null&&S.path?e.req.path:typeof window!="undefined"?window.location.pathname+window.location.search:null;if(!s)return null;let c=Object.keys(t.routes);for(let i=0;i<c.length;i+=1){let g=c[i],v=h(t.routes[g]);for(let p=0;p<v.length;p+=1){let x=v[p],R=y(x).parse(s);if(!!R)return(0,m.makeEvent)("Pushed",{activityId:(0,m.id)(),activityName:g,params:f({},R),preloadRef:(o=t.experimental_initialPreloadRef)==null?void 0:o.call(t,{context:e,path:s}),eventDate:new Date().getTime()-I})}}let u=t.fallbackActivity({context:e}),l=h(t.routes[u]);return(0,m.makeEvent)("Pushed",{activityId:(0,m.id)(),activityName:u,params:{},preloadRef:(d=t.experimental_initialPreloadRef)==null?void 0:d.call(t,{context:e,path:l[0]}),eventDate:new Date().getTime()-I})},onInit({actions:{getStack:a,dispatchEvent:s}}){let c=a().activities[0],u=y(h(t.routes[c.name])[0]);B({url:u.fill(c.params),state:{_TAG:P,activity:c},useHash:t.useHash});let l=S=>{let o=k(S.state);if(!o)return;let{activities:d}=a(),i=d.find(p=>p.id===o.activity.pushedBy.activityId),g=!i&&o.activity.pushedBy.activityId<d[0].id||(i==null?void 0:i.transitionState)==="enter-active"||(i==null?void 0:i.transitionState)==="enter-done",v=!i&&o.activity.pushedBy.activityId>d[d.length-1].id||(i==null?void 0:i.transitionState)==="exit-active"||(i==null?void 0:i.transitionState)==="exit-done";g&&(s("Popped",{}),i||(n=!0,s("Pushed",f({},o.activity.pushedBy)))),v&&(n=!0,s("Pushed",{activityId:o.activity.pushedBy.activityId,activityName:o.activity.pushedBy.activityName,params:o.activity.pushedBy.params}))};r==null||r(),typeof window!="undefined"&&window.addEventListener("popstate",l),r=()=>{typeof window!="undefined"&&window.removeEventListener("popstate",l)}},onPushed({effect:{activity:a}}){if(n){n=!1;return}let s=y(h(t.routes[a.name])[0]);W({url:s.fill(a.params),state:{_TAG:P,activity:a},useHash:t.useHash})},onReplaced({effect:{activity:a}}){let s=y(h(t.routes[a.name])[0]);B({url:s.fill(a.params),state:{_TAG:P,activity:a},useHash:t.useHash})},onBeforePush({params:a,actions:{overrideParams:s}}){var l;let u=y(h(t.routes[a.activityName])[0]).fill(a.params);s(T(f({},a),{preloadRef:(l=t.experimental_preloadRef)==null?void 0:l.call(t,{context:e,path:u})}))},onBeforePop({actions:{preventDefault:a}}){a();do typeof window!="undefined"&&window.history.back();while(!k(b()))}}}} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@stackflow/plugin-history-sync", | ||
"version": "0.4.1-alpha.2+f09174e", | ||
"version": "0.4.1-alpha.3+06c64c3", | ||
"license": "Apache-2.0", | ||
@@ -52,3 +52,3 @@ "exports": { | ||
}, | ||
"gitHead": "f09174e5860adb00c04deec2000d8b34eb5587d9" | ||
"gitHead": "06c64c3c834dc9ee1c5f5d80060dfc69ed6c26ea" | ||
} |
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
59548
380