Socket
Socket
Sign inDemoInstall

@stackflow/plugin-history-sync

Package Overview
Dependencies
9
Maintainers
1
Versions
110
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.6.0 to 0.6.1

README.md

14

dist/historySyncPlugin.d.ts
import { ActivityParams } from "@stackflow/core";
import { StackflowReactPlugin } from "@stackflow/react";
declare type HistorySyncPluginOptions<T extends {
[activityName: string]: any;
}> = {
declare type HistorySyncPluginOptions<K extends string> = {
routes: {
[key in keyof T]: string | string[];
[key in K]: string | string[];
};
fallbackActivity: (args: {
context: any;
}) => Extract<keyof T, string>;
}) => K;
useHash?: boolean;

@@ -17,3 +15,3 @@ experimental_initialPreloadRef?: (args: {

activityId: string;
activityName: string;
activityName: K;
activityParams: ActivityParams;

@@ -26,3 +24,3 @@ context: any;

activityId: string;
activityName: string;
activityName: K;
activityParams: ActivityParams;

@@ -35,3 +33,3 @@ context: any;

[activityName: string]: any;
}>(options: HistorySyncPluginOptions<T>): StackflowReactPlugin<T>;
}>(options: HistorySyncPluginOptions<Extract<keyof T, string>>): StackflowReactPlugin<T>;
export {};

@@ -1,2 +0,2 @@

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

@@ -16,3 +16,4 @@ ".": {

"dist",
"src"
"src",
"README.md"
],

@@ -30,9 +31,9 @@ "scripts": {

"devDependencies": {
"@stackflow/core": "^0.4.0",
"@stackflow/esbuild-config": "^0.2.1",
"@stackflow/react": "^0.5.0",
"@stackflow/core": "^0.4.1",
"@stackflow/esbuild-config": "^0.2.2",
"@stackflow/react": "^0.5.1",
"@types/react": "^18.0.10",
"react": "^18.1.0",
"rimraf": "^3.0.2",
"typescript": "^4.6.3"
"typescript": "^4.7.4"
},

@@ -54,3 +55,3 @@ "peerDependencies": {

},
"gitHead": "fd15108ea159510977b2932a50f78f3ff9fefcd3"
"gitHead": "5ed301496b246955d52c135d308858847a58a90c"
}

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc