@ossy/router-react 3.11.0 → 3.14.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.
- package/build/index.js +1 -1
- package/package.json +2 -2
package/build/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import n,{createContext as e,useMemo as t,useState as a,useEffect as o,useCallback as i,useContext as r}from"react";import{Router as u,isCatchAllRoutePath as c}from"@ossy/router";var l=function(){return l=Object.assign||function(n){for(var e,t=1,a=arguments.length;t<a;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},l.apply(this,arguments)};function d(n){if(null!=n){if("string"==typeof n)return n.replace(/^\?/,"").trim()||void 0;for(var e=new URLSearchParams,t=0,a=Object.entries(n);t<a.length;t++){var o=a[t],i=o[0],r=o[1];null!=r&&""!==r&&e.set(i,r)}return e.toString()||void 0}}function
|
|
1
|
+
import n,{createContext as e,useMemo as t,useState as a,useEffect as o,useCallback as i,useContext as r}from"react";import{Router as u,isCatchAllRoutePath as c}from"@ossy/router";var l=function(){return l=Object.assign||function(n){for(var e,t=1,a=arguments.length;t<a;t++)for(var o in e=arguments[t])Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o]);return n},l.apply(this,arguments)};function d(n){if(null!=n){if("string"==typeof n)return n.replace(/^\?/,"").trim()||void 0;for(var e=new URLSearchParams,t=0,a=Object.entries(n);t<a.length;t++){var o=a[t],i=o[0],r=o[1];null!=r&&""!==r&&e.set(i,r)}return e.toString()||void 0}}function s(n){if(null!=n)return n.replace(/^#/,"").trim()||void 0}"function"==typeof SuppressedError&&SuppressedError;var f=e({href:"",pages:[],language:void 0,defaultLanguage:void 0,supportedLanguages:[],params:{},navigate:function(){},getHref:function(){return""},back:function(){}}),v=e({set:function(){},delete:function(){},patch:function(){}}),p=function(){return r(v)},h=function(){var n=r(f),e=r(v);return t(function(){return l(l({},n),{searchParams:e})},[n,e])},w=function(e){var r,p,h,w,g=e.url,m=e.pages,y=void 0===m?[]:m,P=e.defaultLanguage,L=void 0===P?void 0:P,b=e.supportedLanguages,S=void 0===b?[]:b,E=e.children;if(g){var R=g.match(/([^?#]*)(\?[^#]*)?(#.*)?/);r=g,p=(null==R?void 0:R[1])||"",h=(null==R?void 0:R[3])||"",w=(null==R?void 0:R[2])||""}else{if("undefined"==typeof window)return n.createElement(n.Fragment,null);r=window.location.href,p=window.location.pathname,h=window.location.hash,w=(null==h?void 0:h.includes("?"))?h.split("?")[1]:window.location.search}var j=S.length>1&&!!L,H=p.split("/")[1]||"",O=S.includes(H)?H:L,k=t(function(){return u.of({pages:y,defaultLanguage:L,supportedLanguages:S})},[y,L,S]),F=t(function(){return k.getParamsFromUrl(r)},[k,r]),U=a(function(){return"undefined"==typeof window?w:window.location.search}),I=U[0],W=U[1];o(function(){if("undefined"!=typeof window){var n=function(){return W(window.location.search)};return window.addEventListener("popstate",n),function(){return window.removeEventListener("popstate",n)}}},[]);var x="undefined"==typeof window&&g?w:I,B=new URLSearchParams(x.replace(/^\?/,"")),N=i(function(n){if("undefined"!=typeof window){var e=new URLSearchParams(window.location.search);n(e);var t=e.toString(),a=t?"".concat(window.location.pathname,"?").concat(t):window.location.pathname;a!=="".concat(window.location.pathname).concat(window.location.search)&&(window.history.pushState({},"",a),W(window.location.search))}},[]),q=i(function(n,e){N(function(t){null==e||""===e?t.delete(n):t.set(n,e)})},[N]),z=i(function(n){N(function(e){e.delete(n)})},[N]),A=i(function(n){n&&"object"==typeof n&&N(function(e){for(var t=0,a=Object.entries(n);t<a.length;t++){var o=a[t],i=o[0],r=o[1];null==r||""===r?e.delete(i):e.set(i,r)}})},[N]),C=k.getPageByUrl(r);C||(j&&"/"===p&&"undefined"!=typeof window&&(window.location.href="/"+L),C=j?y.find(function(n){var e,t=n.path,a=null!==(e=null==t?void 0:t[O])&&void 0!==e?e:null==t?void 0:t[L];return c(a)}):y.find(function(n){return c(n.path)})),C||console.warn("[RouterReact] No active page found for",p);var D=i(function(n){var e;return function(n,e){var t,a,o,i,r,u,c,l=e.activePageId,f=void 0===l?"":l,v=e.params,p=e.language,h=e.activeSearch,w=e.activeHash,g=e.getPathname,m={},y=!1,P=!1,L=!1;if("string"==typeof n)t=n,m=v,a=p;else if((c=n)&&!c.id&&void 0!==c.language)t=f,m=v,a=n.language,y=void 0===(r=n.search),P=void 0===(u=n.hash);else{t=(null==n?void 0:n.id)||f||"",m=(null==n?void 0:n.params)||v,a=(null==n?void 0:n.language)||p,r=null==n?void 0:n.search,u=null==n?void 0:n.hash;var b=f.replace(/^@/,""),S=t.replace(/^@/,""),E=!(null==n?void 0:n.id)||S===b;(null==n?void 0:n.language)&&E&&(y=void 0===r,P=void 0===u)}if(t.includes("#")){var R=t.split("#");if(t=R[0],(o=R[1]).includes("?")){var j=o.split("?");o=j[0],i=j[1],L=!0}}else if(t.includes("?")){var H=t.split("?");t=H[0],i=H[1]}void 0!==r?(i=d(r),L=!1):y&&(i=d(h),L=!1),void 0!==u?o=s(u):P&&(o=s(w));var O=g({id:t.replace("@",""),params:m,language:a});return function(n,e){var t=e.search,a=e.hash,o=e.searchFromHashRoute,i=n;return void 0!==o&&o?(a&&(i="".concat(i,"#").concat(a)),t&&(i="".concat(i,"?").concat(t))):(t&&(i="".concat(i,"?").concat(t)),a&&(i="".concat(i,"#").concat(a))),i}(null!=O?O:"",{search:i,hash:o,searchFromHashRoute:L})}(n,{activePageId:null!==(e=null==C?void 0:C.id)&&void 0!==e?e:"",params:F,language:O,activeSearch:x,activeHash:"undefined"!=typeof window?window.location.hash:h,getPathname:function(n){return k.getPathname(n)}})},[k,O,F,C,x,h]),G=i(function(n){if("undefined"!=typeof window&&n)if("@back"!==n)if("string"!=typeof n||!n.startsWith("/")||n.startsWith("//")){var e=D(n);e&&(window.location.href=e)}else window.location.assign(n);else window.history.back()},[D]),J=i(function(){"undefined"!=typeof window&&window.history.back()},[]),K=t(function(){var n=Object.fromEntries(B.entries());return l(l({},n),{set:q,delete:z,patch:A})},[I,q,z,A]),M=t(function(){return{href:r,pages:y,language:O,defaultLanguage:L,supportedLanguages:S,params:F,navigate:G,getHref:D,back:J}},[r,y,O,L,S,F,G,D,J]);(null==C?void 0:C.redirect)&&G({id:C.redirect,search:x});var Q=t(function(){var n,e;return null!==(n=null==C?void 0:C.element)&&void 0!==n?n:null===(e=null==C?void 0:C.render)||void 0===e?void 0:e.call(C)},[C]);return C?n.createElement(f.Provider,{value:M},n.createElement(v.Provider,{value:K},E||Q)):n.createElement(n.Fragment,null)};export{w as Router,f as RouterContext,v as SearchParamsContext,h as useRouter,p as useSearchParams};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/router-react",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.14.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ossy-se/packages.git"
|
|
@@ -69,5 +69,5 @@
|
|
|
69
69
|
"/build",
|
|
70
70
|
"README.md"
|
|
71
71
|
],
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "539cc1b14a57e9f6472a89648939e21821dc204d"
|
|
73
73
|
}
|