react-intlayer 9.5.11 → 9.6.0
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/IntlayerProvider.cjs +6 -5
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +2 -2
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +2 -2
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +5 -4
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs +2 -0
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +2 -2
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +2 -2
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +7 -6
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +2 -2
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +6 -6
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/plugins.mjs +6 -5
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +2 -0
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs +2 -2
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +5 -5
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/types/client/IntlayerProvider.d.ts.map +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/server/IntlayerServerProvider.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -37,11 +37,12 @@ const useIntlayerContext = () => (0, react.useContext)(IntlayerClientContext) ??
|
|
|
37
37
|
*/
|
|
38
38
|
const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLocaleProp, variant, children, setLocale: setLocaleProp, disableEditor, isCookieEnabled }) => {
|
|
39
39
|
const { locales: availableLocales, defaultLocale: defaultLocaleConfig } = _intlayer_config_built.internationalization ?? {};
|
|
40
|
+
const deferredLocaleProp = (0, react.useDeferredValue)(localeProp);
|
|
40
41
|
const [currentLocale, setCurrentLocale] = (0, react.useState)(() => localeProp ?? require_client_useLocaleStorage.getLocaleInStorage() ?? defaultLocaleProp ?? defaultLocaleConfig);
|
|
41
|
-
const [adoptedLocaleProp, setAdoptedLocaleProp] = (0, react.useState)(
|
|
42
|
-
if (
|
|
43
|
-
setAdoptedLocaleProp(
|
|
44
|
-
if (
|
|
42
|
+
const [adoptedLocaleProp, setAdoptedLocaleProp] = (0, react.useState)(deferredLocaleProp);
|
|
43
|
+
if (deferredLocaleProp !== adoptedLocaleProp) {
|
|
44
|
+
setAdoptedLocaleProp(deferredLocaleProp);
|
|
45
|
+
if (deferredLocaleProp && deferredLocaleProp !== currentLocale) setCurrentLocale(deferredLocaleProp);
|
|
45
46
|
}
|
|
46
47
|
(0, react.useEffect)(() => {
|
|
47
48
|
(0, _intlayer_config_client.setIntlayerIdentifier)();
|
|
@@ -59,7 +60,7 @@ const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLoc
|
|
|
59
60
|
availableLocales,
|
|
60
61
|
isCookieEnabled
|
|
61
62
|
]);
|
|
62
|
-
const setLocale = setLocaleProp ?? setLocaleBase;
|
|
63
|
+
const setLocale = (0, react.useCallback)((newLocale) => (0, react.startTransition)(() => (setLocaleProp ?? setLocaleBase)(newLocale)), [setLocaleProp, setLocaleBase]);
|
|
63
64
|
const resolvedLocale = (0, _intlayer_core_localization.localeResolver)(currentLocale);
|
|
64
65
|
const contextValue = (0, react.useMemo)(() => ({
|
|
65
66
|
locale: resolvedLocale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.cjs","names":["createContext","getLocaleInStorage","internationalization","useContext","useState","useCallback","localeResolver","useMemo","EditorProvider","AnalyticsProvider"],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport { AnalyticsProvider } from '../analytics/AnalyticsProvider';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { getLocaleInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n /**\n * Ambient variant applied to every dictionary read below the provider, the\n * same way `locale` is. Overridden per call by an explicit selector.\n */\n variant?: ProviderVariant;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n // Read on demand: only a tree rendered without a provider needs it\n get locale() {\n return getLocaleInStorage() ?? internationalization?.defaultLocale;\n },\n setLocale: () => null,\n isCookieEnabled: true,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext) ?? {};\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension that is fixed for the whole session (tenant, school type, plan\n * tier…) and that therefore no component should have to pass by hand.\n *\n * Accepts three forms:\n * - `variant=\"school1\"` — one named variant for every key\n * - `variant={['school1', 'default']}` — an ordered preference chain: the\n * first variant the key actually declares wins\n * - `variant={{ key1: 'school1', key2: ['school1', 'default'], default: 'base' }}`\n * — per dictionary key, with `default` covering every key not listed\n *\n * A plain object is always read as the per-key map. To pin a structured\n * variant globally, nest it: `variant={{ default: { id: 'prod_abc' } }}`.\n *\n * A call-site selector always wins: `useIntlayer('key', { variant: 'x' })`\n * replaces this default rather than extending it.\n */\n variant?: ProviderVariant;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n variant,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n // Storage is only read when no locale is passed, and only on mount\n const [currentLocale, setCurrentLocale] = useState<LocalesValues>(\n () =>\n localeProp ??\n getLocaleInStorage() ??\n defaultLocaleProp ??\n defaultLocaleConfig\n );\n const [adoptedLocaleProp, setAdoptedLocaleProp]
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.cjs","names":["createContext","getLocaleInStorage","internationalization","useContext","useDeferredValue","useState","useCallback","startTransition","localeResolver","useMemo","EditorProvider","AnalyticsProvider"],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n startTransition,\n useCallback,\n useContext,\n useDeferredValue,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport { AnalyticsProvider } from '../analytics/AnalyticsProvider';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { getLocaleInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n /**\n * Ambient variant applied to every dictionary read below the provider, the\n * same way `locale` is. Overridden per call by an explicit selector.\n */\n variant?: ProviderVariant;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n // Read on demand: only a tree rendered without a provider needs it\n get locale() {\n return getLocaleInStorage() ?? internationalization?.defaultLocale;\n },\n setLocale: () => null,\n isCookieEnabled: true,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext) ?? {};\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension that is fixed for the whole session (tenant, school type, plan\n * tier…) and that therefore no component should have to pass by hand.\n *\n * Accepts three forms:\n * - `variant=\"school1\"` — one named variant for every key\n * - `variant={['school1', 'default']}` — an ordered preference chain: the\n * first variant the key actually declares wins\n * - `variant={{ key1: 'school1', key2: ['school1', 'default'], default: 'base' }}`\n * — per dictionary key, with `default` covering every key not listed\n *\n * A plain object is always read as the per-key map. To pin a structured\n * variant globally, nest it: `variant={{ default: { id: 'prod_abc' } }}`.\n *\n * A call-site selector always wins: `useIntlayer('key', { variant: 'x' })`\n * replaces this default rather than extending it.\n */\n variant?: ProviderVariant;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n variant,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n // A router usually changes the prop through a sync update, which would\n // suspend on the new locale's dynamic dictionaries and hide the page behind\n // the Suspense fallback. Deferred, the new locale renders in the background\n // and the current UI stays until it is ready.\n const deferredLocaleProp = useDeferredValue(localeProp);\n\n // Storage is only read when no locale is passed, and only on mount\n const [currentLocale, setCurrentLocale] = useState<LocalesValues>(\n () =>\n localeProp ??\n getLocaleInStorage() ??\n defaultLocaleProp ??\n defaultLocaleConfig\n );\n const [adoptedLocaleProp, setAdoptedLocaleProp] =\n useState(deferredLocaleProp);\n\n // Adopt a new `locale` prop during render rather than in an effect: an\n // effect commits the whole subtree once with the stale locale, then renders\n // it again with the new one.\n if (deferredLocaleProp !== adoptedLocaleProp) {\n setAdoptedLocaleProp(deferredLocaleProp);\n\n if (deferredLocaleProp && deferredLocaleProp !== currentLocale) {\n setCurrentLocale(deferredLocaleProp);\n }\n }\n\n useEffect(() => {\n setIntlayerIdentifier();\n }, []);\n\n const setLocaleBase = useCallback(\n (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale);\n setLocaleInStorage(newLocale, isCookieEnabled);\n },\n [currentLocale, availableLocales, isCookieEnabled]\n );\n\n const setLocale = useCallback(\n (newLocale: LocalesValues) =>\n startTransition(() => (setLocaleProp ?? setLocaleBase)(newLocale)),\n [setLocaleProp, setLocaleBase]\n );\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(currentLocale);\n\n // Stable value so a parent re-render does not re-render every consumer\n const contextValue = useMemo<IntlayerValue>(\n () => ({\n locale: resolvedLocale,\n setLocale,\n variant,\n disableEditor,\n }),\n [resolvedLocale, setLocale, variant, disableEditor]\n );\n\n return (\n <IntlayerClientContext.Provider value={contextValue}>\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in React applications.\n *\n * It includes the editor provider by default, allowing for live content editing\n * if configured.\n *\n * @param props - The provider props.\n * @returns The provider component with editor support.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n ...props\n}) => (\n <IntlayerProviderContent {...props}>\n {/* Build flags drop these, and their modules, when the feature is off */}\n {process.env.INTLAYER_EDITOR_ENABLED !== 'false' && <EditorProvider />}\n {process.env.INTLAYER_ANALYTICS_ENABLED !== 'false' && (\n <AnalyticsProvider />\n )}\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;;;;;AAwCA,MAAa,4BAAwBA,qBAA6B;CAEhE,IAAI,SAAS;EACX,OAAOC,mDAAmB,KAAKC,6CAAsB;CACvD;CACA,iBAAiB;CACjB,iBAAiB;AACnB,CAAC;;;;;;AAOD,MAAa,+BAA2BC,kBAAW,qBAAqB,KAAK,CAAC;;;;;;;;;AAuD9E,MAAa,2BAAsD,EACjE,QAAQ,YACR,eAAe,mBACf,SACA,UACA,WAAW,eAC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AErB;CACsB"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
5
5
|
const require_client_useDictionary = require('./useDictionary.cjs');
|
|
6
|
-
let
|
|
6
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
7
7
|
let react = require("react");
|
|
8
8
|
|
|
9
9
|
//#region src/client/useDictionaryAsync.ts
|
|
@@ -14,7 +14,7 @@ let react = require("react");
|
|
|
14
14
|
*/
|
|
15
15
|
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
16
16
|
const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
17
|
-
const localeTarget = (0, react.useMemo)(() => locale ?? currentLocale ??
|
|
17
|
+
const localeTarget = (0, react.useMemo)(() => locale ?? currentLocale ?? (0, _intlayer_core_interpreter.resolveInterpreterLocale)(), [currentLocale, locale]);
|
|
18
18
|
const dictionary = await (0, react.useMemo)(async () => await dictionaryPromise[localeTarget]?.(), [dictionaryPromise, localeTarget]);
|
|
19
19
|
return require_client_useDictionary.useDictionary(dictionary, localeTarget);
|
|
20
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.cjs","names":["useContext","IntlayerClientContext","useMemo","
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["useContext","IntlayerClientContext","useMemo","resolveInterpreterLocale","useDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <\n const T extends Dictionary,\n const L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const localeTarget = useMemo(\n () => locale ?? currentLocale ?? resolveInterpreterLocale(),\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L) as any;\n};\n"],"mappings":";;;;;;;;;;;;;;AAkBA,MAAa,qBAAqB,OAIhC,mBACA,WACe;CACf,MAAM,EAAE,QAAQ,sBAAkBA,kBAAWC,qDAAqB,KAAK,CAAC;CAExE,MAAM,mBAAeC,qBACb,UAAU,qBAAiBC,qDAAyB,GAC1D,CAAC,eAAe,MAAM,CACxB;CAEA,MAAM,aAAa,UAAMD,eACvB,YACG,MAAM,kBACL,aACD,GAAG,GACN,CAAC,mBAAmB,YAAY,CAClC;CAEA,OAAOE,2CAAoB,YAAY,YAAiB;AAC1D"}
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
4
4
|
const require_client_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
5
5
|
const require_getDictionary = require('../getDictionary.cjs');
|
|
6
6
|
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
7
|
-
let
|
|
7
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
8
8
|
let react = require("react");
|
|
9
9
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
10
10
|
|
|
@@ -31,7 +31,7 @@ const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
|
31
31
|
locale: localeOrSelector,
|
|
32
32
|
selector: void 0
|
|
33
33
|
};
|
|
34
|
-
const localeTarget = selectorLocale ?? currentLocale ??
|
|
34
|
+
const localeTarget = selectorLocale ?? currentLocale ?? (0, _intlayer_core_interpreter.resolveInterpreterLocale)();
|
|
35
35
|
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && (0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) return (0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContent)({
|
|
36
36
|
loaderMap: dictionaryPromise,
|
|
37
37
|
key: String(key),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["useContext","IntlayerClientContext","parseDictionarySelector","resolveDictionaryArgument","
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["useContext","IntlayerClientContext","parseDictionarySelector","resolveDictionaryArgument","resolveInterpreterLocale","isQualifiedDynamicLoaderMap","resolveQualifiedDynamicContent","loadDynamicChunk","getDictionary","getPreloadedDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport {\n getPreloadedDictionary,\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryArgument,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'react';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n// `useLoadDynamic` is a suspender cache, not a React hook — aliased to a\n// non-hook name so it can be invoked in loops / conditionally (e.g. when a\n// collection loads several chunks at once).\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Client-side hook that lazily loads a dictionary and returns its content.\n *\n * The dictionary entry is either a plain dynamic loader map\n * (`locale → loader`) or a qualified one (`locale → qualifierId → loader`,\n * tagged with the qualifier dimension). For qualified maps, only the chunk(s)\n * the selector targets are loaded; the resolution mirrors static mode.\n *\n * If the locale is not provided (directly or through the selector), the client\n * context locale is used.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale, variant: contextVariant } =\n useContext(IntlayerClientContext) ?? {};\n\n const { locale: selectorLocale, selector } =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? parseDictionarySelector<LocalesValues>(\n // Layers the provider's ambient variant under the call-site argument\n // before the chunk walk, so only the targeted chunk is loaded.\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey: String(key),\n })\n )\n : {\n locale: localeOrSelector as LocalesValues | undefined,\n selector: undefined,\n };\n\n const localeTarget =\n selectorLocale ?? currentLocale ?? resolveInterpreterLocale();\n\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryPromise)\n ) {\n return resolveQualifiedDynamicContent({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n });\n }\n\n // A build-tool plugin may have started this locale's chunk while the entry\n // point itself was evaluating, in which case the content is already here and\n // reading it must not go through the suspender — see `getPreloadedDictionary`.\n const preloadedDictionary = getPreloadedDictionary(\n dictionaryPromise,\n localeTarget\n );\n if (preloadedDictionary) {\n return getDictionary(preloadedDictionary as T, localeTarget);\n }\n\n const plainLoaders = dictionaryPromise as StrictModeLocaleMap<\n () => Promise<T>\n >;\n\n const dictionary = loadDynamicChunk<T>(\n `${String(key)}.${localeTarget}`,\n plainLoaders[localeTarget as keyof typeof plainLoaders]?.() as Promise<T>\n );\n\n return getDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,eAAe,SAAS,uBACtCA,kBAAWC,qDAAqB,KAAK,CAAC;CAExC,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,QAAQ,IAAI,iCAAiC,cACzCC,kEAGEC,gEAA0B;EACxB;EACA,eAAe;EACf;EACA,eAAe,OAAO,GAAG;CAC3B,CAAC,CACH,IACA;EACE,QAAQ;EACR,UAAU;CACZ;CAEN,MAAM,eACJ,kBAAkB,qBAAiBC,qDAAyB;CAE9D,IACE,QAAQ,IAAI,iCAAiC,eAC7CC,kEAA4B,iBAAiB,GAE7C,WAAOC,qEAA+B;EACpC,WAAW;EACX,KAAK,OAAO,GAAG;EACf,QAAQ;EACR;EACA,YAAY,UAAU,YAAYC,6CAAiB,UAAU,OAAO;EACpE,YAAY,eAAeC,oCAAc,YAAY,YAAY;CACnE,CAAC;CAMH,MAAM,0BAAsBC,6DAC1B,mBACA,YACF;CACA,IAAI,qBACF,OAAOD,oCAAc,qBAA0B,YAAY;CAG7D,MAAM,eAAe;CAIrB,MAAM,aAAaD,6CACjB,GAAG,OAAO,GAAG,EAAE,GAAG,gBAClB,aAAa,aAA0C,GAAG,CAC5D;CAEA,OAAOC,oCAAc,YAAY,YAAY;AAC/C"}
|
package/dist/cjs/plugins.cjs
CHANGED
|
@@ -214,15 +214,16 @@ const pluginsCache = /* @__PURE__ */ new Map();
|
|
|
214
214
|
* This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
|
|
215
215
|
*/
|
|
216
216
|
const getPlugins = (locale, fallback = true) => {
|
|
217
|
-
const
|
|
217
|
+
const currentLocale = (0, _intlayer_core_interpreter.resolveInterpreterLocale)(locale);
|
|
218
|
+
const cacheKey = `${currentLocale}_${fallback}`;
|
|
218
219
|
if (pluginsCache.has(cacheKey)) return pluginsCache.get(cacheKey);
|
|
219
220
|
const enabledPlugins = [
|
|
220
221
|
intlayerNodePlugins,
|
|
221
|
-
(0, _intlayer_core_interpreter.translationPlugin)(
|
|
222
|
+
(0, _intlayer_core_interpreter.translationPlugin)(currentLocale, fallback ? _intlayer_config_built.internationalization.defaultLocale : void 0),
|
|
222
223
|
_intlayer_core_interpreter.enumerationPlugin,
|
|
223
|
-
(0, _intlayer_core_interpreter.pluralPlugin)(
|
|
224
|
+
(0, _intlayer_core_interpreter.pluralPlugin)(currentLocale),
|
|
224
225
|
_intlayer_core_interpreter.conditionPlugin,
|
|
225
|
-
(0, _intlayer_core_interpreter.nestedPlugin)(
|
|
226
|
+
(0, _intlayer_core_interpreter.nestedPlugin)(currentLocale),
|
|
226
227
|
_intlayer_core_interpreter.filePlugin,
|
|
227
228
|
_intlayer_core_interpreter.genderPlugin,
|
|
228
229
|
_intlayer_core_interpreter.selectPlugin,
|
package/dist/cjs/plugins.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.cjs","names":["editor","renderIntlayerNode","ContentSelector","fallbackPlugin","renderReactElement","splitInsertionTemplate","createElement","Fragment","NodeTypes","isInterpolableWrapperNode","transformInterpolableNode","resolveInsertedSelector","useLoadDynamic","getMarkdownMetadata","internationalization","translationPlugin","enumerationPlugin","pluralPlugin","conditionPlugin","nestedPlugin","filePlugin","genderPlugin","selectPlugin"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n resolveInsertedSelector,\n selectPlugin,\n splitInsertionTemplate,\n transformInterpolableNode,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { createElement, type FC, Fragment, type ReactNode } from 'react';\nimport { reportExposure } from './analytics/exposureSink';\nimport { useLoadDynamic } from './client/useLoadDynamic';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\nconst markdownRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false'\n ? import('./markdown/MarkdownRendererPlugin').then(\n (m) => m.MarkdownRendererPlugin\n )\n : null;\n\nconst htmlRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n ? import('./html/HTMLRendererPlugin').then((m) => m.HTMLRendererPlugin)\n : null;\n\n// These preloads are read later by `useLoadDynamic`, so the rejection must stay\n// on the promise: a `.catch()` chained into it would resolve with `undefined`\n// and be mistaken for a loaded module. Handle it on the side instead, so an\n// aborted chunk load never escapes as an unhandled rejection.\nmarkdownRendererModulePromise?.catch(() => {});\nhtmlRendererModulePromise?.catch(() => {});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, props) => {\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: props.dictionaryKey,\n keyPath: props.keyPath,\n locale: props.locale,\n nodeType: 'text',\n });\n }\n\n // Props are only forwarded to the editor selector: copying them for every\n // leaf would cost an allocation per rendered string\n if (process.env.INTLAYER_EDITOR_ENABLED !== 'false' && editor.enabled) {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n return renderIntlayerNode({\n value: rest.children,\n children: <ContentSelector {...rest}>{rest.children}</ContentSelector>,\n });\n }\n\n return renderIntlayerNode({\n value: props.children,\n children: props.children,\n });\n },\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins =\n process.env.INTLAYER_NODE_TYPE_REACT_NODE === 'false'\n ? fallbackPlugin\n : {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'react-node',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n });\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => I extends string\n ? V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : DeepTransformContent<I>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n // React nodes cannot be injected into a raw markup string, so\n // string interpolation (not `splitAndJoinInsertion`) is used here.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n return resolveInsertedSelector(children, result);\n },\n };\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\n >\n : never;\n\nconst MarkdownSuspenseRenderer: FC<Record<string, any>> = ({\n children,\n ...props\n}) => {\n const MarkdownRendererPlugin = useLoadDynamic(\n 'markdown-renderer-plugin',\n markdownRendererModulePromise!\n );\n return createElement(MarkdownRendererPlugin as any, { ...props, children });\n};\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n </ContentSelector>\n ) : (\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n use: render,\n },\n });\n\n return render();\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\nconst HTMLSuspenseRenderer: FC<Record<string, any>> = (props) => {\n const HTMLRendererPlugin = useLoadDynamic(\n 'html-renderer-plugin',\n htmlRendererModulePromise!\n );\n return createElement(HTMLRendererPlugin as any, props);\n};\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </ContentSelector>\n ) : (\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n ),\n additionalProps: { use: render },\n });\n\n return render();\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<T>;\n};\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // First: most nodes are plain strings, which every other plugin rejects\n intlayerNodePlugins,\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n\n filePlugin,\n genderPlugin,\n selectPlugin,\n // Always include: handle React elements\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n // Plugins disabled at build time never match: skip them on every node\n const enabledPlugins = plugins.filter((plugin) => plugin !== fallbackPlugin);\n\n pluginsCache.set(cacheKey, enabledPlugins);\n\n return enabledPlugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAwCA,MAAM,gCACJ,QA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EACA;CAI2B,CAAC,CAAC,QAAQ,WAAW,WAAWnB,yCAAc;CAE3E,aAAa,IAAI,UAAU,cAAc;CAEzC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"plugins.cjs","names":["editor","renderIntlayerNode","ContentSelector","fallbackPlugin","renderReactElement","splitInsertionTemplate","createElement","Fragment","NodeTypes","isInterpolableWrapperNode","transformInterpolableNode","resolveInsertedSelector","useLoadDynamic","getMarkdownMetadata","resolveInterpreterLocale","translationPlugin","internationalization","enumerationPlugin","pluralPlugin","conditionPlugin","nestedPlugin","filePlugin","genderPlugin","selectPlugin"],"sources":["../../src/plugins.tsx"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n resolveInsertedSelector,\n resolveInterpreterLocale,\n selectPlugin,\n splitInsertionTemplate,\n transformInterpolableNode,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { createElement, type FC, Fragment, type ReactNode } from 'react';\nimport { reportExposure } from './analytics/exposureSink';\nimport { useLoadDynamic } from './client/useLoadDynamic';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\nconst markdownRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false'\n ? import('./markdown/MarkdownRendererPlugin').then(\n (m) => m.MarkdownRendererPlugin\n )\n : null;\n\nconst htmlRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n ? import('./html/HTMLRendererPlugin').then((m) => m.HTMLRendererPlugin)\n : null;\n\n// These preloads are read later by `useLoadDynamic`, so the rejection must stay\n// on the promise: a `.catch()` chained into it would resolve with `undefined`\n// and be mistaken for a loaded module. Handle it on the side instead, so an\n// aborted chunk load never escapes as an unhandled rejection.\nmarkdownRendererModulePromise?.catch(() => {});\nhtmlRendererModulePromise?.catch(() => {});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, props) => {\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: props.dictionaryKey,\n keyPath: props.keyPath,\n locale: props.locale,\n nodeType: 'text',\n });\n }\n\n // Props are only forwarded to the editor selector: copying them for every\n // leaf would cost an allocation per rendered string\n if (process.env.INTLAYER_EDITOR_ENABLED !== 'false' && editor.enabled) {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n return renderIntlayerNode({\n value: rest.children,\n children: <ContentSelector {...rest}>{rest.children}</ContentSelector>,\n });\n }\n\n return renderIntlayerNode({\n value: props.children,\n children: props.children,\n });\n },\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins =\n process.env.INTLAYER_NODE_TYPE_REACT_NODE === 'false'\n ? fallbackPlugin\n : {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'react-node',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n });\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => I extends string\n ? V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : DeepTransformContent<I>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n // React nodes cannot be injected into a raw markup string, so\n // string interpolation (not `splitAndJoinInsertion`) is used here.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n return resolveInsertedSelector(children, result);\n },\n };\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\n >\n : never;\n\nconst MarkdownSuspenseRenderer: FC<Record<string, any>> = ({\n children,\n ...props\n}) => {\n const MarkdownRendererPlugin = useLoadDynamic(\n 'markdown-renderer-plugin',\n markdownRendererModulePromise!\n );\n return createElement(MarkdownRendererPlugin as any, { ...props, children });\n};\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n </ContentSelector>\n ) : (\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n use: render,\n },\n });\n\n return render();\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\nconst HTMLSuspenseRenderer: FC<Record<string, any>> = (props) => {\n const HTMLRendererPlugin = useLoadDynamic(\n 'html-renderer-plugin',\n htmlRendererModulePromise!\n );\n return createElement(HTMLRendererPlugin as any, props);\n};\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </ContentSelector>\n ) : (\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n ),\n additionalProps: { use: render },\n });\n\n return render();\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<T>;\n};\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = resolveInterpreterLocale(locale);\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // First: most nodes are plain strings, which every other plugin rejects\n intlayerNodePlugins,\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\n translationPlugin(\n currentLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(currentLocale),\n conditionPlugin,\n nestedPlugin(currentLocale),\n\n filePlugin,\n genderPlugin,\n selectPlugin,\n // Always include: handle React elements\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n // Plugins disabled at build time never match: skip them on every node\n const enabledPlugins = plugins.filter((plugin) => plugin !== fallbackPlugin);\n\n pluginsCache.set(cacheKey, enabledPlugins);\n\n return enabledPlugins;\n};\n"],"mappings":";;;;;;;;;;;;;;;;AAyCA,MAAM,gCACJ,QAAQ,IAAI,gCAAgC,+CACxC,0CAA4C,MACzC,MAAM,EAAE,sBACX,IACA;AAEN,MAAM,4BACJ,QAAQ,IAAI,4BAA4B,+CACpC,kCAAoC,MAAM,MAAM,EAAE,kBAAkB,IACpE;AAMN,+BAA+B,YAAY,CAAC,CAAC;AAC7C,2BAA2B,YAAY,CAAC,CAAC;;AAWzC,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YAAY,OAAO,UAAU;EAG3B,IAAI,QAAQ,IAAI,+BAA+B,SAC7C,8CAAe;GACb,eAAe,MAAM;GACrB,SAAS,MAAM;GACf,QAAQ,MAAM;GACd,UAAU;EACZ,CAAC;EAKH,IAAI,QAAQ,IAAI,4BAA4B,WAAWA,8BAAO,SAAS;GACrE,MAAM,EACJ,SACA,GAAG,SACD;GAEJ,OAAOC,wCAAmB;IACxB,OAAO,KAAK;IACZ,UAAU,2CAACC,gDAAD;KAAiB,GAAI;eAAO,KAAK;IAA0B;GACvE,CAAC;EACH;EAEA,OAAOD,wCAAmB;GACxB,O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ACc,KAEjB,2CAAC,sBAAD;IACE,GAAI;IACE;IACU;GACjB;GAEL,iBAAiB,EAAE,KAAK,OAAO;EACjC,CAAC;EAEH,OAAO,OAAO;CAChB;AACF;AAmCN,MAAM,+BAAe,IAAI,IAAuB;;;;;AAMhD,MAAa,cACX,QACA,WAAoB,SACN;CACd,MAAM,oBAAgBY,qDAAyB,MAAM;CACrD,MAAM,WAAW,GAAG,cAAc,GAAG;CAErC,IAAI,aAAa,IAAI,QAAQ,GAC3B,OAAO,aAAa,IAAI,QAAQ;CA2BlC,MAAM,iBAAiB;EAtBrB;MAEAC,8CACE,eACA,WAAWC,4CAAqB,gBAAgB,MAClD;EACAC;MACAC,yCAAa,aAAa;EAC1BC;MACAC,yCAAa,aAAa;EAE1BC;EACAC;EACAC;EAEA;EACA;EACA;EACA;CAI2B,CAAC,CAAC,QAAQ,WAAW,WAAWpB,yCAAc;CAE3E,aAAa,IAAI,UAAU,cAAc;CAEzC,OAAO;AACT"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_server_serverContext = require('./serverContext.cjs');
|
|
3
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
3
4
|
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
5
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
6
|
|
|
@@ -9,6 +10,7 @@ const { defaultLocale } = _intlayer_config_built.internationalization ?? {};
|
|
|
9
10
|
* Context that store the current locale on the server side
|
|
10
11
|
*/
|
|
11
12
|
const IntlayerServerContext = require_server_serverContext.createServerContext(defaultLocale);
|
|
13
|
+
(0, _intlayer_core_interpreter.registerAmbientLocaleResolver)(() => IntlayerServerContext._storage()?.value);
|
|
12
14
|
/**
|
|
13
15
|
* Context that stores the ambient variant on the server side.
|
|
14
16
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerServerProvider.cjs","names":["internationalization","createServerContext","getServerContext"],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\n\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = internationalization ?? {};\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<LocalesValues>(defaultLocale);\n\n/**\n * Context that stores the ambient variant on the server side.\n *\n * Kept separate from {@link IntlayerServerContext} so the locale context keeps\n * its plain `LocalesValues` shape for the packages already reading it.\n */\nexport const IntlayerServerVariantContext =\n createServerContext<ProviderVariant>(undefined);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\n/**\n * Seeds the request-scoped server context locale imperatively — the equivalent\n * of mounting {@link IntlayerServerProvider} without wrapping the tree.\n *\n * Useful in pages that must stay statically rendered while no ambient\n * request-derived locale source is static-safe (Next.js < 16):\n *\n * ```tsx\n * const Page = async ({ params }) => {\n * const { locale } = await params;\n * setLocale(locale);\n * return <PageContent />;\n * };\n * ```\n */\nexport const setLocale = (locale: LocalesValues): void => {\n IntlayerServerContext._storage().value = locale;\n};\n\n/**\n * Seeds the request-scoped ambient variant imperatively — the equivalent of\n * the `variant` prop of {@link IntlayerServerProvider} without wrapping the\n * tree. See that prop for the accepted shapes.\n */\nexport const setVariant = (variant: ProviderVariant): void => {\n IntlayerServerVariantContext._storage().value = variant;\n};\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension resolved once per request (tenant, school type, plan tier…).\n *\n * Accepts a name (`'school1'`), an ordered preference chain\n * (`['school1', 'default']`), or a per-key map\n * (`{ key1: 'school1', default: 'base' }`). A call-site selector wins.\n */\n variant?: ProviderVariant;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n variant,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n <IntlayerServerVariantContext.Provider value={variant}>\n {children}\n </IntlayerServerVariantContext.Provider>\n </IntlayerServerContext.Provider>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IntlayerServerProvider.cjs","names":["internationalization","createServerContext","registerAmbientLocaleResolver","getServerContext"],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { registerAmbientLocaleResolver } from '@intlayer/core/interpreter';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\n\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = internationalization ?? {};\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<LocalesValues>(defaultLocale);\n\n// Lets a bare `getIntlayer` / `getDictionary` rendered on the server resolve to\n// the locale seeded by `IntlayerServerProvider` / `setLocale`. Read from the\n// store rather than `getServerContext`, whose default locale would shadow the\n// other resolvers.\nregisterAmbientLocaleResolver(() => IntlayerServerContext._storage()?.value);\n\n/**\n * Context that stores the ambient variant on the server side.\n *\n * Kept separate from {@link IntlayerServerContext} so the locale context keeps\n * its plain `LocalesValues` shape for the packages already reading it.\n */\nexport const IntlayerServerVariantContext =\n createServerContext<ProviderVariant>(undefined);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\n/**\n * Seeds the request-scoped server context locale imperatively — the equivalent\n * of mounting {@link IntlayerServerProvider} without wrapping the tree.\n *\n * Useful in pages that must stay statically rendered while no ambient\n * request-derived locale source is static-safe (Next.js < 16):\n *\n * ```tsx\n * const Page = async ({ params }) => {\n * const { locale } = await params;\n * setLocale(locale);\n * return <PageContent />;\n * };\n * ```\n */\nexport const setLocale = (locale: LocalesValues): void => {\n IntlayerServerContext._storage().value = locale;\n};\n\n/**\n * Seeds the request-scoped ambient variant imperatively — the equivalent of\n * the `variant` prop of {@link IntlayerServerProvider} without wrapping the\n * tree. See that prop for the accepted shapes.\n */\nexport const setVariant = (variant: ProviderVariant): void => {\n IntlayerServerVariantContext._storage().value = variant;\n};\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension resolved once per request (tenant, school type, plan tier…).\n *\n * Accepts a name (`'school1'`), an ordered preference chain\n * (`['school1', 'default']`), or a per-key map\n * (`{ key1: 'school1', default: 'base' }`). A call-site selector wins.\n */\n variant?: ProviderVariant;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n variant,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n <IntlayerServerVariantContext.Provider value={variant}>\n {children}\n </IntlayerServerVariantContext.Provider>\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;;;AAUA,MAAM,EAAE,kBAAkBA,+CAAwB,CAAC;;;;AAKnD,MAAa,wBACXC,iDAAmC,aAAa;IAMlDC,gEAAoC,sBAAsB,SAAS,CAAC,EAAE,KAAK;;;;;;;AAQ3E,MAAa,+BACXD,iDAAqC,MAAS;;;;AAKhD,MAAa,oBAAoBE,8CAAiB,qBAAqB;;;;AAKvE,MAAa,SAASA,8CAAiB,qBAAqB;;;;;;;;;;;;;;;;AAiB5D,MAAa,aAAa,WAAgC;CACxD,sBAAsB,SAAS,CAAC,CAAC,QAAQ;AAC3C;;;;;;AAOA,MAAa,cAAc,YAAmC;CAC5D,6BAA6B,SAAS,CAAC,CAAC,QAAQ;AAClD;;;;AAkBA,MAAa,0BAA2D,EACtE,UACA,SAAS,eACT,cAEA,2CAAC,sBAAsB,UAAvB;CAAgC,OAAO;WACrC,2CAAC,6BAA6B,UAA9B;EAAuC,OAAO;EAC3C;CACoC;AACT"}
|
|
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_server_serverContext = require('./serverContext.cjs');
|
|
3
3
|
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
4
4
|
const require_server_useDictionary = require('./useDictionary.cjs');
|
|
5
|
-
let
|
|
5
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
6
6
|
|
|
7
7
|
//#region src/server/useDictionaryAsync.ts
|
|
8
8
|
/**
|
|
@@ -11,7 +11,7 @@ let _intlayer_config_built = require("@intlayer/config/built");
|
|
|
11
11
|
* If the locale is not provided, it will use the locale from the server context
|
|
12
12
|
*/
|
|
13
13
|
const useDictionaryAsync = async (dictionaryPromise, locale, fallbackLocale) => {
|
|
14
|
-
const localeTarget = locale ?? require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext) ?? fallbackLocale ??
|
|
14
|
+
const localeTarget = locale ?? require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext) ?? fallbackLocale ?? (0, _intlayer_core_interpreter.resolveInterpreterLocale)();
|
|
15
15
|
const dictionary = await dictionaryPromise[localeTarget]?.();
|
|
16
16
|
return require_server_useDictionary.useDictionary(dictionary, localeTarget);
|
|
17
17
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.cjs","names":["getServerContext","IntlayerServerContext","
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["getServerContext","IntlayerServerContext","resolveInterpreterLocale","useDictionary"],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n const T extends Dictionary,\n const L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n resolveInterpreterLocale();\n\n const dictionary = await (dictionaryPromise as any)[localeTarget]?.();\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,qBAAqB,OAIhC,mBACA,QACA,mBACG;CACH,MAAM,eACJ,UACAA,8CAAgCC,2DAAqB,KACrD,sBACAC,qDAAyB;CAE3B,MAAM,aAAa,MAAO,kBAA0B,aAAa,GAAG;CAEpE,OAAOC,2CAAoB,YAAY,YAAiB;AAC1D"}
|
|
@@ -3,7 +3,7 @@ const require_getDictionary = require('../getDictionary.cjs');
|
|
|
3
3
|
const require_server_useLoadDynamic = require('./useLoadDynamic.cjs');
|
|
4
4
|
const require_server_serverContext = require('./serverContext.cjs');
|
|
5
5
|
const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.cjs');
|
|
6
|
-
let
|
|
6
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
7
7
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
8
8
|
|
|
9
9
|
//#region src/server/useDictionaryDynamic.ts
|
|
@@ -29,7 +29,7 @@ const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector, fallback
|
|
|
29
29
|
locale: localeOrSelector,
|
|
30
30
|
selector: void 0
|
|
31
31
|
};
|
|
32
|
-
const localeTarget = selectorLocale ?? contextLocale ?? fallbackLocale ??
|
|
32
|
+
const localeTarget = selectorLocale ?? contextLocale ?? fallbackLocale ?? (0, _intlayer_core_interpreter.resolveInterpreterLocale)();
|
|
33
33
|
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && (0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) return (0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContent)({
|
|
34
34
|
loaderMap: dictionaryPromise,
|
|
35
35
|
key: String(key),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getServerContext","IntlayerServerContext","parseDictionarySelector","resolveDictionaryArgument","IntlayerServerVariantContext","
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getServerContext","IntlayerServerContext","parseDictionarySelector","resolveDictionaryArgument","IntlayerServerVariantContext","resolveInterpreterLocale","isQualifiedDynamicLoaderMap","resolveQualifiedDynamicContent","loadDynamicChunk","getDictionary"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryArgument,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n ProviderVariant,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport {\n IntlayerServerContext,\n IntlayerServerVariantContext,\n} from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n// `useLoadDynamic` wraps `react.use`, which may be called in loops /\n// conditionally — aliased to a non-hook name so a collection can load several\n// chunks at once.\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Server-side hook that lazily loads a dictionary and returns its content.\n *\n * The dictionary entry is either a plain dynamic loader map\n * (`locale → loader`) or a qualified one (`locale → qualifierId → loader`,\n * tagged with the qualifier dimension). For qualified maps, only the chunk(s)\n * the selector targets are loaded; the resolution mirrors static mode.\n *\n * If the locale is not provided (directly or through the selector), the server\n * context locale is used.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n const { locale: selectorLocale, selector } =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? parseDictionarySelector<LocalesValues>(\n // Layers the request's ambient variant under the call-site argument\n // before the chunk walk, so only the targeted chunk is loaded.\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale,\n contextVariant: getServerContext<ProviderVariant>(\n IntlayerServerVariantContext\n ),\n dictionaryKey: String(key),\n })\n )\n : {\n locale: localeOrSelector as LocalesValues | undefined,\n selector: undefined,\n };\n\n const localeTarget =\n selectorLocale ??\n contextLocale ??\n fallbackLocale ??\n resolveInterpreterLocale();\n\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryPromise)\n ) {\n return resolveQualifiedDynamicContent({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n });\n }\n\n const plainLoaders = dictionaryPromise as StrictModeLocaleMap<\n () => Promise<T>\n >;\n\n const dictionary = loadDynamicChunk<T>(\n `${String(key)}.${localeTarget}`,\n plainLoaders[localeTarget as keyof typeof plainLoaders]?.() as Promise<T>\n );\n\n return getDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAwCA,MAAa,wBAIX,mBAGA,KACA,kBACA,mBACG;CACH,MAAM,gBAAgBA,8CAAgCC,2DAAqB;CAE3E,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,QAAQ,IAAI,iCAAiC,cACzCC,kEAGEC,gEAA0B;EACxB;EACA;EACA,gBAAgBH,8CACdI,kEACF;EACA,eAAe,OAAO,GAAG;CAC3B,CAAC,CACH,IACA;EACE,QAAQ;EACR,UAAU;CACZ;CAEN,MAAM,eACJ,kBACA,iBACA,sBACAC,qDAAyB;CAE3B,IACE,QAAQ,IAAI,iCAAiC,eAC7CC,kEAA4B,iBAAiB,GAE7C,WAAOC,qEAA+B;EACpC,WAAW;EACX,KAAK,OAAO,GAAG;EACf,QAAQ;EACR;EACA,YAAY,UAAU,YAAYC,6CAAiB,UAAU,OAAO;EACpE,YAAY,eAAeC,oCAAc,YAAY,YAAY;CACnE,CAAC;CAGH,MAAM,eAAe;CAIrB,MAAM,aAAaD,6CACjB,GAAG,OAAO,GAAG,EAAE,GAAG,gBAClB,aAAa,aAA0C,GAAG,CAC5D;CAEA,OAAOC,oCAAc,YAAY,YAAY;AAC/C"}
|
|
@@ -4,7 +4,7 @@ import { EditorProvider } from "../editor/EditorProvider.mjs";
|
|
|
4
4
|
import { getLocaleInStorage, setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
5
5
|
import { AnalyticsProvider } from "../analytics/AnalyticsProvider.mjs";
|
|
6
6
|
import { internationalization } from "@intlayer/config/built";
|
|
7
|
-
import { createContext, useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
7
|
+
import { createContext, startTransition, useCallback, useContext, useDeferredValue, useEffect, useMemo, useState } from "react";
|
|
8
8
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
import { setIntlayerIdentifier } from "@intlayer/config/client";
|
|
10
10
|
import { localeResolver } from "@intlayer/core/localization";
|
|
@@ -36,11 +36,12 @@ const useIntlayerContext = () => useContext(IntlayerClientContext) ?? {};
|
|
|
36
36
|
*/
|
|
37
37
|
const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLocaleProp, variant, children, setLocale: setLocaleProp, disableEditor, isCookieEnabled }) => {
|
|
38
38
|
const { locales: availableLocales, defaultLocale: defaultLocaleConfig } = internationalization ?? {};
|
|
39
|
+
const deferredLocaleProp = useDeferredValue(localeProp);
|
|
39
40
|
const [currentLocale, setCurrentLocale] = useState(() => localeProp ?? getLocaleInStorage() ?? defaultLocaleProp ?? defaultLocaleConfig);
|
|
40
|
-
const [adoptedLocaleProp, setAdoptedLocaleProp] = useState(
|
|
41
|
-
if (
|
|
42
|
-
setAdoptedLocaleProp(
|
|
43
|
-
if (
|
|
41
|
+
const [adoptedLocaleProp, setAdoptedLocaleProp] = useState(deferredLocaleProp);
|
|
42
|
+
if (deferredLocaleProp !== adoptedLocaleProp) {
|
|
43
|
+
setAdoptedLocaleProp(deferredLocaleProp);
|
|
44
|
+
if (deferredLocaleProp && deferredLocaleProp !== currentLocale) setCurrentLocale(deferredLocaleProp);
|
|
44
45
|
}
|
|
45
46
|
useEffect(() => {
|
|
46
47
|
setIntlayerIdentifier();
|
|
@@ -58,7 +59,7 @@ const IntlayerProviderContent = ({ locale: localeProp, defaultLocale: defaultLoc
|
|
|
58
59
|
availableLocales,
|
|
59
60
|
isCookieEnabled
|
|
60
61
|
]);
|
|
61
|
-
const setLocale = setLocaleProp ?? setLocaleBase;
|
|
62
|
+
const setLocale = useCallback((newLocale) => startTransition(() => (setLocaleProp ?? setLocaleBase)(newLocale)), [setLocaleProp, setLocaleBase]);
|
|
62
63
|
const resolvedLocale = localeResolver(currentLocale);
|
|
63
64
|
const contextValue = useMemo(() => ({
|
|
64
65
|
locale: resolvedLocale,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport { AnalyticsProvider } from '../analytics/AnalyticsProvider';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { getLocaleInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n /**\n * Ambient variant applied to every dictionary read below the provider, the\n * same way `locale` is. Overridden per call by an explicit selector.\n */\n variant?: ProviderVariant;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n // Read on demand: only a tree rendered without a provider needs it\n get locale() {\n return getLocaleInStorage() ?? internationalization?.defaultLocale;\n },\n setLocale: () => null,\n isCookieEnabled: true,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext) ?? {};\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension that is fixed for the whole session (tenant, school type, plan\n * tier…) and that therefore no component should have to pass by hand.\n *\n * Accepts three forms:\n * - `variant=\"school1\"` — one named variant for every key\n * - `variant={['school1', 'default']}` — an ordered preference chain: the\n * first variant the key actually declares wins\n * - `variant={{ key1: 'school1', key2: ['school1', 'default'], default: 'base' }}`\n * — per dictionary key, with `default` covering every key not listed\n *\n * A plain object is always read as the per-key map. To pin a structured\n * variant globally, nest it: `variant={{ default: { id: 'prod_abc' } }}`.\n *\n * A call-site selector always wins: `useIntlayer('key', { variant: 'x' })`\n * replaces this default rather than extending it.\n */\n variant?: ProviderVariant;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n variant,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n // Storage is only read when no locale is passed, and only on mount\n const [currentLocale, setCurrentLocale] = useState<LocalesValues>(\n () =>\n localeProp ??\n getLocaleInStorage() ??\n defaultLocaleProp ??\n defaultLocaleConfig\n );\n const [adoptedLocaleProp, setAdoptedLocaleProp]
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport { setIntlayerIdentifier } from '@intlayer/config/client';\nimport { localeResolver } from '@intlayer/core/localization';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n startTransition,\n useCallback,\n useContext,\n useDeferredValue,\n useEffect,\n useMemo,\n useState,\n} from 'react';\nimport { AnalyticsProvider } from '../analytics/AnalyticsProvider';\nimport { EditorProvider } from '../editor/EditorProvider';\nimport { getLocaleInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n /**\n * Ambient variant applied to every dictionary read below the provider, the\n * same way `locale` is. Overridden per call by an explicit selector.\n */\n variant?: ProviderVariant;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n // Read on demand: only a tree rendered without a provider needs it\n get locale() {\n return getLocaleInStorage() ?? internationalization?.defaultLocale;\n },\n setLocale: () => null,\n isCookieEnabled: true,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext) ?? {};\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension that is fixed for the whole session (tenant, school type, plan\n * tier…) and that therefore no component should have to pass by hand.\n *\n * Accepts three forms:\n * - `variant=\"school1\"` — one named variant for every key\n * - `variant={['school1', 'default']}` — an ordered preference chain: the\n * first variant the key actually declares wins\n * - `variant={{ key1: 'school1', key2: ['school1', 'default'], default: 'base' }}`\n * — per dictionary key, with `default` covering every key not listed\n *\n * A plain object is always read as the per-key map. To pin a structured\n * variant globally, nest it: `variant={{ default: { id: 'prod_abc' } }}`.\n *\n * A call-site selector always wins: `useIntlayer('key', { variant: 'x' })`\n * replaces this default rather than extending it.\n */\n variant?: ProviderVariant;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n variant,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n // A router usually changes the prop through a sync update, which would\n // suspend on the new locale's dynamic dictionaries and hide the page behind\n // the Suspense fallback. Deferred, the new locale renders in the background\n // and the current UI stays until it is ready.\n const deferredLocaleProp = useDeferredValue(localeProp);\n\n // Storage is only read when no locale is passed, and only on mount\n const [currentLocale, setCurrentLocale] = useState<LocalesValues>(\n () =>\n localeProp ??\n getLocaleInStorage() ??\n defaultLocaleProp ??\n defaultLocaleConfig\n );\n const [adoptedLocaleProp, setAdoptedLocaleProp] =\n useState(deferredLocaleProp);\n\n // Adopt a new `locale` prop during render rather than in an effect: an\n // effect commits the whole subtree once with the stale locale, then renders\n // it again with the new one.\n if (deferredLocaleProp !== adoptedLocaleProp) {\n setAdoptedLocaleProp(deferredLocaleProp);\n\n if (deferredLocaleProp && deferredLocaleProp !== currentLocale) {\n setCurrentLocale(deferredLocaleProp);\n }\n }\n\n useEffect(() => {\n setIntlayerIdentifier();\n }, []);\n\n const setLocaleBase = useCallback(\n (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale);\n setLocaleInStorage(newLocale, isCookieEnabled);\n },\n [currentLocale, availableLocales, isCookieEnabled]\n );\n\n const setLocale = useCallback(\n (newLocale: LocalesValues) =>\n startTransition(() => (setLocaleProp ?? setLocaleBase)(newLocale)),\n [setLocaleProp, setLocaleBase]\n );\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(currentLocale);\n\n // Stable value so a parent re-render does not re-render every consumer\n const contextValue = useMemo<IntlayerValue>(\n () => ({\n locale: resolvedLocale,\n setLocale,\n variant,\n disableEditor,\n }),\n [resolvedLocale, setLocale, variant, disableEditor]\n );\n\n return (\n <IntlayerClientContext.Provider value={contextValue}>\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in React applications.\n *\n * It includes the editor provider by default, allowing for live content editing\n * if configured.\n *\n * @param props - The provider props.\n * @returns The provider component with editor support.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = ({\n children,\n ...props\n}) => (\n <IntlayerProviderContent {...props}>\n {/* Build flags drop these, and their modules, when the feature is off */}\n {process.env.INTLAYER_EDITOR_ENABLED !== 'false' && <EditorProvider />}\n {process.env.INTLAYER_ANALYTICS_ENABLED !== 'false' && (\n <AnalyticsProvider />\n )}\n {children}\n </IntlayerProviderContent>\n);\n"],"mappings":";;;;;;;;;;;;;;;AAwCA,MAAa,wBAAwB,cAA6B;CAEhE,IAAI,SAAS;EACX,OAAO,mBAAmB,KAAK,sBAAsB;CACvD;CACA,iBAAiB;CACjB,iBAAiB;AACnB,CAAC;;;;;;AAOD,MAAa,2BAA2B,WAAW,qBAAqB,KAAK,CAAC;;;;;;;;;AAuD9E,MAAa,2BAAsD,EACjE,QAAQ,YACR,eAAe,mBACf,SACA,UACA,WAAW,eACX,eACA,sBACI;CACJ,MAAM,EAAE,SAAS,kBAAkB,eAAe,wBAChD,wBAAwB,CAAC;CAM3B,MAAM,qBAAqB,iBAAiB,UAAU;CAGtD,MAAM,CAAC,eAAe,oBAAoB,eAEtC,cACA,mBAAmB,KACnB,qBACA,mBACJ;CACA,MAAM,CAAC,mBAAmB,wBACxB,SAAS,kBAAkB;CAK7B,IAAI,uBAAuB,mBAAmB;EAC5C,qBAAqB,kBAAkB;EAEvC,IAAI,sBAAsB,uBAAuB,eAC/C,iBAAiB,kBAAkB;CAEvC;CAEA,gBAAgB;EACd,sBAAsB;CACxB,GAAG,CAAC,CAAC;CAEL,MAAM,gBAAgB,aACnB,cAA6B;EAC5B,IAAI,cAAc,SAAS,MAAM,UAAU,SAAS,GAAG;EAEvD,IAAI,CAAC,kBAAkB,IAAI,MAAM,CAAC,CAAC,SAAS,SAAS,GAAG;GACtD,QAAQ,MAAM,UAAU,UAAU,kBAAkB;GACpD;EACF;EAEA,iBAAiB,SAAS;EAC1B,mBAAmB,WAAW,eAAe;CAC/C,GACA;EAAC;EAAe;EAAkB;CAAe,CACnD;CAEA,MAAM,YAAY,aACf,cACC,uBAAuB,iBAAiB,cAAa,CAAE,SAAS,CAAC,GACnE,CAAC,eAAe,aAAa,CAC/B;CAGA,MAAM,iBAAiB,eAAe,aAAa;CAGnD,MAAM,eAAe,eACZ;EACL,QAAQ;EACR;EACA;EACA;CACF,IACA;EAAC;EAAgB;EAAW;EAAS;CAAa,CACpD;CAEA,OACE,oBAAC,sBAAsB,UAAvB;EAAgC,OAAO;EACpC;CAC6B;AAEpC;;;;;;;;;;;;;;;;;;;;;AAsBA,MAAa,oBAA+C,EAC1D,UACA,GAAG,YAEH,qBAAC,yBAAD;CAAyB,GAAI;WAA7B;EAEG,QAAQ,IAAI,4BAA4B,WAAW,oBAAC,gBAAD,CAAiB;EACpE,QAAQ,IAAI,+BAA+B,WAC1C,oBAAC,mBAAD,CAAoB;EAErB;CACsB"}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
4
|
import { useDictionary } from "./useDictionary.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
6
6
|
import { useContext, useMemo } from "react";
|
|
7
7
|
|
|
8
8
|
//#region src/client/useDictionaryAsync.ts
|
|
@@ -13,7 +13,7 @@ import { useContext, useMemo } from "react";
|
|
|
13
13
|
*/
|
|
14
14
|
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
15
15
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
16
|
-
const localeTarget = useMemo(() => locale ?? currentLocale ??
|
|
16
|
+
const localeTarget = useMemo(() => locale ?? currentLocale ?? resolveInterpreterLocale(), [currentLocale, locale]);
|
|
17
17
|
const dictionary = await useMemo(async () => await dictionaryPromise[localeTarget]?.(), [dictionaryPromise, localeTarget]);
|
|
18
18
|
return useDictionary(dictionary, localeTarget);
|
|
19
19
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["'use client';\n\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <\n const T extends Dictionary,\n const L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n): Promise<T> => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const localeTarget = useMemo(\n () => locale ?? currentLocale ?? resolveInterpreterLocale(),\n [currentLocale, locale]\n );\n\n const dictionary = await useMemo(\n async () =>\n (await dictionaryPromise[\n localeTarget as keyof typeof dictionaryPromise\n ]?.()) as T,\n [dictionaryPromise, localeTarget]\n );\n\n return useDictionary<T, L>(dictionary, localeTarget as L) as any;\n};\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAa,qBAAqB,OAIhC,mBACA,WACe;CACf,MAAM,EAAE,QAAQ,kBAAkB,WAAW,qBAAqB,KAAK,CAAC;CAExE,MAAM,eAAe,cACb,UAAU,iBAAiB,yBAAyB,GAC1D,CAAC,eAAe,MAAM,CACxB;CAEA,MAAM,aAAa,MAAM,QACvB,YACG,MAAM,kBACL,aACD,GAAG,GACN,CAAC,mBAAmB,YAAY,CAClC;CAEA,OAAO,cAAoB,YAAY,YAAiB;AAC1D"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
4
|
-
import { getDictionary } from "../getDictionary.mjs";
|
|
4
|
+
import { getDictionary as getDictionary$1 } from "../getDictionary.mjs";
|
|
5
5
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
6
|
-
import {
|
|
6
|
+
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
7
7
|
import { useContext } from "react";
|
|
8
8
|
import { getPreloadedDictionary, isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveDictionaryArgument, resolveQualifiedDynamicContent } from "@intlayer/core/dictionaryManipulator";
|
|
9
9
|
|
|
@@ -30,20 +30,20 @@ const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
|
30
30
|
locale: localeOrSelector,
|
|
31
31
|
selector: void 0
|
|
32
32
|
};
|
|
33
|
-
const localeTarget = selectorLocale ?? currentLocale ??
|
|
33
|
+
const localeTarget = selectorLocale ?? currentLocale ?? resolveInterpreterLocale();
|
|
34
34
|
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && isQualifiedDynamicLoaderMap(dictionaryPromise)) return resolveQualifiedDynamicContent({
|
|
35
35
|
loaderMap: dictionaryPromise,
|
|
36
36
|
key: String(key),
|
|
37
37
|
locale: localeTarget,
|
|
38
38
|
selector,
|
|
39
39
|
loadChunk: (cacheKey, promise) => useLoadDynamic(cacheKey, promise),
|
|
40
|
-
transform: (dictionary) => getDictionary(dictionary, localeTarget)
|
|
40
|
+
transform: (dictionary) => getDictionary$1(dictionary, localeTarget)
|
|
41
41
|
});
|
|
42
42
|
const preloadedDictionary = getPreloadedDictionary(dictionaryPromise, localeTarget);
|
|
43
|
-
if (preloadedDictionary) return getDictionary(preloadedDictionary, localeTarget);
|
|
43
|
+
if (preloadedDictionary) return getDictionary$1(preloadedDictionary, localeTarget);
|
|
44
44
|
const plainLoaders = dictionaryPromise;
|
|
45
45
|
const dictionary = useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.());
|
|
46
|
-
return getDictionary(dictionary, localeTarget);
|
|
46
|
+
return getDictionary$1(dictionary, localeTarget);
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport {\n getPreloadedDictionary,\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryArgument,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'react';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n// `useLoadDynamic` is a suspender cache, not a React hook — aliased to a\n// non-hook name so it can be invoked in loops / conditionally (e.g. when a\n// collection loads several chunks at once).\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Client-side hook that lazily loads a dictionary and returns its content.\n *\n * The dictionary entry is either a plain dynamic loader map\n * (`locale → loader`) or a qualified one (`locale → qualifierId → loader`,\n * tagged with the qualifier dimension). For qualified maps, only the chunk(s)\n * the selector targets are loaded; the resolution mirrors static mode.\n *\n * If the locale is not provided (directly or through the selector), the client\n * context locale is used.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const K extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<K> = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale, variant: contextVariant } =\n useContext(IntlayerClientContext) ?? {};\n\n const { locale: selectorLocale, selector } =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? parseDictionarySelector<LocalesValues>(\n // Layers the provider's ambient variant under the call-site argument\n // before the chunk walk, so only the targeted chunk is loaded.\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey: String(key),\n })\n )\n : {\n locale: localeOrSelector as LocalesValues | undefined,\n selector: undefined,\n };\n\n const localeTarget =\n selectorLocale ?? currentLocale ?? resolveInterpreterLocale();\n\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryPromise)\n ) {\n return resolveQualifiedDynamicContent({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n });\n }\n\n // A build-tool plugin may have started this locale's chunk while the entry\n // point itself was evaluating, in which case the content is already here and\n // reading it must not go through the suspender — see `getPreloadedDictionary`.\n const preloadedDictionary = getPreloadedDictionary(\n dictionaryPromise,\n localeTarget\n );\n if (preloadedDictionary) {\n return getDictionary(preloadedDictionary as T, localeTarget);\n }\n\n const plainLoaders = dictionaryPromise as StrictModeLocaleMap<\n () => Promise<T>\n >;\n\n const dictionary = loadDynamicChunk<T>(\n `${String(key)}.${localeTarget}`,\n plainLoaders[localeTarget as keyof typeof plainLoaders]?.() as Promise<T>\n );\n\n return getDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,eAAe,SAAS,mBACtC,WAAW,qBAAqB,KAAK,CAAC;CAExC,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,QAAQ,IAAI,iCAAiC,UACzC,wBAGE,0BAA0B;EACxB;EACA,eAAe;EACf;EACA,eAAe,OAAO,GAAG;CAC3B,CAAC,CACH,IACA;EACE,QAAQ;EACR,UAAU;CACZ;CAEN,MAAM,eACJ,kBAAkB,iBAAiB,yBAAyB;CAE9D,IACE,QAAQ,IAAI,iCAAiC,WAC7C,4BAA4B,iBAAiB,GAE7C,OAAO,+BAA+B;EACpC,WAAW;EACX,KAAK,OAAO,GAAG;EACf,QAAQ;EACR;EACA,YAAY,UAAU,YAAYA,eAAiB,UAAU,OAAO;EACpE,YAAY,eAAeC,gBAAc,YAAY,YAAY;CACnE,CAAC;CAMH,MAAM,sBAAsB,uBAC1B,mBACA,YACF;CACA,IAAI,qBACF,OAAOA,gBAAc,qBAA0B,YAAY;CAG7D,MAAM,eAAe;CAIrB,MAAM,aAAaD,eACjB,GAAG,OAAO,GAAG,EAAE,GAAG,gBAClB,aAAa,aAA0C,GAAG,CAC5D;CAEA,OAAOC,gBAAc,YAAY,YAAY;AAC/C"}
|
package/dist/esm/plugins.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { useLoadDynamic } from "./client/useLoadDynamic.mjs";
|
|
|
3
3
|
import { ContentSelector } from "./editor/ContentSelector.mjs";
|
|
4
4
|
import { renderIntlayerNode } from "./IntlayerNode.mjs";
|
|
5
5
|
import { renderReactElement } from "./reactElement/renderReactElement.mjs";
|
|
6
|
-
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, isInterpolableWrapperNode, nestedPlugin, pluralPlugin, resolveInsertedSelector, selectPlugin, splitInsertionTemplate, transformInterpolableNode, translationPlugin } from "@intlayer/core/interpreter";
|
|
6
|
+
import { conditionPlugin, enumerationPlugin, fallbackPlugin, filePlugin, genderPlugin, isInterpolableWrapperNode, nestedPlugin, pluralPlugin, resolveInsertedSelector, resolveInterpreterLocale, selectPlugin, splitInsertionTemplate, transformInterpolableNode, translationPlugin } from "@intlayer/core/interpreter";
|
|
7
7
|
import { editor, internationalization } from "@intlayer/config/built";
|
|
8
8
|
import { getMarkdownMetadata } from "@intlayer/core/markdown";
|
|
9
9
|
import * as NodeTypes from "@intlayer/types/nodeType";
|
|
@@ -211,15 +211,16 @@ const pluginsCache = /* @__PURE__ */ new Map();
|
|
|
211
211
|
* This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.
|
|
212
212
|
*/
|
|
213
213
|
const getPlugins = (locale, fallback = true) => {
|
|
214
|
-
const
|
|
214
|
+
const currentLocale = resolveInterpreterLocale(locale);
|
|
215
|
+
const cacheKey = `${currentLocale}_${fallback}`;
|
|
215
216
|
if (pluginsCache.has(cacheKey)) return pluginsCache.get(cacheKey);
|
|
216
217
|
const enabledPlugins = [
|
|
217
218
|
intlayerNodePlugins,
|
|
218
|
-
translationPlugin(
|
|
219
|
+
translationPlugin(currentLocale, fallback ? internationalization.defaultLocale : void 0),
|
|
219
220
|
enumerationPlugin,
|
|
220
|
-
pluralPlugin(
|
|
221
|
+
pluralPlugin(currentLocale),
|
|
221
222
|
conditionPlugin,
|
|
222
|
-
nestedPlugin(
|
|
223
|
+
nestedPlugin(currentLocale),
|
|
223
224
|
filePlugin,
|
|
224
225
|
genderPlugin,
|
|
225
226
|
selectPlugin,
|
package/dist/esm/plugins.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.tsx"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n resolveInsertedSelector,\n selectPlugin,\n splitInsertionTemplate,\n transformInterpolableNode,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { createElement, type FC, Fragment, type ReactNode } from 'react';\nimport { reportExposure } from './analytics/exposureSink';\nimport { useLoadDynamic } from './client/useLoadDynamic';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\nconst markdownRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false'\n ? import('./markdown/MarkdownRendererPlugin').then(\n (m) => m.MarkdownRendererPlugin\n )\n : null;\n\nconst htmlRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n ? import('./html/HTMLRendererPlugin').then((m) => m.HTMLRendererPlugin)\n : null;\n\n// These preloads are read later by `useLoadDynamic`, so the rejection must stay\n// on the promise: a `.catch()` chained into it would resolve with `undefined`\n// and be mistaken for a loaded module. Handle it on the side instead, so an\n// aborted chunk load never escapes as an unhandled rejection.\nmarkdownRendererModulePromise?.catch(() => {});\nhtmlRendererModulePromise?.catch(() => {});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, props) => {\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: props.dictionaryKey,\n keyPath: props.keyPath,\n locale: props.locale,\n nodeType: 'text',\n });\n }\n\n // Props are only forwarded to the editor selector: copying them for every\n // leaf would cost an allocation per rendered string\n if (process.env.INTLAYER_EDITOR_ENABLED !== 'false' && editor.enabled) {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n return renderIntlayerNode({\n value: rest.children,\n children: <ContentSelector {...rest}>{rest.children}</ContentSelector>,\n });\n }\n\n return renderIntlayerNode({\n value: props.children,\n children: props.children,\n });\n },\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins =\n process.env.INTLAYER_NODE_TYPE_REACT_NODE === 'false'\n ? fallbackPlugin\n : {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'react-node',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n });\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => I extends string\n ? V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : DeepTransformContent<I>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n // React nodes cannot be injected into a raw markup string, so\n // string interpolation (not `splitAndJoinInsertion`) is used here.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n return resolveInsertedSelector(children, result);\n },\n };\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\n >\n : never;\n\nconst MarkdownSuspenseRenderer: FC<Record<string, any>> = ({\n children,\n ...props\n}) => {\n const MarkdownRendererPlugin = useLoadDynamic(\n 'markdown-renderer-plugin',\n markdownRendererModulePromise!\n );\n return createElement(MarkdownRendererPlugin as any, { ...props, children });\n};\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n </ContentSelector>\n ) : (\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n use: render,\n },\n });\n\n return render();\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\nconst HTMLSuspenseRenderer: FC<Record<string, any>> = (props) => {\n const HTMLRendererPlugin = useLoadDynamic(\n 'html-renderer-plugin',\n htmlRendererModulePromise!\n );\n return createElement(HTMLRendererPlugin as any, props);\n};\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </ContentSelector>\n ) : (\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n ),\n additionalProps: { use: render },\n });\n\n return render();\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<T>;\n};\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = locale ?? internationalization.defaultLocale;\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // First: most nodes are plain strings, which every other plugin rejects\n intlayerNodePlugins,\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\n translationPlugin(\n locale ?? internationalization.defaultLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(locale ?? internationalization.defaultLocale),\n conditionPlugin,\n nestedPlugin(locale ?? internationalization.defaultLocale),\n\n filePlugin,\n genderPlugin,\n selectPlugin,\n // Always include: handle React elements\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n // Plugins disabled at build time never match: skip them on every node\n const enabledPlugins = plugins.filter((plugin) => plugin !== fallbackPlugin);\n\n pluginsCache.set(cacheKey, enabledPlugins);\n\n return enabledPlugins;\n};\n"],"mappings":";;;;;;;;;;;;;AAwCA,MAAM,gCACJ,QAAQ,IAAI,gCAAgC,UACxC,OAAO,wCAAoC,CAAC,MACzC,MAAM,EAAE,sBACX,IACA;AAEN,MAAM,4BACJ,QAAQ,IAAI,4BAA4B,UACpC,OAAO,gCAA4B,CAAC,MAAM,MAAM,EAAE,kBAAkB,IACpE;AAMN,+BAA+B,YAAY,CAAC,CAAC;AAC7C,2BAA2B,YAAY,CAAC,CAAC;;AAWzC,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YAAY,OAAO,UAAU;EAG3B,IAAI,QAAQ,IAAI,+BAA+B,SAC7C,eAAe;GACb,eAAe,MAAM;GACrB,SAAS,MAAM;GACf,QAAQ,MAAM;GACd,UAAU;EACZ,CAAC;EAKH,IAAI,QAAQ,IAAI,4BAA4B,WAAW,OAAO,SAAS;GACrE,MAAM,EACJ,SACA,GAAG,SACD;GAEJ,OAAO,mBAAmB;IACxB,OAAO,KAAK;IACZ,UAAU,oBAAC,iBAAD;KAAiB,GAAI;eAAO,KAAK;IAA0B;GACvE,CAAC;EACH;EAEA,OAAO,mBAAmB;GACxB,OAAO,MAAM;GACb,UAAU,MAAM;EAClB,CAAC;CACH;AACF;;AAcA,MAAa,mBACX,QAAQ,IAAI,kCAAkC,UAC1C,iBACA;CACE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,MAAM,UAAU,eACvB,OAAO,KAAK,QAAQ;CAEtB,YACE,MACA,EACE,SACA,GAAG,WAEF;EACH,IAAI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;CA2BlC,MAAM,iBAAiB;EAtBrB;EAEA,kBACE,UAAU,qBAAqB,eAC/B,WAAW,qBAAqB,gBAAgB,MAClD;EACA;EACA,aAAa,UAAU,qBAAqB,aAAa;EACzD;EACA,aAAa,UAAU,qBAAqB,aAAa;EAEzD;EACA;EACA;EAEA;EACA;EACA;EACA;CAI2B,CAAC,CAAC,QAAQ,WAAW,WAAW,cAAc;CAE3E,aAAa,IAAI,UAAU,cAAc;CAEzC,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"plugins.mjs","names":[],"sources":["../../src/plugins.tsx"],"sourcesContent":["import { editor, internationalization } from '@intlayer/config/built';\nimport {\n conditionPlugin,\n type DeepTransformContent as DeepTransformContentCore,\n enumerationPlugin,\n fallbackPlugin,\n filePlugin,\n genderPlugin,\n type IInterpreterPluginState as IInterpreterPluginStateCore,\n isInterpolableWrapperNode,\n nestedPlugin,\n type Plugins,\n pluralPlugin,\n resolveInsertedSelector,\n resolveInterpreterLocale,\n selectPlugin,\n splitInsertionTemplate,\n transformInterpolableNode,\n translationPlugin,\n} from '@intlayer/core/interpreter';\nimport { getMarkdownMetadata } from '@intlayer/core/markdown';\nimport type {\n HTMLContent,\n InsertionContent,\n MarkdownContent,\n} from '@intlayer/core/transpiler';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport * as NodeTypes from '@intlayer/types/nodeType';\nimport { createElement, type FC, Fragment, type ReactNode } from 'react';\nimport { reportExposure } from './analytics/exposureSink';\nimport { useLoadDynamic } from './client/useLoadDynamic';\nimport { ContentSelector } from './editor/ContentSelector';\nimport type { HTMLComponents } from './html/HTMLComponentTypes';\nimport { type IntlayerNode, renderIntlayerNode } from './IntlayerNode';\nimport { renderReactElement } from './reactElement/renderReactElement';\n\nconst markdownRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN !== 'false'\n ? import('./markdown/MarkdownRendererPlugin').then(\n (m) => m.MarkdownRendererPlugin\n )\n : null;\n\nconst htmlRendererModulePromise =\n process.env.INTLAYER_NODE_TYPE_HTML !== 'false'\n ? import('./html/HTMLRendererPlugin').then((m) => m.HTMLRendererPlugin)\n : null;\n\n// These preloads are read later by `useLoadDynamic`, so the rejection must stay\n// on the promise: a `.catch()` chained into it would resolve with `undefined`\n// and be mistaken for a loaded module. Handle it on the side instead, so an\n// aborted chunk load never escapes as an unhandled rejection.\nmarkdownRendererModulePromise?.catch(() => {});\nhtmlRendererModulePromise?.catch(() => {});\n\n/** ---------------------------------------------\n * INTLAYER NODE PLUGIN\n * --------------------------------------------- */\n\nexport type IntlayerNodeCond<T> = T extends number | string\n ? IntlayerNode<T>\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const intlayerNodePlugins: Plugins = {\n id: 'intlayer-node-plugin',\n canHandle: (node) =>\n typeof node === 'bigint' ||\n typeof node === 'string' ||\n typeof node === 'number',\n transform: (_node, props) => {\n // Node-level analytics: record which content is resolved for display.\n // No-op (and dead-code-eliminated) when analytics is disabled.\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: props.dictionaryKey,\n keyPath: props.keyPath,\n locale: props.locale,\n nodeType: 'text',\n });\n }\n\n // Props are only forwarded to the editor selector: copying them for every\n // leaf would cost an allocation per rendered string\n if (process.env.INTLAYER_EDITOR_ENABLED !== 'false' && editor.enabled) {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n return renderIntlayerNode({\n value: rest.children,\n children: <ContentSelector {...rest}>{rest.children}</ContentSelector>,\n });\n }\n\n return renderIntlayerNode({\n value: props.children,\n children: props.children,\n });\n },\n};\n\n/** ---------------------------------------------\n * REACT NODE PLUGIN\n * --------------------------------------------- */\n\nexport type ReactNodeCond<T> = T extends {\n props: any;\n key: any;\n}\n ? ReactNode\n : never;\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const reactNodePlugins: Plugins =\n process.env.INTLAYER_NODE_TYPE_REACT_NODE === 'false'\n ? fallbackPlugin\n : {\n id: 'react-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' &&\n typeof node?.props !== 'undefined' &&\n typeof node.key !== 'undefined',\n\n transform: (\n node,\n {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n }\n ) => {\n if (process.env.INTLAYER_ANALYTICS_ENABLED !== 'false') {\n reportExposure({\n dictionaryKey: rest.dictionaryKey,\n keyPath: rest.keyPath,\n locale: rest.locale,\n nodeType: 'react-node',\n });\n }\n\n return renderIntlayerNode({\n ...rest,\n value: '[[react-element]]',\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n {renderReactElement(node)}\n </ContentSelector>\n ) : (\n renderReactElement(node)\n ),\n });\n },\n };\n\n/** ---------------------------------------------\n * INSERTION PLUGIN\n * --------------------------------------------- */\n\nexport type InsertionCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.INSERTION]: infer I;\n fields: readonly string[];\n}\n ? <V extends { [K in T['fields'][number]]: ReactNode }>(\n values: V\n ) => I extends string\n ? V[keyof V] extends string | number\n ? IntlayerNode<string>\n : IntlayerNode<ReactNode>\n : DeepTransformContent<I>\n : never;\n\n/**\n * Split insertion string and join with React nodes using shared core logic\n */\nconst splitAndJoinInsertion = (\n template: string,\n values: Record<string, string | number | ReactNode>\n): ReactNode => {\n const result = splitInsertionTemplate(template, values);\n\n if (result.isSimple) {\n // Simple string replacement\n return result.parts as string;\n }\n\n // Return as Fragment with proper keys\n return createElement(\n Fragment,\n null,\n ...(result.parts as any[]).map((part, index) =>\n createElement(Fragment, { key: index }, part)\n )\n );\n};\n\n/** Insertion plugin for React. Handles component/node insertion. */\nexport const insertionPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_INSERTION === 'false'\n ? fallbackPlugin\n : {\n id: 'insertion-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.INSERTION,\n transform: (node: InsertionContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.INSERTION,\n },\n ];\n\n const children = node[NodeTypes.INSERTION];\n\n /** Insertion string plugin. Replaces string node with a component that render the insertion. */\n const insertionStringPlugin: Plugins = {\n id: 'insertion-string-plugin',\n canHandle: (node) =>\n typeof node === 'string' || isInterpolableWrapperNode(node),\n transform: (node, subProps, deepTransformNode) => {\n // `html()`/`markdown()` nodes carry their `{{ … }}` placeholders\n // inside a raw string. Interpolate into that string, then re-run\n // the transform so the html/markdown renderer applies afterwards.\n // React nodes cannot be injected into a raw markup string, so\n // string interpolation (not `splitAndJoinInsertion`) is used here.\n if (isInterpolableWrapperNode(node)) {\n return (\n values: {\n [K in InsertionContent['fields'][number]]: string | number;\n }\n ) =>\n transformInterpolableNode(\n node,\n values,\n subProps,\n props.plugins,\n deepTransformNode\n );\n }\n\n const transformedResult = deepTransformNode(node, {\n ...subProps,\n children: node,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'intlayer-node-plugin'\n ),\n ],\n });\n\n return (\n values: {\n [K in InsertionContent['fields'][number]]:\n | string\n | number\n | ReactNode;\n }\n ) => {\n const result = splitAndJoinInsertion(transformedResult, values);\n\n return deepTransformNode(result, {\n ...subProps,\n plugins: props.plugins,\n children: result,\n });\n };\n },\n };\n\n const result = deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [insertionStringPlugin, ...(props.plugins ?? [])],\n });\n\n return resolveInsertedSelector(children, result);\n },\n };\n\n/**\n * MARKDOWN PLUGIN\n */\n\nexport type MarkdownStringCond<T> = T extends string\n ? IntlayerNode<\n string,\n {\n metadata: DeepTransformContent<string>;\n use: (components: HTMLComponents<'permissive', {}>) => ReactNode;\n }\n >\n : never;\n\nconst MarkdownSuspenseRenderer: FC<Record<string, any>> = ({\n children,\n ...props\n}) => {\n const MarkdownRendererPlugin = useLoadDynamic(\n 'markdown-renderer-plugin',\n markdownRendererModulePromise!\n );\n return createElement(MarkdownRendererPlugin as any, { ...props, children });\n};\n\n/** Markdown string plugin. Replaces string node with a component that render the markdown. */\nexport const markdownStringPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-string-plugin',\n canHandle: (node) => typeof node === 'string',\n transform: (node: string, props, deepTransformNode) => {\n const {\n plugins, // Removed to avoid next error - Functions cannot be passed directly to Client Components\n ...rest\n } = props;\n\n const metadata = getMarkdownMetadata(node) ?? {};\n\n const metadataPlugins: Plugins = {\n id: 'markdown-metadata-plugin',\n canHandle: (metadataNode) =>\n typeof metadataNode === 'string' ||\n typeof metadataNode === 'number' ||\n typeof metadataNode === 'boolean' ||\n !metadataNode,\n transform: (metadataNode, props) =>\n renderIntlayerNode({\n ...props,\n value: metadataNode,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>{node}</ContentSelector>\n ) : (\n node\n ),\n }),\n };\n\n // Transform metadata while keeping the same structure\n const metadataNodes = deepTransformNode(metadata, {\n plugins: [metadataPlugins],\n dictionaryKey: rest.dictionaryKey,\n keyPath: [],\n });\n\n const render = (components?: HTMLComponents) =>\n renderIntlayerNode({\n ...props,\n value: node,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n </ContentSelector>\n ) : (\n <MarkdownSuspenseRenderer {...rest} components={components}>\n {node}\n </MarkdownSuspenseRenderer>\n ),\n additionalProps: {\n metadata: metadataNodes,\n use: render,\n },\n });\n\n return render();\n },\n };\n\nexport type MarkdownCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.MARKDOWN]: infer M;\n tags?: infer U;\n metadata?: infer V;\n}\n ? IntlayerNode<\n M,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n metadata: DeepTransformContent<V>;\n }\n >\n : never;\n\nexport const markdownPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_MARKDOWN === 'false'\n ? fallbackPlugin\n : {\n id: 'markdown-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.MARKDOWN,\n transform: (node: MarkdownContent, props, deepTransformNode) => {\n const newKeyPath: KeyPath[] = [\n ...props.keyPath,\n {\n type: NodeTypes.MARKDOWN,\n },\n ];\n\n const children = node[NodeTypes.MARKDOWN];\n\n return deepTransformNode(children, {\n ...props,\n children,\n keyPath: newKeyPath,\n plugins: [markdownStringPlugin, ...(props.plugins ?? [])],\n });\n },\n };\n\n/** ---------------------------------------------\n * HTML PLUGIN\n * --------------------------------------------- */\n\n/**\n * HTML conditional type that enforces:\n * - All components (Standard or Custom) are OPTIONAL in the `use()` method.\n * - Custom components props are strictly inferred from the dictionary definition.\n *\n * This ensures type safety:\n * - `html('<div>Hello <CustomComponent /></div>').use({ CustomComponent: ... })` - optional but typed\n */\nexport type HTMLPluginCond<T> = T extends {\n nodeType: NodeType | string;\n [NodeTypes.HTML]: infer I;\n tags?: infer U;\n}\n ? IntlayerNode<\n I,\n {\n use: (components?: HTMLComponents<'permissive', U>) => ReactNode;\n }\n >\n : never;\n\nconst HTMLSuspenseRenderer: FC<Record<string, any>> = (props) => {\n const HTMLRendererPlugin = useLoadDynamic(\n 'html-renderer-plugin',\n htmlRendererModulePromise!\n );\n return createElement(HTMLRendererPlugin as any, props);\n};\n\n/** HTML plugin. Replaces node with a function that takes components => ReactNode. */\nexport const htmlPlugin: Plugins =\n process.env.INTLAYER_NODE_TYPE_HTML === 'false'\n ? fallbackPlugin\n : {\n id: 'html-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeTypes.HTML,\n\n transform: (node: HTMLContent<string>, props) => {\n const html = node[NodeTypes.HTML];\n const { plugins, ...rest } = props;\n\n // Type-safe render function that accepts properly typed components\n const render = (userComponents?: HTMLComponents): ReactNode =>\n renderIntlayerNode({\n ...rest,\n value: html,\n children:\n process.env.INTLAYER_EDITOR_ENABLED !== 'false' &&\n editor.enabled ? (\n <ContentSelector {...rest}>\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n </ContentSelector>\n ) : (\n <HTMLSuspenseRenderer\n {...rest}\n html={html}\n userComponents={userComponents}\n />\n ),\n additionalProps: { use: render },\n });\n\n return render();\n },\n };\n\n/** ---------------------------------------------\n * PLUGINS RESULT\n * --------------------------------------------- */\n\nexport type IInterpreterPluginReact<T, _S, _L extends LocalesValues> = {\n reactNode: ReactNodeCond<T>;\n reactIntlayerNode: IntlayerNodeCond<T>;\n reactInsertion: InsertionCond<T>;\n reactMarkdown: MarkdownCond<T>;\n reactHtml: HTMLPluginCond<T>;\n};\n\n/**\n * Insert this type as param of `DeepTransformContent` to avoid `intlayer` package pollution.\n *\n * Otherwise the the `react-intlayer` plugins will override the types of `intlayer` functions.\n */\nexport type IInterpreterPluginState = Omit<\n IInterpreterPluginStateCore,\n 'insertion' // Remove insertion type from core package\n> & {\n reactNode: true;\n reactIntlayerNode: true;\n reactMarkdown: true;\n reactHtml: true;\n reactInsertion: true;\n};\n\nexport type DeepTransformContent<\n T,\n L extends LocalesValues = DeclaredLocales,\n> = DeepTransformContentCore<T, IInterpreterPluginState, L>;\n\nconst pluginsCache = new Map<string, Plugins[]>();\n\n/**\n * Get the plugins array for React content transformation.\n * This function is used by both getIntlayer and getDictionary to ensure consistent plugin configuration.\n */\nexport const getPlugins = (\n locale?: LocalesValues,\n fallback: boolean = true\n): Plugins[] => {\n const currentLocale = resolveInterpreterLocale(locale);\n const cacheKey = `${currentLocale}_${fallback}`;\n\n if (pluginsCache.has(cacheKey)) {\n return pluginsCache.get(cacheKey)!;\n }\n\n const plugins = [\n // First: most nodes are plain strings, which every other plugin rejects\n intlayerNodePlugins,\n // Env var allows the bundler to to remove the plugin if not used to make the bundle smaller\n translationPlugin(\n currentLocale,\n fallback ? internationalization.defaultLocale : undefined\n ),\n enumerationPlugin,\n pluralPlugin(currentLocale),\n conditionPlugin,\n nestedPlugin(currentLocale),\n\n filePlugin,\n genderPlugin,\n selectPlugin,\n // Always include: handle React elements\n reactNodePlugins,\n insertionPlugin,\n markdownPlugin,\n htmlPlugin,\n ] as Plugins[];\n\n // Plugins disabled at build time never match: skip them on every node\n const enabledPlugins = plugins.filter((plugin) => plugin !== fallbackPlugin);\n\n pluginsCache.set(cacheKey, enabledPlugins);\n\n return enabledPlugins;\n};\n"],"mappings":";;;;;;;;;;;;;AAyCA,MAAM,gCACJ,QAAQ,IAAI,gCAAgC,UACxC,OAAO,wCAAoC,CAAC,MACzC,MAAM,EAAE,sBACX,IACA;AAEN,MAAM,4BACJ,QAAQ,IAAI,4BAA4B,UACpC,OAAO,gCAA4B,CAAC,MAAM,MAAM,EAAE,kBAAkB,IACpE;AAMN,+BAA+B,YAAY,CAAC,CAAC;AAC7C,2BAA2B,YAAY,CAAC,CAAC;;AAWzC,MAAa,sBAA+B;CAC1C,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAChB,OAAO,SAAS,YAChB,OAAO,SAAS;CAClB,YAAY,OAAO,UAAU;EAG3B,IAAI,QAAQ,IAAI,+BAA+B,SAC7C,eAAe;GACb,eAAe,MAAM;GACrB,SAAS,MAAM;GACf,QAAQ,MAAM;GACd,UAAU;EACZ,CAAC;EAKH,IAAI,QAAQ,IAAI,4BAA4B,WAAW,OAAO,SAAS;GACrE,MAAM,EACJ,SACA,GAAG,SACD;GAEJ,OAAO,mBAAmB;IACxB,OAAO,KAAK;IACZ,UAAU,oBAAC,iBAAD;KAAiB,GAAI;eAAO,KAAK;IAA0B;GACvE,CAAC;EACH;EAEA,OAAO,mBAAmB;GACxB,OAAO,MAAM;GACb,UAAU,MA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C;EAEH,OAAO,OAAO;CAChB;AACF;AAmCN,MAAM,+BAAe,IAAI,IAAuB;;;;;AAMhD,MAAa,cACX,QACA,WAAoB,SACN;CACd,MAAM,gBAAgB,yBAAyB,MAAM;CACrD,MAAM,WAAW,GAAG,cAAc,GAAG;CAErC,IAAI,aAAa,IAAI,QAAQ,GAC3B,OAAO,aAAa,IAAI,QAAQ;CA2BlC,MAAM,iBAAiB;EAtBrB;EAEA,kBACE,eACA,WAAW,qBAAqB,gBAAgB,MAClD;EACA;EACA,aAAa,aAAa;EAC1B;EACA,aAAa,aAAa;EAE1B;EACA;EACA;EAEA;EACA;EACA;EACA;CAI2B,CAAC,CAAC,QAAQ,WAAW,WAAW,cAAc;CAE3E,aAAa,IAAI,UAAU,cAAc;CAEzC,OAAO;AACT"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createServerContext, getServerContext } from "./serverContext.mjs";
|
|
2
|
+
import { registerAmbientLocaleResolver } from "@intlayer/core/interpreter";
|
|
2
3
|
import { internationalization } from "@intlayer/config/built";
|
|
3
4
|
import { jsx } from "react/jsx-runtime";
|
|
4
5
|
|
|
@@ -8,6 +9,7 @@ const { defaultLocale } = internationalization ?? {};
|
|
|
8
9
|
* Context that store the current locale on the server side
|
|
9
10
|
*/
|
|
10
11
|
const IntlayerServerContext = createServerContext(defaultLocale);
|
|
12
|
+
registerAmbientLocaleResolver(() => IntlayerServerContext._storage()?.value);
|
|
11
13
|
/**
|
|
12
14
|
* Context that stores the ambient variant on the server side.
|
|
13
15
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerServerProvider.mjs","names":[],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\n\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = internationalization ?? {};\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<LocalesValues>(defaultLocale);\n\n/**\n * Context that stores the ambient variant on the server side.\n *\n * Kept separate from {@link IntlayerServerContext} so the locale context keeps\n * its plain `LocalesValues` shape for the packages already reading it.\n */\nexport const IntlayerServerVariantContext =\n createServerContext<ProviderVariant>(undefined);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\n/**\n * Seeds the request-scoped server context locale imperatively — the equivalent\n * of mounting {@link IntlayerServerProvider} without wrapping the tree.\n *\n * Useful in pages that must stay statically rendered while no ambient\n * request-derived locale source is static-safe (Next.js < 16):\n *\n * ```tsx\n * const Page = async ({ params }) => {\n * const { locale } = await params;\n * setLocale(locale);\n * return <PageContent />;\n * };\n * ```\n */\nexport const setLocale = (locale: LocalesValues): void => {\n IntlayerServerContext._storage().value = locale;\n};\n\n/**\n * Seeds the request-scoped ambient variant imperatively — the equivalent of\n * the `variant` prop of {@link IntlayerServerProvider} without wrapping the\n * tree. See that prop for the accepted shapes.\n */\nexport const setVariant = (variant: ProviderVariant): void => {\n IntlayerServerVariantContext._storage().value = variant;\n};\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension resolved once per request (tenant, school type, plan tier…).\n *\n * Accepts a name (`'school1'`), an ordered preference chain\n * (`['school1', 'default']`), or a per-key map\n * (`{ key1: 'school1', default: 'base' }`). A call-site selector wins.\n */\n variant?: ProviderVariant;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n variant,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n <IntlayerServerVariantContext.Provider value={variant}>\n {children}\n </IntlayerServerVariantContext.Provider>\n </IntlayerServerContext.Provider>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IntlayerServerProvider.mjs","names":[],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport { registerAmbientLocaleResolver } from '@intlayer/core/interpreter';\nimport type {\n LocalesValues,\n ProviderVariant,\n} from '@intlayer/types/module_augmentation';\n\nimport type { FC, PropsWithChildren } from 'react';\nimport { createServerContext, getServerContext } from './serverContext';\n\nconst { defaultLocale } = internationalization ?? {};\n\n/**\n * Context that store the current locale on the server side\n */\nexport const IntlayerServerContext =\n createServerContext<LocalesValues>(defaultLocale);\n\n// Lets a bare `getIntlayer` / `getDictionary` rendered on the server resolve to\n// the locale seeded by `IntlayerServerProvider` / `setLocale`. Read from the\n// store rather than `getServerContext`, whose default locale would shadow the\n// other resolvers.\nregisterAmbientLocaleResolver(() => IntlayerServerContext._storage()?.value);\n\n/**\n * Context that stores the ambient variant on the server side.\n *\n * Kept separate from {@link IntlayerServerContext} so the locale context keeps\n * its plain `LocalesValues` shape for the packages already reading it.\n */\nexport const IntlayerServerVariantContext =\n createServerContext<ProviderVariant>(undefined);\n\n/**\n * Hook that provides the current locale\n */\nexport const useIntlayer = () => getServerContext(IntlayerServerContext);\n\n/**\n * Get the current locale\n */\nexport const locale = getServerContext(IntlayerServerContext);\n\n/**\n * Seeds the request-scoped server context locale imperatively — the equivalent\n * of mounting {@link IntlayerServerProvider} without wrapping the tree.\n *\n * Useful in pages that must stay statically rendered while no ambient\n * request-derived locale source is static-safe (Next.js < 16):\n *\n * ```tsx\n * const Page = async ({ params }) => {\n * const { locale } = await params;\n * setLocale(locale);\n * return <PageContent />;\n * };\n * ```\n */\nexport const setLocale = (locale: LocalesValues): void => {\n IntlayerServerContext._storage().value = locale;\n};\n\n/**\n * Seeds the request-scoped ambient variant imperatively — the equivalent of\n * the `variant` prop of {@link IntlayerServerProvider} without wrapping the\n * tree. See that prop for the accepted shapes.\n */\nexport const setVariant = (variant: ProviderVariant): void => {\n IntlayerServerVariantContext._storage().value = variant;\n};\n\nexport type IntlayerServerProviderProps = PropsWithChildren & {\n locale?: LocalesValues;\n /**\n * Ambient variant applied to every dictionary read below this provider — for\n * a dimension resolved once per request (tenant, school type, plan tier…).\n *\n * Accepts a name (`'school1'`), an ordered preference chain\n * (`['school1', 'default']`), or a per-key map\n * (`{ key1: 'school1', default: 'base' }`). A call-site selector wins.\n */\n variant?: ProviderVariant;\n};\n\n/**\n * Provider that store the current locale on the server side\n */\nexport const IntlayerServerProvider: FC<IntlayerServerProviderProps> = ({\n children,\n locale = defaultLocale,\n variant,\n}) => (\n <IntlayerServerContext.Provider value={locale}>\n <IntlayerServerVariantContext.Provider value={variant}>\n {children}\n </IntlayerServerVariantContext.Provider>\n </IntlayerServerContext.Provider>\n);\n"],"mappings":";;;;;;AAUA,MAAM,EAAE,kBAAkB,wBAAwB,CAAC;;;;AAKnD,MAAa,wBACX,oBAAmC,aAAa;AAMlD,oCAAoC,sBAAsB,SAAS,CAAC,EAAE,KAAK;;;;;;;AAQ3E,MAAa,+BACX,oBAAqC,MAAS;;;;AAKhD,MAAa,oBAAoB,iBAAiB,qBAAqB;;;;AAKvE,MAAa,SAAS,iBAAiB,qBAAqB;;;;;;;;;;;;;;;;AAiB5D,MAAa,aAAa,WAAgC;CACxD,sBAAsB,SAAS,CAAC,CAAC,QAAQ;AAC3C;;;;;;AAOA,MAAa,cAAc,YAAmC;CAC5D,6BAA6B,SAAS,CAAC,CAAC,QAAQ;AAClD;;;;AAkBA,MAAa,0BAA2D,EACtE,UACA,SAAS,eACT,cAEA,oBAAC,sBAAsB,UAAvB;CAAgC,OAAO;WACrC,oBAAC,6BAA6B,UAA9B;EAAuC,OAAO;EAC3C;CACoC;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { getServerContext } from "./serverContext.mjs";
|
|
2
2
|
import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
3
3
|
import { useDictionary } from "./useDictionary.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
5
5
|
|
|
6
6
|
//#region src/server/useDictionaryAsync.ts
|
|
7
7
|
/**
|
|
@@ -10,7 +10,7 @@ import { internationalization } from "@intlayer/config/built";
|
|
|
10
10
|
* If the locale is not provided, it will use the locale from the server context
|
|
11
11
|
*/
|
|
12
12
|
const useDictionaryAsync = async (dictionaryPromise, locale, fallbackLocale) => {
|
|
13
|
-
const localeTarget = locale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale ??
|
|
13
|
+
const localeTarget = locale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale ?? resolveInterpreterLocale();
|
|
14
14
|
const dictionary = await dictionaryPromise[localeTarget]?.();
|
|
15
15
|
return useDictionary(dictionary, localeTarget);
|
|
16
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\nimport { useDictionary } from './useDictionary';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n const T extends Dictionary,\n const L extends LocalesValues = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L,\n fallbackLocale?: DeclaredLocales\n) => {\n const localeTarget =\n locale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n resolveInterpreterLocale();\n\n const dictionary = await (dictionaryPromise as any)[localeTarget]?.();\n\n return useDictionary<T, L>(dictionary, localeTarget as L);\n};\n"],"mappings":";;;;;;;;;;;AAgBA,MAAa,qBAAqB,OAIhC,mBACA,QACA,mBACG;CACH,MAAM,eACJ,UACA,iBAAgC,qBAAqB,KACrD,kBACA,yBAAyB;CAE3B,MAAM,aAAa,MAAO,kBAA0B,aAAa,GAAG;CAEpE,OAAO,cAAoB,YAAY,YAAiB;AAC1D"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { getDictionary } from "../getDictionary.mjs";
|
|
1
|
+
import { getDictionary as getDictionary$1 } from "../getDictionary.mjs";
|
|
2
2
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
3
3
|
import { getServerContext } from "./serverContext.mjs";
|
|
4
4
|
import { IntlayerServerContext, IntlayerServerVariantContext } from "./IntlayerServerProvider.mjs";
|
|
5
|
-
import {
|
|
5
|
+
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
6
6
|
import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveDictionaryArgument, resolveQualifiedDynamicContent } from "@intlayer/core/dictionaryManipulator";
|
|
7
7
|
|
|
8
8
|
//#region src/server/useDictionaryDynamic.ts
|
|
@@ -28,18 +28,18 @@ const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector, fallback
|
|
|
28
28
|
locale: localeOrSelector,
|
|
29
29
|
selector: void 0
|
|
30
30
|
};
|
|
31
|
-
const localeTarget = selectorLocale ?? contextLocale ?? fallbackLocale ??
|
|
31
|
+
const localeTarget = selectorLocale ?? contextLocale ?? fallbackLocale ?? resolveInterpreterLocale();
|
|
32
32
|
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && isQualifiedDynamicLoaderMap(dictionaryPromise)) return resolveQualifiedDynamicContent({
|
|
33
33
|
loaderMap: dictionaryPromise,
|
|
34
34
|
key: String(key),
|
|
35
35
|
locale: localeTarget,
|
|
36
36
|
selector,
|
|
37
37
|
loadChunk: (cacheKey, promise) => useLoadDynamic(cacheKey, promise),
|
|
38
|
-
transform: (dictionary) => getDictionary(dictionary, localeTarget)
|
|
38
|
+
transform: (dictionary) => getDictionary$1(dictionary, localeTarget)
|
|
39
39
|
});
|
|
40
40
|
const plainLoaders = dictionaryPromise;
|
|
41
41
|
const dictionary = useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.());
|
|
42
|
-
return getDictionary(dictionary, localeTarget);
|
|
42
|
+
return getDictionary$1(dictionary, localeTarget);
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk","getDictionary"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryArgument,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n ProviderVariant,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport {\n IntlayerServerContext,\n IntlayerServerVariantContext,\n} from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n// `useLoadDynamic` wraps `react.use`, which may be called in loops /\n// conditionally — aliased to a non-hook name so a collection can load several\n// chunks at once.\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Server-side hook that lazily loads a dictionary and returns its content.\n *\n * The dictionary entry is either a plain dynamic loader map\n * (`locale → loader`) or a qualified one (`locale → qualifierId → loader`,\n * tagged with the qualifier dimension). For qualified maps, only the chunk(s)\n * the selector targets are loaded; the resolution mirrors static mode.\n *\n * If the locale is not provided (directly or through the selector), the server\n * context locale is used.\n */\nexport const useDictionaryDynamic = <\n const T extends Dictionary,\n const A extends LocalesValues | DictionarySelector = DeclaredLocales,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale = getServerContext<LocalesValues>(IntlayerServerContext);\n\n const { locale: selectorLocale, selector } =\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false'\n ? parseDictionarySelector<LocalesValues>(\n // Layers the request's ambient variant under the call-site argument\n // before the chunk walk, so only the targeted chunk is loaded.\n resolveDictionaryArgument({\n localeOrSelector,\n contextLocale,\n contextVariant: getServerContext<ProviderVariant>(\n IntlayerServerVariantContext\n ),\n dictionaryKey: String(key),\n })\n )\n : {\n locale: localeOrSelector as LocalesValues | undefined,\n selector: undefined,\n };\n\n const localeTarget =\n selectorLocale ??\n contextLocale ??\n fallbackLocale ??\n resolveInterpreterLocale();\n\n if (\n process.env.INTLAYER_DICTIONARY_SELECTOR !== 'false' &&\n isQualifiedDynamicLoaderMap(dictionaryPromise)\n ) {\n return resolveQualifiedDynamicContent({\n loaderMap: dictionaryPromise,\n key: String(key),\n locale: localeTarget,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary) => getDictionary(dictionary, localeTarget),\n });\n }\n\n const plainLoaders = dictionaryPromise as StrictModeLocaleMap<\n () => Promise<T>\n >;\n\n const dictionary = loadDynamicChunk<T>(\n `${String(key)}.${localeTarget}`,\n plainLoaders[localeTarget as keyof typeof plainLoaders]?.() as Promise<T>\n );\n\n return getDictionary(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwCA,MAAa,wBAIX,mBAGA,KACA,kBACA,mBACG;CACH,MAAM,gBAAgB,iBAAgC,qBAAqB;CAE3E,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,QAAQ,IAAI,iCAAiC,UACzC,wBAGE,0BAA0B;EACxB;EACA;EACA,gBAAgB,iBACd,4BACF;EACA,eAAe,OAAO,GAAG;CAC3B,CAAC,CACH,IACA;EACE,QAAQ;EACR,UAAU;CACZ;CAEN,MAAM,eACJ,kBACA,iBACA,kBACA,yBAAyB;CAE3B,IACE,QAAQ,IAAI,iCAAiC,WAC7C,4BAA4B,iBAAiB,GAE7C,OAAO,+BAA+B;EACpC,WAAW;EACX,KAAK,OAAO,GAAG;EACf,QAAQ;EACR;EACA,YAAY,UAAU,YAAYA,eAAiB,UAAU,OAAO;EACpE,YAAY,eAAeC,gBAAc,YAAY,YAAY;CACnE,CAAC;CAGH,MAAM,eAAe;CAIrB,MAAM,aAAaD,eACjB,GAAG,OAAO,GAAG,EAAE,GAAG,gBAClB,aAAa,aAA0C,GAAG,CAC5D;CAEA,OAAOC,gBAAc,YAAY,YAAY;AAC/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.d.ts","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.d.ts","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"mappings":";;;KAyBK;EACH,QAAQ;EACR,YAAY,WAAW;;;;;EAKvB,UAAU;EACV;EACA;;;;;qBAMW,uCAAqB,QAAA;;;;;;qBAcrB;;;;YAKD,wBAAwB;;;;EAIlC,SAAS;;;;;;;;;;;;;;;;;;;EAmBT,UAAU;;;;EAIV,gBAAgB;;;;EAIhB,aAAa,QAAQ;;;;EAIrB;;;;EAIA;;;;;;;;;;qBAWW,yBAAyB,GAAG;;;;;;;;;;;;;;;;;;;;;qBA0G5B,kBAAkB,GAAG"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.d.ts","names":[],"sources":["../../src/plugins.tsx"],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"plugins.d.ts","names":[],"sources":["../../src/plugins.tsx"],"mappings":";;;;;;;;;;;YAgEY,iBAAiB,KAAK,4BAC9B,aAAa;;qBAIJ,qBAAqB;;;;YA2CtB,cAAc,KAAK;EAC7B;EACA;IAEE;;qBAIS,kBAAkB;;;;YA8CnB,cAAc,KAAK;EAC7B,UAAU;GACT,UAAU,kBAAkB;EAC7B;KAEG,aAAa,KAAK,sBAAsB,cACvC,QAAQ,MACL,mBACD,QAAQ,6BACN,uBACA,aAAa,aACf,qBAAqB;;qBA4BhB,iBAAiB;;;;YAuFlB,mBAAmB,KAAK,mBAChC;EAGI,UAAU;EACV,MAAM,YAAY,qCAAqC;;;qBAiBlD,sBAAsB;YAqEvB,aAAa,KAAK;EAC5B,UAAU;GACT,UAAU,iBAAiB;EAC5B,aAAa;EACb,iBAAiB;IAEf,aACE;EAEE,MAAM,aAAa,6BAA6B,OAAO;EACvD,UAAU,qBAAqB;;qBAK1B,gBAAgB;;;;;;;;;;;;YAsCjB,eAAe,KAAK;EAC9B,UAAU;GACT,UAAU,aAAa;EACxB,aAAa;IAEX,aACE;EAEE,MAAM,aAAa,6BAA6B,OAAO;;;qBAclD,YAAY;;;;YA6Cb,wBAAwB,GAAG,IAAI,WAAW;EACpD,WAAW,cAAc;EACzB,mBAAmB,iBAAiB;EACpC,gBAAgB,cAAc;EAC9B,eAAe,aAAa;EAC5B,WAAW,eAAe;;;;;;;YAQhB,0BAA0B,KACpC;EAGA;EACA;EACA;EACA;EACA;;YAGU,qBACV,GACA,UAAU,gBAAgB,mBACxB,uBAAyB,GAAG,yBAAyB;;;;;qBAQ5C,aAAU,SACZ,eAAa,uBAErB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerServerProvider.d.ts","names":[],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"IntlayerServerProvider.d.ts","names":[],"sources":["../../../src/server/IntlayerServerProvider.tsx"],"mappings":";;;;;;;qBAea,uBAAqB,cAAA;;;;;;;qBAerB,8BAA4B,cAAA;;;;qBAM5B,mBAAW;;;;qBAKX,QAAM;;;;;;;;;;;;;;;;qBAiBN,YAAS,QAAY;;;;;;qBASrB,aAAU,SAAa;YAIxB,8BAA8B;EACxC,SAAS;;;;;;;;;EAST,UAAU;;;;;qBAMC,wBAAwB,GAAG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your React applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -133,12 +133,12 @@
|
|
|
133
133
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
134
134
|
},
|
|
135
135
|
"dependencies": {
|
|
136
|
-
"@intlayer/api": "9.
|
|
137
|
-
"@intlayer/config": "9.
|
|
138
|
-
"@intlayer/core": "9.
|
|
139
|
-
"@intlayer/dictionaries-entry": "9.
|
|
140
|
-
"@intlayer/editor": "9.
|
|
141
|
-
"@intlayer/types": "9.
|
|
136
|
+
"@intlayer/api": "9.6.0",
|
|
137
|
+
"@intlayer/config": "9.6.0",
|
|
138
|
+
"@intlayer/core": "9.6.0",
|
|
139
|
+
"@intlayer/dictionaries-entry": "9.6.0",
|
|
140
|
+
"@intlayer/editor": "9.6.0",
|
|
141
|
+
"@intlayer/types": "9.6.0"
|
|
142
142
|
},
|
|
143
143
|
"devDependencies": {
|
|
144
144
|
"@craco/types": "7.1.0",
|
|
@@ -152,14 +152,14 @@
|
|
|
152
152
|
"rimraf": "6.1.3",
|
|
153
153
|
"tsdown": "0.23.0",
|
|
154
154
|
"typescript": "7.0.2",
|
|
155
|
-
"vitest": "5.0.
|
|
155
|
+
"vitest": "5.0.3"
|
|
156
156
|
},
|
|
157
157
|
"peerDependencies": {
|
|
158
158
|
"react": ">=16.0.0",
|
|
159
159
|
"react-dom": ">=16.0.0"
|
|
160
160
|
},
|
|
161
161
|
"optionalDependencies": {
|
|
162
|
-
"@intlayer/analytics": "9.
|
|
162
|
+
"@intlayer/analytics": "9.6.0"
|
|
163
163
|
},
|
|
164
164
|
"engines": {
|
|
165
165
|
"node": ">=14.18"
|