react-intlayer 9.0.0-canary.1 → 9.0.0-canary.3
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/useDictionary.cjs +1 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +5 -2
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +1 -1
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +5 -2
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +1 -1
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +5 -2
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +1 -1
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +5 -2
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +1 -1
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/markdown/MarkdownRenderer.d.ts +1 -1
- package/dist/types/markdown/MarkdownRenderer.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -17,7 +17,7 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
|
|
|
17
17
|
*/
|
|
18
18
|
const useDictionary = (dictionary, localeOrSelector) => {
|
|
19
19
|
const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
20
|
-
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
20
|
+
const isSelector = process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
21
21
|
const localeOrSelectorIdentity = isSelector ? `${localeOrSelector.locale ?? ""}|${(0, _intlayer_core_dictionaryManipulator.getDictionarySelectorCacheKey)(localeOrSelector)}` : localeOrSelector;
|
|
22
22
|
return (0, react.useMemo)(() => {
|
|
23
23
|
if (isSelector) return require_getDictionary.getDictionary(dictionary, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["IntlayerClientContext","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that transforms a dictionary (or qualified dictionary\n * group) and returns the content.\n *\n * If the locale is not provided (directly or through the selector), it will\n * use the locale from the client context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["IntlayerClientContext","getDictionary"],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that transforms a dictionary (or qualified dictionary\n * group) and returns the content.\n *\n * If the locale is not provided (directly or through the selector), it will\n * use the locale from the client context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n\n // Stable identity of the second argument for memoization\n const localeOrSelectorIdentity = isSelector\n ? `${localeOrSelector.locale ?? ''}|${getDictionarySelectorCacheKey(localeOrSelector)}`\n : localeOrSelector;\n\n return useMemo(() => {\n if (isSelector) {\n return getDictionary(dictionary, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? currentLocale) as A;\n\n return getDictionary<T, A>(dictionary, localeTarget);\n }, [dictionary.key, currentLocale, localeOrSelectorIdentity]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,MAAa,iBAMX,YACA,qBACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB,IAAI,EAAE;CAEzE,MAAM,aACJ,QAAQ,IAAI,oCAAoC,WAChD,OAAO,qBAAqB,YAC5B,qBAAqB;CAGvB,MAAM,2BAA2B,aAC7B,GAAG,iBAAiB,UAAU,GAAG,2EAAiC,iBAAiB,KACnF;AAEJ,iCAAqB;AACnB,MAAI,WACF,QAAOC,oCAAc,YAAY;GAC/B,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAKT,SAAOA,oCAAoB,YAFL,oBAAoB,cAEU;IACnD;EAAC,WAAW;EAAK;EAAe;EAAyB,CAAC"}
|
|
@@ -23,9 +23,12 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
|
|
|
23
23
|
*/
|
|
24
24
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
25
25
|
const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
26
|
-
const { locale: selectorLocale, selector } = (0, _intlayer_core_dictionaryManipulator.parseDictionarySelector)(localeOrSelector)
|
|
26
|
+
const { locale: selectorLocale, selector } = process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" ? (0, _intlayer_core_dictionaryManipulator.parseDictionarySelector)(localeOrSelector) : {
|
|
27
|
+
locale: localeOrSelector,
|
|
28
|
+
selector: void 0
|
|
29
|
+
};
|
|
27
30
|
const localeTarget = selectorLocale ?? currentLocale ?? _intlayer_config_built.internationalization.defaultLocale;
|
|
28
|
-
if ((0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) return (0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContent)({
|
|
31
|
+
if (process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && (0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) return (0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContent)({
|
|
29
32
|
loaderMap: dictionaryPromise,
|
|
30
33
|
key: String(key),
|
|
31
34
|
locale: localeTarget,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","internationalization","loadDynamicChunk","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\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> = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n\n const localeTarget =\n selectorLocale ?? currentLocale ?? internationalization.defaultLocale;\n\n if (isQualifiedDynamicLoaderMap(dictionaryPromise)) {\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":";;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB,IAAI,EAAE;CAEzE,MAAM,EAAE,QAAQ,gBAAgB
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["IntlayerClientContext","internationalization","loadDynamicChunk","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\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> = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const { locale: selectorLocale, selector } =\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false'\n ? parseDictionarySelector<LocalesValues>(localeOrSelector)\n : {\n locale: localeOrSelector as LocalesValues | undefined,\n selector: undefined,\n };\n\n const localeTarget =\n selectorLocale ?? currentLocale ?? internationalization.defaultLocale;\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":";;;;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB,IAAI,EAAE;CAEzE,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,QAAQ,IAAI,oCAAoC,4EACL,iBAAiB,GACxD;EACE,QAAQ;EACR,UAAU;EACX;CAEP,MAAM,eACJ,kBAAkB,iBAAiBC,4CAAqB;AAE1D,KACE,QAAQ,IAAI,oCAAoC,iFACpB,kBAAkB,CAE9C,iFAAsC;EACpC,WAAW;EACX,KAAK,OAAO,IAAI;EAChB,QAAQ;EACR;EACA,YAAY,UAAU,YAAYC,6CAAiB,UAAU,QAAQ;EACrE,YAAY,eAAeC,oCAAc,YAAY,aAAa;EACnE,CAAC;CAGJ,MAAM,eAAe;AASrB,QAAOA,oCALYD,6CACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBAClB,aAAa,iBAA8C,CAG9B,EAAE,aAAa"}
|
|
@@ -35,7 +35,7 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
|
|
|
35
35
|
*/
|
|
36
36
|
const useIntlayer = (key, localeOrSelector) => {
|
|
37
37
|
const { locale: currentLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
38
|
-
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
38
|
+
const isSelector = process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
39
39
|
return (0, react.useMemo)(() => {
|
|
40
40
|
if (isSelector) return require_getIntlayer.getIntlayer(key, {
|
|
41
41
|
...localeOrSelector,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ id: 'prod_abc', ...metaFields }` — meta record\n * - `locale` composes with any selector and overrides the context locale\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The dictionary content for the resolved entry and locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n * const faq2 = useIntlayer('faq', { item: 2 });\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["IntlayerClientContext","getIntlayer"],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ id: 'prod_abc', ...metaFields }` — meta record\n * - `locale` composes with any selector and overrides the context locale\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The dictionary content for the resolved entry and locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n * const faq2 = useIntlayer('faq', { item: 2 });\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n\n // Stable identity of the second argument for memoization\n const localeOrSelectorIdentity = isSelector\n ? `${localeOrSelector.locale ?? ''}|${getDictionarySelectorCacheKey(localeOrSelector)}`\n : localeOrSelector;\n\n return useMemo(() => {\n if (isSelector) {\n return getIntlayer(key, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? currentLocale) as A;\n\n return getIntlayer<T, A>(key, localeTarget);\n }, [key, currentLocale, localeOrSelectorIdentity]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,eAIX,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,wCAA6BA,sDAAsB,IAAI,EAAE;CAEzE,MAAM,aACJ,QAAQ,IAAI,oCAAoC,WAChD,OAAO,qBAAqB,YAC5B,qBAAqB;AAOvB,iCAAqB;AACnB,MAAI,WACF,QAAOC,gCAAY,KAAK;GACtB,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAKT,SAAOA,gCAAkB,KAFH,oBAAoB,cAEC;IAC1C;EAAC;EAAK;EAfwB,aAC7B,GAAG,iBAAiB,UAAU,GAAG,2EAAiC,iBAAiB,KACnF;EAa6C,CAAC"}
|
|
@@ -13,7 +13,7 @@ const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.
|
|
|
13
13
|
*/
|
|
14
14
|
const useDictionary = (dictionary, localeOrSelector, fallbackLocale) => {
|
|
15
15
|
const contextLocale = require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext) ?? fallbackLocale;
|
|
16
|
-
if (typeof localeOrSelector === "object" && localeOrSelector !== null) return require_getDictionary.getDictionary(dictionary, {
|
|
16
|
+
if (process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null) return require_getDictionary.getDictionary(dictionary, {
|
|
17
17
|
...localeOrSelector,
|
|
18
18
|
locale: localeOrSelector.locale ?? contextLocale
|
|
19
19
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.cjs","names":["getServerContext","IntlayerServerContext","getDictionary"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary (or qualified\n * dictionary group) and return the content\n *\n * If the locale is not provided (directly or through the selector), it will\n * use the locale from the server context\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale =\n getServerContext<LocalesValues>(IntlayerServerContext) ?? fallbackLocale;\n\n if (typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["getServerContext","IntlayerServerContext","getDictionary"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary (or qualified\n * dictionary group) and return the content\n *\n * If the locale is not provided (directly or through the selector), it will\n * use the locale from the server context\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale =\n getServerContext<LocalesValues>(IntlayerServerContext) ?? fallbackLocale;\n\n if (\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null\n ) {\n return getDictionary(dictionary, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? contextLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? contextLocale) as A;\n\n return getDictionary<T, A>(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;AAoBA,MAAa,iBAMX,YACA,kBACA,mBACG;CACH,MAAM,gBACJA,8CAAgCC,4DAAsB,IAAI;AAE5D,KACE,QAAQ,IAAI,oCAAoC,WAChD,OAAO,qBAAqB,YAC5B,qBAAqB,KAErB,QAAOC,oCAAc,YAAY;EAC/B,GAAG;EACH,QAAQ,iBAAiB,UAAU;EACpC,CAAM;AAKT,QAAOA,oCAAoB,YAFL,oBAAoB,cAEU"}
|
|
@@ -20,9 +20,12 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
|
|
|
20
20
|
* context locale is used.
|
|
21
21
|
*/
|
|
22
22
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector, fallbackLocale) => {
|
|
23
|
-
const { locale: selectorLocale, selector } = (0, _intlayer_core_dictionaryManipulator.parseDictionarySelector)(localeOrSelector)
|
|
23
|
+
const { locale: selectorLocale, selector } = process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" ? (0, _intlayer_core_dictionaryManipulator.parseDictionarySelector)(localeOrSelector) : {
|
|
24
|
+
locale: localeOrSelector,
|
|
25
|
+
selector: void 0
|
|
26
|
+
};
|
|
24
27
|
const localeTarget = selectorLocale ?? require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext) ?? fallbackLocale ?? _intlayer_config_built.internationalization.defaultLocale;
|
|
25
|
-
if ((0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) return (0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContent)({
|
|
28
|
+
if (process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && (0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) return (0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContent)({
|
|
26
29
|
loaderMap: dictionaryPromise,
|
|
27
30
|
key: String(key),
|
|
28
31
|
locale: localeTarget,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getServerContext","IntlayerServerContext","internationalization","loadDynamicChunk","getDictionary"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } 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 = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n\n const localeTarget =\n selectorLocale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n internationalization.defaultLocale;\n\n if (isQualifiedDynamicLoaderMap(dictionaryPromise)) {\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":";;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAIX,mBAGA,KACA,kBACA,mBACG;CACH,MAAM,EAAE,QAAQ,gBAAgB
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["getServerContext","IntlayerServerContext","internationalization","loadDynamicChunk","getDictionary"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } 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 = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const { locale: selectorLocale, selector } =\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false'\n ? parseDictionarySelector<LocalesValues>(localeOrSelector)\n : {\n locale: localeOrSelector as LocalesValues | undefined,\n selector: undefined,\n };\n\n const localeTarget =\n selectorLocale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n internationalization.defaultLocale;\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":";;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAIX,mBAGA,KACA,kBACA,mBACG;CACH,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,QAAQ,IAAI,oCAAoC,4EACL,iBAAiB,GACxD;EACE,QAAQ;EACR,UAAU;EACX;CAEP,MAAM,eACJ,kBACAA,8CAAgCC,4DAAsB,IACtD,kBACAC,4CAAqB;AAEvB,KACE,QAAQ,IAAI,oCAAoC,iFACpB,kBAAkB,CAE9C,iFAAsC;EACpC,WAAW;EACX,KAAK,OAAO,IAAI;EAChB,QAAQ;EACR;EACA,YAAY,UAAU,YAAYC,6CAAiB,UAAU,QAAQ;EACrE,YAAY,eAAeC,oCAAc,YAAY,aAAa;EACnE,CAAC;CAGJ,MAAM,eAAe;AASrB,QAAOA,oCALYD,6CACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBAClB,aAAa,iBAA8C,CAG9B,EAAE,aAAa"}
|
|
@@ -14,7 +14,7 @@ const require_server_IntlayerServerProvider = require('./IntlayerServerProvider.
|
|
|
14
14
|
*/
|
|
15
15
|
const useIntlayer = (key, localeOrSelector, fallbackLocale) => {
|
|
16
16
|
const contextLocale = require_server_serverContext.getServerContext(require_server_IntlayerServerProvider.IntlayerServerContext) ?? fallbackLocale;
|
|
17
|
-
if (typeof localeOrSelector === "object" && localeOrSelector !== null) return require_getIntlayer.getIntlayer(key, {
|
|
17
|
+
if (process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null) return require_getIntlayer.getIntlayer(key, {
|
|
18
18
|
...localeOrSelector,
|
|
19
19
|
locale: localeOrSelector.locale ?? contextLocale
|
|
20
20
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.cjs","names":["getServerContext","IntlayerServerContext","getIntlayer"],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * The second argument is either a locale or a selector object\n * (`{ item }`, `{ variant }`, `{ id, ...meta }`, optionally with `locale`).\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale =\n getServerContext<LocalesValues>(IntlayerServerContext) ?? fallbackLocale;\n\n if (typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["getServerContext","IntlayerServerContext","getIntlayer"],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * The second argument is either a locale or a selector object\n * (`{ item }`, `{ variant }`, `{ id, ...meta }`, optionally with `locale`).\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale =\n getServerContext<LocalesValues>(IntlayerServerContext) ?? fallbackLocale;\n\n if (\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null\n ) {\n return getIntlayer(key, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? contextLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? contextLocale) as A;\n\n return getIntlayer<T, A>(key, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;;AAkBA,MAAa,eAIX,KACA,kBACA,mBACG;CACH,MAAM,gBACJA,8CAAgCC,4DAAsB,IAAI;AAE5D,KACE,QAAQ,IAAI,oCAAoC,WAChD,OAAO,qBAAqB,YAC5B,qBAAqB,KAErB,QAAOC,gCAAY,KAAK;EACtB,GAAG;EACH,QAAQ,iBAAiB,UAAU;EACpC,CAAM;AAKT,QAAOA,gCAAkB,KAFH,oBAAoB,cAEC"}
|
|
@@ -15,7 +15,7 @@ import { getDictionarySelectorCacheKey } from "@intlayer/core/dictionaryManipula
|
|
|
15
15
|
*/
|
|
16
16
|
const useDictionary = (dictionary, localeOrSelector) => {
|
|
17
17
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
18
|
-
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
18
|
+
const isSelector = process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
19
19
|
const localeOrSelectorIdentity = isSelector ? `${localeOrSelector.locale ?? ""}|${getDictionarySelectorCacheKey(localeOrSelector)}` : localeOrSelector;
|
|
20
20
|
return useMemo(() => {
|
|
21
21
|
if (isSelector) return getDictionary(dictionary, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that transforms a dictionary (or qualified dictionary\n * group) and returns the content.\n *\n * If the locale is not provided (directly or through the selector), it will\n * use the locale from the client context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that transforms a dictionary (or qualified dictionary\n * group) and returns the content.\n *\n * If the locale is not provided (directly or through the selector), it will\n * use the locale from the client context.\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n\n // Stable identity of the second argument for memoization\n const localeOrSelectorIdentity = isSelector\n ? `${localeOrSelector.locale ?? ''}|${getDictionarySelectorCacheKey(localeOrSelector)}`\n : localeOrSelector;\n\n return useMemo(() => {\n if (isSelector) {\n return getDictionary(dictionary, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? currentLocale) as A;\n\n return getDictionary<T, A>(dictionary, localeTarget);\n }, [dictionary.key, currentLocale, localeOrSelectorIdentity]);\n};\n"],"mappings":";;;;;;;;;;;;;;;AAuBA,MAAa,iBAMX,YACA,qBACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB,IAAI,EAAE;CAEzE,MAAM,aACJ,QAAQ,IAAI,oCAAoC,WAChD,OAAO,qBAAqB,YAC5B,qBAAqB;CAGvB,MAAM,2BAA2B,aAC7B,GAAG,iBAAiB,UAAU,GAAG,GAAG,8BAA8B,iBAAiB,KACnF;AAEJ,QAAO,cAAc;AACnB,MAAI,WACF,QAAO,cAAc,YAAY;GAC/B,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAKT,SAAO,cAAoB,YAFL,oBAAoB,cAEU;IACnD;EAAC,WAAW;EAAK;EAAe;EAAyB,CAAC"}
|
|
@@ -21,9 +21,12 @@ import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveQualifiedD
|
|
|
21
21
|
*/
|
|
22
22
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
23
23
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
24
|
-
const { locale: selectorLocale, selector } = parseDictionarySelector(localeOrSelector)
|
|
24
|
+
const { locale: selectorLocale, selector } = process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" ? parseDictionarySelector(localeOrSelector) : {
|
|
25
|
+
locale: localeOrSelector,
|
|
26
|
+
selector: void 0
|
|
27
|
+
};
|
|
25
28
|
const localeTarget = selectorLocale ?? currentLocale ?? internationalization.defaultLocale;
|
|
26
|
-
if (isQualifiedDynamicLoaderMap(dictionaryPromise)) return resolveQualifiedDynamicContent({
|
|
29
|
+
if (process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && isQualifiedDynamicLoaderMap(dictionaryPromise)) return resolveQualifiedDynamicContent({
|
|
27
30
|
loaderMap: dictionaryPromise,
|
|
28
31
|
key: String(key),
|
|
29
32
|
locale: localeTarget,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\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> = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n\n const localeTarget =\n selectorLocale ?? currentLocale ?? internationalization.defaultLocale;\n\n if (isQualifiedDynamicLoaderMap(dictionaryPromise)) {\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":";;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB,IAAI,EAAE;CAEzE,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,wBAAuC,iBAAiB;
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\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> = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: K,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const { locale: selectorLocale, selector } =\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false'\n ? parseDictionarySelector<LocalesValues>(localeOrSelector)\n : {\n locale: localeOrSelector as LocalesValues | undefined,\n selector: undefined,\n };\n\n const localeTarget =\n selectorLocale ?? currentLocale ?? internationalization.defaultLocale;\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":";;;;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB,IAAI,EAAE;CAEzE,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,QAAQ,IAAI,oCAAoC,UAC5C,wBAAuC,iBAAiB,GACxD;EACE,QAAQ;EACR,UAAU;EACX;CAEP,MAAM,eACJ,kBAAkB,iBAAiB,qBAAqB;AAE1D,KACE,QAAQ,IAAI,oCAAoC,WAChD,4BAA4B,kBAAkB,CAE9C,QAAO,+BAA+B;EACpC,WAAW;EACX,KAAK,OAAO,IAAI;EAChB,QAAQ;EACR;EACA,YAAY,UAAU,YAAYA,eAAiB,UAAU,QAAQ;EACrE,YAAY,eAAe,cAAc,YAAY,aAAa;EACnE,CAAC;CAGJ,MAAM,eAAe;AASrB,QAAO,cALYA,eACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBAClB,aAAa,iBAA8C,CAG9B,EAAE,aAAa"}
|
|
@@ -33,7 +33,7 @@ import { getDictionarySelectorCacheKey } from "@intlayer/core/dictionaryManipula
|
|
|
33
33
|
*/
|
|
34
34
|
const useIntlayer = (key, localeOrSelector) => {
|
|
35
35
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
36
|
-
const isSelector = typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
36
|
+
const isSelector = process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null;
|
|
37
37
|
return useMemo(() => {
|
|
38
38
|
if (isSelector) return getIntlayer(key, {
|
|
39
39
|
...localeOrSelector,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ id: 'prod_abc', ...metaFields }` — meta record\n * - `locale` composes with any selector and overrides the context locale\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The dictionary content for the resolved entry and locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n * const faq2 = useIntlayer('faq', { item: 2 });\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport { getDictionarySelectorCacheKey } from '@intlayer/core/dictionaryManipulator';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * The second argument is either a locale or a selector object:\n * - `{ item: 2 }` — collection item (omit `item` to get every item as array)\n * - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)\n * - `{ id: 'prod_abc', ...metaFields }` — meta record\n * - `locale` composes with any selector and overrides the context locale\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param localeOrSelector - Optional locale or selector.\n * @returns The dictionary content for the resolved entry and locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n * const faq2 = useIntlayer('faq', { item: 2 });\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n\n const isSelector =\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null;\n\n // Stable identity of the second argument for memoization\n const localeOrSelectorIdentity = isSelector\n ? `${localeOrSelector.locale ?? ''}|${getDictionarySelectorCacheKey(localeOrSelector)}`\n : localeOrSelector;\n\n return useMemo(() => {\n if (isSelector) {\n return getIntlayer(key, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? currentLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? currentLocale) as A;\n\n return getIntlayer<T, A>(key, localeTarget);\n }, [key, currentLocale, localeOrSelectorIdentity]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,eAIX,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB,IAAI,EAAE;CAEzE,MAAM,aACJ,QAAQ,IAAI,oCAAoC,WAChD,OAAO,qBAAqB,YAC5B,qBAAqB;AAOvB,QAAO,cAAc;AACnB,MAAI,WACF,QAAO,YAAY,KAAK;GACtB,GAAG;GACH,QAAQ,iBAAiB,UAAU;GACpC,CAAM;AAKT,SAAO,YAAkB,KAFH,oBAAoB,cAEC;IAC1C;EAAC;EAAK;EAfwB,aAC7B,GAAG,iBAAiB,UAAU,GAAG,GAAG,8BAA8B,iBAAiB,KACnF;EAa6C,CAAC"}
|
|
@@ -12,7 +12,7 @@ import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
|
12
12
|
*/
|
|
13
13
|
const useDictionary = (dictionary, localeOrSelector, fallbackLocale) => {
|
|
14
14
|
const contextLocale = getServerContext(IntlayerServerContext) ?? fallbackLocale;
|
|
15
|
-
if (typeof localeOrSelector === "object" && localeOrSelector !== null) return getDictionary(dictionary, {
|
|
15
|
+
if (process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null) return getDictionary(dictionary, {
|
|
16
16
|
...localeOrSelector,
|
|
17
17
|
locale: localeOrSelector.locale ?? contextLocale
|
|
18
18
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary (or qualified\n * dictionary group) and return the content\n *\n * If the locale is not provided (directly or through the selector), it will\n * use the locale from the server context\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale =\n getServerContext<LocalesValues>(IntlayerServerContext) ?? fallbackLocale;\n\n if (typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type {\n Dictionary,\n DictionarySelectorForGroup,\n QualifiedDictionaryGroup,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that transform a dictionary (or qualified\n * dictionary group) and return the content\n *\n * If the locale is not provided (directly or through the selector), it will\n * use the locale from the server context\n */\nexport const useDictionary = <\n const T extends Dictionary | QualifiedDictionaryGroup,\n const A extends\n | LocalesValues\n | DictionarySelectorForGroup<T> = DeclaredLocales,\n>(\n dictionary: T,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale =\n getServerContext<LocalesValues>(IntlayerServerContext) ?? fallbackLocale;\n\n if (\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null\n ) {\n return getDictionary(dictionary, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? contextLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? contextLocale) as A;\n\n return getDictionary<T, A>(dictionary, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;AAoBA,MAAa,iBAMX,YACA,kBACA,mBACG;CACH,MAAM,gBACJ,iBAAgC,sBAAsB,IAAI;AAE5D,KACE,QAAQ,IAAI,oCAAoC,WAChD,OAAO,qBAAqB,YAC5B,qBAAqB,KAErB,QAAO,cAAc,YAAY;EAC/B,GAAG;EACH,QAAQ,iBAAiB,UAAU;EACpC,CAAM;AAKT,QAAO,cAAoB,YAFL,oBAAoB,cAEU"}
|
|
@@ -18,9 +18,12 @@ import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveQualifiedD
|
|
|
18
18
|
* context locale is used.
|
|
19
19
|
*/
|
|
20
20
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector, fallbackLocale) => {
|
|
21
|
-
const { locale: selectorLocale, selector } = parseDictionarySelector(localeOrSelector)
|
|
21
|
+
const { locale: selectorLocale, selector } = process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" ? parseDictionarySelector(localeOrSelector) : {
|
|
22
|
+
locale: localeOrSelector,
|
|
23
|
+
selector: void 0
|
|
24
|
+
};
|
|
22
25
|
const localeTarget = selectorLocale ?? getServerContext(IntlayerServerContext) ?? fallbackLocale ?? internationalization.defaultLocale;
|
|
23
|
-
if (isQualifiedDynamicLoaderMap(dictionaryPromise)) return resolveQualifiedDynamicContent({
|
|
26
|
+
if (process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && isQualifiedDynamicLoaderMap(dictionaryPromise)) return resolveQualifiedDynamicContent({
|
|
24
27
|
loaderMap: dictionaryPromise,
|
|
25
28
|
key: String(key),
|
|
26
29
|
locale: localeTarget,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } 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 = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const { locale: selectorLocale, selector } =\n parseDictionarySelector<LocalesValues>(localeOrSelector);\n\n const localeTarget =\n selectorLocale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n internationalization.defaultLocale;\n\n if (isQualifiedDynamicLoaderMap(dictionaryPromise)) {\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":";;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAIX,mBAGA,KACA,kBACA,mBACG;CACH,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,wBAAuC,iBAAiB;
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import { internationalization } from '@intlayer/config/built';\nimport {\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\nimport type {\n Dictionary,\n DictionarySelector,\n} from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerServerContext } 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 = LocalesValues,\n>(\n dictionaryPromise:\n | StrictModeLocaleMap<() => Promise<T>>\n | QualifiedDynamicLoaderMap,\n key: string,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const { locale: selectorLocale, selector } =\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false'\n ? parseDictionarySelector<LocalesValues>(localeOrSelector)\n : {\n locale: localeOrSelector as LocalesValues | undefined,\n selector: undefined,\n };\n\n const localeTarget =\n selectorLocale ??\n getServerContext<LocalesValues>(IntlayerServerContext) ??\n fallbackLocale ??\n internationalization.defaultLocale;\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":";;;;;;;;;;;;;;;;;;;AAmCA,MAAa,wBAIX,mBAGA,KACA,kBACA,mBACG;CACH,MAAM,EAAE,QAAQ,gBAAgB,aAC9B,QAAQ,IAAI,oCAAoC,UAC5C,wBAAuC,iBAAiB,GACxD;EACE,QAAQ;EACR,UAAU;EACX;CAEP,MAAM,eACJ,kBACA,iBAAgC,sBAAsB,IACtD,kBACA,qBAAqB;AAEvB,KACE,QAAQ,IAAI,oCAAoC,WAChD,4BAA4B,kBAAkB,CAE9C,QAAO,+BAA+B;EACpC,WAAW;EACX,KAAK,OAAO,IAAI;EAChB,QAAQ;EACR;EACA,YAAY,UAAU,YAAYA,eAAiB,UAAU,QAAQ;EACrE,YAAY,eAAe,cAAc,YAAY,aAAa;EACnE,CAAC;CAGJ,MAAM,eAAe;AASrB,QAAO,cALYA,eACjB,GAAG,OAAO,IAAI,CAAC,GAAG,gBAClB,aAAa,iBAA8C,CAG9B,EAAE,aAAa"}
|
|
@@ -13,7 +13,7 @@ import { IntlayerServerContext } from "./IntlayerServerProvider.mjs";
|
|
|
13
13
|
*/
|
|
14
14
|
const useIntlayer = (key, localeOrSelector, fallbackLocale) => {
|
|
15
15
|
const contextLocale = getServerContext(IntlayerServerContext) ?? fallbackLocale;
|
|
16
|
-
if (typeof localeOrSelector === "object" && localeOrSelector !== null) return getIntlayer(key, {
|
|
16
|
+
if (process.env["INTLAYER_DICTIONARY_SELECTOR"] !== "false" && typeof localeOrSelector === "object" && localeOrSelector !== null) return getIntlayer(key, {
|
|
17
17
|
...localeOrSelector,
|
|
18
18
|
locale: localeOrSelector.locale ?? contextLocale
|
|
19
19
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * The second argument is either a locale or a selector object\n * (`{ item }`, `{ variant }`, `{ id, ...meta }`, optionally with `locale`).\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale =\n getServerContext<LocalesValues>(IntlayerServerContext) ?? fallbackLocale;\n\n if (typeof localeOrSelector === 'object'
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n DictionaryKeys,\n DictionarySelectorForKey,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerServerContext } from './IntlayerServerProvider';\nimport { getServerContext } from './serverContext';\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * The second argument is either a locale or a selector object\n * (`{ item }`, `{ variant }`, `{ id, ...meta }`, optionally with `locale`).\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n const T extends DictionaryKeys,\n const A extends LocalesValues | DictionarySelectorForKey<T> = DeclaredLocales,\n>(\n key: T,\n localeOrSelector?: A,\n fallbackLocale?: DeclaredLocales\n) => {\n const contextLocale =\n getServerContext<LocalesValues>(IntlayerServerContext) ?? fallbackLocale;\n\n if (\n process.env['INTLAYER_DICTIONARY_SELECTOR'] !== 'false' &&\n typeof localeOrSelector === 'object' &&\n localeOrSelector !== null\n ) {\n return getIntlayer(key, {\n ...localeOrSelector,\n locale: localeOrSelector.locale ?? contextLocale,\n } as A);\n }\n\n const localeTarget = (localeOrSelector ?? contextLocale) as A;\n\n return getIntlayer<T, A>(key, localeTarget);\n};\n"],"mappings":";;;;;;;;;;;;;AAkBA,MAAa,eAIX,KACA,kBACA,mBACG;CACH,MAAM,gBACJ,iBAAgC,sBAAsB,IAAI;AAE5D,KACE,QAAQ,IAAI,oCAAoC,WAChD,OAAO,qBAAqB,YAC5B,qBAAqB,KAErB,QAAO,YAAY,KAAK;EACtB,GAAG;EACH,QAAQ,iBAAiB,UAAU;EACpC,CAAM;AAKT,QAAO,YAAkB,KAFH,oBAAoB,cAEC"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -71,7 +71,7 @@ declare const useMarkdownRenderer: ({
|
|
|
71
71
|
forceInline,
|
|
72
72
|
preserveFrontmatter,
|
|
73
73
|
tagfilter
|
|
74
|
-
}?: RenderMarkdownProps$1) => (content: string | _$_intlayer_core_markdown0.ParsedMarkdown) => string | number | bigint | boolean | Iterable<_$react.ReactNode> | _$react.
|
|
74
|
+
}?: RenderMarkdownProps$1) => (content: string | _$_intlayer_core_markdown0.ParsedMarkdown) => string | number | bigint | boolean | Iterable<_$react.ReactNode> | Promise<_$react.ReactNode> | _$react.JSX.Element;
|
|
75
75
|
/**
|
|
76
76
|
* @deprecated import from react-intlayer/markdown instead
|
|
77
77
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;YAIY,kBAAA,iBAAmC,aAAA,UACnC,uBAAA,CAAwB,CAAA,EAAG,CAAA,EAAG,CAAA;AAAA;;;;;;;cAqD7B,gBAAA,UAAgB,EAAA,CAAA,yBAAA;eAAA,cAAA;;4FAxBlB,yBAAA,EAAA,UAAA,GAAA,cAAA,oBAEG,OAAA,GAEN,OAAA,CAAA,EAAA,CAAA,OAAA,CAAA,cAAA,CAAA,WAAA,OAAA,OAAA,CAAA,SAAA,GAAA,OAAA,CAAA,OAAA,CAAA,SAAA;AAAA;aAAA,OAAA,CAAA,SAAA;AAAA;;;;cAwBK,kBAAA;eAAwC,cAAA;2FAvCG,yBAAA,EAAA,UAAA,GAAA,cAAA,oBAC5B,OAAA,GACI,OAAA,CAAA,EAAA,CAAA,OAAA,CAAA,cAAA,CAAA,WAAA,OAAA,OAAA,CAAA,SAAA,GAAA,OAAA,CAAA,OAAA,CAAA,SAAA;AAAA;;;;KAyCpB,uBAAA,GAA0B,yBAAA;AARtC;;;AAAA,cAYa,cAAA,GAAc,OAAA,WAAkB,0BAAA,CAAlB,cAAA;EAAA,UAAA;EAAA,OAAA;EAAA,UAAA;EAAA,WAAA;EAAA,mBAAA;EAAA;AAAA,IAAA,qBAAA,KAAA,OAAA,CAAA,GAAA,CAAA,OAAA;;;;cAId,mBAAA;EAAmB,UAAA;EAAA,OAAA;EAAA,UAAA;EAAA,WAAA;EAAA,mBAAA;EAAA;AAAA,IAAA,qBAAA,MAak1C,OAAA,WAbl1C,0BAAA,CAak1C,cAAA,0CAAgC,QAAA,CAAA,OAAA,CAAA,SAAA,IAAA,OAAA,CAAA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;YAIY,kBAAA,iBAAmC,aAAA,UACnC,uBAAA,CAAwB,CAAA,EAAG,CAAA,EAAG,CAAA;AAAA;;;;;;;cAqD7B,gBAAA,UAAgB,EAAA,CAAA,yBAAA;eAAA,cAAA;;4FAxBlB,yBAAA,EAAA,UAAA,GAAA,cAAA,oBAEG,OAAA,GAEN,OAAA,CAAA,EAAA,CAAA,OAAA,CAAA,cAAA,CAAA,WAAA,OAAA,OAAA,CAAA,SAAA,GAAA,OAAA,CAAA,OAAA,CAAA,SAAA;AAAA;aAAA,OAAA,CAAA,SAAA;AAAA;;;;cAwBK,kBAAA;eAAwC,cAAA;2FAvCG,yBAAA,EAAA,UAAA,GAAA,cAAA,oBAC5B,OAAA,GACI,OAAA,CAAA,EAAA,CAAA,OAAA,CAAA,cAAA,CAAA,WAAA,OAAA,OAAA,CAAA,SAAA,GAAA,OAAA,CAAA,OAAA,CAAA,SAAA;AAAA;;;;KAyCpB,uBAAA,GAA0B,yBAAA;AARtC;;;AAAA,cAYa,cAAA,GAAc,OAAA,WAAkB,0BAAA,CAAlB,cAAA;EAAA,UAAA;EAAA,OAAA;EAAA,UAAA;EAAA,WAAA;EAAA,mBAAA;EAAA;AAAA,IAAA,qBAAA,KAAA,OAAA,CAAA,GAAA,CAAA,OAAA;;;;cAId,mBAAA;EAAmB,UAAA;EAAA,OAAA;EAAA,UAAA;EAAA,WAAA;EAAA,mBAAA;EAAA;AAAA,IAAA,qBAAA,MAak1C,OAAA,WAbl1C,0BAAA,CAak1C,cAAA,0CAAgC,QAAA,CAAA,OAAA,CAAA,SAAA,IAAA,OAAA,CAAA,OAAA,CAAA,SAAA,IAAA,OAAA,CAAA,GAAA,CAAA,OAAA;;;;cATr4C,gBAAA,EAAgB,OAAA,CAAA,EAAA,CAAA,uBAAA;;;;KAIjB,mBAAA,GAAsB,qBAAA;;;;KAItB,qBAAA,GAAwB,uBAAA"}
|
|
@@ -134,7 +134,7 @@ declare const useMarkdownRenderer: ({
|
|
|
134
134
|
forceInline,
|
|
135
135
|
preserveFrontmatter,
|
|
136
136
|
tagfilter
|
|
137
|
-
}?: RenderMarkdownProps) => (content: string | ParsedMarkdown) => string | number | bigint | boolean | Iterable<ReactNode> | JSX.Element
|
|
137
|
+
}?: RenderMarkdownProps) => (content: string | ParsedMarkdown) => string | number | bigint | boolean | Iterable<ReactNode> | Promise<ReactNode> | JSX.Element;
|
|
138
138
|
/**
|
|
139
139
|
* Props for the MarkdownRenderer component.
|
|
140
140
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkdownRenderer.d.ts","names":[],"sources":["../../../src/markdown/MarkdownRenderer.tsx"],"mappings":";;;;;;;;AAiCA;;;;;;;;;;;;;;;;;KAAY,mBAAA,GAAsB,uBAAA;EAwBO;AA4BzC;;;;;;;;;;;;EAtCE,UAAA,GAAa,cAAA;EA6Dd;;;;;;;;;EAnDC,OAAA,GAAU,EAAA,CAAG,cAAA,CAAe,WAAA;AAAA;;;;;;;;;;AAkG9B;;;;;;;;;;;;;;;;cAtEa,cAAA,GACX,OAAA,WAAkB,cAAA;EAClB,UAAA;EAAA,OAAA;EAAA,UAAA;EAAA,WAAA;EAAA,mBAAA;EAAA;AAAA,IAOG,mBAAA,KACF,GAAA,CAAI,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;AA+GP;;;;;;;;;;;;;;;;;;;;;cAnDa,mBAAA;EAAuB,UAAA;EAAA,OAAA;EAAA,UAAA;EAAA,WAAA;EAAA,mBAAA;EAAA;AAAA,IAOjC,mBAAA,MAGO,OAAA,WAAkB,cAAA,0CAAc,QAAA,CAAA,SAAA,IAAA,
|
|
1
|
+
{"version":3,"file":"MarkdownRenderer.d.ts","names":[],"sources":["../../../src/markdown/MarkdownRenderer.tsx"],"mappings":";;;;;;;;AAiCA;;;;;;;;;;;;;;;;;KAAY,mBAAA,GAAsB,uBAAA;EAwBO;AA4BzC;;;;;;;;;;;;EAtCE,UAAA,GAAa,cAAA;EA6Dd;;;;;;;;;EAnDC,OAAA,GAAU,EAAA,CAAG,cAAA,CAAe,WAAA;AAAA;;;;;;;;;;AAkG9B;;;;;;;;;;;;;;;;cAtEa,cAAA,GACX,OAAA,WAAkB,cAAA;EAClB,UAAA;EAAA,OAAA;EAAA,UAAA;EAAA,WAAA;EAAA,mBAAA;EAAA;AAAA,IAOG,mBAAA,KACF,GAAA,CAAI,OAAA;;;;;;;;;;;;;;;;;;;;;;;;;AA+GP;;;;;;;;;;;;;;;;;;;;;cAnDa,mBAAA;EAAuB,UAAA;EAAA,OAAA;EAAA,UAAA;EAAA,WAAA;EAAA,mBAAA;EAAA;AAAA,IAOjC,mBAAA,MAGO,OAAA,WAAkB,cAAA,0CAAc,QAAA,CAAA,SAAA,IAAA,OAAA,CAAA,SAAA,IAAA,GAAA,CAAA,OAAA;;;;;;;;;;;;AAmJ1C;;;;KA1GY,qBAAA,GAAwB,mBAAA;;;;;;;;;;;EAWlC,QAAA,WAAmB,cAAA;;;;;;;;;;;;;;;;;;;;;EAqBnB,cAAA,IACE,QAAA,WAAmB,cAAA,EACnB,OAAA;IACE,UAAA,GAAa,cAAA;IACb,OAAA,GAAU,EAAA;IACV,UAAA;IACA,WAAA;IACA,mBAAA;IACA,SAAA;EAAA,MAEC,SAAA,GAAY,OAAA,CAAQ,SAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAgEd,gBAAA,EAAkB,EAAA,CAAG,qBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "9.0.0-canary.
|
|
3
|
+
"version": "9.0.0-canary.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your React applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -124,13 +124,13 @@
|
|
|
124
124
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
125
125
|
},
|
|
126
126
|
"dependencies": {
|
|
127
|
-
"@intlayer/api": "9.0.0-canary.
|
|
128
|
-
"@intlayer/config": "9.0.0-canary.
|
|
129
|
-
"@intlayer/core": "9.0.0-canary.
|
|
130
|
-
"@intlayer/dictionaries-entry": "9.0.0-canary.
|
|
131
|
-
"@intlayer/editor": "9.0.0-canary.
|
|
132
|
-
"@intlayer/editor-react": "9.0.0-canary.
|
|
133
|
-
"@intlayer/types": "9.0.0-canary.
|
|
127
|
+
"@intlayer/api": "9.0.0-canary.3",
|
|
128
|
+
"@intlayer/config": "9.0.0-canary.3",
|
|
129
|
+
"@intlayer/core": "9.0.0-canary.3",
|
|
130
|
+
"@intlayer/dictionaries-entry": "9.0.0-canary.3",
|
|
131
|
+
"@intlayer/editor": "9.0.0-canary.3",
|
|
132
|
+
"@intlayer/editor-react": "9.0.0-canary.3",
|
|
133
|
+
"@intlayer/types": "9.0.0-canary.3"
|
|
134
134
|
},
|
|
135
135
|
"devDependencies": {
|
|
136
136
|
"@craco/types": "7.1.0",
|