@bleedingdev/modern-js-plugin-i18n 3.5.0-ultramodern.9 → 3.5.0-ultramodern.91
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/cli/index.js +2 -1
- package/dist/cjs/cli/locales.js +15 -15
- package/dist/cjs/runtime/Link.js +8 -89
- package/dist/cjs/runtime/context.js +78 -91
- package/dist/cjs/runtime/contextHelpers.js +143 -0
- package/dist/cjs/runtime/core.js +32 -132
- package/dist/cjs/runtime/hooks.js +54 -21
- package/dist/cjs/runtime/i18n/backend/defaults.node.js +7 -7
- package/dist/cjs/runtime/i18n/detection/cache.js +150 -0
- package/dist/cjs/runtime/i18n/detection/detector.js +100 -0
- package/dist/cjs/runtime/i18n/detection/index.js +8 -263
- package/dist/cjs/runtime/i18n/detection/initOptions.js +69 -0
- package/dist/cjs/runtime/i18n/detection/language.js +62 -0
- package/dist/cjs/runtime/i18n/detection/path.js +49 -0
- package/dist/cjs/runtime/i18n/detection/priority.js +66 -0
- package/dist/cjs/runtime/i18n/detection/ssr.js +70 -0
- package/dist/cjs/runtime/i18n/detection/types.js +18 -0
- package/dist/cjs/runtime/i18n/instance.js +34 -10
- package/dist/cjs/runtime/linkHelpers.js +148 -0
- package/dist/cjs/runtime/pluginSetup.js +102 -0
- package/dist/cjs/runtime/providerComposition.js +115 -0
- package/dist/cjs/runtime/reactI18next.js +43 -0
- package/dist/cjs/runtime/routerAdapter.js +16 -8
- package/dist/cjs/runtime/utils.js +1 -9
- package/dist/cjs/server/apiPrefix.js +72 -0
- package/dist/cjs/server/detectorOptions.js +97 -0
- package/dist/cjs/server/index.js +17 -144
- package/dist/cjs/server/redirectPolicy.js +96 -0
- package/dist/cjs/shared/detection.js +2 -104
- package/dist/cjs/shared/localisedUrls/config.js +49 -0
- package/dist/cjs/shared/localisedUrls/index.js +91 -0
- package/dist/cjs/shared/localisedUrls/normalise.js +87 -0
- package/dist/cjs/shared/localisedUrls/pathname.js +68 -0
- package/dist/cjs/shared/localisedUrls/patterns.js +130 -0
- package/dist/cjs/shared/localisedUrls/redirect.js +103 -0
- package/dist/cjs/shared/localisedUrls/resolve.js +88 -0
- package/dist/cjs/shared/localisedUrls/routes.js +130 -0
- package/dist/cjs/shared/localisedUrls/types.js +18 -0
- package/dist/cjs/shared/localisedUrls.js +28 -294
- package/dist/cjs/shared/utils.js +2 -8
- package/dist/esm/cli/index.mjs +2 -1
- package/dist/esm/cli/locales.mjs +13 -13
- package/dist/esm/runtime/Link.mjs +1 -82
- package/dist/esm/runtime/context.mjs +76 -92
- package/dist/esm/runtime/contextHelpers.mjs +87 -0
- package/dist/esm/runtime/core.mjs +30 -133
- package/dist/esm/runtime/hooks.mjs +56 -23
- package/dist/esm/runtime/i18n/backend/defaults.node.mjs +5 -5
- package/dist/esm/runtime/i18n/detection/cache.mjs +103 -0
- package/dist/esm/runtime/i18n/detection/detector.mjs +62 -0
- package/dist/esm/runtime/i18n/detection/index.mjs +4 -260
- package/dist/esm/runtime/i18n/detection/initOptions.mjs +28 -0
- package/dist/esm/runtime/i18n/detection/language.mjs +21 -0
- package/dist/esm/runtime/i18n/detection/path.mjs +11 -0
- package/dist/esm/runtime/i18n/detection/priority.mjs +28 -0
- package/dist/esm/runtime/i18n/detection/ssr.mjs +26 -0
- package/dist/esm/runtime/i18n/detection/types.mjs +0 -0
- package/dist/esm/runtime/i18n/instance.mjs +35 -8
- package/dist/esm/runtime/linkHelpers.mjs +98 -0
- package/dist/esm/runtime/pluginSetup.mjs +64 -0
- package/dist/esm/runtime/providerComposition.mjs +77 -0
- package/dist/esm/runtime/reactI18next.mjs +5 -0
- package/dist/esm/runtime/routerAdapter.mjs +16 -8
- package/dist/esm/runtime/utils.mjs +2 -10
- package/dist/esm/server/apiPrefix.mjs +31 -0
- package/dist/esm/server/detectorOptions.mjs +59 -0
- package/dist/esm/server/index.mjs +8 -135
- package/dist/esm/server/redirectPolicy.mjs +46 -0
- package/dist/esm/shared/detection.mjs +1 -71
- package/dist/esm/shared/localisedUrls/config.mjs +11 -0
- package/dist/esm/shared/localisedUrls/index.mjs +7 -0
- package/dist/esm/shared/localisedUrls/normalise.mjs +37 -0
- package/dist/esm/shared/localisedUrls/pathname.mjs +24 -0
- package/dist/esm/shared/localisedUrls/patterns.mjs +86 -0
- package/dist/esm/shared/localisedUrls/redirect.mjs +56 -0
- package/dist/esm/shared/localisedUrls/resolve.mjs +47 -0
- package/dist/esm/shared/localisedUrls/routes.mjs +89 -0
- package/dist/esm/shared/localisedUrls/types.mjs +0 -0
- package/dist/esm/shared/localisedUrls.mjs +1 -283
- package/dist/esm/shared/utils.mjs +1 -1
- package/dist/esm-node/cli/index.mjs +2 -1
- package/dist/esm-node/cli/locales.mjs +13 -13
- package/dist/esm-node/runtime/Link.mjs +1 -82
- package/dist/esm-node/runtime/context.mjs +76 -92
- package/dist/esm-node/runtime/contextHelpers.mjs +88 -0
- package/dist/esm-node/runtime/core.mjs +30 -133
- package/dist/esm-node/runtime/hooks.mjs +56 -23
- package/dist/esm-node/runtime/i18n/backend/defaults.node.mjs +5 -5
- package/dist/esm-node/runtime/i18n/detection/cache.mjs +104 -0
- package/dist/esm-node/runtime/i18n/detection/detector.mjs +63 -0
- package/dist/esm-node/runtime/i18n/detection/index.mjs +4 -260
- package/dist/esm-node/runtime/i18n/detection/initOptions.mjs +29 -0
- package/dist/esm-node/runtime/i18n/detection/language.mjs +22 -0
- package/dist/esm-node/runtime/i18n/detection/path.mjs +12 -0
- package/dist/esm-node/runtime/i18n/detection/priority.mjs +29 -0
- package/dist/esm-node/runtime/i18n/detection/ssr.mjs +27 -0
- package/dist/esm-node/runtime/i18n/detection/types.mjs +1 -0
- package/dist/esm-node/runtime/i18n/instance.mjs +35 -8
- package/dist/esm-node/runtime/linkHelpers.mjs +99 -0
- package/dist/esm-node/runtime/pluginSetup.mjs +65 -0
- package/dist/esm-node/runtime/providerComposition.mjs +78 -0
- package/dist/esm-node/runtime/reactI18next.mjs +6 -0
- package/dist/esm-node/runtime/routerAdapter.mjs +16 -8
- package/dist/esm-node/runtime/utils.mjs +2 -10
- package/dist/esm-node/server/apiPrefix.mjs +32 -0
- package/dist/esm-node/server/detectorOptions.mjs +60 -0
- package/dist/esm-node/server/index.mjs +8 -135
- package/dist/esm-node/server/redirectPolicy.mjs +47 -0
- package/dist/esm-node/shared/detection.mjs +1 -71
- package/dist/esm-node/shared/localisedUrls/config.mjs +12 -0
- package/dist/esm-node/shared/localisedUrls/index.mjs +8 -0
- package/dist/esm-node/shared/localisedUrls/normalise.mjs +38 -0
- package/dist/esm-node/shared/localisedUrls/pathname.mjs +25 -0
- package/dist/esm-node/shared/localisedUrls/patterns.mjs +87 -0
- package/dist/esm-node/shared/localisedUrls/redirect.mjs +57 -0
- package/dist/esm-node/shared/localisedUrls/resolve.mjs +48 -0
- package/dist/esm-node/shared/localisedUrls/routes.mjs +90 -0
- package/dist/esm-node/shared/localisedUrls/types.mjs +1 -0
- package/dist/esm-node/shared/localisedUrls.mjs +1 -283
- package/dist/esm-node/shared/utils.mjs +1 -1
- package/dist/types/cli/locales.d.ts +1 -1
- package/dist/types/runtime/Link.d.ts +3 -7
- package/dist/types/runtime/context.d.ts +21 -5
- package/dist/types/runtime/contextHelpers.d.ts +29 -0
- package/dist/types/runtime/core.d.ts +4 -8
- package/dist/types/runtime/hooks.d.ts +3 -7
- package/dist/types/runtime/i18n/backend/middleware.common.d.ts +2 -1
- package/dist/types/runtime/i18n/detection/cache.d.ts +14 -0
- package/dist/types/runtime/i18n/detection/detector.d.ts +8 -0
- package/dist/types/runtime/i18n/detection/index.d.ts +5 -50
- package/dist/types/runtime/i18n/detection/initOptions.d.ts +10 -0
- package/dist/types/runtime/i18n/detection/language.d.ts +11 -0
- package/dist/types/runtime/i18n/detection/middleware.d.ts +4 -4
- package/dist/types/runtime/i18n/detection/middleware.node.d.ts +4 -4
- package/dist/types/runtime/i18n/detection/path.d.ts +5 -0
- package/dist/types/runtime/i18n/detection/priority.d.ts +10 -0
- package/dist/types/runtime/i18n/detection/ssr.d.ts +9 -0
- package/dist/types/runtime/i18n/detection/types.d.ts +32 -0
- package/dist/types/runtime/i18n/instance.d.ts +31 -27
- package/dist/types/runtime/i18n/react-i18next.d.ts +1 -6
- package/dist/types/runtime/i18n/utils.d.ts +14 -5
- package/dist/types/runtime/linkHelpers.d.ts +17 -0
- package/dist/types/runtime/pluginSetup.d.ts +32 -0
- package/dist/types/runtime/providerComposition.d.ts +16 -0
- package/dist/types/runtime/reactI18next.d.ts +7 -0
- package/dist/types/runtime/routerAdapter.d.ts +7 -6
- package/dist/types/runtime/utils.d.ts +7 -2
- package/dist/types/server/apiPrefix.d.ts +7 -0
- package/dist/types/server/detectorOptions.d.ts +21 -0
- package/dist/types/server/index.d.ts +1 -6
- package/dist/types/server/redirectPolicy.d.ts +22 -0
- package/dist/types/shared/detection.d.ts +1 -11
- package/dist/types/shared/localisedUrls/config.d.ts +9 -0
- package/dist/types/shared/localisedUrls/index.d.ts +9 -0
- package/dist/types/shared/localisedUrls/normalise.d.ts +10 -0
- package/dist/types/shared/localisedUrls/pathname.d.ts +4 -0
- package/dist/types/shared/localisedUrls/patterns.d.ts +5 -0
- package/dist/types/shared/localisedUrls/redirect.d.ts +11 -0
- package/dist/types/shared/localisedUrls/resolve.d.ts +7 -0
- package/dist/types/shared/localisedUrls/routes.d.ts +3 -0
- package/dist/types/shared/localisedUrls/types.d.ts +14 -0
- package/dist/types/shared/localisedUrls.d.ts +2 -36
- package/dist/types/shared/utils.d.ts +0 -2
- package/package.json +17 -20
- package/rstest.config.mts +8 -1
- package/src/cli/index.ts +5 -4
- package/src/cli/locales.ts +3 -3
- package/src/runtime/Link.tsx +11 -138
- package/src/runtime/context.tsx +170 -207
- package/src/runtime/contextHelpers.ts +242 -0
- package/src/runtime/core.tsx +48 -275
- package/src/runtime/hooks.ts +86 -24
- package/src/runtime/i18n/backend/defaults.node.ts +2 -2
- package/src/runtime/i18n/backend/middleware.common.ts +5 -4
- package/src/runtime/i18n/detection/cache.ts +189 -0
- package/src/runtime/i18n/detection/detector.ts +166 -0
- package/src/runtime/i18n/detection/index.ts +10 -641
- package/src/runtime/i18n/detection/initOptions.ts +74 -0
- package/src/runtime/i18n/detection/language.ts +64 -0
- package/src/runtime/i18n/detection/middleware.node.ts +26 -7
- package/src/runtime/i18n/detection/middleware.ts +15 -7
- package/src/runtime/i18n/detection/path.ts +41 -0
- package/src/runtime/i18n/detection/priority.ts +82 -0
- package/src/runtime/i18n/detection/ssr.ts +47 -0
- package/src/runtime/i18n/detection/types.ts +41 -0
- package/src/runtime/i18n/instance.ts +98 -34
- package/src/runtime/i18n/react-i18next.ts +1 -6
- package/src/runtime/i18n/utils.ts +18 -9
- package/src/runtime/linkHelpers.ts +174 -0
- package/src/runtime/pluginSetup.ts +189 -0
- package/src/runtime/providerComposition.tsx +148 -0
- package/src/runtime/reactI18next.ts +20 -0
- package/src/runtime/routerAdapter.tsx +36 -15
- package/src/runtime/utils.ts +13 -35
- package/src/server/apiPrefix.ts +67 -0
- package/src/server/detectorOptions.ts +105 -0
- package/src/server/index.ts +14 -319
- package/src/server/redirectPolicy.ts +127 -0
- package/src/shared/detection.ts +1 -1
- package/src/shared/localisedUrls/config.ts +18 -0
- package/src/shared/localisedUrls/index.ts +24 -0
- package/src/shared/localisedUrls/normalise.ts +67 -0
- package/src/shared/localisedUrls/pathname.ts +60 -0
- package/src/shared/localisedUrls/patterns.ts +160 -0
- package/src/shared/localisedUrls/redirect.ts +93 -0
- package/src/shared/localisedUrls/resolve.ts +135 -0
- package/src/shared/localisedUrls/routes.ts +234 -0
- package/src/shared/localisedUrls/types.ts +18 -0
- package/src/shared/localisedUrls.ts +26 -623
- package/src/shared/utils.ts +2 -2
- package/tests/federatedI18nBoundary.client.test.tsx +112 -0
- package/tests/federatedI18nBoundary.test.tsx +120 -0
- package/tests/fixtures/localised-routes.golden.json +156 -0
- package/tests/link.test.tsx +111 -0
- package/tests/localisedUrlRewriteMatrix.fork.test.ts +147 -0
- package/tests/localisedUrls.test.ts +148 -2
- package/tests/reactI18nextRuntimeBoundary.test.ts +6 -3
- package/tests/redirectPolicy.test.ts +45 -0
- package/tests/routerAdapter.test.tsx +603 -0
- package/tests/type-fixture/fixture-globals.d.ts +11 -0
- package/tests/type-fixture/tsconfig.json +1 -0
|
@@ -29,9 +29,11 @@ var __webpack_exports__ = {};
|
|
|
29
29
|
__webpack_require__.r(__webpack_exports__);
|
|
30
30
|
function isI18nWrapperInstance(obj) {
|
|
31
31
|
if (!obj || 'object' != typeof obj) return false;
|
|
32
|
-
|
|
33
|
-
if (!
|
|
34
|
-
|
|
32
|
+
const candidate = obj;
|
|
33
|
+
if (!candidate.i18nInstance || 'object' != typeof candidate.i18nInstance) return false;
|
|
34
|
+
const wrapper = candidate.i18nInstance;
|
|
35
|
+
if (!wrapper.instance) return false;
|
|
36
|
+
if ('function' != typeof candidate.init || 'function' != typeof candidate.use) return false;
|
|
35
37
|
return true;
|
|
36
38
|
}
|
|
37
39
|
function getI18nWrapperI18nextInstance(wrapperInstance) {
|
|
@@ -48,7 +50,8 @@ function getActualI18nextInstance(instance) {
|
|
|
48
50
|
function isI18nInstance(obj) {
|
|
49
51
|
if (!obj || 'object' != typeof obj) return false;
|
|
50
52
|
if (isI18nWrapperInstance(obj)) return true;
|
|
51
|
-
|
|
53
|
+
const candidate = obj;
|
|
54
|
+
return 'function' == typeof candidate.init && 'function' == typeof candidate.use;
|
|
52
55
|
}
|
|
53
56
|
async function tryImportI18next() {
|
|
54
57
|
try {
|
|
@@ -69,12 +72,36 @@ async function createI18nextInstance() {
|
|
|
69
72
|
return null;
|
|
70
73
|
}
|
|
71
74
|
}
|
|
72
|
-
function getI18nextInstanceForProvider(instance) {
|
|
75
|
+
function getI18nextInstanceForProvider(instance, language) {
|
|
76
|
+
let providerInstance = instance;
|
|
73
77
|
if (isI18nWrapperInstance(instance)) {
|
|
74
78
|
const i18nextInstance = getI18nWrapperI18nextInstance(instance);
|
|
75
|
-
if (i18nextInstance)
|
|
79
|
+
if (i18nextInstance) providerInstance = i18nextInstance;
|
|
76
80
|
}
|
|
77
|
-
return
|
|
81
|
+
if (!language || "u" < typeof Proxy) return providerInstance;
|
|
82
|
+
return new Proxy(providerInstance, {
|
|
83
|
+
get (target, property, receiver) {
|
|
84
|
+
if ('language' === property || 'resolvedLanguage' === property) return language;
|
|
85
|
+
if ('languages' === property) {
|
|
86
|
+
const languages = Reflect.get(target, property, receiver);
|
|
87
|
+
return Array.isArray(languages) ? [
|
|
88
|
+
language,
|
|
89
|
+
...languages.filter((item)=>item !== language)
|
|
90
|
+
] : [
|
|
91
|
+
language
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
if ('t' === property && 'function' == typeof target.getFixedT) return target.getFixedT(language);
|
|
95
|
+
if ('hasLoadedNamespace' === property && 'function' == typeof target.hasLoadedNamespace) {
|
|
96
|
+
const hasLoadedNamespace = target.hasLoadedNamespace;
|
|
97
|
+
return (namespace, options)=>hasLoadedNamespace.call(target, namespace, {
|
|
98
|
+
...options,
|
|
99
|
+
lng: options?.lng || language
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
return Reflect.get(target, property, receiver);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
78
105
|
}
|
|
79
106
|
async function getI18nInstance(userInstance) {
|
|
80
107
|
if (userInstance) {
|
|
@@ -88,21 +115,18 @@ async function getI18nInstance(userInstance) {
|
|
|
88
115
|
__webpack_require__.d(__webpack_exports__, {
|
|
89
116
|
getActualI18nextInstance: ()=>getActualI18nextInstance,
|
|
90
117
|
getI18nInstance: ()=>getI18nInstance,
|
|
91
|
-
getI18nWrapperI18nextInstance: ()=>getI18nWrapperI18nextInstance,
|
|
92
118
|
getI18nextInstanceForProvider: ()=>getI18nextInstanceForProvider,
|
|
93
119
|
isI18nInstance: ()=>isI18nInstance,
|
|
94
120
|
isI18nWrapperInstance: ()=>isI18nWrapperInstance
|
|
95
121
|
});
|
|
96
122
|
exports.getActualI18nextInstance = __webpack_exports__.getActualI18nextInstance;
|
|
97
123
|
exports.getI18nInstance = __webpack_exports__.getI18nInstance;
|
|
98
|
-
exports.getI18nWrapperI18nextInstance = __webpack_exports__.getI18nWrapperI18nextInstance;
|
|
99
124
|
exports.getI18nextInstanceForProvider = __webpack_exports__.getI18nextInstanceForProvider;
|
|
100
125
|
exports.isI18nInstance = __webpack_exports__.isI18nInstance;
|
|
101
126
|
exports.isI18nWrapperInstance = __webpack_exports__.isI18nWrapperInstance;
|
|
102
127
|
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
103
128
|
"getActualI18nextInstance",
|
|
104
129
|
"getI18nInstance",
|
|
105
|
-
"getI18nWrapperI18nextInstance",
|
|
106
130
|
"getI18nextInstanceForProvider",
|
|
107
131
|
"isI18nInstance",
|
|
108
132
|
"isI18nWrapperInstance"
|
|
@@ -0,0 +1,148 @@
|
|
|
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
|
+
const warnedTargets = new Set();
|
|
31
|
+
const warnOnce = (key, message)=>{
|
|
32
|
+
if ('development' !== process.env.NODE_ENV || warnedTargets.has(key)) return;
|
|
33
|
+
warnedTargets.add(key);
|
|
34
|
+
console.warn(message);
|
|
35
|
+
};
|
|
36
|
+
const interpolateRouteParams = (pathname, params)=>{
|
|
37
|
+
if (!/[$:*{]/.test(pathname)) return pathname;
|
|
38
|
+
const resolveParam = (name)=>{
|
|
39
|
+
const value = params?.[name];
|
|
40
|
+
return void 0 === value ? void 0 : String(value);
|
|
41
|
+
};
|
|
42
|
+
const segments = pathname.split('/').map((segment)=>{
|
|
43
|
+
if (!segment) return segment;
|
|
44
|
+
if (segment.startsWith('{-$') && segment.endsWith('}')) {
|
|
45
|
+
const value = resolveParam(segment.slice(3, -1));
|
|
46
|
+
return void 0 === value ? null : encodeURIComponent(value);
|
|
47
|
+
}
|
|
48
|
+
if ('$' === segment || '*' === segment) {
|
|
49
|
+
const value = resolveParam('_splat') ?? resolveParam('*');
|
|
50
|
+
return void 0 === value ? null : value.split('/').map(encodeURIComponent).join('/');
|
|
51
|
+
}
|
|
52
|
+
if (segment.startsWith('$')) {
|
|
53
|
+
const value = resolveParam(segment.slice(1));
|
|
54
|
+
if (void 0 === value) {
|
|
55
|
+
warnOnce(`missing-param:${pathname}:${segment}`, `[plugin-i18n] <Link to="${pathname}"> is missing required param "${segment.slice(1)}".`);
|
|
56
|
+
return segment;
|
|
57
|
+
}
|
|
58
|
+
return encodeURIComponent(value);
|
|
59
|
+
}
|
|
60
|
+
if (segment.startsWith(':')) {
|
|
61
|
+
const optional = segment.endsWith('?');
|
|
62
|
+
const name = segment.slice(1, optional ? -1 : void 0);
|
|
63
|
+
const value = resolveParam(name);
|
|
64
|
+
if (void 0 === value) {
|
|
65
|
+
if (optional) return null;
|
|
66
|
+
warnOnce(`missing-param:${pathname}:${segment}`, `[plugin-i18n] <Link to="${pathname}"> is missing required param "${name}".`);
|
|
67
|
+
return segment;
|
|
68
|
+
}
|
|
69
|
+
return encodeURIComponent(value);
|
|
70
|
+
}
|
|
71
|
+
return segment;
|
|
72
|
+
}).filter((segment)=>null !== segment);
|
|
73
|
+
return segments.join('/') || '/';
|
|
74
|
+
};
|
|
75
|
+
const normalizeSearch = (search, searchFromTo)=>{
|
|
76
|
+
if (search && 'object' == typeof search) {
|
|
77
|
+
const searchObject = {};
|
|
78
|
+
const params = new URLSearchParams();
|
|
79
|
+
for (const [key, value] of Object.entries(search)){
|
|
80
|
+
if (null == value) continue;
|
|
81
|
+
if (Array.isArray(value)) {
|
|
82
|
+
const values = value.filter((item)=>null != item).map(String);
|
|
83
|
+
if (0 === values.length) continue;
|
|
84
|
+
searchObject[key] = values;
|
|
85
|
+
for (const item of values)params.append(key, item);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
const stringValue = String(value);
|
|
89
|
+
searchObject[key] = stringValue;
|
|
90
|
+
params.append(key, stringValue);
|
|
91
|
+
}
|
|
92
|
+
const serialized = params.toString();
|
|
93
|
+
return {
|
|
94
|
+
searchString: serialized ? `?${serialized}` : '',
|
|
95
|
+
searchObject: Object.keys(searchObject).length > 0 ? searchObject : void 0
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
const raw = 'string' == typeof search ? search : searchFromTo;
|
|
99
|
+
if (!raw) return {
|
|
100
|
+
searchString: '',
|
|
101
|
+
searchObject: void 0
|
|
102
|
+
};
|
|
103
|
+
const searchString = raw.startsWith('?') ? raw : `?${raw}`;
|
|
104
|
+
const searchObject = {};
|
|
105
|
+
new URLSearchParams(searchString).forEach((value, key)=>{
|
|
106
|
+
const existing = searchObject[key];
|
|
107
|
+
if (void 0 === existing) searchObject[key] = value;
|
|
108
|
+
else if (Array.isArray(existing)) existing.push(value);
|
|
109
|
+
else searchObject[key] = [
|
|
110
|
+
existing,
|
|
111
|
+
value
|
|
112
|
+
];
|
|
113
|
+
});
|
|
114
|
+
return {
|
|
115
|
+
searchString,
|
|
116
|
+
searchObject
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
const splitActiveProps = (active, activeProps)=>{
|
|
120
|
+
if (!active || !activeProps) return {};
|
|
121
|
+
return activeProps;
|
|
122
|
+
};
|
|
123
|
+
const mergeClassNames = (...values)=>{
|
|
124
|
+
const classNames = values.filter((value)=>'string' == typeof value && value.length > 0);
|
|
125
|
+
return classNames.length > 0 ? classNames.join(' ') : void 0;
|
|
126
|
+
};
|
|
127
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
128
|
+
interpolateRouteParams: interpolateRouteParams,
|
|
129
|
+
mergeClassNames: mergeClassNames,
|
|
130
|
+
normalizeSearch: normalizeSearch,
|
|
131
|
+
splitActiveProps: splitActiveProps,
|
|
132
|
+
warnOnce: warnOnce
|
|
133
|
+
});
|
|
134
|
+
exports.interpolateRouteParams = __webpack_exports__.interpolateRouteParams;
|
|
135
|
+
exports.mergeClassNames = __webpack_exports__.mergeClassNames;
|
|
136
|
+
exports.normalizeSearch = __webpack_exports__.normalizeSearch;
|
|
137
|
+
exports.splitActiveProps = __webpack_exports__.splitActiveProps;
|
|
138
|
+
exports.warnOnce = __webpack_exports__.warnOnce;
|
|
139
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
140
|
+
"interpolateRouteParams",
|
|
141
|
+
"mergeClassNames",
|
|
142
|
+
"normalizeSearch",
|
|
143
|
+
"splitActiveProps",
|
|
144
|
+
"warnOnce"
|
|
145
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
146
|
+
Object.defineProperty(exports, '__esModule', {
|
|
147
|
+
value: true
|
|
148
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
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
|
+
setupI18nBeforeRender: ()=>setupI18nBeforeRender
|
|
32
|
+
});
|
|
33
|
+
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
34
|
+
const merge_namespaceObject = require("@modern-js/runtime-utils/merge");
|
|
35
|
+
const index_js_namespaceObject = require("./i18n/index.js");
|
|
36
|
+
const backend_index_js_namespaceObject = require("./i18n/backend/index.js");
|
|
37
|
+
const detection_index_js_namespaceObject = require("./i18n/detection/index.js");
|
|
38
|
+
const middleware_js_namespaceObject = require("./i18n/detection/middleware.js");
|
|
39
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
40
|
+
let i18nLifecycleHelpersPromise;
|
|
41
|
+
function loadI18nLifecycleHelpers() {
|
|
42
|
+
i18nLifecycleHelpersPromise ??= Promise.all([
|
|
43
|
+
import("./i18n/backend/middleware.js"),
|
|
44
|
+
import("./i18n/utils.js")
|
|
45
|
+
]).then(([backendMiddleware, utils])=>({
|
|
46
|
+
useI18nextBackend: backendMiddleware.useI18nextBackend,
|
|
47
|
+
changeI18nLanguage: utils.changeI18nLanguage,
|
|
48
|
+
ensureLanguageMatch: utils.ensureLanguageMatch,
|
|
49
|
+
initializeI18nInstance: utils.initializeI18nInstance,
|
|
50
|
+
setupClonedInstance: utils.setupClonedInstance
|
|
51
|
+
}));
|
|
52
|
+
return i18nLifecycleHelpersPromise;
|
|
53
|
+
}
|
|
54
|
+
async function setupI18nBeforeRender(context, options) {
|
|
55
|
+
const { api, userI18nInstance, initOptions, backend, backendEnabled, i18nextDetector, detection, localePathRedirect, languages, fallbackLanguage, resolveReactI18nextIntegration, setI18nextProvider } = options;
|
|
56
|
+
const { useI18nextBackend, changeI18nLanguage, ensureLanguageMatch, initializeI18nInstance, setupClonedInstance } = await loadI18nLifecycleHelpers();
|
|
57
|
+
let i18nInstance = await (0, index_js_namespaceObject.getI18nInstance)(userI18nInstance);
|
|
58
|
+
const { i18n: otherConfig } = api.getRuntimeConfig();
|
|
59
|
+
const { initOptions: otherInitOptions } = otherConfig || {};
|
|
60
|
+
const userInitOptions = (0, merge_namespaceObject.merge)(otherInitOptions || {}, initOptions || {});
|
|
61
|
+
const reactI18nextIntegration = await resolveReactI18nextIntegration();
|
|
62
|
+
setI18nextProvider(reactI18nextIntegration?.I18nextProvider ?? null);
|
|
63
|
+
if (reactI18nextIntegration?.initReactI18next) i18nInstance.use(reactI18nextIntegration.initReactI18next);
|
|
64
|
+
const pathname = (0, external_utils_js_namespaceObject.getPathname)(context);
|
|
65
|
+
if (i18nextDetector) (0, middleware_js_namespaceObject.useI18nextLanguageDetector)(i18nInstance);
|
|
66
|
+
const mergedDetection = (0, detection_index_js_namespaceObject.mergeDetectionOptions)(i18nextDetector, detection, localePathRedirect, userInitOptions);
|
|
67
|
+
const mergedBackend = (0, backend_index_js_namespaceObject.mergeBackendOptions)(backend, userInitOptions);
|
|
68
|
+
const hasSdkConfig = 'function' == typeof userInitOptions?.backend?.sdk || mergedBackend?.sdk && 'function' == typeof mergedBackend.sdk;
|
|
69
|
+
if (mergedBackend && (backendEnabled || hasSdkConfig)) useI18nextBackend(i18nInstance, mergedBackend);
|
|
70
|
+
const { finalLanguage } = await (0, detection_index_js_namespaceObject.detectLanguageWithPriority)(i18nInstance, {
|
|
71
|
+
languages,
|
|
72
|
+
fallbackLanguage,
|
|
73
|
+
localePathRedirect,
|
|
74
|
+
i18nextDetector,
|
|
75
|
+
detection,
|
|
76
|
+
userInitOptions,
|
|
77
|
+
mergedBackend,
|
|
78
|
+
pathname,
|
|
79
|
+
ssrContext: context.ssrContext
|
|
80
|
+
});
|
|
81
|
+
await initializeI18nInstance(i18nInstance, finalLanguage, fallbackLanguage, languages, mergedDetection, mergedBackend, userInitOptions);
|
|
82
|
+
if (!(0, runtime_namespaceObject.isBrowser)() && i18nInstance.cloneInstance) {
|
|
83
|
+
i18nInstance = i18nInstance.cloneInstance();
|
|
84
|
+
await setupClonedInstance(i18nInstance, finalLanguage, fallbackLanguage, languages, backendEnabled, backend, i18nextDetector, detection, localePathRedirect, userInitOptions);
|
|
85
|
+
}
|
|
86
|
+
if (localePathRedirect) await ensureLanguageMatch(i18nInstance, finalLanguage);
|
|
87
|
+
if (!(0, runtime_namespaceObject.isBrowser)()) (0, detection_index_js_namespaceObject.exportServerLngToWindow)(context, finalLanguage);
|
|
88
|
+
context.i18nInstance = i18nInstance;
|
|
89
|
+
context.changeLanguage = async (newLang)=>{
|
|
90
|
+
await changeI18nLanguage(i18nInstance, newLang, {
|
|
91
|
+
detectionOptions: mergedDetection
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
return i18nInstance;
|
|
95
|
+
}
|
|
96
|
+
exports.setupI18nBeforeRender = __webpack_exports__.setupI18nBeforeRender;
|
|
97
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
98
|
+
"setupI18nBeforeRender"
|
|
99
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
100
|
+
Object.defineProperty(exports, '__esModule', {
|
|
101
|
+
value: true
|
|
102
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
createI18nRootWrapper: ()=>createI18nRootWrapper
|
|
32
|
+
});
|
|
33
|
+
const jsx_runtime_namespaceObject = require("react/jsx-runtime");
|
|
34
|
+
const runtime_namespaceObject = require("@modern-js/runtime");
|
|
35
|
+
const head_namespaceObject = require("@modern-js/runtime/head");
|
|
36
|
+
const external_react_namespaceObject = require("react");
|
|
37
|
+
const external_context_js_namespaceObject = require("./context.js");
|
|
38
|
+
const external_hooks_js_namespaceObject = require("./hooks.js");
|
|
39
|
+
const instance_js_namespaceObject = require("./i18n/instance.js");
|
|
40
|
+
const external_routerAdapter_js_namespaceObject = require("./routerAdapter.js");
|
|
41
|
+
const createI18nRootWrapper = (options)=>(App)=>(props)=>{
|
|
42
|
+
const { entryName, htmlLangAttr, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls, getLatestI18nInstance, getI18nextProvider } = options;
|
|
43
|
+
const runtimeContext = (0, external_react_namespaceObject.useContext)(runtime_namespaceObject.RuntimeContext);
|
|
44
|
+
const i18nInstance = runtimeContext.i18nInstance || getLatestI18nInstance();
|
|
45
|
+
const initialLang = (0, external_react_namespaceObject.useMemo)(()=>i18nInstance?.language || fallbackLanguage, [
|
|
46
|
+
i18nInstance?.language,
|
|
47
|
+
fallbackLanguage
|
|
48
|
+
]);
|
|
49
|
+
const [lang, setLang] = (0, external_react_namespaceObject.useState)(initialLang);
|
|
50
|
+
const [forceUpdate, setForceUpdate] = (0, external_react_namespaceObject.useState)(0);
|
|
51
|
+
const prevLangRef = (0, external_react_namespaceObject.useRef)(lang);
|
|
52
|
+
const { location } = (0, external_routerAdapter_js_namespaceObject.useI18nRouterAdapter)();
|
|
53
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
54
|
+
if (i18nInstance?.language) {
|
|
55
|
+
const translator = i18nInstance.translator;
|
|
56
|
+
if (translator) translator.language = i18nInstance.language;
|
|
57
|
+
}
|
|
58
|
+
}, [
|
|
59
|
+
i18nInstance?.language
|
|
60
|
+
]);
|
|
61
|
+
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
62
|
+
prevLangRef.current = lang;
|
|
63
|
+
}, [
|
|
64
|
+
lang
|
|
65
|
+
]);
|
|
66
|
+
(0, external_hooks_js_namespaceObject.useSdkResourcesLoader)(i18nInstance, setForceUpdate);
|
|
67
|
+
const synchronizeLanguage = (0, external_hooks_js_namespaceObject.useLanguageSync)(i18nInstance, localePathRedirect, languages, location?.pathname, prevLangRef, setLang);
|
|
68
|
+
(0, external_hooks_js_namespaceObject.useClientSideRedirect)(i18nInstance, localePathRedirect, languages, fallbackLanguage, ignoreRedirectRoutes, localisedUrls);
|
|
69
|
+
const contextValue = (0, external_react_namespaceObject.useMemo)(()=>(0, external_hooks_js_namespaceObject.createContextValue)(lang, i18nInstance, entryName, languages, localePathRedirect, ignoreRedirectRoutes, localisedUrls, setLang, synchronizeLanguage), [
|
|
70
|
+
lang,
|
|
71
|
+
i18nInstance,
|
|
72
|
+
entryName,
|
|
73
|
+
languages,
|
|
74
|
+
localePathRedirect,
|
|
75
|
+
ignoreRedirectRoutes,
|
|
76
|
+
localisedUrls,
|
|
77
|
+
forceUpdate,
|
|
78
|
+
synchronizeLanguage
|
|
79
|
+
]);
|
|
80
|
+
const children = props.children;
|
|
81
|
+
let appContent = App ? /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(App, {
|
|
82
|
+
...props,
|
|
83
|
+
children: children
|
|
84
|
+
}) : children;
|
|
85
|
+
if (i18nInstance) {
|
|
86
|
+
const I18nextProvider = getI18nextProvider();
|
|
87
|
+
if (I18nextProvider) {
|
|
88
|
+
const i18nextInstanceForProvider = (0, instance_js_namespaceObject.getI18nextInstanceForProvider)(i18nInstance, lang);
|
|
89
|
+
appContent = /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(I18nextProvider, {
|
|
90
|
+
i18n: i18nextInstanceForProvider,
|
|
91
|
+
children: appContent
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsxs)(jsx_runtime_namespaceObject.Fragment, {
|
|
96
|
+
children: [
|
|
97
|
+
Boolean(htmlLangAttr) && /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(head_namespaceObject.Helmet, {
|
|
98
|
+
htmlAttributes: {
|
|
99
|
+
lang
|
|
100
|
+
}
|
|
101
|
+
}),
|
|
102
|
+
/*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(external_context_js_namespaceObject.ModernI18nProvider, {
|
|
103
|
+
value: contextValue,
|
|
104
|
+
children: appContent
|
|
105
|
+
})
|
|
106
|
+
]
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
exports.createI18nRootWrapper = __webpack_exports__.createI18nRootWrapper;
|
|
110
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
111
|
+
"createI18nRootWrapper"
|
|
112
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
113
|
+
Object.defineProperty(exports, '__esModule', {
|
|
114
|
+
value: true
|
|
115
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
const resolveReactI18nextIntegration = async (reactI18next, loadReactI18nextIntegration)=>{
|
|
31
|
+
if (!reactI18next) return null;
|
|
32
|
+
return loadReactI18nextIntegration?.() ?? null;
|
|
33
|
+
};
|
|
34
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
35
|
+
resolveReactI18nextIntegration: resolveReactI18nextIntegration
|
|
36
|
+
});
|
|
37
|
+
exports.resolveReactI18nextIntegration = __webpack_exports__.resolveReactI18nextIntegration;
|
|
38
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
39
|
+
"resolveReactI18nextIntegration"
|
|
40
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
41
|
+
Object.defineProperty(exports, '__esModule', {
|
|
42
|
+
value: true
|
|
43
|
+
});
|
|
@@ -97,28 +97,36 @@ const useI18nRouterAdapter = ()=>{
|
|
|
97
97
|
const [, setRouterVersion] = (0, external_react_namespaceObject.useState)(0);
|
|
98
98
|
const hasRouter = 'tanstack' === framework || 'react-router' === framework || Boolean(reactRouterNavigate);
|
|
99
99
|
(0, external_react_namespaceObject.useEffect)(()=>{
|
|
100
|
-
if ('tanstack' !== framework) return;
|
|
101
100
|
const router = getRouterInstance(internalContext, contextRouter);
|
|
102
101
|
if (!router) return;
|
|
103
102
|
const update = ()=>setRouterVersion((version)=>version + 1);
|
|
104
103
|
const unsubscribers = [];
|
|
105
|
-
if ('function' == typeof router.
|
|
106
|
-
const
|
|
104
|
+
if ('react-router' === framework && !inReactRouter && 'function' == typeof router.subscribe) {
|
|
105
|
+
const subscribe = router.subscribe;
|
|
106
|
+
const unsubscribe = subscribe.call(router, update);
|
|
107
107
|
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
108
108
|
}
|
|
109
|
-
if ('function' == typeof router.subscribe)
|
|
110
|
-
|
|
111
|
-
'onBeforeLoad'
|
|
112
|
-
]){
|
|
113
|
-
const unsubscribe = router.subscribe(eventType, update);
|
|
109
|
+
if ('tanstack' === framework && 'function' == typeof router.stores?.location?.subscribe) {
|
|
110
|
+
const unsubscribe = router.stores.location.subscribe(update);
|
|
114
111
|
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
115
112
|
}
|
|
113
|
+
if ('tanstack' === framework && 'function' == typeof router.subscribe) {
|
|
114
|
+
const subscribe = router.subscribe;
|
|
115
|
+
for (const eventType of [
|
|
116
|
+
'onBeforeNavigate',
|
|
117
|
+
'onBeforeLoad'
|
|
118
|
+
]){
|
|
119
|
+
const unsubscribe = subscribe.call(router, eventType, update);
|
|
120
|
+
if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
116
123
|
return ()=>{
|
|
117
124
|
for (const unsubscribe of unsubscribers)unsubscribe();
|
|
118
125
|
};
|
|
119
126
|
}, [
|
|
120
127
|
contextRouter,
|
|
121
128
|
framework,
|
|
129
|
+
inReactRouter,
|
|
122
130
|
internalContext
|
|
123
131
|
]);
|
|
124
132
|
const navigate = (0, external_react_namespaceObject.useCallback)((href, options)=>{
|
|
@@ -89,15 +89,7 @@ const detectLanguageFromPath = (pathname, languages, localePathRedirect)=>{
|
|
|
89
89
|
detected: false
|
|
90
90
|
};
|
|
91
91
|
};
|
|
92
|
-
const shouldIgnoreRedirect = (pathname, languages, ignoreRedirectRoutes)=>
|
|
93
|
-
if (!ignoreRedirectRoutes) return false;
|
|
94
|
-
const segments = pathname.split('/').filter(Boolean);
|
|
95
|
-
let pathWithoutLang = pathname;
|
|
96
|
-
if (segments.length > 0 && languages.includes(segments[0])) pathWithoutLang = `/${segments.slice(1).join('/')}`;
|
|
97
|
-
const normalizedPath = pathWithoutLang.startsWith('/') ? pathWithoutLang : `/${pathWithoutLang}`;
|
|
98
|
-
if ('function' == typeof ignoreRedirectRoutes) return ignoreRedirectRoutes(normalizedPath);
|
|
99
|
-
return ignoreRedirectRoutes.some((pattern)=>normalizedPath === pattern || normalizedPath.startsWith(`${pattern}/`));
|
|
100
|
-
};
|
|
92
|
+
const shouldIgnoreRedirect = (pathname, languages, ignoreRedirectRoutes)=>(0, localisedUrls_js_namespaceObject.shouldSkipLocaleRedirect)(pathname, languages, ignoreRedirectRoutes);
|
|
101
93
|
exports.buildLocalizedUrl = __webpack_exports__.buildLocalizedUrl;
|
|
102
94
|
exports.detectLanguageFromPath = __webpack_exports__.detectLanguageFromPath;
|
|
103
95
|
exports.getEntryPath = __webpack_exports__.getEntryPath;
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
const normalizeApiPrefix = (prefix)=>{
|
|
31
|
+
const trimmedPrefix = prefix.trim();
|
|
32
|
+
if (!trimmedPrefix) return null;
|
|
33
|
+
const prefixedPath = trimmedPrefix.startsWith('/') ? trimmedPrefix : `/${trimmedPrefix}`;
|
|
34
|
+
const withoutWildcard = prefixedPath.replace(/\/\*$/, '');
|
|
35
|
+
const normalizedPrefix = withoutWildcard.length > 1 ? withoutWildcard.replace(/\/+$/, '') : withoutWildcard;
|
|
36
|
+
return '/' === normalizedPrefix ? null : normalizedPrefix;
|
|
37
|
+
};
|
|
38
|
+
const collectApiPrefixes = (routes, bffPrefix)=>{
|
|
39
|
+
const prefixes = new Set();
|
|
40
|
+
for (const route of routes){
|
|
41
|
+
if (!route.isApi || !route.urlPath) continue;
|
|
42
|
+
const normalizedPrefix = normalizeApiPrefix(route.urlPath);
|
|
43
|
+
if (normalizedPrefix) prefixes.add(normalizedPrefix);
|
|
44
|
+
}
|
|
45
|
+
const bffPrefixes = Array.isArray(bffPrefix) ? bffPrefix : bffPrefix ? [
|
|
46
|
+
bffPrefix
|
|
47
|
+
] : [];
|
|
48
|
+
for (const prefix of bffPrefixes){
|
|
49
|
+
const normalizedPrefix = normalizeApiPrefix(prefix);
|
|
50
|
+
if (normalizedPrefix) prefixes.add(normalizedPrefix);
|
|
51
|
+
}
|
|
52
|
+
return [
|
|
53
|
+
...prefixes
|
|
54
|
+
];
|
|
55
|
+
};
|
|
56
|
+
const matchesApiPrefix = (pathname, apiPrefixes)=>{
|
|
57
|
+
const normalizedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`;
|
|
58
|
+
return apiPrefixes.some((prefix)=>normalizedPathname === prefix || normalizedPathname.startsWith(`${prefix}/`));
|
|
59
|
+
};
|
|
60
|
+
__webpack_require__.d(__webpack_exports__, {}, {
|
|
61
|
+
collectApiPrefixes: collectApiPrefixes,
|
|
62
|
+
matchesApiPrefix: matchesApiPrefix
|
|
63
|
+
});
|
|
64
|
+
exports.collectApiPrefixes = __webpack_exports__.collectApiPrefixes;
|
|
65
|
+
exports.matchesApiPrefix = __webpack_exports__.matchesApiPrefix;
|
|
66
|
+
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
67
|
+
"collectApiPrefixes",
|
|
68
|
+
"matchesApiPrefix"
|
|
69
|
+
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
70
|
+
Object.defineProperty(exports, '__esModule', {
|
|
71
|
+
value: true
|
|
72
|
+
});
|