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