@bleedingdev/modern-js-i18n-runtime-extensions 3.9.0-ultramodern.2 → 3.9.0-ultramodern.20
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 +15 -8
- package/dist/cjs/localeRedirectPolicy.js +96 -0
- package/dist/cjs/paths.js +56 -0
- package/dist/cjs/router-navigation/adapter.js +93 -0
- package/dist/cjs/{localisedUrls/config.js → router-navigation/index.js} +5 -14
- package/dist/esm/index.mjs +2 -1
- package/dist/esm/localeRedirectPolicy.mjs +46 -0
- package/dist/esm/paths.mjs +12 -0
- package/dist/esm/router-navigation/adapter.mjs +55 -0
- package/dist/esm/router-navigation/index.mjs +1 -0
- package/dist/esm-node/index.mjs +2 -1
- package/dist/esm-node/localeRedirectPolicy.mjs +47 -0
- package/dist/esm-node/paths.mjs +13 -0
- package/dist/esm-node/router-navigation/adapter.mjs +56 -0
- package/dist/esm-node/router-navigation/index.mjs +2 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/localeRedirectPolicy.d.ts +22 -0
- package/dist/types/paths.d.ts +9 -0
- package/dist/types/router-navigation/adapter.d.ts +23 -0
- package/dist/types/router-navigation/index.d.ts +1 -0
- package/package.json +33 -9
- package/src/index.ts +2 -1
- package/src/localeRedirectPolicy.ts +127 -0
- package/src/paths.ts +37 -0
- package/src/router-navigation/adapter.tsx +120 -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/paths.test.ts +24 -0
- package/tests/reactLanguageSync.test.tsx +21 -2
- package/tests/routerNavigation.test.tsx +80 -0
- package/dist/cjs/localisedUrls/index.js +0 -91
- package/dist/cjs/localisedUrls/normalise.js +0 -87
- package/dist/cjs/localisedUrls/pathname.js +0 -68
- package/dist/cjs/localisedUrls/patterns.js +0 -214
- package/dist/cjs/localisedUrls/redirect.js +0 -103
- package/dist/cjs/localisedUrls/resolve.js +0 -78
- package/dist/cjs/localisedUrls/routes.js +0 -202
- package/dist/cjs/localisedUrls/types.js +0 -18
- package/dist/esm/localisedUrls/config.mjs +0 -11
- package/dist/esm/localisedUrls/index.mjs +0 -7
- package/dist/esm/localisedUrls/normalise.mjs +0 -37
- package/dist/esm/localisedUrls/pathname.mjs +0 -24
- package/dist/esm/localisedUrls/patterns.mjs +0 -152
- package/dist/esm/localisedUrls/redirect.mjs +0 -56
- package/dist/esm/localisedUrls/resolve.mjs +0 -37
- package/dist/esm/localisedUrls/routes.mjs +0 -161
- package/dist/esm/localisedUrls/types.mjs +0 -0
- package/dist/esm-node/localisedUrls/config.mjs +0 -12
- package/dist/esm-node/localisedUrls/index.mjs +0 -8
- package/dist/esm-node/localisedUrls/normalise.mjs +0 -38
- package/dist/esm-node/localisedUrls/pathname.mjs +0 -25
- package/dist/esm-node/localisedUrls/patterns.mjs +0 -153
- package/dist/esm-node/localisedUrls/redirect.mjs +0 -57
- package/dist/esm-node/localisedUrls/resolve.mjs +0 -38
- package/dist/esm-node/localisedUrls/routes.mjs +0 -162
- package/dist/esm-node/localisedUrls/types.mjs +0 -1
- package/dist/types/localisedUrls/config.d.ts +0 -9
- package/dist/types/localisedUrls/index.d.ts +0 -9
- package/dist/types/localisedUrls/normalise.d.ts +0 -10
- package/dist/types/localisedUrls/pathname.d.ts +0 -4
- package/dist/types/localisedUrls/patterns.d.ts +0 -11
- package/dist/types/localisedUrls/redirect.d.ts +0 -11
- package/dist/types/localisedUrls/resolve.d.ts +0 -7
- package/dist/types/localisedUrls/routes.d.ts +0 -3
- package/dist/types/localisedUrls/types.d.ts +0 -14
- package/src/localisedUrls/config.ts +0 -18
- package/src/localisedUrls/index.ts +0 -24
- package/src/localisedUrls/normalise.ts +0 -62
- package/src/localisedUrls/pathname.ts +0 -60
- package/src/localisedUrls/patterns.ts +0 -283
- package/src/localisedUrls/redirect.ts +0 -93
- package/src/localisedUrls/resolve.ts +0 -106
- package/src/localisedUrls/routes.ts +0 -422
- package/src/localisedUrls/types.ts +0 -18
- package/tests/clientRedirectIntegration.test.tsx +0 -74
- package/tests/localisedUrls.test.ts +0 -673
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { act, Suspense, startTransition } from 'react';
|
|
2
2
|
import { createRoot } from 'react-dom/client';
|
|
3
3
|
import { useLatestLanguageSync } from '../src/language-sync/react';
|
|
4
4
|
|
|
@@ -7,6 +7,14 @@ interface Target {
|
|
|
7
7
|
language: string;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
rstest.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
rstest.unstubAllGlobals();
|
|
16
|
+
});
|
|
17
|
+
|
|
10
18
|
test('an abandoned suspended render cannot publish an uncommitted target', async () => {
|
|
11
19
|
let resolveFirst!: () => void;
|
|
12
20
|
const firstChange = new Promise<void>(resolve => {
|
|
@@ -14,6 +22,7 @@ test('an abandoned suspended render cannot publish an uncommitted target', async
|
|
|
14
22
|
});
|
|
15
23
|
const changes: string[] = [];
|
|
16
24
|
const commits: string[] = [];
|
|
25
|
+
let suspended = false;
|
|
17
26
|
const neverSettles = new Promise<never>(() => undefined);
|
|
18
27
|
const first = { id: 'first', language: 'en' };
|
|
19
28
|
const speculative = { id: 'speculative', language: 'en' };
|
|
@@ -41,6 +50,7 @@ test('an abandoned suspended render cannot publish an uncommitted target', async
|
|
|
41
50
|
},
|
|
42
51
|
});
|
|
43
52
|
if (suspend) {
|
|
53
|
+
suspended = true;
|
|
44
54
|
throw neverSettles;
|
|
45
55
|
}
|
|
46
56
|
return <main>{target.id}</main>;
|
|
@@ -49,7 +59,11 @@ test('an abandoned suspended render cannot publish an uncommitted target', async
|
|
|
49
59
|
const container = document.createElement('div');
|
|
50
60
|
const root = createRoot(container);
|
|
51
61
|
await act(async () => {
|
|
52
|
-
root.render(
|
|
62
|
+
root.render(
|
|
63
|
+
<Suspense fallback={<p>loading</p>}>
|
|
64
|
+
<Harness target={first} />
|
|
65
|
+
</Suspense>,
|
|
66
|
+
);
|
|
53
67
|
});
|
|
54
68
|
expect(changes).toEqual(['first']);
|
|
55
69
|
|
|
@@ -64,6 +78,11 @@ test('an abandoned suspended render cannot publish an uncommitted target', async
|
|
|
64
78
|
await Promise.resolve();
|
|
65
79
|
});
|
|
66
80
|
|
|
81
|
+
expect(suspended).toBe(true);
|
|
82
|
+
expect(container.textContent).toBe('first');
|
|
83
|
+
expect(changes).toEqual(['first']);
|
|
84
|
+
expect(commits).toEqual([]);
|
|
85
|
+
|
|
67
86
|
await act(async () => {
|
|
68
87
|
resolveFirst();
|
|
69
88
|
await firstChange;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import {
|
|
2
|
+
InternalRuntimeContext,
|
|
3
|
+
RuntimeContext,
|
|
4
|
+
} from '@modern-js/runtime/context';
|
|
5
|
+
import {
|
|
6
|
+
applyRouterRuntimeState,
|
|
7
|
+
type RouterNavigationCapability,
|
|
8
|
+
} from '@modern-js/runtime-extensions/router-state';
|
|
9
|
+
import React, { act, createContext, useContext, useEffect } from 'react';
|
|
10
|
+
import { createRoot } from 'react-dom/client';
|
|
11
|
+
import {
|
|
12
|
+
createI18nRouterNavigation,
|
|
13
|
+
type I18nRouterAdapterShape,
|
|
14
|
+
} from '../src/router-navigation/adapter';
|
|
15
|
+
|
|
16
|
+
test('late navigation installation preserves the mounted router and native fallback', async () => {
|
|
17
|
+
rstest.stubGlobal('IS_REACT_ACT_ENVIRONMENT', true);
|
|
18
|
+
const context = {} as React.ContextType<typeof InternalRuntimeContext>;
|
|
19
|
+
const navigationContext = createContext<I18nRouterAdapterShape | null>(null);
|
|
20
|
+
const native: I18nRouterAdapterShape = {
|
|
21
|
+
hasRouter: false,
|
|
22
|
+
location: null,
|
|
23
|
+
navigate: null,
|
|
24
|
+
Link: null,
|
|
25
|
+
params: {},
|
|
26
|
+
};
|
|
27
|
+
const { I18nRouterNavigationProvider } = createI18nRouterNavigation({
|
|
28
|
+
I18nNavigationProvider: navigationContext.Provider,
|
|
29
|
+
useNativeI18nRouterAdapter: () => native,
|
|
30
|
+
});
|
|
31
|
+
const snapshot = {
|
|
32
|
+
location: { pathname: '/cs/produkty/bota', search: '', hash: '' },
|
|
33
|
+
params: { lang: 'cs', slug: 'bota' },
|
|
34
|
+
};
|
|
35
|
+
const navigation: RouterNavigationCapability = {
|
|
36
|
+
getSnapshot: () => snapshot,
|
|
37
|
+
subscribe: () => () => {},
|
|
38
|
+
navigate: () => {},
|
|
39
|
+
Link: () => null,
|
|
40
|
+
};
|
|
41
|
+
const mounted = rstest.fn();
|
|
42
|
+
const unmounted = rstest.fn();
|
|
43
|
+
const Router = () => {
|
|
44
|
+
const adapter = useContext(navigationContext);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
mounted();
|
|
47
|
+
return unmounted;
|
|
48
|
+
}, []);
|
|
49
|
+
return <p>{adapter?.location?.pathname ?? 'native fallback'}</p>;
|
|
50
|
+
};
|
|
51
|
+
const container = document.createElement('div');
|
|
52
|
+
const root = createRoot(container);
|
|
53
|
+
try {
|
|
54
|
+
await act(async () => {
|
|
55
|
+
root.render(
|
|
56
|
+
<InternalRuntimeContext.Provider value={context}>
|
|
57
|
+
<RuntimeContext.Provider value={context}>
|
|
58
|
+
<I18nRouterNavigationProvider>
|
|
59
|
+
<Router />
|
|
60
|
+
</I18nRouterNavigationProvider>
|
|
61
|
+
</RuntimeContext.Provider>
|
|
62
|
+
</InternalRuntimeContext.Provider>,
|
|
63
|
+
);
|
|
64
|
+
});
|
|
65
|
+
expect(container.textContent).toBe('native fallback');
|
|
66
|
+
await act(async () => {
|
|
67
|
+
applyRouterRuntimeState(context, { framework: 'tanstack', navigation });
|
|
68
|
+
});
|
|
69
|
+
expect(container.textContent).toBe('/cs/produkty/bota');
|
|
70
|
+
await act(async () => {
|
|
71
|
+
applyRouterRuntimeState(context, { navigation: undefined });
|
|
72
|
+
});
|
|
73
|
+
expect(container.textContent).toBe('native fallback');
|
|
74
|
+
expect(mounted).toHaveBeenCalledTimes(1);
|
|
75
|
+
expect(unmounted).not.toHaveBeenCalled();
|
|
76
|
+
} finally {
|
|
77
|
+
await act(async () => root.unmount());
|
|
78
|
+
rstest.unstubAllGlobals();
|
|
79
|
+
}
|
|
80
|
+
});
|
|
@@ -1,91 +0,0 @@
|
|
|
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
|
-
DEFAULT_LOCALE_REDIRECT_SKIP_RULES: ()=>external_redirect_js_namespaceObject.DEFAULT_LOCALE_REDIRECT_SKIP_RULES,
|
|
32
|
-
applyLocalisedUrlsToRoutes: ()=>external_routes_js_namespaceObject.applyLocalisedUrlsToRoutes,
|
|
33
|
-
buildPathFromPattern: ()=>external_patterns_js_namespaceObject.buildPathFromPattern,
|
|
34
|
-
canonicalTargetPathname: ()=>external_pathname_js_namespaceObject.canonicalTargetPathname,
|
|
35
|
-
isDefaultLocaleRedirectSkipPath: ()=>external_redirect_js_namespaceObject.isDefaultLocaleRedirectSkipPath,
|
|
36
|
-
localiseTargetPathname: ()=>external_pathname_js_namespaceObject.localiseTargetPathname,
|
|
37
|
-
matchPathPattern: ()=>external_patterns_js_namespaceObject.matchPathPattern,
|
|
38
|
-
matchesPathPrefix: ()=>external_redirect_js_namespaceObject.matchesPathPrefix,
|
|
39
|
-
normalisePathPattern: ()=>external_normalise_js_namespaceObject.normalisePathPattern,
|
|
40
|
-
normalisePathname: ()=>external_normalise_js_namespaceObject.normalisePathname,
|
|
41
|
-
resolveCanonicalLocalisedPath: ()=>external_resolve_js_namespaceObject.resolveCanonicalLocalisedPath,
|
|
42
|
-
resolveLocalisedPath: ()=>external_resolve_js_namespaceObject.resolveLocalisedPath,
|
|
43
|
-
resolveLocalisedUrlsConfig: ()=>external_config_js_namespaceObject.resolveLocalisedUrlsConfig,
|
|
44
|
-
shouldSkipLocaleRedirect: ()=>external_redirect_js_namespaceObject.shouldSkipLocaleRedirect,
|
|
45
|
-
stripLanguagePrefix: ()=>external_pathname_js_namespaceObject.stripLanguagePrefix,
|
|
46
|
-
validateLocalisedUrls: ()=>external_routes_js_namespaceObject.validateLocalisedUrls
|
|
47
|
-
});
|
|
48
|
-
const external_config_js_namespaceObject = require("./config.js");
|
|
49
|
-
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
50
|
-
const external_pathname_js_namespaceObject = require("./pathname.js");
|
|
51
|
-
const external_patterns_js_namespaceObject = require("./patterns.js");
|
|
52
|
-
const external_redirect_js_namespaceObject = require("./redirect.js");
|
|
53
|
-
const external_resolve_js_namespaceObject = require("./resolve.js");
|
|
54
|
-
const external_routes_js_namespaceObject = require("./routes.js");
|
|
55
|
-
exports.DEFAULT_LOCALE_REDIRECT_SKIP_RULES = __webpack_exports__.DEFAULT_LOCALE_REDIRECT_SKIP_RULES;
|
|
56
|
-
exports.applyLocalisedUrlsToRoutes = __webpack_exports__.applyLocalisedUrlsToRoutes;
|
|
57
|
-
exports.buildPathFromPattern = __webpack_exports__.buildPathFromPattern;
|
|
58
|
-
exports.canonicalTargetPathname = __webpack_exports__.canonicalTargetPathname;
|
|
59
|
-
exports.isDefaultLocaleRedirectSkipPath = __webpack_exports__.isDefaultLocaleRedirectSkipPath;
|
|
60
|
-
exports.localiseTargetPathname = __webpack_exports__.localiseTargetPathname;
|
|
61
|
-
exports.matchPathPattern = __webpack_exports__.matchPathPattern;
|
|
62
|
-
exports.matchesPathPrefix = __webpack_exports__.matchesPathPrefix;
|
|
63
|
-
exports.normalisePathPattern = __webpack_exports__.normalisePathPattern;
|
|
64
|
-
exports.normalisePathname = __webpack_exports__.normalisePathname;
|
|
65
|
-
exports.resolveCanonicalLocalisedPath = __webpack_exports__.resolveCanonicalLocalisedPath;
|
|
66
|
-
exports.resolveLocalisedPath = __webpack_exports__.resolveLocalisedPath;
|
|
67
|
-
exports.resolveLocalisedUrlsConfig = __webpack_exports__.resolveLocalisedUrlsConfig;
|
|
68
|
-
exports.shouldSkipLocaleRedirect = __webpack_exports__.shouldSkipLocaleRedirect;
|
|
69
|
-
exports.stripLanguagePrefix = __webpack_exports__.stripLanguagePrefix;
|
|
70
|
-
exports.validateLocalisedUrls = __webpack_exports__.validateLocalisedUrls;
|
|
71
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
72
|
-
"DEFAULT_LOCALE_REDIRECT_SKIP_RULES",
|
|
73
|
-
"applyLocalisedUrlsToRoutes",
|
|
74
|
-
"buildPathFromPattern",
|
|
75
|
-
"canonicalTargetPathname",
|
|
76
|
-
"isDefaultLocaleRedirectSkipPath",
|
|
77
|
-
"localiseTargetPathname",
|
|
78
|
-
"matchPathPattern",
|
|
79
|
-
"matchesPathPrefix",
|
|
80
|
-
"normalisePathPattern",
|
|
81
|
-
"normalisePathname",
|
|
82
|
-
"resolveCanonicalLocalisedPath",
|
|
83
|
-
"resolveLocalisedPath",
|
|
84
|
-
"resolveLocalisedUrlsConfig",
|
|
85
|
-
"shouldSkipLocaleRedirect",
|
|
86
|
-
"stripLanguagePrefix",
|
|
87
|
-
"validateLocalisedUrls"
|
|
88
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
89
|
-
Object.defineProperty(exports, '__esModule', {
|
|
90
|
-
value: true
|
|
91
|
-
});
|
|
@@ -1,87 +0,0 @@
|
|
|
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 LOCALE_PARAM_NAMES = new Set([
|
|
31
|
-
'lang',
|
|
32
|
-
'locale',
|
|
33
|
-
'language'
|
|
34
|
-
]);
|
|
35
|
-
const normaliseSlashes = (path)=>{
|
|
36
|
-
const withoutDuplicateSlashes = path.replace(/\/+/g, '/');
|
|
37
|
-
const withLeadingSlash = withoutDuplicateSlashes.startsWith('/') ? withoutDuplicateSlashes : `/${withoutDuplicateSlashes}`;
|
|
38
|
-
return withLeadingSlash.length > 1 ? withLeadingSlash.replace(/\/+$/, '') : withLeadingSlash;
|
|
39
|
-
};
|
|
40
|
-
const normalisePathPattern = (path)=>normaliseSlashes(path).replace(/\[(.+?)\]/g, ':$1');
|
|
41
|
-
const normalisePathname = (pathname)=>normaliseSlashes(pathname);
|
|
42
|
-
const normaliseRoutePath = (path)=>{
|
|
43
|
-
const normalized = normalisePathPattern(path);
|
|
44
|
-
return '/' === normalized ? '' : normalized.slice(1);
|
|
45
|
-
};
|
|
46
|
-
const getLocaleParamSegment = (segment)=>{
|
|
47
|
-
if (!segment.startsWith(':')) return null;
|
|
48
|
-
const paramName = segment.slice(1).replace(/\?$/, '');
|
|
49
|
-
return LOCALE_PARAM_NAMES.has(paramName) ? segment : null;
|
|
50
|
-
};
|
|
51
|
-
const splitPathSegments = (path)=>{
|
|
52
|
-
if (!path) return [];
|
|
53
|
-
return normalisePathPattern(path).split('/').filter(Boolean);
|
|
54
|
-
};
|
|
55
|
-
const stripLeadingLocaleParam = (path)=>{
|
|
56
|
-
const segments = splitPathSegments(path);
|
|
57
|
-
const leadingLocaleParam = getLocaleParamSegment(segments[0] || '');
|
|
58
|
-
if (!leadingLocaleParam) return path;
|
|
59
|
-
const remainingPath = segments.slice(1).join('/');
|
|
60
|
-
return remainingPath ? `/${remainingPath}` : void 0;
|
|
61
|
-
};
|
|
62
|
-
const getLeadingLocaleParam = (path)=>{
|
|
63
|
-
const segments = splitPathSegments(path);
|
|
64
|
-
return getLocaleParamSegment(segments[0] || '');
|
|
65
|
-
};
|
|
66
|
-
__webpack_require__.d(__webpack_exports__, {}, {
|
|
67
|
-
getLeadingLocaleParam: getLeadingLocaleParam,
|
|
68
|
-
normalisePathPattern: normalisePathPattern,
|
|
69
|
-
normalisePathname: normalisePathname,
|
|
70
|
-
normaliseRoutePath: normaliseRoutePath,
|
|
71
|
-
stripLeadingLocaleParam: stripLeadingLocaleParam
|
|
72
|
-
});
|
|
73
|
-
exports.getLeadingLocaleParam = __webpack_exports__.getLeadingLocaleParam;
|
|
74
|
-
exports.normalisePathPattern = __webpack_exports__.normalisePathPattern;
|
|
75
|
-
exports.normalisePathname = __webpack_exports__.normalisePathname;
|
|
76
|
-
exports.normaliseRoutePath = __webpack_exports__.normaliseRoutePath;
|
|
77
|
-
exports.stripLeadingLocaleParam = __webpack_exports__.stripLeadingLocaleParam;
|
|
78
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
79
|
-
"getLeadingLocaleParam",
|
|
80
|
-
"normalisePathPattern",
|
|
81
|
-
"normalisePathname",
|
|
82
|
-
"normaliseRoutePath",
|
|
83
|
-
"stripLeadingLocaleParam"
|
|
84
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
85
|
-
Object.defineProperty(exports, '__esModule', {
|
|
86
|
-
value: true
|
|
87
|
-
});
|
|
@@ -1,68 +0,0 @@
|
|
|
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
|
-
canonicalTargetPathname: ()=>canonicalTargetPathname,
|
|
32
|
-
localiseTargetPathname: ()=>localiseTargetPathname,
|
|
33
|
-
stripLanguagePrefix: ()=>stripLanguagePrefix
|
|
34
|
-
});
|
|
35
|
-
const external_config_js_namespaceObject = require("./config.js");
|
|
36
|
-
const external_resolve_js_namespaceObject = require("./resolve.js");
|
|
37
|
-
const stripLanguagePrefix = (pathname, languages)=>{
|
|
38
|
-
const segments = pathname.split('/').filter(Boolean);
|
|
39
|
-
const firstSegment = segments[0]?.toLowerCase();
|
|
40
|
-
if (firstSegment && languages.some((language)=>language.toLowerCase() === firstSegment)) return `/${segments.slice(1).join('/')}`;
|
|
41
|
-
return pathname || '/';
|
|
42
|
-
};
|
|
43
|
-
const localiseTargetPathname = (pathname, language, languages, localisedUrls)=>{
|
|
44
|
-
const pathWithoutLanguage = stripLanguagePrefix(pathname, languages);
|
|
45
|
-
const localisedUrlsConfig = (0, external_config_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
|
|
46
|
-
const resolvedPath = localisedUrlsConfig.enabled ? (0, external_resolve_js_namespaceObject.resolveLocalisedPath)(pathWithoutLanguage, language, languages, localisedUrlsConfig.map) : pathWithoutLanguage;
|
|
47
|
-
const resolvedSegments = resolvedPath.split('/').filter(Boolean);
|
|
48
|
-
return `/${[
|
|
49
|
-
language,
|
|
50
|
-
...resolvedSegments
|
|
51
|
-
].join('/')}`;
|
|
52
|
-
};
|
|
53
|
-
const canonicalTargetPathname = (pathname, languages, localisedUrls)=>{
|
|
54
|
-
const pathWithoutLanguage = stripLanguagePrefix(pathname, languages);
|
|
55
|
-
const localisedUrlsConfig = (0, external_config_js_namespaceObject.resolveLocalisedUrlsConfig)(localisedUrls);
|
|
56
|
-
return localisedUrlsConfig.enabled ? (0, external_resolve_js_namespaceObject.resolveCanonicalLocalisedPath)(pathWithoutLanguage, languages, localisedUrlsConfig.map) : pathWithoutLanguage;
|
|
57
|
-
};
|
|
58
|
-
exports.canonicalTargetPathname = __webpack_exports__.canonicalTargetPathname;
|
|
59
|
-
exports.localiseTargetPathname = __webpack_exports__.localiseTargetPathname;
|
|
60
|
-
exports.stripLanguagePrefix = __webpack_exports__.stripLanguagePrefix;
|
|
61
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
62
|
-
"canonicalTargetPathname",
|
|
63
|
-
"localiseTargetPathname",
|
|
64
|
-
"stripLanguagePrefix"
|
|
65
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
66
|
-
Object.defineProperty(exports, '__esModule', {
|
|
67
|
-
value: true
|
|
68
|
-
});
|
|
@@ -1,214 +0,0 @@
|
|
|
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
|
-
buildPathFromPattern: ()=>buildPathFromPattern,
|
|
32
|
-
doPathPatternsOverlap: ()=>doPathPatternsOverlap,
|
|
33
|
-
getOrderedPathParamSignature: ()=>getOrderedPathParamSignature,
|
|
34
|
-
getPathParamSignature: ()=>getPathParamSignature,
|
|
35
|
-
getPathPatternValidationIssue: ()=>getPathPatternValidationIssue,
|
|
36
|
-
getPhysicalPathPattern: ()=>getPhysicalPathPattern,
|
|
37
|
-
haveEqualPatternSpecificity: ()=>haveEqualPatternSpecificity,
|
|
38
|
-
matchPathPattern: ()=>matchPathPattern,
|
|
39
|
-
sortPatternsBySpecificity: ()=>sortPatternsBySpecificity
|
|
40
|
-
});
|
|
41
|
-
const external_normalise_js_namespaceObject = require("./normalise.js");
|
|
42
|
-
const escapeRegExp = (value)=>value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
43
|
-
const getParamName = (segment)=>segment.slice(1).replace(/\?$/, '');
|
|
44
|
-
const getOrderedPathParamSignature = (pattern)=>(0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean).flatMap((segment)=>{
|
|
45
|
-
if ('*' === segment) return [
|
|
46
|
-
'*'
|
|
47
|
-
];
|
|
48
|
-
if (!segment.startsWith(':')) return [];
|
|
49
|
-
return [
|
|
50
|
-
`:${getParamName(segment)}${segment.endsWith('?') ? '?' : ''}`
|
|
51
|
-
];
|
|
52
|
-
});
|
|
53
|
-
const getPathParamSignature = (pattern)=>getOrderedPathParamSignature(pattern).sort((left, right)=>left < right ? -1 : left > right ? 1 : 0);
|
|
54
|
-
const getPathPatternValidationIssue = (pattern)=>{
|
|
55
|
-
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
56
|
-
const seenParams = new Set();
|
|
57
|
-
for (const [index, segment] of segments.entries()){
|
|
58
|
-
if ('*' === segment) {
|
|
59
|
-
if (index !== segments.length - 1) return 'splat parameter "*" must be the final segment';
|
|
60
|
-
if (seenParams.has('*')) return 'duplicate splat parameter "*"';
|
|
61
|
-
seenParams.add('*');
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
if (!segment.startsWith(':')) continue;
|
|
65
|
-
const paramName = getParamName(segment);
|
|
66
|
-
if (seenParams.has(paramName)) return `duplicate path parameter ":${paramName}"`;
|
|
67
|
-
seenParams.add(paramName);
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
const getPhysicalPathPattern = (pattern)=>{
|
|
71
|
-
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
72
|
-
const physicalSegments = segments.map((segment)=>{
|
|
73
|
-
if ('*' === segment) return '*';
|
|
74
|
-
if (segment.startsWith(':')) return segment.endsWith('?') ? ':param?' : ':param';
|
|
75
|
-
return segment;
|
|
76
|
-
});
|
|
77
|
-
return `/${physicalSegments.join('/')}`;
|
|
78
|
-
};
|
|
79
|
-
const compiledPathPatternCache = new Map();
|
|
80
|
-
const compilePathPattern = (pattern)=>{
|
|
81
|
-
const normalizedPattern = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern);
|
|
82
|
-
const cached = compiledPathPatternCache.get(normalizedPattern);
|
|
83
|
-
if (cached) return cached;
|
|
84
|
-
const names = [];
|
|
85
|
-
const segments = normalizedPattern.split('/').filter(Boolean);
|
|
86
|
-
const source = segments.map((segment)=>{
|
|
87
|
-
if (segment.startsWith(':')) {
|
|
88
|
-
names.push(getParamName(segment));
|
|
89
|
-
const paramPattern = '([^/]+)';
|
|
90
|
-
return segment.endsWith('?') ? `(?:/${paramPattern})?` : `/${paramPattern}`;
|
|
91
|
-
}
|
|
92
|
-
if ('*' === segment) {
|
|
93
|
-
names.push('*');
|
|
94
|
-
return '(?:/(.*))?';
|
|
95
|
-
}
|
|
96
|
-
return `/${escapeRegExp(segment)}`;
|
|
97
|
-
}).join('');
|
|
98
|
-
const compiled = {
|
|
99
|
-
names,
|
|
100
|
-
regexp: new RegExp(`^${source || '/'}$`)
|
|
101
|
-
};
|
|
102
|
-
compiledPathPatternCache.set(normalizedPattern, compiled);
|
|
103
|
-
return compiled;
|
|
104
|
-
};
|
|
105
|
-
const getPatternSpecificity = (pattern)=>{
|
|
106
|
-
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
107
|
-
let staticSegments = 0;
|
|
108
|
-
let dynamicSegments = 0;
|
|
109
|
-
let optionalSegments = 0;
|
|
110
|
-
let splatSegments = 0;
|
|
111
|
-
for (const segment of segments)if ('*' === segment) splatSegments++;
|
|
112
|
-
else if (segment.startsWith(':')) {
|
|
113
|
-
dynamicSegments++;
|
|
114
|
-
if (segment.endsWith('?')) optionalSegments++;
|
|
115
|
-
} else staticSegments++;
|
|
116
|
-
return {
|
|
117
|
-
staticSegments,
|
|
118
|
-
dynamicSegments,
|
|
119
|
-
optionalSegments,
|
|
120
|
-
splatSegments,
|
|
121
|
-
totalSegments: segments.length
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
const comparePatternSpecificity = (left, right)=>{
|
|
125
|
-
const a = getPatternSpecificity(left);
|
|
126
|
-
const b = getPatternSpecificity(right);
|
|
127
|
-
return b.staticSegments - a.staticSegments || a.splatSegments - b.splatSegments || a.optionalSegments - b.optionalSegments || b.totalSegments - a.totalSegments || a.dynamicSegments - b.dynamicSegments;
|
|
128
|
-
};
|
|
129
|
-
const haveEqualPatternSpecificity = (left, right)=>0 === comparePatternSpecificity(left, right);
|
|
130
|
-
const doPathPatternsOverlap = (left, right)=>{
|
|
131
|
-
const leftSegments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(left).split('/').filter(Boolean);
|
|
132
|
-
const rightSegments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(right).split('/').filter(Boolean);
|
|
133
|
-
if (leftSegments.length !== rightSegments.length) return false;
|
|
134
|
-
return leftSegments.every((leftSegment, index)=>{
|
|
135
|
-
const rightSegment = rightSegments[index];
|
|
136
|
-
const leftIsDynamic = '*' === leftSegment || leftSegment.startsWith(':');
|
|
137
|
-
const rightIsDynamic = '*' === rightSegment || rightSegment.startsWith(':');
|
|
138
|
-
return leftIsDynamic || rightIsDynamic || leftSegment === rightSegment;
|
|
139
|
-
});
|
|
140
|
-
};
|
|
141
|
-
const comparePatternNames = (left, right)=>{
|
|
142
|
-
const normalizedLeft = (0, external_normalise_js_namespaceObject.normalisePathPattern)(left);
|
|
143
|
-
const normalizedRight = (0, external_normalise_js_namespaceObject.normalisePathPattern)(right);
|
|
144
|
-
return normalizedLeft < normalizedRight ? -1 : normalizedLeft > normalizedRight ? 1 : 0;
|
|
145
|
-
};
|
|
146
|
-
const sortPatternsBySpecificity = (patterns)=>patterns.map((pattern, index)=>({
|
|
147
|
-
pattern,
|
|
148
|
-
index
|
|
149
|
-
})).sort((left, right)=>comparePatternSpecificity(left.pattern.pattern, right.pattern.pattern) || comparePatternNames(left.pattern.pattern, right.pattern.pattern) || left.index - right.index).map(({ pattern })=>pattern);
|
|
150
|
-
const decodePathParam = (value)=>{
|
|
151
|
-
try {
|
|
152
|
-
return decodeURIComponent(value);
|
|
153
|
-
} catch {
|
|
154
|
-
return null;
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
const encodeSplatParam = (value)=>value.split('/').map(encodeURIComponent).join('/');
|
|
158
|
-
const matchPathPattern = (pathname, pattern)=>{
|
|
159
|
-
const { names, regexp } = compilePathPattern(pattern);
|
|
160
|
-
const match = regexp.exec((0, external_normalise_js_namespaceObject.normalisePathname)(pathname));
|
|
161
|
-
if (!match) return null;
|
|
162
|
-
const params = {};
|
|
163
|
-
for(let index = 0; index < names.length; index++){
|
|
164
|
-
const decoded = decodePathParam(match[index + 1] || '');
|
|
165
|
-
if (null === decoded) return null;
|
|
166
|
-
Object.defineProperty(params, names[index], {
|
|
167
|
-
configurable: true,
|
|
168
|
-
enumerable: true,
|
|
169
|
-
value: decoded,
|
|
170
|
-
writable: true
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
return params;
|
|
174
|
-
};
|
|
175
|
-
const buildPathFromPattern = (pattern, params)=>{
|
|
176
|
-
const segments = (0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern).split('/').filter(Boolean);
|
|
177
|
-
const path = segments.map((segment)=>{
|
|
178
|
-
if (segment.startsWith(':')) {
|
|
179
|
-
const paramName = getParamName(segment);
|
|
180
|
-
const param = Object.hasOwn(params, paramName) ? params[paramName] : void 0;
|
|
181
|
-
if (void 0 === param || '' === param) {
|
|
182
|
-
if (segment.endsWith('?')) return '';
|
|
183
|
-
throw new Error(`Missing required path parameter "${paramName}" for pattern "${(0, external_normalise_js_namespaceObject.normalisePathPattern)(pattern)}".`);
|
|
184
|
-
}
|
|
185
|
-
return encodeURIComponent(param);
|
|
186
|
-
}
|
|
187
|
-
if ('*' === segment) return encodeSplatParam(params['*'] || '');
|
|
188
|
-
return segment;
|
|
189
|
-
}).filter(Boolean).join('/');
|
|
190
|
-
return `/${path}`;
|
|
191
|
-
};
|
|
192
|
-
exports.buildPathFromPattern = __webpack_exports__.buildPathFromPattern;
|
|
193
|
-
exports.doPathPatternsOverlap = __webpack_exports__.doPathPatternsOverlap;
|
|
194
|
-
exports.getOrderedPathParamSignature = __webpack_exports__.getOrderedPathParamSignature;
|
|
195
|
-
exports.getPathParamSignature = __webpack_exports__.getPathParamSignature;
|
|
196
|
-
exports.getPathPatternValidationIssue = __webpack_exports__.getPathPatternValidationIssue;
|
|
197
|
-
exports.getPhysicalPathPattern = __webpack_exports__.getPhysicalPathPattern;
|
|
198
|
-
exports.haveEqualPatternSpecificity = __webpack_exports__.haveEqualPatternSpecificity;
|
|
199
|
-
exports.matchPathPattern = __webpack_exports__.matchPathPattern;
|
|
200
|
-
exports.sortPatternsBySpecificity = __webpack_exports__.sortPatternsBySpecificity;
|
|
201
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
202
|
-
"buildPathFromPattern",
|
|
203
|
-
"doPathPatternsOverlap",
|
|
204
|
-
"getOrderedPathParamSignature",
|
|
205
|
-
"getPathParamSignature",
|
|
206
|
-
"getPathPatternValidationIssue",
|
|
207
|
-
"getPhysicalPathPattern",
|
|
208
|
-
"haveEqualPatternSpecificity",
|
|
209
|
-
"matchPathPattern",
|
|
210
|
-
"sortPatternsBySpecificity"
|
|
211
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
212
|
-
Object.defineProperty(exports, '__esModule', {
|
|
213
|
-
value: true
|
|
214
|
-
});
|