@bleedingdev/modern-js-i18n-runtime-extensions 3.8.3-ultramodern.6 → 3.9.0-ultramodern.10
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/dist/cjs/index.js +9 -2
- package/dist/cjs/localeRedirectPolicy.js +96 -0
- package/dist/cjs/localisedUrls/index.js +7 -0
- package/dist/cjs/localisedUrls/redirect.js +3 -6
- package/dist/cjs/localisedUrls/routeIdentity.js +118 -0
- package/dist/cjs/localisedUrls/routes.js +8 -0
- package/dist/cjs/paths.js +56 -0
- package/dist/cjs/router-navigation/adapter.js +235 -0
- package/dist/cjs/router-navigation/index.js +40 -0
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/localeRedirectPolicy.mjs +46 -0
- package/dist/esm/localisedUrls/index.mjs +1 -0
- package/dist/esm/localisedUrls/redirect.mjs +3 -6
- package/dist/esm/localisedUrls/routeIdentity.mjs +77 -0
- package/dist/esm/localisedUrls/routes.mjs +8 -0
- package/dist/esm/paths.mjs +12 -0
- package/dist/esm/router-navigation/adapter.mjs +197 -0
- package/dist/esm/router-navigation/index.mjs +1 -0
- package/dist/esm-node/index.mjs +1 -0
- package/dist/esm-node/localeRedirectPolicy.mjs +47 -0
- package/dist/esm-node/localisedUrls/index.mjs +1 -0
- package/dist/esm-node/localisedUrls/redirect.mjs +3 -6
- package/dist/esm-node/localisedUrls/routeIdentity.mjs +78 -0
- package/dist/esm-node/localisedUrls/routes.mjs +8 -0
- package/dist/esm-node/paths.mjs +13 -0
- package/dist/esm-node/router-navigation/adapter.mjs +198 -0
- package/dist/esm-node/router-navigation/index.mjs +2 -0
- package/dist/types/index.d.ts +4 -3
- package/dist/types/language-sync/react.d.ts +1 -1
- package/dist/types/localeRedirectPolicy.d.ts +22 -0
- package/dist/types/localisedUrls/config.d.ts +1 -1
- package/dist/types/localisedUrls/index.d.ts +10 -9
- package/dist/types/localisedUrls/pathname.d.ts +1 -1
- package/dist/types/localisedUrls/redirect.d.ts +8 -0
- package/dist/types/localisedUrls/resolve.d.ts +1 -1
- package/dist/types/localisedUrls/routeIdentity.d.ts +24 -0
- package/dist/types/localisedUrls/routes.d.ts +1 -1
- package/dist/types/paths.d.ts +9 -0
- package/dist/types/router-navigation/adapter.d.ts +71 -0
- package/dist/types/router-navigation/index.d.ts +1 -0
- package/package.json +30 -6
- package/src/index.ts +1 -0
- package/src/localeRedirectPolicy.ts +127 -0
- package/src/localisedUrls/index.ts +4 -0
- package/src/localisedUrls/redirect.ts +16 -2
- package/src/localisedUrls/routeIdentity.ts +107 -0
- package/src/localisedUrls/routes.ts +10 -0
- package/src/paths.ts +37 -0
- package/src/router-navigation/adapter.tsx +536 -0
- package/src/router-navigation/index.ts +6 -0
- package/tests/languageSyncController.test.ts +0 -77
- package/tests/localeRedirectPolicy.test.ts +173 -0
- package/tests/localisedUrls.test.ts +0 -141
- package/tests/paths.test.ts +24 -0
- package/tests/reactLanguageSync.test.tsx +20 -1
- package/tests/clientRedirectIntegration.test.tsx +0 -74
package/dist/cjs/index.js
CHANGED
|
@@ -6,6 +6,9 @@ var __webpack_modules__ = {
|
|
|
6
6
|
"./language-sync/react" (module) {
|
|
7
7
|
module.exports = require("./language-sync/react.js");
|
|
8
8
|
},
|
|
9
|
+
"./localeRedirectPolicy" (module) {
|
|
10
|
+
module.exports = require("./localeRedirectPolicy.js");
|
|
11
|
+
},
|
|
9
12
|
"./localisedUrls/index" (module) {
|
|
10
13
|
module.exports = require("./localisedUrls/index.js");
|
|
11
14
|
}
|
|
@@ -65,9 +68,13 @@ var __webpack_exports__ = {};
|
|
|
65
68
|
var __rspack_reexport = {};
|
|
66
69
|
for(const __rspack_import_key in _language_sync_react__rspack_import_1)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_language_sync_react__rspack_import_1[__rspack_import_key];
|
|
67
70
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
68
|
-
var
|
|
71
|
+
var _localeRedirectPolicy__rspack_import_2 = __webpack_require__("./localeRedirectPolicy");
|
|
72
|
+
var __rspack_reexport = {};
|
|
73
|
+
for(const __rspack_import_key in _localeRedirectPolicy__rspack_import_2)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_localeRedirectPolicy__rspack_import_2[__rspack_import_key];
|
|
74
|
+
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
75
|
+
var _localisedUrls_index__rspack_import_3 = __webpack_require__("./localisedUrls/index");
|
|
69
76
|
var __rspack_reexport = {};
|
|
70
|
-
for(const __rspack_import_key in
|
|
77
|
+
for(const __rspack_import_key in _localisedUrls_index__rspack_import_3)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_localisedUrls_index__rspack_import_3[__rspack_import_key];
|
|
71
78
|
__webpack_require__.d(__webpack_exports__, __rspack_reexport);
|
|
72
79
|
})();
|
|
73
80
|
for(var __rspack_i in __webpack_exports__)exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
buildLocalizedUrl: ()=>buildLocalizedUrl,
|
|
32
|
+
createLocaleRedirectResponse: ()=>createLocaleRedirectResponse,
|
|
33
|
+
getLanguageFromPath: ()=>getLanguageFromPath,
|
|
34
|
+
isStaticResourceRequest: ()=>isStaticResourceRequest,
|
|
35
|
+
shouldIgnoreRedirect: ()=>shouldIgnoreRedirect
|
|
36
|
+
});
|
|
37
|
+
const index_js_namespaceObject = require("./localisedUrls/index.js");
|
|
38
|
+
const stripUrlPathPrefix = (pathname, urlPath)=>{
|
|
39
|
+
const basePath = urlPath.replace('/*', '');
|
|
40
|
+
if (!basePath || '/' === basePath) return pathname;
|
|
41
|
+
const remainingPath = pathname.startsWith(basePath) ? pathname.slice(basePath.length) : pathname;
|
|
42
|
+
return remainingPath || '/';
|
|
43
|
+
};
|
|
44
|
+
const shouldIgnoreRedirect = (pathname, urlPath, ignoreRedirectRoutes)=>{
|
|
45
|
+
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
46
|
+
return (0, index_js_namespaceObject.shouldSkipLocaleRedirect)(remainingPath, [], ignoreRedirectRoutes);
|
|
47
|
+
};
|
|
48
|
+
const isStaticResourceRequest = (pathname, staticRoutePrefixes, languages = [])=>{
|
|
49
|
+
if ((0, index_js_namespaceObject.isDefaultLocaleRedirectSkipPath)(pathname, languages)) return true;
|
|
50
|
+
const matchesStaticRoutePrefix = (targetPathname)=>staticRoutePrefixes.some((prefix)=>(0, index_js_namespaceObject.matchesPathPrefix)(targetPathname, prefix));
|
|
51
|
+
if (matchesStaticRoutePrefix(pathname)) return true;
|
|
52
|
+
const pathWithoutLanguage = (0, index_js_namespaceObject.stripLanguagePrefix)(pathname, languages);
|
|
53
|
+
return pathWithoutLanguage !== pathname && matchesStaticRoutePrefix(pathWithoutLanguage);
|
|
54
|
+
};
|
|
55
|
+
const getLanguageFromPath = (req, urlPath, languages)=>{
|
|
56
|
+
const url = new URL(req.url, `http://${req.header().host}`);
|
|
57
|
+
const pathname = url.pathname;
|
|
58
|
+
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
59
|
+
const segments = remainingPath.split('/').filter(Boolean);
|
|
60
|
+
const firstSegment = segments[0];
|
|
61
|
+
if (languages.includes(firstSegment)) return firstSegment;
|
|
62
|
+
return null;
|
|
63
|
+
};
|
|
64
|
+
const buildLocalizedUrl = (req, urlPath, language, languages, localisedUrls)=>{
|
|
65
|
+
const url = new URL(req.url);
|
|
66
|
+
const pathname = url.pathname;
|
|
67
|
+
const basePath = urlPath.replace('/*', '');
|
|
68
|
+
const remainingPath = stripUrlPathPrefix(pathname, urlPath);
|
|
69
|
+
const newPathname = (0, index_js_namespaceObject.localiseTargetPathname)(remainingPath, language, languages, localisedUrls);
|
|
70
|
+
const suffix = `${url.search}${url.hash}`;
|
|
71
|
+
const localizedUrl = '/' === basePath ? newPathname + suffix : basePath + newPathname + suffix;
|
|
72
|
+
return localizedUrl;
|
|
73
|
+
};
|
|
74
|
+
const createLocaleRedirectResponse = (location)=>new Response(null, {
|
|
75
|
+
status: 302,
|
|
76
|
+
headers: {
|
|
77
|
+
'Cache-Control': 'private, no-store',
|
|
78
|
+
Location: location,
|
|
79
|
+
Vary: 'Accept-Language, Cookie'
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
83
|
+
exports.createLocaleRedirectResponse = __webpack_exports__.createLocaleRedirectResponse;
|
|
84
|
+
exports.getLanguageFromPath = __webpack_exports__.getLanguageFromPath;
|
|
85
|
+
exports.isStaticResourceRequest = __webpack_exports__.isStaticResourceRequest;
|
|
86
|
+
exports.shouldIgnoreRedirect = __webpack_exports__.shouldIgnoreRedirect;
|
|
87
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
88
|
+
"buildLocalizedUrl",
|
|
89
|
+
"createLocaleRedirectResponse",
|
|
90
|
+
"getLanguageFromPath",
|
|
91
|
+
"isStaticResourceRequest",
|
|
92
|
+
"shouldIgnoreRedirect"
|
|
93
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
94
|
+
Object.defineProperty(exports, '__esModule', {
|
|
95
|
+
value: true
|
|
96
|
+
});
|
|
@@ -32,6 +32,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
32
32
|
applyLocalisedUrlsToRoutes: ()=>external_routes_js_namespaceObject.applyLocalisedUrlsToRoutes,
|
|
33
33
|
buildPathFromPattern: ()=>external_patterns_js_namespaceObject.buildPathFromPattern,
|
|
34
34
|
canonicalTargetPathname: ()=>external_pathname_js_namespaceObject.canonicalTargetPathname,
|
|
35
|
+
canonicaliseLocalisedRoutes: ()=>external_routeIdentity_js_namespaceObject.canonicaliseLocalisedRoutes,
|
|
36
|
+
createLocalisedRouteRewrite: ()=>external_routeIdentity_js_namespaceObject.createLocalisedRouteRewrite,
|
|
35
37
|
isDefaultLocaleRedirectSkipPath: ()=>external_redirect_js_namespaceObject.isDefaultLocaleRedirectSkipPath,
|
|
36
38
|
localiseTargetPathname: ()=>external_pathname_js_namespaceObject.localiseTargetPathname,
|
|
37
39
|
matchPathPattern: ()=>external_patterns_js_namespaceObject.matchPathPattern,
|
|
@@ -51,11 +53,14 @@ const external_pathname_js_namespaceObject = require("./pathname.js");
|
|
|
51
53
|
const external_patterns_js_namespaceObject = require("./patterns.js");
|
|
52
54
|
const external_redirect_js_namespaceObject = require("./redirect.js");
|
|
53
55
|
const external_resolve_js_namespaceObject = require("./resolve.js");
|
|
56
|
+
const external_routeIdentity_js_namespaceObject = require("./routeIdentity.js");
|
|
54
57
|
const external_routes_js_namespaceObject = require("./routes.js");
|
|
55
58
|
exports.DEFAULT_LOCALE_REDIRECT_SKIP_RULES = __webpack_exports__.DEFAULT_LOCALE_REDIRECT_SKIP_RULES;
|
|
56
59
|
exports.applyLocalisedUrlsToRoutes = __webpack_exports__.applyLocalisedUrlsToRoutes;
|
|
57
60
|
exports.buildPathFromPattern = __webpack_exports__.buildPathFromPattern;
|
|
58
61
|
exports.canonicalTargetPathname = __webpack_exports__.canonicalTargetPathname;
|
|
62
|
+
exports.canonicaliseLocalisedRoutes = __webpack_exports__.canonicaliseLocalisedRoutes;
|
|
63
|
+
exports.createLocalisedRouteRewrite = __webpack_exports__.createLocalisedRouteRewrite;
|
|
59
64
|
exports.isDefaultLocaleRedirectSkipPath = __webpack_exports__.isDefaultLocaleRedirectSkipPath;
|
|
60
65
|
exports.localiseTargetPathname = __webpack_exports__.localiseTargetPathname;
|
|
61
66
|
exports.matchPathPattern = __webpack_exports__.matchPathPattern;
|
|
@@ -73,6 +78,8 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
|
73
78
|
"applyLocalisedUrlsToRoutes",
|
|
74
79
|
"buildPathFromPattern",
|
|
75
80
|
"canonicalTargetPathname",
|
|
81
|
+
"canonicaliseLocalisedRoutes",
|
|
82
|
+
"createLocalisedRouteRewrite",
|
|
76
83
|
"isDefaultLocaleRedirectSkipPath",
|
|
77
84
|
"localiseTargetPathname",
|
|
78
85
|
"matchPathPattern",
|
|
@@ -40,10 +40,6 @@ const DEFAULT_LOCALE_REDIRECT_SKIP_RULES = [
|
|
|
40
40
|
type: 'exact',
|
|
41
41
|
path: '/backend-mf-manifest.json'
|
|
42
42
|
},
|
|
43
|
-
{
|
|
44
|
-
type: 'exact',
|
|
45
|
-
path: '/backendRemoteEntry.cjs'
|
|
46
|
-
},
|
|
47
43
|
{
|
|
48
44
|
type: 'exact',
|
|
49
45
|
path: '/mf-manifest.json'
|
|
@@ -53,8 +49,8 @@ const DEFAULT_LOCALE_REDIRECT_SKIP_RULES = [
|
|
|
53
49
|
path: '/mf-stats.json'
|
|
54
50
|
},
|
|
55
51
|
{
|
|
56
|
-
type: '
|
|
57
|
-
path:
|
|
52
|
+
type: 'pattern',
|
|
53
|
+
path: /^\/(?:backendRemoteEntry(?:\.[a-zA-Z0-9_-]+)?\.cjs|remoteEntry(?:\.[a-zA-Z0-9_-]+)?\.js)$/
|
|
58
54
|
},
|
|
59
55
|
{
|
|
60
56
|
type: 'prefix',
|
|
@@ -73,6 +69,7 @@ const matchesPathPrefix = (pathname, prefix)=>{
|
|
|
73
69
|
};
|
|
74
70
|
const matchesSkipRule = (pathname, rule)=>{
|
|
75
71
|
if ('exact' === rule.type) return (0, external_normalise_js_namespaceObject.normalisePathname)(pathname) === (0, external_normalise_js_namespaceObject.normalisePathname)(rule.path);
|
|
72
|
+
if ('pattern' === rule.type) return rule.path.test((0, external_normalise_js_namespaceObject.normalisePathname)(pathname));
|
|
76
73
|
return matchesPathPrefix(pathname, rule.path);
|
|
77
74
|
};
|
|
78
75
|
const isDefaultLocaleRedirectSkipPath = (pathname, languages = [])=>{
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
canonicaliseLocalisedRoutes: ()=>canonicaliseLocalisedRoutes,
|
|
32
|
+
createLocalisedRouteRewrite: ()=>createLocalisedRouteRewrite
|
|
33
|
+
});
|
|
34
|
+
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
35
|
+
const external_patterns_js_namespaceObject = require("./patterns.js");
|
|
36
|
+
function canonicaliseLocalisedRoutes(routes) {
|
|
37
|
+
const seen = new Set();
|
|
38
|
+
return routes.flatMap((route)=>{
|
|
39
|
+
const identity = route.modernLocalisedRoute;
|
|
40
|
+
const key = identity?.id ?? identity?.path;
|
|
41
|
+
if (void 0 !== key) {
|
|
42
|
+
if (seen.has(key)) return [];
|
|
43
|
+
seen.add(key);
|
|
44
|
+
}
|
|
45
|
+
return [
|
|
46
|
+
{
|
|
47
|
+
...route,
|
|
48
|
+
...identity ? {
|
|
49
|
+
id: identity.id,
|
|
50
|
+
path: identity.path
|
|
51
|
+
} : {},
|
|
52
|
+
...route.children ? {
|
|
53
|
+
children: canonicaliseLocalisedRoutes(route.children)
|
|
54
|
+
} : {}
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function rewritePath(url, mappings) {
|
|
60
|
+
for (const { from, to } of mappings){
|
|
61
|
+
const params = (0, external_patterns_js_namespaceObject.matchPathPattern)(url.pathname, from);
|
|
62
|
+
if (params) {
|
|
63
|
+
url.pathname = (0, external_patterns_js_namespaceObject.buildPathFromPattern)(to, params);
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return url;
|
|
68
|
+
}
|
|
69
|
+
function createLocalisedRouteRewrite(routes) {
|
|
70
|
+
const input = [];
|
|
71
|
+
const output = [];
|
|
72
|
+
const visit = (nodes, parent)=>{
|
|
73
|
+
for (const route of nodes){
|
|
74
|
+
const fullPath = (0, external_normalise_js_namespaceObject.normalisePathPattern)(`${parent}/${route.path ?? ''}`);
|
|
75
|
+
const identity = route.modernLocalisedRoute;
|
|
76
|
+
if (identity?.paths && fullPath.endsWith(identity.canonicalPath)) {
|
|
77
|
+
const prefix = fullPath.slice(0, -identity.canonicalPath.length);
|
|
78
|
+
const hasLocale = prefix.split('/').some((segment)=>/^:(?:lang|locale|language)\??$/.test(segment));
|
|
79
|
+
for (const [language, localisedPath] of Object.entries(identity.paths)){
|
|
80
|
+
const localePrefix = prefix.split('/').map((segment)=>/^:(?:lang|locale|language)\??$/.test(segment) ? language : segment).join('/');
|
|
81
|
+
const canonical = (0, external_normalise_js_namespaceObject.normalisePathPattern)(`${localePrefix}/${identity.canonicalPath}`);
|
|
82
|
+
const localised = (0, external_normalise_js_namespaceObject.normalisePathPattern)(`${localePrefix}/${localisedPath}`);
|
|
83
|
+
if (canonical !== localised) {
|
|
84
|
+
input.push({
|
|
85
|
+
from: localised,
|
|
86
|
+
to: canonical
|
|
87
|
+
});
|
|
88
|
+
if (hasLocale) output.push({
|
|
89
|
+
from: canonical,
|
|
90
|
+
to: localised
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (route.children) visit(route.children, fullPath);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
visit(canonicaliseLocalisedRoutes(routes), '');
|
|
99
|
+
if (0 === input.length) return;
|
|
100
|
+
const specificity = (pattern)=>pattern.split('/').filter((segment)=>segment && !segment.startsWith(':') && '*' !== segment).length;
|
|
101
|
+
for (const mappings of [
|
|
102
|
+
input,
|
|
103
|
+
output
|
|
104
|
+
])mappings.sort((a, b)=>specificity(b.from) - specificity(a.from));
|
|
105
|
+
return {
|
|
106
|
+
input: ({ url })=>rewritePath(url, input),
|
|
107
|
+
output: ({ url })=>rewritePath(url, output)
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
exports.canonicaliseLocalisedRoutes = __webpack_exports__.canonicaliseLocalisedRoutes;
|
|
111
|
+
exports.createLocalisedRouteRewrite = __webpack_exports__.createLocalisedRouteRewrite;
|
|
112
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
113
|
+
"canonicaliseLocalisedRoutes",
|
|
114
|
+
"createLocalisedRouteRewrite"
|
|
115
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
116
|
+
Object.defineProperty(exports, '__esModule', {
|
|
117
|
+
value: true
|
|
118
|
+
});
|
|
@@ -134,6 +134,14 @@ const transformLocalisedRoute = (route, parentCanonicalPath, parentLocalisedPath
|
|
|
134
134
|
const children = 'children' in route && route.children ? route.children.flatMap((child)=>transformLocalisedRoute(child, canonicalPath, routeLocalisedPaths, languages, localisedUrls)) : void 0;
|
|
135
135
|
const baseRoute = {
|
|
136
136
|
...route,
|
|
137
|
+
...!isFrameworkInternalRoutePath(canonicalPath) ? {
|
|
138
|
+
modernLocalisedRoute: {
|
|
139
|
+
id: route.id,
|
|
140
|
+
path: route.path,
|
|
141
|
+
canonicalPath,
|
|
142
|
+
paths: localisedUrlEntry
|
|
143
|
+
}
|
|
144
|
+
} : {},
|
|
137
145
|
...children ? {
|
|
138
146
|
children
|
|
139
147
|
} : {}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
buildLocalizedUrl: ()=>buildLocalizedUrl,
|
|
32
|
+
canonicalPath: ()=>canonicalPath,
|
|
33
|
+
localizePath: ()=>localizePath
|
|
34
|
+
});
|
|
35
|
+
const url_namespaceObject = require("@modern-js/runtime-utils/url");
|
|
36
|
+
const index_js_namespaceObject = require("./localisedUrls/index.js");
|
|
37
|
+
const buildLocalizedUrl = (target, language, languages, localisedUrls)=>{
|
|
38
|
+
const { pathname, search, hash } = (0, url_namespaceObject.splitUrlTarget)(target);
|
|
39
|
+
return `${(0, index_js_namespaceObject.localiseTargetPathname)(pathname, language, languages, localisedUrls)}${search}${hash}`;
|
|
40
|
+
};
|
|
41
|
+
const localizePath = (target, language, config)=>buildLocalizedUrl(target, language, config.languages, config.localisedUrls);
|
|
42
|
+
const canonicalPath = (target, config)=>{
|
|
43
|
+
const { pathname, search, hash } = (0, url_namespaceObject.splitUrlTarget)(target);
|
|
44
|
+
return `${(0, index_js_namespaceObject.canonicalTargetPathname)(pathname, config.languages, config.localisedUrls)}${search}${hash}`;
|
|
45
|
+
};
|
|
46
|
+
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
47
|
+
exports.canonicalPath = __webpack_exports__.canonicalPath;
|
|
48
|
+
exports.localizePath = __webpack_exports__.localizePath;
|
|
49
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
50
|
+
"buildLocalizedUrl",
|
|
51
|
+
"canonicalPath",
|
|
52
|
+
"localizePath"
|
|
53
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
54
|
+
Object.defineProperty(exports, '__esModule', {
|
|
55
|
+
value: true
|
|
56
|
+
});
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
createI18nRouterNavigation: ()=>createI18nRouterNavigation
|
|
32
|
+
});
|
|
33
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
34
|
+
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
35
|
+
const context_namespaceObject = require("@modern-js/runtime/context");
|
|
36
|
+
const router_state_namespaceObject = require("@modern-js/runtime-extensions/router-state");
|
|
37
|
+
const external_react_namespaceObject = require("react");
|
|
38
|
+
const normalizeUrlPart = (value, prefix)=>{
|
|
39
|
+
if ('string' != typeof value || !value) return '';
|
|
40
|
+
return value.startsWith(prefix) ? value : `${prefix}${value}`;
|
|
41
|
+
};
|
|
42
|
+
const normalizeLocation = (location)=>{
|
|
43
|
+
if (!location || 'object' != typeof location) return null;
|
|
44
|
+
const locationValue = location;
|
|
45
|
+
if ('string' != typeof locationValue.pathname) return null;
|
|
46
|
+
return {
|
|
47
|
+
pathname: locationValue.pathname,
|
|
48
|
+
search: normalizeUrlPart('string' == typeof locationValue.search ? locationValue.search : locationValue.searchStr, '?'),
|
|
49
|
+
hash: normalizeUrlPart(locationValue.hash, '#')
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
const getWindowLocation = ()=>{
|
|
53
|
+
if (!(0, runtime_namespaceObject.isBrowser)()) return null;
|
|
54
|
+
return {
|
|
55
|
+
pathname: window.location.pathname,
|
|
56
|
+
search: window.location.search,
|
|
57
|
+
hash: window.location.hash
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
const getRouterFramework = (runtimeContext, internalContext, inReactRouter)=>{
|
|
61
|
+
const framework = (0, router_state_namespaceObject.getRouterRuntimeState)(internalContext)?.framework || (0, router_state_namespaceObject.getRouterRuntimeState)(runtimeContext)?.framework;
|
|
62
|
+
if (framework) return framework;
|
|
63
|
+
if (internalContext.router?.useRouter || runtimeContext.router?.useRouter) return 'tanstack';
|
|
64
|
+
if (internalContext.router?.useLocation || internalContext.router?.useHref || runtimeContext.router?.useLocation || runtimeContext.router?.useHref) return 'react-router';
|
|
65
|
+
if (inReactRouter) return 'react-router';
|
|
66
|
+
};
|
|
67
|
+
const getRouterInstance = (internalContext, contextRouter)=>{
|
|
68
|
+
if (contextRouter) return contextRouter;
|
|
69
|
+
const router = (0, router_state_namespaceObject.getRouterRuntimeState)(internalContext)?.instance;
|
|
70
|
+
if (!router || 'object' != typeof router) return null;
|
|
71
|
+
return router;
|
|
72
|
+
};
|
|
73
|
+
const getRouterStateLocation = (internalContext, contextRouter)=>{
|
|
74
|
+
const router = getRouterInstance(internalContext, contextRouter);
|
|
75
|
+
return normalizeLocation(router?.stores?.location?.get?.()) || normalizeLocation(router?.state?.location);
|
|
76
|
+
};
|
|
77
|
+
const getRouterParams = (internalContext, contextRouter)=>{
|
|
78
|
+
const router = getRouterInstance(internalContext, contextRouter);
|
|
79
|
+
const matches = router?.stores?.matches?.get?.() || router?.state?.matches;
|
|
80
|
+
if (!Array.isArray(matches)) return {};
|
|
81
|
+
return matches.reduce((params, match)=>{
|
|
82
|
+
if (match?.params) Object.assign(params, match.params);
|
|
83
|
+
return params;
|
|
84
|
+
}, {});
|
|
85
|
+
};
|
|
86
|
+
const getRouterSnapshot = (internalContext, contextRouter)=>{
|
|
87
|
+
const location = getRouterStateLocation(internalContext, contextRouter);
|
|
88
|
+
const params = getRouterParams(internalContext, contextRouter);
|
|
89
|
+
return JSON.stringify([
|
|
90
|
+
location?.pathname ?? '',
|
|
91
|
+
location?.search ?? '',
|
|
92
|
+
location?.hash ?? '',
|
|
93
|
+
Object.entries(params).sort(([left], [right])=>left.localeCompare(right))
|
|
94
|
+
]);
|
|
95
|
+
};
|
|
96
|
+
const createI18nRouterNavigation = ({ I18nNavigationProvider, useNativeI18nRouterAdapter })=>{
|
|
97
|
+
const useIntegratedRouterAdapter = ()=>{
|
|
98
|
+
const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
|
|
99
|
+
const internalContext = (0, external_react_namespaceObject.useContext)(context_namespaceObject.InternalRuntimeContext);
|
|
100
|
+
const routerApi = internalContext.router || runtimeContext.router;
|
|
101
|
+
const native = useNativeI18nRouterAdapter();
|
|
102
|
+
const inReactRouter = native.hasRouter;
|
|
103
|
+
const reactRouterNavigate = native.navigate;
|
|
104
|
+
const reactRouterLocation = inReactRouter ? native.location : null;
|
|
105
|
+
const reactRouterParams = native.params;
|
|
106
|
+
const framework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
|
|
107
|
+
const contextUseRouter = inReactRouter || 'tanstack' !== framework ? void 0 : internalContext.router?.useRouter || runtimeContext.router?.useRouter;
|
|
108
|
+
const contextRouter = contextUseRouter ? contextUseRouter({
|
|
109
|
+
warn: false
|
|
110
|
+
}) : null;
|
|
111
|
+
const slotRouter = getRouterInstance(internalContext, contextRouter);
|
|
112
|
+
const drivableSlotRouter = ('tanstack' === framework || 'react-router' === framework) && 'function' == typeof slotRouter?.navigate;
|
|
113
|
+
const hasRouter = Boolean(reactRouterNavigate) || drivableSlotRouter;
|
|
114
|
+
const subscribeToRouter = (0, external_react_namespaceObject.useCallback)((update)=>{
|
|
115
|
+
const unsubscribers = [];
|
|
116
|
+
const unsubscribeFromSlot = (0, router_state_namespaceObject.subscribeRouterRuntimeState)(internalContext, update);
|
|
117
|
+
if ('function' == typeof unsubscribeFromSlot) unsubscribers.push(unsubscribeFromSlot);
|
|
118
|
+
const router = getRouterInstance(internalContext, contextRouter);
|
|
119
|
+
if (!router) return ()=>{
|
|
120
|
+
for (const unsubscribe of unsubscribers)unsubscribe();
|
|
121
|
+
};
|
|
122
|
+
if ('react-router' === framework && !inReactRouter && 'function' == typeof router.subscribe) {
|
|
123
|
+
const subscribe = router.subscribe;
|
|
124
|
+
const unsubscribe = subscribe.call(router, update);
|
|
125
|
+
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
126
|
+
}
|
|
127
|
+
if ('tanstack' === framework && 'function' == typeof router.stores?.location?.subscribe) {
|
|
128
|
+
const unsubscribe = router.stores.location.subscribe(update);
|
|
129
|
+
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
130
|
+
}
|
|
131
|
+
if ('tanstack' === framework && 'function' == typeof router.subscribe) {
|
|
132
|
+
const subscribe = router.subscribe;
|
|
133
|
+
for (const eventType of [
|
|
134
|
+
'onBeforeNavigate',
|
|
135
|
+
'onBeforeLoad'
|
|
136
|
+
]){
|
|
137
|
+
const unsubscribe = subscribe.call(router, eventType, update);
|
|
138
|
+
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return ()=>{
|
|
142
|
+
for (const unsubscribe of unsubscribers)unsubscribe();
|
|
143
|
+
};
|
|
144
|
+
}, [
|
|
145
|
+
contextRouter,
|
|
146
|
+
framework,
|
|
147
|
+
inReactRouter,
|
|
148
|
+
internalContext
|
|
149
|
+
]);
|
|
150
|
+
const getSnapshot = (0, external_react_namespaceObject.useCallback)(()=>getRouterSnapshot(internalContext, contextRouter), [
|
|
151
|
+
contextRouter,
|
|
152
|
+
internalContext
|
|
153
|
+
]);
|
|
154
|
+
(0, external_react_namespaceObject.useSyncExternalStore)(subscribeToRouter, getSnapshot, getSnapshot);
|
|
155
|
+
const navigate = (0, external_react_namespaceObject.useCallback)((href, options)=>{
|
|
156
|
+
const router = getRouterInstance(internalContext, contextRouter);
|
|
157
|
+
const activeFramework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
|
|
158
|
+
if ('tanstack' === activeFramework) {
|
|
159
|
+
if ('function' == typeof router?.navigate) return router.navigate({
|
|
160
|
+
to: href,
|
|
161
|
+
replace: options?.replace,
|
|
162
|
+
...options?.state === void 0 ? {} : {
|
|
163
|
+
state: options.state
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
throw new Error('TanStack router instance is not available.');
|
|
167
|
+
}
|
|
168
|
+
if (reactRouterNavigate) return reactRouterNavigate(href, options);
|
|
169
|
+
if ('react-router' === activeFramework) {
|
|
170
|
+
if ('function' == typeof router?.navigate) return router.navigate(href, options);
|
|
171
|
+
throw new Error('React Router instance is not available.');
|
|
172
|
+
}
|
|
173
|
+
}, [
|
|
174
|
+
contextRouter,
|
|
175
|
+
internalContext,
|
|
176
|
+
inReactRouter,
|
|
177
|
+
reactRouterNavigate,
|
|
178
|
+
runtimeContext
|
|
179
|
+
]);
|
|
180
|
+
const location = (reactRouterLocation ? normalizeLocation(reactRouterLocation) : getRouterStateLocation(internalContext, contextRouter)) || getWindowLocation();
|
|
181
|
+
const params = inReactRouter ? reactRouterParams : getRouterParams(internalContext, contextRouter);
|
|
182
|
+
const Link = 'tanstack' === framework ? internalContext.router?.Link || runtimeContext.router?.Link || null : 'react-router' === framework || inReactRouter ? routerApi?.Link ?? null : null;
|
|
183
|
+
return {
|
|
184
|
+
framework,
|
|
185
|
+
hasRouter,
|
|
186
|
+
location,
|
|
187
|
+
navigate: hasRouter ? navigate : null,
|
|
188
|
+
Link,
|
|
189
|
+
params,
|
|
190
|
+
...'tanstack' === framework ? {
|
|
191
|
+
createLinkProps: createTanstackLinkProps
|
|
192
|
+
} : {}
|
|
193
|
+
};
|
|
194
|
+
};
|
|
195
|
+
const createTanstackLinkProps = (target)=>{
|
|
196
|
+
const preload = void 0 !== target.preload ? target.preload : 'none' === target.prefetch ? false : target.prefetch;
|
|
197
|
+
return {
|
|
198
|
+
to: target.pathname,
|
|
199
|
+
...target.search ? {
|
|
200
|
+
search: target.search
|
|
201
|
+
} : {},
|
|
202
|
+
...target.hash ? {
|
|
203
|
+
hash: target.hash
|
|
204
|
+
} : {},
|
|
205
|
+
...void 0 === target.hashScrollIntoView ? {} : {
|
|
206
|
+
hashScrollIntoView: target.hashScrollIntoView
|
|
207
|
+
},
|
|
208
|
+
...void 0 === preload ? {} : {
|
|
209
|
+
preload
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
};
|
|
213
|
+
const I18nRouterNavigationProvider = ({ children })=>{
|
|
214
|
+
const value = useIntegratedRouterAdapter();
|
|
215
|
+
const native = useNativeI18nRouterAdapter();
|
|
216
|
+
if (!value.hasRouter || native.hasRouter) return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(jsx_runtime_namespaceObject.Fragment, {
|
|
217
|
+
children: children
|
|
218
|
+
});
|
|
219
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nNavigationProvider, {
|
|
220
|
+
value: value,
|
|
221
|
+
children: children
|
|
222
|
+
});
|
|
223
|
+
};
|
|
224
|
+
return {
|
|
225
|
+
useIntegratedRouterAdapter,
|
|
226
|
+
I18nRouterNavigationProvider
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
exports.createI18nRouterNavigation = __webpack_exports__.createI18nRouterNavigation;
|
|
230
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
231
|
+
"createI18nRouterNavigation"
|
|
232
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
233
|
+
Object.defineProperty(exports, '__esModule', {
|
|
234
|
+
value: true
|
|
235
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_require__ = {};
|
|
3
|
+
(()=>{
|
|
4
|
+
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
+
var define = (defs, kind)=>{
|
|
6
|
+
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
[kind]: defs[key]
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
define(getters, "get");
|
|
12
|
+
define(values, "value");
|
|
13
|
+
};
|
|
14
|
+
})();
|
|
15
|
+
(()=>{
|
|
16
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
+
})();
|
|
18
|
+
(()=>{
|
|
19
|
+
__webpack_require__.r = (exports1)=>{
|
|
20
|
+
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
+
value: 'Module'
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
+
value: true
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
})();
|
|
28
|
+
var __webpack_exports__ = {};
|
|
29
|
+
__webpack_require__.r(__webpack_exports__);
|
|
30
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
31
|
+
createI18nRouterNavigation: ()=>external_adapter_js_namespaceObject.createI18nRouterNavigation
|
|
32
|
+
});
|
|
33
|
+
const external_adapter_js_namespaceObject = require("./adapter.js");
|
|
34
|
+
exports.createI18nRouterNavigation = __webpack_exports__.createI18nRouterNavigation;
|
|
35
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
36
|
+
"createI18nRouterNavigation"
|
|
37
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
38
|
+
Object.defineProperty(exports, '__esModule', {
|
|
39
|
+
value: true
|
|
40
|
+
});
|
package/dist/esm/index.mjs
CHANGED