@ossy/router-react 0.13.4 → 0.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 e,{createContext as n,useCallback as
|
|
1
|
+
import e,{createContext as n,useCallback as a,useContext as r}from"react";import{Router as o,isCatchAllRoutePath as t}from"@ossy/router";var i=function(){return i=Object.assign||function(e){for(var n,a=1,r=arguments.length;a<r;a++)for(var o in n=arguments[a])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},i.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var u=n({pages:[],defaultLanguage:void 0,supportedLanguages:[]}),l=function(){return r(u)},d=function(n){var r,l,d,s,c,f=n.url,p=n.pages,g=void 0===p?[]:p,v=n.defaultLanguage,w=void 0===v?void 0:v,h=n.supportedLanguages,m=void 0===h?[]:h;if(f){var y=f.match(/([^?#]*)(\?[^#]*)?(#.*)?/);l=f,d=(null==y?void 0:y[1])||"",s=(null==y?void 0:y[3])||"",c=(null==y?void 0:y[2])||""}else{if("undefined"==typeof window)return e.createElement(e.Fragment,null);l=window.location.href,d=window.location.pathname,c=(null==(s=window.location.hash)?void 0:s.includes("?"))?s.split("?")[1]:window.location.search}var L=m.length>1&&!!w,P=d.split("/")[1]||"",S=m.includes(P)?P:w,b=o.of({pages:g,defaultLanguage:w,supportedLanguages:m}),E=b.getParamsFromUrl(l),R=new URLSearchParams(c),k=b.getPageByUrl(l);if(k||(L&&"/"===d&&"undefined"!=typeof window&&(window.location.href="/"+w),k=L?g.find(function(e){var n,a=e.path,r=null!==(n=null==a?void 0:a[S])&&void 0!==n?n:null==a?void 0:a[w];return t(r)}):g.find(function(e){return t(e.path)})),!k)return console.warn("[RouterReact] No active page found for",d),e.createElement(e.Fragment,null);a(function(e,n){if("undefined"!=typeof window){window.history.pushState({},"","".concat(d,"?").concat(R.toString()));var a=new URLSearchParams(R);a.set(e,n),history.pushState({},"","?".concat(a.toString()))}},[R]);var U=a(function(e){var n,a,r,o,t,i={};if("string"==typeof e?(n=e,i=E,a=S):(t=e).id||void 0===t.language?(n=(null==e?void 0:e.id)||k.id,i=(null==e?void 0:e.params)||E,a=(null==e?void 0:e.language)||S):(n=k.id,i=E,a=e.language),n.includes("#")){var u=n.split("#");if(n=u[0],(r=u[1]).includes("?")){var l=n.split("?");r=l[0],o=l[1]}}else if(n.includes("?")){var d=n.split("?");n=d[0],o=d[1]}var s=b.getPathname({id:n.replace("@",""),params:i,language:a});return r&&(s=s+"#"+r),o&&(s=s+"?"+o),s},[b,S]),F=a(function(e){if("undefined"!=typeof window&&e)if("@back"!==e){var n=U(e);n&&(window.location.href=n)}else window.history.back()},[U]),O=a(function(){"undefined"!=typeof window&&window.history.back()},[]),j={href:l,pages:g,language:S,defaultLanguage:w,supportedLanguages:m,params:E,searchParams:i({},Array.from(R.entries()).reduce(function(e,n){var a,r=n[0],o=n[1];return i(i({},e),((a={})[r]=o,a))},{})),navigate:F,getHref:U,back:O};(null==k?void 0:k.redirect)&&F({id:k.redirect});var x=(null==k?void 0:k.element)||(null===(r=null==k?void 0:k.render)||void 0===r?void 0:r.call(k));return e.createElement(u.Provider,{value:j},x)};export{d as Router,u as RouterContext,l as useRouter};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/router-react",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/ossy-se/packages.git"
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"/build",
|
|
62
62
|
"README.md"
|
|
63
63
|
],
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "032e21b623b973a715d532580022f393b1f9d389"
|
|
65
65
|
}
|