@ossy/router-react 0.0.10 → 0.0.16
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/CHANGELOG.md +48 -0
- package/package.json +11 -19
- package/rollup.config.js +5 -6
- package/tsconfig.json +1 -1
- package/build/cjs/esm/router-react.d.ts +0 -51
- package/build/cjs/index.js +0 -1
- package/build/esm/index.js +0 -1
- package/build/esm/router-react.d.ts +0 -51
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,54 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.0.16 (2025-10-30)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 0.0.15 (2025-10-27)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## 0.0.14 (2025-10-27)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## 0.0.13 (2025-10-27)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
## 0.0.12 (2025-10-27)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## 0.0.11 (2025-10-27)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @ossy/router-react
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
6
54
|
## 0.0.10 (2025-10-25)
|
|
7
55
|
|
|
8
56
|
**Note:** Version bump only for package @ossy/router-react
|
package/package.json
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ossy/router-react",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"repository":
|
|
3
|
+
"version": "0.0.16",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/ossy-se/packages.git"
|
|
7
|
+
},
|
|
5
8
|
"description": "React router built for server side rendering and multi-language support with localized paths",
|
|
6
9
|
"keywords": [
|
|
7
10
|
"react",
|
|
@@ -19,9 +22,8 @@
|
|
|
19
22
|
],
|
|
20
23
|
"source": "src/index.js",
|
|
21
24
|
"type": "module",
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"license": "MIT License",
|
|
25
|
+
"module": "build/index.js",
|
|
26
|
+
"license": "MIT",
|
|
25
27
|
"author": "Ossy <yourfriends@ossy.se> (https://ossy.se)",
|
|
26
28
|
"scripts": {
|
|
27
29
|
"build": "rollup -c rollup.config.js",
|
|
@@ -46,25 +48,15 @@
|
|
|
46
48
|
"@babel/preset-env": "^7.26.0",
|
|
47
49
|
"@babel/preset-react": "^7.24.1",
|
|
48
50
|
"@babel/preset-typescript": "^7.26.0",
|
|
49
|
-
"@rollup/plugin-babel": "6.0.4"
|
|
50
|
-
"@rollup/plugin-commonjs": "^25.0.5",
|
|
51
|
-
"@rollup/plugin-node-resolve": "^15.3.0",
|
|
52
|
-
"@rollup/plugin-terser": "0.4.4",
|
|
53
|
-
"@rollup/plugin-typescript": "^11.1.5",
|
|
54
|
-
"@types/react": "^18.2.79",
|
|
55
|
-
"rollup": "^4.24.3",
|
|
56
|
-
"rollup-plugin-dts": "^6.1.0",
|
|
57
|
-
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
58
|
-
"rollup-plugin-postcss-modules": "^2.1.1",
|
|
59
|
-
"rollup-plugin-preserve-directives": "^0.4.0",
|
|
60
|
-
"tslib": "^2.8.1"
|
|
51
|
+
"@rollup/plugin-babel": "6.0.4"
|
|
61
52
|
},
|
|
62
53
|
"peerDependencies": {
|
|
63
54
|
"@ossy/router": ">=0.0.1 <1.0.0",
|
|
64
55
|
"react": ">=19.0.0 <20.0.0"
|
|
65
56
|
},
|
|
66
57
|
"publishConfig": {
|
|
67
|
-
"access": "public"
|
|
58
|
+
"access": "public",
|
|
59
|
+
"registry": "https://registry.npmjs.org"
|
|
68
60
|
},
|
|
69
|
-
"gitHead": "
|
|
61
|
+
"gitHead": "6cf3fe944bcbd61a2deb8d2e24f982374415e6d4"
|
|
70
62
|
}
|
package/rollup.config.js
CHANGED
|
@@ -11,11 +11,7 @@ export default [
|
|
|
11
11
|
input: 'src/router-react.tsx',
|
|
12
12
|
output: [
|
|
13
13
|
{
|
|
14
|
-
file: 'build/
|
|
15
|
-
format: 'cjs'
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
file: 'build/esm/index.js',
|
|
14
|
+
file: 'build/index.js',
|
|
19
15
|
format: 'esm'
|
|
20
16
|
}
|
|
21
17
|
],
|
|
@@ -29,7 +25,10 @@ export default [
|
|
|
29
25
|
}),
|
|
30
26
|
minifyJS(),
|
|
31
27
|
preserveDirectives(),
|
|
32
|
-
typescript({
|
|
28
|
+
typescript({
|
|
29
|
+
tsconfig: "./tsconfig.json",
|
|
30
|
+
outDir: 'build',
|
|
31
|
+
}),
|
|
33
32
|
]
|
|
34
33
|
},
|
|
35
34
|
]
|
package/tsconfig.json
CHANGED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { MultiLanguagePage, RouterOptions, SingleLanguagePage } from '@ossy/router';
|
|
3
|
-
export declare const RouterContext: React.Context<{
|
|
4
|
-
pages: RouterPage[];
|
|
5
|
-
defaultLanguage: string | undefined;
|
|
6
|
-
supportedLanguages: string[];
|
|
7
|
-
}>;
|
|
8
|
-
export declare const useRouter: () => {
|
|
9
|
-
pages: RouterPage[];
|
|
10
|
-
defaultLanguage: string | undefined;
|
|
11
|
-
supportedLanguages: string[];
|
|
12
|
-
};
|
|
13
|
-
export declare const Router: <T extends RouterPage>({ url, pages, defaultLanguage, supportedLanguages }: RouterProps<T>) => React.JSX.Element;
|
|
14
|
-
export interface RouterProps<T extends RouterPage> extends RouterOptions<T> {
|
|
15
|
-
/**
|
|
16
|
-
* Render page associated with the given url.
|
|
17
|
-
* Used to render the page on server side where window.location is not available
|
|
18
|
-
* @type string
|
|
19
|
-
* @default undefined
|
|
20
|
-
*/
|
|
21
|
-
url?: string;
|
|
22
|
-
}
|
|
23
|
-
export type RouterPage = SingleLanguageRouterPage | MultiLanguageRouterPage;
|
|
24
|
-
export interface SingleLanguageRouterPage extends SingleLanguagePage {
|
|
25
|
-
/** If provided the page will redirect to the given page id
|
|
26
|
-
* @default undefined
|
|
27
|
-
* @type {string}
|
|
28
|
-
* @example { redirect: '@home'}
|
|
29
|
-
*/
|
|
30
|
-
redirect?: string;
|
|
31
|
-
element?: React.ReactNode;
|
|
32
|
-
render: () => React.ReactNode;
|
|
33
|
-
}
|
|
34
|
-
export interface MultiLanguageRouterPage extends MultiLanguagePage {
|
|
35
|
-
/** If provided the page will redirect to the given page id
|
|
36
|
-
* @default undefined
|
|
37
|
-
* @type {string}
|
|
38
|
-
* @example { redirect: '@home'}
|
|
39
|
-
*/
|
|
40
|
-
redirect?: string;
|
|
41
|
-
element?: React.ReactNode;
|
|
42
|
-
render: () => React.ReactNode;
|
|
43
|
-
}
|
|
44
|
-
export interface GetHrefRequest {
|
|
45
|
-
id?: string;
|
|
46
|
-
language?: string;
|
|
47
|
-
params?: Record<string, string>;
|
|
48
|
-
}
|
|
49
|
-
export interface GetHrefOfActivePageByLanguageRequest {
|
|
50
|
-
language: string;
|
|
51
|
-
}
|
package/build/cjs/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("react"),n=require("@ossy/router"),r=function(){return r=Object.assign||function(e){for(var n,r=1,t=arguments.length;r<t;r++)for(var a in n=arguments[r])Object.prototype.hasOwnProperty.call(n,a)&&(e[a]=n[a]);return e},r.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var t=e.createContext({pages:[],defaultLanguage:void 0,supportedLanguages:[]}),a=function(e){return void 0===e&&(e=""),function(e){return"/"===e[e.length-1]?e:"".concat(e,"/")}(function(e){return"/"===e[0]?e:"/".concat(e)}(e))};exports.Router=function(o){var i,u,l,d,c,s=o.url,f=o.pages,g=void 0===f?[]:f,p=o.defaultLanguage,v=void 0===p?void 0:p,w=o.supportedLanguages,h=void 0===w?[]:w;if(s){var m=s.match(/([^?#]*)(\?[^#]*)?(#.*)?/);u=s,l=(null==m?void 0:m[1])||"",d=(null==m?void 0:m[3])||"",c=(null==m?void 0:m[2])||""}else{if("undefined"==typeof window)return e.createElement(e.Fragment,null);u=window.location.href,l=window.location.pathname,c=(null==(d=window.location.hash)?void 0:d.includes("?"))?d.split("?")[1]:window.location.search}var y=h.length>1&&!!v,b=l.split("/")[1]||"",L=h.includes(b)?b:v,k=n.Router.of({pages:g,defaultLanguage:v,supportedLanguages:h}),P=k.getParamsFromUrl(u),R=new URLSearchParams(c),S=k.getPageByUrl(u);if(S||(y&&"/"===l&&"undefined"!=typeof window&&(window.location.href="/"+v),S=y?g.find(function(e){return"*"===a(e.path[L])}):g.find(function(e){return"*"===a(e.path)})),!S)return console.warn("[RouterReact] No active page found for",l),e.createElement(e.Fragment,null);e.useCallback(function(e,n){if("undefined"!=typeof window){window.history.pushState({},"","".concat(l,"?").concat(R.toString()));var r=new URLSearchParams(R);r.set(e,n),history.pushState({},"","?".concat(r.toString()))}},[R]);var C=e.useCallback(function(e){var n,r,t,a,o,i={};if("string"==typeof e?(n=e,i=P,r=L):(o=e).id||void 0===o.language?(n=(null==e?void 0:e.id)||S.id,i=(null==e?void 0:e.params)||P,r=(null==e?void 0:e.language)||L):(n=S.id,i=P,r=e.language),n.includes("#")){var u=n.split("#");if(n=u[0],(t=u[1]).includes("?")){var l=n.split("?");t=l[0],a=l[1]}}else if(n.includes("?")){var d=n.split("?");n=d[0],a=d[1]}var c=k.getPathname({id:n.replace("@",""),params:i,language:r});return t&&(c=c+"#"+t),a&&(c=c+"?"+a),c},[k,L]),x=e.useCallback(function(e){if("undefined"!=typeof window&&e)if("@back"!==e){var n=C(e);n&&(window.location.href=n)}else window.history.back()},[C]),E=e.useCallback(function(){"undefined"!=typeof window&&window.history.back()},[]),U={href:u,pages:g,language:L,defaultLanguage:v,supportedLanguages:h,params:P,searchParams:r({},Array.from(R.entries()).reduce(function(e,n){var t,a=n[0],o=n[1];return r(r({},e),((t={})[a]=o,t))},{})),navigate:x,getHref:C,back:E};(null==S?void 0:S.redirect)&&x({id:S.redirect});var F=(null==S?void 0:S.element)||(null===(i=null==S?void 0:S.render)||void 0===i?void 0:i.call(S));return e.createElement(t.Provider,{value:U},F)},exports.RouterContext=t,exports.useRouter=function(){return e.useContext(t)};
|
package/build/esm/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import e,{createContext as n,useContext as r,useCallback as a}from"react";import{Router as t}from"@ossy/router";var o=function(){return o=Object.assign||function(e){for(var n,r=1,a=arguments.length;r<a;r++)for(var t in n=arguments[r])Object.prototype.hasOwnProperty.call(n,t)&&(e[t]=n[t]);return e},o.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var i=n({pages:[],defaultLanguage:void 0,supportedLanguages:[]}),u=function(){return r(i)},d=function(e){return void 0===e&&(e=""),function(e){return"/"===e[e.length-1]?e:"".concat(e,"/")}(function(e){return"/"===e[0]?e:"/".concat(e)}(e))},l=function(n){var r,u,l,c,s,f=n.url,g=n.pages,p=void 0===g?[]:g,v=n.defaultLanguage,w=void 0===v?void 0:v,h=n.supportedLanguages,m=void 0===h?[]:h;if(f){var y=f.match(/([^?#]*)(\?[^#]*)?(#.*)?/);u=f,l=(null==y?void 0:y[1])||"",c=(null==y?void 0:y[3])||"",s=(null==y?void 0:y[2])||""}else{if("undefined"==typeof window)return e.createElement(e.Fragment,null);u=window.location.href,l=window.location.pathname,s=(null==(c=window.location.hash)?void 0:c.includes("?"))?c.split("?")[1]:window.location.search}var L=m.length>1&&!!w,P=l.split("/")[1]||"",S=m.includes(P)?P:w,b=t.of({pages:p,defaultLanguage:w,supportedLanguages:m}),E=b.getParamsFromUrl(u),R=new URLSearchParams(s),k=b.getPageByUrl(u);if(k||(L&&"/"===l&&"undefined"!=typeof window&&(window.location.href="/"+w),k=L?p.find(function(e){return"*"===d(e.path[S])}):p.find(function(e){return"*"===d(e.path)})),!k)return console.warn("[RouterReact] No active page found for",l),e.createElement(e.Fragment,null);a(function(e,n){if("undefined"!=typeof window){window.history.pushState({},"","".concat(l,"?").concat(R.toString()));var r=new URLSearchParams(R);r.set(e,n),history.pushState({},"","?".concat(r.toString()))}},[R]);var U=a(function(e){var n,r,a,t,o,i={};if("string"==typeof e?(n=e,i=E,r=S):(o=e).id||void 0===o.language?(n=(null==e?void 0:e.id)||k.id,i=(null==e?void 0:e.params)||E,r=(null==e?void 0:e.language)||S):(n=k.id,i=E,r=e.language),n.includes("#")){var u=n.split("#");if(n=u[0],(a=u[1]).includes("?")){var d=n.split("?");a=d[0],t=d[1]}}else if(n.includes("?")){var l=n.split("?");n=l[0],t=l[1]}var c=b.getPathname({id:n.replace("@",""),params:i,language:r});return a&&(c=c+"#"+a),t&&(c=c+"?"+t),c},[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:u,pages:p,language:S,defaultLanguage:w,supportedLanguages:m,params:E,searchParams:o({},Array.from(R.entries()).reduce(function(e,n){var r,a=n[0],t=n[1];return o(o({},e),((r={})[a]=t,r))},{})),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(i.Provider,{value:j},x)};export{l as Router,i as RouterContext,u as useRouter};
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { MultiLanguagePage, RouterOptions, SingleLanguagePage } from '@ossy/router';
|
|
3
|
-
export declare const RouterContext: React.Context<{
|
|
4
|
-
pages: RouterPage[];
|
|
5
|
-
defaultLanguage: string | undefined;
|
|
6
|
-
supportedLanguages: string[];
|
|
7
|
-
}>;
|
|
8
|
-
export declare const useRouter: () => {
|
|
9
|
-
pages: RouterPage[];
|
|
10
|
-
defaultLanguage: string | undefined;
|
|
11
|
-
supportedLanguages: string[];
|
|
12
|
-
};
|
|
13
|
-
export declare const Router: <T extends RouterPage>({ url, pages, defaultLanguage, supportedLanguages }: RouterProps<T>) => React.JSX.Element;
|
|
14
|
-
export interface RouterProps<T extends RouterPage> extends RouterOptions<T> {
|
|
15
|
-
/**
|
|
16
|
-
* Render page associated with the given url.
|
|
17
|
-
* Used to render the page on server side where window.location is not available
|
|
18
|
-
* @type string
|
|
19
|
-
* @default undefined
|
|
20
|
-
*/
|
|
21
|
-
url?: string;
|
|
22
|
-
}
|
|
23
|
-
export type RouterPage = SingleLanguageRouterPage | MultiLanguageRouterPage;
|
|
24
|
-
export interface SingleLanguageRouterPage extends SingleLanguagePage {
|
|
25
|
-
/** If provided the page will redirect to the given page id
|
|
26
|
-
* @default undefined
|
|
27
|
-
* @type {string}
|
|
28
|
-
* @example { redirect: '@home'}
|
|
29
|
-
*/
|
|
30
|
-
redirect?: string;
|
|
31
|
-
element?: React.ReactNode;
|
|
32
|
-
render: () => React.ReactNode;
|
|
33
|
-
}
|
|
34
|
-
export interface MultiLanguageRouterPage extends MultiLanguagePage {
|
|
35
|
-
/** If provided the page will redirect to the given page id
|
|
36
|
-
* @default undefined
|
|
37
|
-
* @type {string}
|
|
38
|
-
* @example { redirect: '@home'}
|
|
39
|
-
*/
|
|
40
|
-
redirect?: string;
|
|
41
|
-
element?: React.ReactNode;
|
|
42
|
-
render: () => React.ReactNode;
|
|
43
|
-
}
|
|
44
|
-
export interface GetHrefRequest {
|
|
45
|
-
id?: string;
|
|
46
|
-
language?: string;
|
|
47
|
-
params?: Record<string, string>;
|
|
48
|
-
}
|
|
49
|
-
export interface GetHrefOfActivePageByLanguageRequest {
|
|
50
|
-
language: string;
|
|
51
|
-
}
|