@ossy/router-react 3.0.9 → 3.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/index.js +1 -1
  2. package/package.json +2 -2
package/build/index.js CHANGED
@@ -1 +1 @@
1
- import n,{createContext as e,useMemo as t,useState as o,useEffect as i,useCallback as r,useContext as a}from"react";import{Router as u,isCatchAllRoutePath as l}from"@ossy/router";var d=function(){return d=Object.assign||function(n){for(var e,t=1,o=arguments.length;t<o;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n},d.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var c=e({href:"",pages:[],language:void 0,defaultLanguage:void 0,supportedLanguages:[],params:{},navigate:function(){},getHref:function(){return""},back:function(){}}),f=e({set:function(){},delete:function(){}}),s=function(){return a(f)},v=function(){var n=a(c),e=a(f);return t(function(){return d(d({},n),{searchParams:e})},[n,e])},p=function(e){var a,s,v,p,w=e.url,g=e.pages,h=void 0===g?[]:g,m=e.defaultLanguage,y=void 0===m?void 0:m,L=e.supportedLanguages,E=void 0===L?[]:L,P=e.children;if(w){var b=w.match(/([^?#]*)(\?[^#]*)?(#.*)?/);a=w,s=(null==b?void 0:b[1])||"",v=(null==b?void 0:b[3])||"",p=(null==b?void 0:b[2])||""}else{if("undefined"==typeof window)return n.createElement(n.Fragment,null);a=window.location.href,s=window.location.pathname,v=window.location.hash,p=(null==v?void 0:v.includes("?"))?v.split("?")[1]:window.location.search}var S=E.length>1&&!!y,k=s.split("/")[1]||"",R=E.includes(k)?k:y,O=t(function(){return u.of({pages:h,defaultLanguage:y,supportedLanguages:E})},[h,y,E]),U=t(function(){return O.getParamsFromUrl(a)},[O,a]),j=o(function(){return"undefined"==typeof window?p:window.location.search}),F=j[0],H=j[1];i(function(){if("undefined"!=typeof window){var n=function(){return H(window.location.search)};return window.addEventListener("popstate",n),function(){return window.removeEventListener("popstate",n)}}},[]);var x="undefined"==typeof window&&w?p:F,B=new URLSearchParams(x.replace(/^\?/,"")),N=r(function(n){if("undefined"!=typeof window){var e=new URLSearchParams(window.location.search);n(e);var t=e.toString(),o=t?"".concat(window.location.pathname,"?").concat(t):window.location.pathname;window.history.pushState({},"",o),H(window.location.search)}},[]),q=r(function(n,e){N(function(t){null==e||""===e?t.delete(n):t.set(n,e)})},[N]),z=r(function(n){N(function(e){e.delete(n)})},[N]),A=O.getPageByUrl(a);A||(S&&"/"===s&&"undefined"!=typeof window&&(window.location.href="/"+y),A=S?h.find(function(n){var e,t=n.path,o=null!==(e=null==t?void 0:t[R])&&void 0!==e?e:null==t?void 0:t[y];return l(o)}):h.find(function(n){return l(n.path)})),A||console.warn("[RouterReact] No active page found for",s);var C=r(function(n){var e,t,o,i,r,a,u={};if("string"==typeof n?(t=n,u=U,o=R):(a=n).id||void 0===a.language?(t=(null==n?void 0:n.id)||(null==A?void 0:A.id)||"",u=(null==n?void 0:n.params)||U,o=(null==n?void 0:n.language)||R):(t=null!==(e=null==A?void 0:A.id)&&void 0!==e?e:"",u=U,o=n.language),t.includes("#")){var l=t.split("#");if(t=l[0],(i=l[1]).includes("?")){var d=t.split("?");i=d[0],r=d[1]}}else if(t.includes("?")){var c=t.split("?");t=c[0],r=c[1]}var f=O.getPathname({id:t.replace("@",""),params:u,language:o});return i&&(f=f+"#"+i),r&&(f=f+"?"+r),null!=f?f:""},[O,R,U,A]),D=r(function(n){if("undefined"!=typeof window&&n)if("@back"!==n){var e=C(n);e&&(window.location.href=e)}else window.history.back()},[C]),G=r(function(){"undefined"!=typeof window&&window.history.back()},[]),I=t(function(){var n=Object.fromEntries(B.entries());return d(d({},n),{set:q,delete:z})},[F,q,z]),J=t(function(){return{href:a,pages:h,language:R,defaultLanguage:y,supportedLanguages:E,params:U,navigate:D,getHref:C,back:G}},[a,h,R,y,E,U,D,C,G]);(null==A?void 0:A.redirect)&&D({id:A.redirect});var K=t(function(){var n,e;return null!==(n=null==A?void 0:A.element)&&void 0!==n?n:null===(e=null==A?void 0:A.render)||void 0===e?void 0:e.call(A)},[A]);return A?n.createElement(c.Provider,{value:J},n.createElement(f.Provider,{value:I},P||K)):n.createElement(n.Fragment,null)};export{p as Router,c as RouterContext,f as SearchParamsContext,v as useRouter,s as useSearchParams};
1
+ import n,{createContext as e,useMemo as t,useState as o,useEffect as i,useCallback as r,useContext as a}from"react";import{Router as u,isCatchAllRoutePath as l}from"@ossy/router";var d=function(){return d=Object.assign||function(n){for(var e,t=1,o=arguments.length;t<o;t++)for(var i in e=arguments[t])Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n},d.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var c=e({href:"",pages:[],language:void 0,defaultLanguage:void 0,supportedLanguages:[],params:{},navigate:function(){},getHref:function(){return""},back:function(){}}),f=e({set:function(){},delete:function(){}}),s=function(){return a(f)},v=function(){var n=a(c),e=a(f);return t(function(){return d(d({},n),{searchParams:e})},[n,e])},p=function(e){var a,s,v,p,w=e.url,g=e.pages,h=void 0===g?[]:g,m=e.defaultLanguage,y=void 0===m?void 0:m,L=e.supportedLanguages,E=void 0===L?[]:L,P=e.children;if(w){var b=w.match(/([^?#]*)(\?[^#]*)?(#.*)?/);a=w,s=(null==b?void 0:b[1])||"",v=(null==b?void 0:b[3])||"",p=(null==b?void 0:b[2])||""}else{if("undefined"==typeof window)return n.createElement(n.Fragment,null);a=window.location.href,s=window.location.pathname,v=window.location.hash,p=(null==v?void 0:v.includes("?"))?v.split("?")[1]:window.location.search}var S=E.length>1&&!!y,k=s.split("/")[1]||"",R=E.includes(k)?k:y,O=t(function(){return u.of({pages:h,defaultLanguage:y,supportedLanguages:E})},[h,y,E]),U=t(function(){return O.getParamsFromUrl(a)},[O,a]),j=o(function(){return"undefined"==typeof window?p:window.location.search}),F=j[0],H=j[1];i(function(){if("undefined"!=typeof window){var n=function(){return H(window.location.search)};return window.addEventListener("popstate",n),function(){return window.removeEventListener("popstate",n)}}},[]);var W="undefined"==typeof window&&w?p:F,x=new URLSearchParams(W.replace(/^\?/,"")),B=r(function(n){if("undefined"!=typeof window){var e=new URLSearchParams(window.location.search);n(e);var t=e.toString(),o=t?"".concat(window.location.pathname,"?").concat(t):window.location.pathname;window.history.pushState({},"",o),H(window.location.search)}},[]),N=r(function(n,e){B(function(t){null==e||""===e?t.delete(n):t.set(n,e)})},[B]),q=r(function(n){B(function(e){e.delete(n)})},[B]),z=O.getPageByUrl(a);z||(S&&"/"===s&&"undefined"!=typeof window&&(window.location.href="/"+y),z=S?h.find(function(n){var e,t=n.path,o=null!==(e=null==t?void 0:t[R])&&void 0!==e?e:null==t?void 0:t[y];return l(o)}):h.find(function(n){return l(n.path)})),z||console.warn("[RouterReact] No active page found for",s);var A=r(function(n){var e,t,o,i,r,a,u={};if("string"==typeof n?(t=n,u=U,o=R):(a=n).id||void 0===a.language?(t=(null==n?void 0:n.id)||(null==z?void 0:z.id)||"",u=(null==n?void 0:n.params)||U,o=(null==n?void 0:n.language)||R):(t=null!==(e=null==z?void 0:z.id)&&void 0!==e?e:"",u=U,o=n.language),t.includes("#")){var l=t.split("#");if(t=l[0],(i=l[1]).includes("?")){var d=t.split("?");i=d[0],r=d[1]}}else if(t.includes("?")){var c=t.split("?");t=c[0],r=c[1]}var f=O.getPathname({id:t.replace("@",""),params:u,language:o});return i&&(f=f+"#"+i),r&&(f=f+"?"+r),null!=f?f:""},[O,R,U,z]),C=r(function(n){if("undefined"!=typeof window&&n)if("@back"!==n)if("string"!=typeof n||!n.startsWith("/")||n.startsWith("//")){var e=A(n);e&&(window.location.href=e)}else window.location.assign(n);else window.history.back()},[A]),D=r(function(){"undefined"!=typeof window&&window.history.back()},[]),G=t(function(){var n=Object.fromEntries(x.entries());return d(d({},n),{set:N,delete:q})},[F,N,q]),I=t(function(){return{href:a,pages:h,language:R,defaultLanguage:y,supportedLanguages:E,params:U,navigate:C,getHref:A,back:D}},[a,h,R,y,E,U,C,A,D]);(null==z?void 0:z.redirect)&&C({id:z.redirect});var J=t(function(){var n,e;return null!==(n=null==z?void 0:z.element)&&void 0!==n?n:null===(e=null==z?void 0:z.render)||void 0===e?void 0:e.call(z)},[z]);return z?n.createElement(c.Provider,{value:I},n.createElement(f.Provider,{value:G},P||J)):n.createElement(n.Fragment,null)};export{p as Router,c as RouterContext,f as SearchParamsContext,v as useRouter,s as useSearchParams};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ossy/router-react",
3
- "version": "3.0.9",
3
+ "version": "3.9.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/ossy-se/packages.git"
@@ -65,5 +65,5 @@
65
65
  "/build",
66
66
  "README.md"
67
67
  ],
68
- "gitHead": "908fae28675f6c3c179d4c2eecb451e8a1af886e"
68
+ "gitHead": "f404be69becb27a1fd853a6ff1903554e76e7d17"
69
69
  }