@bleedingdev/modern-js-renderer-octane 3.9.3-ultramodern.7 → 3.9.3-ultramodern.9
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/client.js +56 -6
- package/dist/cjs/entry-application.js +7 -2
- package/dist/cjs/entry-client.js +3 -0
- package/dist/cjs/entry-server.js +13 -5
- package/dist/cjs/federation.js +108 -6
- package/dist/cjs/i18n/I18nProvider.js +6 -14
- package/dist/cjs/i18n/LocalizedLink.js +24 -33
- package/dist/cjs/i18n/index.js +0 -3
- package/dist/cjs/i18n-external-snapshot.js +645 -0
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/manifest.js +2 -2
- package/dist/cjs/plugin/compiler.js +2 -5
- package/dist/cjs/plugin/index.js +2 -2
- package/dist/cjs/plugin/profile.js +12 -10
- package/dist/cjs/router-client.js +1 -1
- package/dist/cjs/router-external-snapshot.js +263 -0
- package/dist/cjs/router-handler.js +11 -8
- package/dist/cjs/router-server.js +3 -11
- package/dist/cjs/router.js +1 -1
- package/dist/cjs/routes.js +11 -17
- package/dist/cjs/server.js +28 -7
- package/dist/cjs/worker-federation-context.js +63 -0
- package/dist/cjs/worker-federation-contexts.js +97 -0
- package/dist/cjs/worker-federation.js +97 -0
- package/dist/esm/client.mjs +56 -6
- package/dist/esm/entry-application.mjs +7 -2
- package/dist/esm/entry-client.mjs +3 -0
- package/dist/esm/entry-server.mjs +11 -6
- package/dist/esm/federation.mjs +110 -8
- package/dist/esm/i18n/I18nProvider.mjs +7 -15
- package/dist/esm/i18n/LocalizedLink.mjs +24 -30
- package/dist/esm/i18n/index.mjs +1 -1
- package/dist/esm/i18n-external-snapshot.mjs +576 -0
- package/dist/esm/index.mjs +4 -4
- package/dist/esm/manifest.mjs +2 -2
- package/dist/esm/router-client.mjs +1 -1
- package/dist/esm/router-external-snapshot.mjs +216 -0
- package/dist/esm/router-handler.mjs +11 -8
- package/dist/esm/router-server.mjs +0 -1
- package/dist/esm/router.mjs +2 -2
- package/dist/esm/routes.mjs +11 -17
- package/dist/esm/server.mjs +24 -3
- package/dist/esm/worker-federation-context.mjs +19 -0
- package/dist/esm/worker-federation-contexts.mjs +47 -0
- package/dist/esm/worker-federation.mjs +59 -0
- package/dist/esm-node/manifest.mjs +2 -2
- package/dist/esm-node/plugin/compiler.mjs +2 -5
- package/dist/esm-node/plugin/index.mjs +2 -2
- package/dist/esm-node/plugin/profile.mjs +12 -10
- package/dist/types/client.d.ts +5 -1
- package/dist/types/entry-client.d.ts +2 -0
- package/dist/types/entry-server.d.ts +4 -1
- package/dist/types/federation.d.ts +2 -0
- package/dist/types/i18n/LocalizedLink.d.ts +5 -32
- package/dist/types/i18n/context.d.ts +1 -1
- package/dist/types/i18n/index.d.ts +1 -1
- package/dist/types/i18n-external-snapshot.d.ts +43 -0
- package/dist/types/index.d.ts +4 -4
- package/dist/types/manifest.d.ts +2 -2
- package/dist/types/router-external-snapshot.d.ts +10 -0
- package/dist/types/router-server.d.ts +0 -2
- package/dist/types/server.d.ts +6 -0
- package/dist/types/worker-federation-context.d.ts +34 -0
- package/dist/types/worker-federation-contexts.d.ts +25 -0
- package/dist/types/worker-federation.d.ts +20 -0
- package/package.json +84 -22
- package/src/client.ts +99 -16
- package/src/entry-application.ts +7 -3
- package/src/entry-client.ts +10 -0
- package/src/entry-server.ts +20 -9
- package/src/federation.ts +159 -15
- package/src/i18n/I18nProvider.ts +11 -20
- package/src/i18n/LocalizedLink.ts +46 -72
- package/src/i18n/context.ts +1 -1
- package/src/i18n/index.ts +1 -5
- package/src/i18n-external-snapshot.ts +803 -0
- package/src/index.ts +4 -4
- package/src/manifest.ts +2 -2
- package/src/plugin/compiler-manifest.cjs +27 -1
- package/src/plugin/compiler.ts +6 -14
- package/src/plugin/index.ts +4 -2
- package/src/plugin/profile.ts +14 -10
- package/src/router-client.ts +1 -1
- package/src/router-external-snapshot.ts +306 -0
- package/src/router-handler.ts +11 -8
- package/src/router-server.ts +0 -2
- package/src/router.ts +2 -2
- package/src/routes.ts +28 -26
- package/src/server.ts +45 -5
- package/src/worker-federation-context.ts +51 -0
- package/src/worker-federation-contexts.ts +91 -0
- package/src/worker-federation.ts +120 -0
- package/dist/cjs/router-injection.js +0 -139
- package/dist/esm/router-injection.mjs +0 -101
- package/dist/types/router-injection.d.ts +0 -8
- package/src/router-injection.ts +0 -145
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
-
canonicalPath,
|
|
3
2
|
configuredLanguage,
|
|
4
3
|
localizePath,
|
|
5
4
|
} from '@modern-js/i18n-runtime-extensions/paths';
|
|
6
5
|
import { createElement, hookSlots, type OctaneNode, useContext } from 'octane';
|
|
7
6
|
import {
|
|
7
|
+
type AnyRouter,
|
|
8
8
|
Link,
|
|
9
9
|
type LinkComponentProps,
|
|
10
10
|
useLocation,
|
|
@@ -14,41 +14,23 @@ import { I18nContext } from './context';
|
|
|
14
14
|
|
|
15
15
|
// Plain TypeScript is not rewritten by the Octane compiler: router hooks take
|
|
16
16
|
// their stable slot explicitly.
|
|
17
|
-
const
|
|
17
|
+
const targetLocationSlot = Symbol(hookSlots(1));
|
|
18
18
|
|
|
19
|
-
export interface LocalizedLinkProps
|
|
19
|
+
export interface LocalizedLinkProps
|
|
20
|
+
extends Omit<
|
|
21
|
+
LinkComponentProps<'a', AnyRouter, string, string>,
|
|
22
|
+
'to' | 'mask' | 'href' | 'publicHref' | '_fromLocation'
|
|
23
|
+
> {
|
|
20
24
|
/** A canonical, language-agnostic target, e.g. `/products/red-shoe`. */
|
|
21
25
|
to: string;
|
|
22
26
|
/** Localize for a specific language instead of the current one. */
|
|
23
27
|
language?: string;
|
|
24
|
-
children?: unknown;
|
|
25
|
-
class?: string;
|
|
26
|
-
activeProps?: LinkComponentProps<'a'>['activeProps'];
|
|
27
|
-
inactiveProps?: LinkComponentProps<'a'>['inactiveProps'];
|
|
28
|
-
activeOptions?: LinkComponentProps<'a'>['activeOptions'];
|
|
29
|
-
replace?: boolean;
|
|
30
|
-
preload?: LinkComponentProps<'a'>['preload'];
|
|
31
28
|
}
|
|
32
29
|
|
|
33
30
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* to the real link — the same contract as `@modern-js/plugin-i18n`'s React
|
|
38
|
-
* `Link`. It resolves the href itself via the shared pathname helpers, so it
|
|
39
|
-
* works with or without the router's i18n `rewrite`. Every link, including
|
|
40
|
-
* one to another language, is the native `Link`: navigation, preloading and
|
|
41
|
-
* active state stay with the router.
|
|
42
|
-
*
|
|
43
|
-
* Under the i18n `rewrite` the router matches canonical paths and localizes
|
|
44
|
-
* outgoing locations to the current language, so a link to another language
|
|
45
|
-
* routes to the canonical `to` and publishes the target language's URL as a
|
|
46
|
-
* route mask (the rewrite keeps a mask's explicit language). The entry's
|
|
47
|
-
* router language synchronization (`syncWithRouter`) switches the i18next
|
|
48
|
-
* instance from the navigated URL, as it does for history navigation.
|
|
49
|
-
*
|
|
50
|
-
* No JSX: built with `createElement`, matching this package's existing
|
|
51
|
-
* style (see `src/routes.ts`).
|
|
31
|
+
* The native router owns client navigation, preloading and active state. Its mask
|
|
32
|
+
* keeps the canonical route while publishing the selected language URL;
|
|
33
|
+
* the entry's i18n router subscription synchronizes the instance on navigation.
|
|
52
34
|
*/
|
|
53
35
|
export function LocalizedLink(props: LocalizedLinkProps): OctaneNode {
|
|
54
36
|
const context = useContext(I18nContext);
|
|
@@ -58,55 +40,47 @@ export function LocalizedLink(props: LocalizedLinkProps): OctaneNode {
|
|
|
58
40
|
);
|
|
59
41
|
}
|
|
60
42
|
const router = useRouter();
|
|
61
|
-
|
|
62
|
-
|
|
43
|
+
const location = useLocation(undefined, targetLocationSlot);
|
|
44
|
+
const { language: requestedLanguage, to, children, ...options } = props;
|
|
63
45
|
const language =
|
|
64
|
-
|
|
46
|
+
requestedLanguage === undefined
|
|
65
47
|
? context.language
|
|
66
|
-
: configuredLanguage(
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
48
|
+
: configuredLanguage(requestedLanguage, context.languages);
|
|
49
|
+
const externalTarget = to.startsWith('//') || URL.canParse(to);
|
|
50
|
+
const pathname = externalTarget
|
|
51
|
+
? to
|
|
52
|
+
: localizePath(
|
|
53
|
+
router.buildLocation({
|
|
54
|
+
to,
|
|
55
|
+
from: options.from,
|
|
56
|
+
params: options.params,
|
|
57
|
+
unsafeRelative: options.unsafeRelative,
|
|
58
|
+
_fromLocation: location,
|
|
59
|
+
}).pathname,
|
|
60
|
+
language,
|
|
61
|
+
{
|
|
62
|
+
languages: [...context.languages],
|
|
63
|
+
localisedUrls: context.localisedUrls,
|
|
64
|
+
},
|
|
65
|
+
);
|
|
73
66
|
|
|
74
67
|
return createElement(
|
|
75
|
-
Link,
|
|
68
|
+
Link<AnyRouter, string, string, string, string>,
|
|
76
69
|
{
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
70
|
+
...options,
|
|
71
|
+
to: router.options.rewrite ? to : pathname,
|
|
72
|
+
...(router.options.rewrite && !externalTarget
|
|
73
|
+
? {
|
|
74
|
+
mask: {
|
|
75
|
+
to: pathname,
|
|
76
|
+
inheritSearch: true,
|
|
77
|
+
hash: options.hash,
|
|
78
|
+
state: options.state,
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
: {}),
|
|
82
|
+
...(language === context.language ? {} : { hreflang: language }),
|
|
89
83
|
},
|
|
90
|
-
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Language-invariant active check: `to="/products"` is active whether the
|
|
96
|
-
* current location is `/en/products` or `/produkty` under a mapped locale.
|
|
97
|
-
*/
|
|
98
|
-
export function useIsLocalizedActive(canonicalTarget: string): boolean {
|
|
99
|
-
const context = useContext(I18nContext);
|
|
100
|
-
if (!context) {
|
|
101
|
-
throw new Error(
|
|
102
|
-
'[renderer-octane] useIsLocalizedActive was used outside of an I18nProvider.',
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
const location = useLocation(undefined, locationSlot);
|
|
106
|
-
return (
|
|
107
|
-
canonicalPath(location.pathname, {
|
|
108
|
-
languages: [...context.languages],
|
|
109
|
-
localisedUrls: context.localisedUrls,
|
|
110
|
-
}) === canonicalTarget
|
|
84
|
+
children,
|
|
111
85
|
);
|
|
112
86
|
}
|
package/src/i18n/context.ts
CHANGED
|
@@ -6,7 +6,7 @@ export type { I18nContextValue, I18nInstanceLike } from './types';
|
|
|
6
6
|
/**
|
|
7
7
|
* Octane's `createContext<T>(defaultValue: T)` requires a default (unlike
|
|
8
8
|
* Solid 2's default-less form), so a missing provider is detected by
|
|
9
|
-
* checking for `null` in `useI18n`/`
|
|
9
|
+
* checking for `null` in `useI18n`/`LocalizedLink` instead — the same
|
|
10
10
|
* guard shape `@modern-js/plugin-i18n`'s React `ModernI18nContext` uses.
|
|
11
11
|
*/
|
|
12
12
|
export const I18nContext = createContext<I18nContextValue | null>(null);
|
package/src/i18n/index.ts
CHANGED
|
@@ -22,11 +22,7 @@ export {
|
|
|
22
22
|
} from '@modern-js/i18n-runtime-extensions/urlRewrite';
|
|
23
23
|
export { I18nContext } from './context';
|
|
24
24
|
export { I18nProvider, type I18nProviderProps } from './I18nProvider';
|
|
25
|
-
export {
|
|
26
|
-
LocalizedLink,
|
|
27
|
-
type LocalizedLinkProps,
|
|
28
|
-
useIsLocalizedActive,
|
|
29
|
-
} from './LocalizedLink';
|
|
25
|
+
export { LocalizedLink, type LocalizedLinkProps } from './LocalizedLink';
|
|
30
26
|
export {
|
|
31
27
|
type OctaneLatestLanguageSyncOptions,
|
|
32
28
|
useLatestLanguageSync,
|