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