@bleedingdev/modern-js-i18n-integration 3.9.0-ultramodern.8 → 3.9.3-ultramodern.1

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.
@@ -1,220 +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
- I18nRouterNavigationProvider: ()=>I18nRouterNavigationProvider
32
- });
33
- const jsx_runtime_namespaceObject = require("react/jsx-runtime");
34
- const no_react_i18next_namespaceObject = require("@modern-js/plugin-i18n/runtime/no-react-i18next");
35
- const runtime_namespaceObject = require("@modern-js/runtime");
36
- const context_namespaceObject = require("@modern-js/runtime/context");
37
- const router_state_namespaceObject = require("@modern-js/runtime-extensions/router-state");
38
- const external_react_namespaceObject = require("react");
39
- const normalizeUrlPart = (value, prefix)=>{
40
- if ('string' != typeof value || !value) return '';
41
- return value.startsWith(prefix) ? value : `${prefix}${value}`;
42
- };
43
- const normalizeLocation = (location)=>{
44
- if (!location || 'object' != typeof location) return null;
45
- const locationValue = location;
46
- if ('string' != typeof locationValue.pathname) return null;
47
- return {
48
- pathname: locationValue.pathname,
49
- search: normalizeUrlPart('string' == typeof locationValue.search ? locationValue.search : locationValue.searchStr, '?'),
50
- hash: normalizeUrlPart(locationValue.hash, '#')
51
- };
52
- };
53
- const getWindowLocation = ()=>{
54
- if (!(0, runtime_namespaceObject.isBrowser)()) return null;
55
- return {
56
- pathname: window.location.pathname,
57
- search: window.location.search,
58
- hash: window.location.hash
59
- };
60
- };
61
- const getRouterFramework = (runtimeContext, internalContext, inReactRouter)=>{
62
- const framework = (0, router_state_namespaceObject.getRouterRuntimeState)(internalContext)?.framework || (0, router_state_namespaceObject.getRouterRuntimeState)(runtimeContext)?.framework;
63
- if (framework) return framework;
64
- if (internalContext.router?.useRouter || runtimeContext.router?.useRouter) return 'tanstack';
65
- if (internalContext.router?.useLocation || internalContext.router?.useHref || runtimeContext.router?.useLocation || runtimeContext.router?.useHref) return 'react-router';
66
- if (inReactRouter) return 'react-router';
67
- };
68
- const getRouterInstance = (internalContext, contextRouter)=>{
69
- if (contextRouter) return contextRouter;
70
- const router = (0, router_state_namespaceObject.getRouterRuntimeState)(internalContext)?.instance;
71
- if (!router || 'object' != typeof router) return null;
72
- return router;
73
- };
74
- const getRouterStateLocation = (internalContext, contextRouter)=>{
75
- const router = getRouterInstance(internalContext, contextRouter);
76
- return normalizeLocation(router?.stores?.location?.get?.()) || normalizeLocation(router?.state?.location);
77
- };
78
- const getRouterParams = (internalContext, contextRouter)=>{
79
- const router = getRouterInstance(internalContext, contextRouter);
80
- const matches = router?.stores?.matches?.get?.() || router?.state?.matches;
81
- if (!Array.isArray(matches)) return {};
82
- return matches.reduce((params, match)=>{
83
- if (match?.params) Object.assign(params, match.params);
84
- return params;
85
- }, {});
86
- };
87
- const getRouterSnapshot = (internalContext, contextRouter)=>{
88
- const location = getRouterStateLocation(internalContext, contextRouter);
89
- const params = getRouterParams(internalContext, contextRouter);
90
- return JSON.stringify([
91
- location?.pathname ?? '',
92
- location?.search ?? '',
93
- location?.hash ?? '',
94
- Object.entries(params).sort(([left], [right])=>left.localeCompare(right))
95
- ]);
96
- };
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 = (0, no_react_i18next_namespaceObject.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 hasRouter = 'tanstack' === framework || 'react-router' === framework || Boolean(reactRouterNavigate);
112
- const subscribeToRouter = (0, external_react_namespaceObject.useCallback)((update)=>{
113
- const router = getRouterInstance(internalContext, contextRouter);
114
- if (!router) return ()=>void 0;
115
- const unsubscribers = [];
116
- if ('react-router' === framework && !inReactRouter && 'function' == typeof router.subscribe) {
117
- const subscribe = router.subscribe;
118
- const unsubscribe = subscribe.call(router, update);
119
- if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
120
- }
121
- if ('tanstack' === framework && 'function' == typeof router.stores?.location?.subscribe) {
122
- const unsubscribe = router.stores.location.subscribe(update);
123
- if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
124
- }
125
- if ('tanstack' === framework && 'function' == typeof router.subscribe) {
126
- const subscribe = router.subscribe;
127
- for (const eventType of [
128
- 'onBeforeNavigate',
129
- 'onBeforeLoad'
130
- ]){
131
- const unsubscribe = subscribe.call(router, eventType, update);
132
- if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
133
- }
134
- }
135
- return ()=>{
136
- for (const unsubscribe of unsubscribers)unsubscribe();
137
- };
138
- }, [
139
- contextRouter,
140
- framework,
141
- inReactRouter,
142
- internalContext
143
- ]);
144
- const getSnapshot = (0, external_react_namespaceObject.useCallback)(()=>getRouterSnapshot(internalContext, contextRouter), [
145
- contextRouter,
146
- internalContext
147
- ]);
148
- (0, external_react_namespaceObject.useSyncExternalStore)(subscribeToRouter, getSnapshot, getSnapshot);
149
- const navigate = (0, external_react_namespaceObject.useCallback)((href, options)=>{
150
- const router = getRouterInstance(internalContext, contextRouter);
151
- const activeFramework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
152
- if ('tanstack' === activeFramework) {
153
- if ('function' == typeof router?.navigate) return router.navigate({
154
- to: href,
155
- replace: options?.replace,
156
- ...options?.state === void 0 ? {} : {
157
- state: options.state
158
- }
159
- });
160
- throw new Error('TanStack router instance is not available.');
161
- }
162
- if (reactRouterNavigate) return reactRouterNavigate(href, options);
163
- if ('react-router' === activeFramework) {
164
- if ('function' == typeof router?.navigate) return router.navigate(href, options);
165
- throw new Error('React Router instance is not available.');
166
- }
167
- }, [
168
- contextRouter,
169
- internalContext,
170
- inReactRouter,
171
- reactRouterNavigate,
172
- runtimeContext
173
- ]);
174
- const location = (reactRouterLocation ? normalizeLocation(reactRouterLocation) : getRouterStateLocation(internalContext, contextRouter)) || getWindowLocation();
175
- const params = inReactRouter ? reactRouterParams : getRouterParams(internalContext, contextRouter);
176
- const Link = 'tanstack' === framework ? internalContext.router?.Link || runtimeContext.router?.Link || null : 'react-router' === framework || inReactRouter ? routerApi?.Link ?? null : null;
177
- return {
178
- framework,
179
- hasRouter,
180
- location,
181
- navigate: hasRouter ? navigate : null,
182
- Link,
183
- params,
184
- ...'tanstack' === framework ? {
185
- createLinkProps: createTanstackLinkProps
186
- } : {}
187
- };
188
- };
189
- const createTanstackLinkProps = (target)=>{
190
- const preload = void 0 !== target.preload ? target.preload : 'none' === target.prefetch ? false : target.prefetch;
191
- return {
192
- to: target.pathname,
193
- ...target.search ? {
194
- search: target.search
195
- } : {},
196
- ...target.hash ? {
197
- hash: target.hash
198
- } : {},
199
- ...void 0 === target.hashScrollIntoView ? {} : {
200
- hashScrollIntoView: target.hashScrollIntoView
201
- },
202
- ...void 0 === preload ? {} : {
203
- preload
204
- }
205
- };
206
- };
207
- const I18nRouterNavigationProvider = ({ children })=>{
208
- const value = useIntegratedRouterAdapter();
209
- return /*#__PURE__*/ (0, jsx_runtime_namespaceObject.jsx)(no_react_i18next_namespaceObject.I18nNavigationProvider, {
210
- value: value,
211
- children: children
212
- });
213
- };
214
- exports.I18nRouterNavigationProvider = __webpack_exports__.I18nRouterNavigationProvider;
215
- for(var __rspack_i in __webpack_exports__)if (-1 === [
216
- "I18nRouterNavigationProvider"
217
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
218
- Object.defineProperty(exports, '__esModule', {
219
- value: true
220
- });
@@ -1,50 +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: ()=>server,
32
- i18nServerPlugin: ()=>i18nServerPlugin
33
- });
34
- const config_namespaceObject = require("@modern-js/plugin-i18n/config");
35
- const server_namespaceObject = require("@modern-js/plugin-i18n/server");
36
- const external_urlStrategy_js_namespaceObject = require("./urlStrategy.js");
37
- const i18nServerPlugin = (options)=>(0, server_namespaceObject.i18nServerPlugin)({
38
- ...options,
39
- resolveUrlStrategy: options.resolveUrlStrategy ?? ((entryName)=>(0, external_urlStrategy_js_namespaceObject.createI18nUrlStrategy)(options.localeDetection ? (0, config_namespaceObject.getLocaleDetectionOptions)(entryName, options.localeDetection).localisedUrls : void 0))
40
- });
41
- const server = i18nServerPlugin;
42
- exports["default"] = __webpack_exports__["default"];
43
- exports.i18nServerPlugin = __webpack_exports__.i18nServerPlugin;
44
- for(var __rspack_i in __webpack_exports__)if (-1 === [
45
- "default",
46
- "i18nServerPlugin"
47
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
48
- Object.defineProperty(exports, '__esModule', {
49
- value: true
50
- });
@@ -1,182 +0,0 @@
1
- import { jsx } from "react/jsx-runtime";
2
- import { I18nNavigationProvider, useNativeI18nRouterAdapter } from "@modern-js/plugin-i18n/runtime/no-react-i18next";
3
- import { RuntimeContext, isBrowser } from "@modern-js/runtime";
4
- import { InternalRuntimeContext } from "@modern-js/runtime/context";
5
- import { getRouterRuntimeState } from "@modern-js/runtime-extensions/router-state";
6
- import { useCallback, useContext, useSyncExternalStore } from "react";
7
- const normalizeUrlPart = (value, prefix)=>{
8
- if ('string' != typeof value || !value) return '';
9
- return value.startsWith(prefix) ? value : `${prefix}${value}`;
10
- };
11
- const normalizeLocation = (location)=>{
12
- if (!location || 'object' != typeof location) return null;
13
- const locationValue = location;
14
- if ('string' != typeof locationValue.pathname) return null;
15
- return {
16
- pathname: locationValue.pathname,
17
- search: normalizeUrlPart('string' == typeof locationValue.search ? locationValue.search : locationValue.searchStr, '?'),
18
- hash: normalizeUrlPart(locationValue.hash, '#')
19
- };
20
- };
21
- const getWindowLocation = ()=>{
22
- if (!isBrowser()) return null;
23
- return {
24
- pathname: window.location.pathname,
25
- search: window.location.search,
26
- hash: window.location.hash
27
- };
28
- };
29
- const getRouterFramework = (runtimeContext, internalContext, inReactRouter)=>{
30
- const framework = getRouterRuntimeState(internalContext)?.framework || getRouterRuntimeState(runtimeContext)?.framework;
31
- if (framework) return framework;
32
- if (internalContext.router?.useRouter || runtimeContext.router?.useRouter) return 'tanstack';
33
- if (internalContext.router?.useLocation || internalContext.router?.useHref || runtimeContext.router?.useLocation || runtimeContext.router?.useHref) return 'react-router';
34
- if (inReactRouter) return 'react-router';
35
- };
36
- const getRouterInstance = (internalContext, contextRouter)=>{
37
- if (contextRouter) return contextRouter;
38
- const router = getRouterRuntimeState(internalContext)?.instance;
39
- if (!router || 'object' != typeof router) return null;
40
- return router;
41
- };
42
- const getRouterStateLocation = (internalContext, contextRouter)=>{
43
- const router = getRouterInstance(internalContext, contextRouter);
44
- return normalizeLocation(router?.stores?.location?.get?.()) || normalizeLocation(router?.state?.location);
45
- };
46
- const getRouterParams = (internalContext, contextRouter)=>{
47
- const router = getRouterInstance(internalContext, contextRouter);
48
- const matches = router?.stores?.matches?.get?.() || router?.state?.matches;
49
- if (!Array.isArray(matches)) return {};
50
- return matches.reduce((params, match)=>{
51
- if (match?.params) Object.assign(params, match.params);
52
- return params;
53
- }, {});
54
- };
55
- const getRouterSnapshot = (internalContext, contextRouter)=>{
56
- const location = getRouterStateLocation(internalContext, contextRouter);
57
- const params = getRouterParams(internalContext, contextRouter);
58
- return JSON.stringify([
59
- location?.pathname ?? '',
60
- location?.search ?? '',
61
- location?.hash ?? '',
62
- Object.entries(params).sort(([left], [right])=>left.localeCompare(right))
63
- ]);
64
- };
65
- const useIntegratedRouterAdapter = ()=>{
66
- const runtimeContext = useContext(RuntimeContext);
67
- const internalContext = useContext(InternalRuntimeContext);
68
- const routerApi = internalContext.router || runtimeContext.router;
69
- const native = useNativeI18nRouterAdapter();
70
- const inReactRouter = native.hasRouter;
71
- const reactRouterNavigate = native.navigate;
72
- const reactRouterLocation = inReactRouter ? native.location : null;
73
- const reactRouterParams = native.params;
74
- const framework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
75
- const contextUseRouter = inReactRouter || 'tanstack' !== framework ? void 0 : internalContext.router?.useRouter || runtimeContext.router?.useRouter;
76
- const contextRouter = contextUseRouter ? contextUseRouter({
77
- warn: false
78
- }) : null;
79
- const hasRouter = 'tanstack' === framework || 'react-router' === framework || Boolean(reactRouterNavigate);
80
- const subscribeToRouter = useCallback((update)=>{
81
- const router = getRouterInstance(internalContext, contextRouter);
82
- if (!router) return ()=>void 0;
83
- const unsubscribers = [];
84
- if ('react-router' === framework && !inReactRouter && 'function' == typeof router.subscribe) {
85
- const subscribe = router.subscribe;
86
- const unsubscribe = subscribe.call(router, update);
87
- if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
88
- }
89
- if ('tanstack' === framework && 'function' == typeof router.stores?.location?.subscribe) {
90
- const unsubscribe = router.stores.location.subscribe(update);
91
- if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
92
- }
93
- if ('tanstack' === framework && 'function' == typeof router.subscribe) {
94
- const subscribe = router.subscribe;
95
- for (const eventType of [
96
- 'onBeforeNavigate',
97
- 'onBeforeLoad'
98
- ]){
99
- const unsubscribe = subscribe.call(router, eventType, update);
100
- if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
101
- }
102
- }
103
- return ()=>{
104
- for (const unsubscribe of unsubscribers)unsubscribe();
105
- };
106
- }, [
107
- contextRouter,
108
- framework,
109
- inReactRouter,
110
- internalContext
111
- ]);
112
- const getSnapshot = useCallback(()=>getRouterSnapshot(internalContext, contextRouter), [
113
- contextRouter,
114
- internalContext
115
- ]);
116
- useSyncExternalStore(subscribeToRouter, getSnapshot, getSnapshot);
117
- const navigate = useCallback((href, options)=>{
118
- const router = getRouterInstance(internalContext, contextRouter);
119
- const activeFramework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
120
- if ('tanstack' === activeFramework) {
121
- if ('function' == typeof router?.navigate) return router.navigate({
122
- to: href,
123
- replace: options?.replace,
124
- ...options?.state === void 0 ? {} : {
125
- state: options.state
126
- }
127
- });
128
- throw new Error('TanStack router instance is not available.');
129
- }
130
- if (reactRouterNavigate) return reactRouterNavigate(href, options);
131
- if ('react-router' === activeFramework) {
132
- if ('function' == typeof router?.navigate) return router.navigate(href, options);
133
- throw new Error('React Router instance is not available.');
134
- }
135
- }, [
136
- contextRouter,
137
- internalContext,
138
- inReactRouter,
139
- reactRouterNavigate,
140
- runtimeContext
141
- ]);
142
- const location = (reactRouterLocation ? normalizeLocation(reactRouterLocation) : getRouterStateLocation(internalContext, contextRouter)) || getWindowLocation();
143
- const params = inReactRouter ? reactRouterParams : getRouterParams(internalContext, contextRouter);
144
- const Link = 'tanstack' === framework ? internalContext.router?.Link || runtimeContext.router?.Link || null : 'react-router' === framework || inReactRouter ? routerApi?.Link ?? null : null;
145
- return {
146
- framework,
147
- hasRouter,
148
- location,
149
- navigate: hasRouter ? navigate : null,
150
- Link,
151
- params,
152
- ...'tanstack' === framework ? {
153
- createLinkProps: createTanstackLinkProps
154
- } : {}
155
- };
156
- };
157
- const createTanstackLinkProps = (target)=>{
158
- const preload = void 0 !== target.preload ? target.preload : 'none' === target.prefetch ? false : target.prefetch;
159
- return {
160
- to: target.pathname,
161
- ...target.search ? {
162
- search: target.search
163
- } : {},
164
- ...target.hash ? {
165
- hash: target.hash
166
- } : {},
167
- ...void 0 === target.hashScrollIntoView ? {} : {
168
- hashScrollIntoView: target.hashScrollIntoView
169
- },
170
- ...void 0 === preload ? {} : {
171
- preload
172
- }
173
- };
174
- };
175
- const I18nRouterNavigationProvider = ({ children })=>{
176
- const value = useIntegratedRouterAdapter();
177
- return /*#__PURE__*/ jsx(I18nNavigationProvider, {
178
- value: value,
179
- children: children
180
- });
181
- };
182
- export { I18nRouterNavigationProvider };
@@ -1,10 +0,0 @@
1
- import { getLocaleDetectionOptions } from "@modern-js/plugin-i18n/config";
2
- import { i18nServerPlugin } from "@modern-js/plugin-i18n/server";
3
- import { createI18nUrlStrategy } from "./urlStrategy.mjs";
4
- const server_i18nServerPlugin = (options)=>i18nServerPlugin({
5
- ...options,
6
- resolveUrlStrategy: options.resolveUrlStrategy ?? ((entryName)=>createI18nUrlStrategy(options.localeDetection ? getLocaleDetectionOptions(entryName, options.localeDetection).localisedUrls : void 0))
7
- });
8
- const server = server_i18nServerPlugin;
9
- export default server;
10
- export { server_i18nServerPlugin as i18nServerPlugin };
@@ -1,183 +0,0 @@
1
- import "node:module";
2
- import { jsx } from "react/jsx-runtime";
3
- import { I18nNavigationProvider, useNativeI18nRouterAdapter } from "@modern-js/plugin-i18n/runtime/no-react-i18next";
4
- import { RuntimeContext, isBrowser } from "@modern-js/runtime";
5
- import { InternalRuntimeContext } from "@modern-js/runtime/context";
6
- import { getRouterRuntimeState } from "@modern-js/runtime-extensions/router-state";
7
- import { useCallback, useContext, useSyncExternalStore } from "react";
8
- const normalizeUrlPart = (value, prefix)=>{
9
- if ('string' != typeof value || !value) return '';
10
- return value.startsWith(prefix) ? value : `${prefix}${value}`;
11
- };
12
- const normalizeLocation = (location)=>{
13
- if (!location || 'object' != typeof location) return null;
14
- const locationValue = location;
15
- if ('string' != typeof locationValue.pathname) return null;
16
- return {
17
- pathname: locationValue.pathname,
18
- search: normalizeUrlPart('string' == typeof locationValue.search ? locationValue.search : locationValue.searchStr, '?'),
19
- hash: normalizeUrlPart(locationValue.hash, '#')
20
- };
21
- };
22
- const getWindowLocation = ()=>{
23
- if (!isBrowser()) return null;
24
- return {
25
- pathname: window.location.pathname,
26
- search: window.location.search,
27
- hash: window.location.hash
28
- };
29
- };
30
- const getRouterFramework = (runtimeContext, internalContext, inReactRouter)=>{
31
- const framework = getRouterRuntimeState(internalContext)?.framework || getRouterRuntimeState(runtimeContext)?.framework;
32
- if (framework) return framework;
33
- if (internalContext.router?.useRouter || runtimeContext.router?.useRouter) return 'tanstack';
34
- if (internalContext.router?.useLocation || internalContext.router?.useHref || runtimeContext.router?.useLocation || runtimeContext.router?.useHref) return 'react-router';
35
- if (inReactRouter) return 'react-router';
36
- };
37
- const getRouterInstance = (internalContext, contextRouter)=>{
38
- if (contextRouter) return contextRouter;
39
- const router = getRouterRuntimeState(internalContext)?.instance;
40
- if (!router || 'object' != typeof router) return null;
41
- return router;
42
- };
43
- const getRouterStateLocation = (internalContext, contextRouter)=>{
44
- const router = getRouterInstance(internalContext, contextRouter);
45
- return normalizeLocation(router?.stores?.location?.get?.()) || normalizeLocation(router?.state?.location);
46
- };
47
- const getRouterParams = (internalContext, contextRouter)=>{
48
- const router = getRouterInstance(internalContext, contextRouter);
49
- const matches = router?.stores?.matches?.get?.() || router?.state?.matches;
50
- if (!Array.isArray(matches)) return {};
51
- return matches.reduce((params, match)=>{
52
- if (match?.params) Object.assign(params, match.params);
53
- return params;
54
- }, {});
55
- };
56
- const getRouterSnapshot = (internalContext, contextRouter)=>{
57
- const location = getRouterStateLocation(internalContext, contextRouter);
58
- const params = getRouterParams(internalContext, contextRouter);
59
- return JSON.stringify([
60
- location?.pathname ?? '',
61
- location?.search ?? '',
62
- location?.hash ?? '',
63
- Object.entries(params).sort(([left], [right])=>left.localeCompare(right))
64
- ]);
65
- };
66
- const useIntegratedRouterAdapter = ()=>{
67
- const runtimeContext = useContext(RuntimeContext);
68
- const internalContext = useContext(InternalRuntimeContext);
69
- const routerApi = internalContext.router || runtimeContext.router;
70
- const native = useNativeI18nRouterAdapter();
71
- const inReactRouter = native.hasRouter;
72
- const reactRouterNavigate = native.navigate;
73
- const reactRouterLocation = inReactRouter ? native.location : null;
74
- const reactRouterParams = native.params;
75
- const framework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
76
- const contextUseRouter = inReactRouter || 'tanstack' !== framework ? void 0 : internalContext.router?.useRouter || runtimeContext.router?.useRouter;
77
- const contextRouter = contextUseRouter ? contextUseRouter({
78
- warn: false
79
- }) : null;
80
- const hasRouter = 'tanstack' === framework || 'react-router' === framework || Boolean(reactRouterNavigate);
81
- const subscribeToRouter = useCallback((update)=>{
82
- const router = getRouterInstance(internalContext, contextRouter);
83
- if (!router) return ()=>void 0;
84
- const unsubscribers = [];
85
- if ('react-router' === framework && !inReactRouter && 'function' == typeof router.subscribe) {
86
- const subscribe = router.subscribe;
87
- const unsubscribe = subscribe.call(router, update);
88
- if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
89
- }
90
- if ('tanstack' === framework && 'function' == typeof router.stores?.location?.subscribe) {
91
- const unsubscribe = router.stores.location.subscribe(update);
92
- if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
93
- }
94
- if ('tanstack' === framework && 'function' == typeof router.subscribe) {
95
- const subscribe = router.subscribe;
96
- for (const eventType of [
97
- 'onBeforeNavigate',
98
- 'onBeforeLoad'
99
- ]){
100
- const unsubscribe = subscribe.call(router, eventType, update);
101
- if ('function' == typeof unsubscribe) unsubscribers.push(unsubscribe);
102
- }
103
- }
104
- return ()=>{
105
- for (const unsubscribe of unsubscribers)unsubscribe();
106
- };
107
- }, [
108
- contextRouter,
109
- framework,
110
- inReactRouter,
111
- internalContext
112
- ]);
113
- const getSnapshot = useCallback(()=>getRouterSnapshot(internalContext, contextRouter), [
114
- contextRouter,
115
- internalContext
116
- ]);
117
- useSyncExternalStore(subscribeToRouter, getSnapshot, getSnapshot);
118
- const navigate = useCallback((href, options)=>{
119
- const router = getRouterInstance(internalContext, contextRouter);
120
- const activeFramework = getRouterFramework(runtimeContext, internalContext, inReactRouter);
121
- if ('tanstack' === activeFramework) {
122
- if ('function' == typeof router?.navigate) return router.navigate({
123
- to: href,
124
- replace: options?.replace,
125
- ...options?.state === void 0 ? {} : {
126
- state: options.state
127
- }
128
- });
129
- throw new Error('TanStack router instance is not available.');
130
- }
131
- if (reactRouterNavigate) return reactRouterNavigate(href, options);
132
- if ('react-router' === activeFramework) {
133
- if ('function' == typeof router?.navigate) return router.navigate(href, options);
134
- throw new Error('React Router instance is not available.');
135
- }
136
- }, [
137
- contextRouter,
138
- internalContext,
139
- inReactRouter,
140
- reactRouterNavigate,
141
- runtimeContext
142
- ]);
143
- const location = (reactRouterLocation ? normalizeLocation(reactRouterLocation) : getRouterStateLocation(internalContext, contextRouter)) || getWindowLocation();
144
- const params = inReactRouter ? reactRouterParams : getRouterParams(internalContext, contextRouter);
145
- const Link = 'tanstack' === framework ? internalContext.router?.Link || runtimeContext.router?.Link || null : 'react-router' === framework || inReactRouter ? routerApi?.Link ?? null : null;
146
- return {
147
- framework,
148
- hasRouter,
149
- location,
150
- navigate: hasRouter ? navigate : null,
151
- Link,
152
- params,
153
- ...'tanstack' === framework ? {
154
- createLinkProps: createTanstackLinkProps
155
- } : {}
156
- };
157
- };
158
- const createTanstackLinkProps = (target)=>{
159
- const preload = void 0 !== target.preload ? target.preload : 'none' === target.prefetch ? false : target.prefetch;
160
- return {
161
- to: target.pathname,
162
- ...target.search ? {
163
- search: target.search
164
- } : {},
165
- ...target.hash ? {
166
- hash: target.hash
167
- } : {},
168
- ...void 0 === target.hashScrollIntoView ? {} : {
169
- hashScrollIntoView: target.hashScrollIntoView
170
- },
171
- ...void 0 === preload ? {} : {
172
- preload
173
- }
174
- };
175
- };
176
- const I18nRouterNavigationProvider = ({ children })=>{
177
- const value = useIntegratedRouterAdapter();
178
- return /*#__PURE__*/ jsx(I18nNavigationProvider, {
179
- value: value,
180
- children: children
181
- });
182
- };
183
- export { I18nRouterNavigationProvider };
@@ -1,11 +0,0 @@
1
- import "node:module";
2
- import { getLocaleDetectionOptions } from "@modern-js/plugin-i18n/config";
3
- import { i18nServerPlugin } from "@modern-js/plugin-i18n/server";
4
- import { createI18nUrlStrategy } from "./urlStrategy.mjs";
5
- const server_i18nServerPlugin = (options)=>i18nServerPlugin({
6
- ...options,
7
- resolveUrlStrategy: options.resolveUrlStrategy ?? ((entryName)=>createI18nUrlStrategy(options.localeDetection ? getLocaleDetectionOptions(entryName, options.localeDetection).localisedUrls : void 0))
8
- });
9
- const server = server_i18nServerPlugin;
10
- export default server;
11
- export { server_i18nServerPlugin as i18nServerPlugin };
@@ -1,3 +0,0 @@
1
- import type React from 'react';
2
- /** Supplies the actual selected router; native links still render its Link. */
3
- export declare const I18nRouterNavigationProvider: ({ children, }: React.PropsWithChildren) => React.JSX.Element;
@@ -1,3 +0,0 @@
1
- import type { I18nServerPluginOptions } from './options.js';
2
- export declare const i18nServerPlugin: (options: I18nServerPluginOptions) => import("@modern-js/server-core").ServerPlugin;
3
- export default i18nServerPlugin;