Socket
Socket
Sign inDemoInstall

@stackflow/plugin-history-sync

Package Overview
Dependencies
Maintainers
1
Versions
123
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stackflow/plugin-history-sync - npm Package Compare versions

Comparing version 0.3.2 to 0.4.0

6

dist/historySyncPlugin.d.ts

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

import { StackflowPlugin } from "@stackflow/core";
import { StackflowReactPlugin } from "@stackflow/react";
declare type HistorySyncPluginOptions<T extends {

@@ -6,3 +6,3 @@ [activityName: string]: any;

routes: {
[key in keyof T]: string;
[key in keyof T]: string | string[];
};

@@ -16,3 +16,3 @@ fallbackActivity: (args: {

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

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

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

@@ -31,2 +31,3 @@ "exports": {

"@stackflow/esbuild-config": "^0.2.1",
"@stackflow/react": "^0.3.0",
"@types/react": "^18.0.10",

@@ -39,2 +40,3 @@ "react": "^18.1.0",

"@stackflow/core": "^0.1.0",
"@stackflow/react": "^0.2.3",
"@types/react": ">=16.8.0",

@@ -52,3 +54,3 @@ "react": ">=16.8.0"

},
"gitHead": "6a0f976f37725efa69291735c3c5708c22af0b54"
"gitHead": "fdd22a39ec24210357789f5977ebc274c02be23e"
}

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc