react-intlayer 9.3.2 → 9.3.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/useDictionaryDynamic.cjs +2 -0
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +32 -5
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +3 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +32 -6
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/types/client/format/useCompact.d.ts +2 -1
- package/dist/types/client/format/useCompact.d.ts.map +1 -1
- package/dist/types/client/format/useCurrency.d.ts +2 -1
- package/dist/types/client/format/useCurrency.d.ts.map +1 -1
- package/dist/types/client/format/useList.d.ts +2 -1
- package/dist/types/client/format/useList.d.ts.map +1 -1
- package/dist/types/client/format/useNumber.d.ts +2 -1
- package/dist/types/client/format/useNumber.d.ts.map +1 -1
- package/dist/types/client/format/usePercentage.d.ts +2 -1
- package/dist/types/client/format/usePercentage.d.ts.map +1 -1
- package/dist/types/client/format/useRelativeTime.d.ts +2 -1
- package/dist/types/client/format/useRelativeTime.d.ts.map +1 -1
- package/dist/types/client/format/useUnit.d.ts +2 -1
- package/dist/types/client/format/useUnit.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useI18n.d.ts +1 -1
- package/dist/types/client/useLoadDynamic.d.ts +21 -1
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -1
- package/dist/types/client/useLocaleBase.d.ts +3 -2
- package/dist/types/client/useLocaleBase.d.ts.map +1 -1
- package/dist/types/client/useLocaleStorage.d.ts +4 -3
- package/dist/types/client/useLocaleStorage.d.ts.map +1 -1
- package/dist/types/intlayer/dist/types/index.d.ts +14 -0
- package/dist/types/server/useI18n.d.ts +1 -1
- package/package.json +8 -8
|
@@ -40,6 +40,8 @@ const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
|
40
40
|
loadChunk: (cacheKey, promise) => require_client_useLoadDynamic.useLoadDynamic(cacheKey, promise),
|
|
41
41
|
transform: (dictionary) => require_getDictionary.getDictionary(dictionary, localeTarget)
|
|
42
42
|
});
|
|
43
|
+
const preloadedDictionary = (0, _intlayer_core_dictionaryManipulator.getPreloadedDictionary)(dictionaryPromise, localeTarget);
|
|
44
|
+
if (preloadedDictionary) return require_getDictionary.getDictionary(preloadedDictionary, localeTarget);
|
|
43
45
|
const plainLoaders = dictionaryPromise;
|
|
44
46
|
const dictionary = require_client_useLoadDynamic.useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.());
|
|
45
47
|
return require_getDictionary.getDictionary(dictionary, localeTarget);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["useContext","IntlayerClientContext","parseDictionarySelector","resolveDictionaryArgument","internationalization","isQualifiedDynamicLoaderMap","resolveQualifiedDynamicContent","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 resolveDictionaryArgument,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\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 ?? 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":";;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["useContext","IntlayerClientContext","parseDictionarySelector","resolveDictionaryArgument","internationalization","isQualifiedDynamicLoaderMap","resolveQualifiedDynamicContent","loadDynamicChunk","getDictionary","getPreloadedDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["'use client';\n\nimport { internationalization } from '@intlayer/config/built';\nimport {\n getPreloadedDictionary,\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryArgument,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\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 ?? 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 // 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,iBAAiBC,4CAAqB;CAE1D,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"}
|
|
@@ -10,18 +10,45 @@ const createSuspender = (promise) => {
|
|
|
10
10
|
status = "error";
|
|
11
11
|
result = e;
|
|
12
12
|
});
|
|
13
|
-
return {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
return {
|
|
14
|
+
settled: suspender,
|
|
15
|
+
read() {
|
|
16
|
+
if (status === "pending") throw suspender;
|
|
17
|
+
if (status === "error") throw result;
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
18
21
|
};
|
|
19
22
|
const cache = /* @__PURE__ */ new Map();
|
|
20
23
|
const useLoadDynamic = (key, promise) => {
|
|
21
24
|
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
22
25
|
return cache.get(key).read();
|
|
23
26
|
};
|
|
27
|
+
/**
|
|
28
|
+
* Fills the same cache {@link useLoadDynamic} reads, ahead of render.
|
|
29
|
+
*
|
|
30
|
+
* A component that reads a dictionary during render suspends whenever the entry
|
|
31
|
+
* is still `pending`, and the nearest boundary shows its fallback. Awaiting this
|
|
32
|
+
* before the render — in a router loader, or during app startup — makes that
|
|
33
|
+
* read synchronous, so no boundary ever falls back.
|
|
34
|
+
*
|
|
35
|
+
* Handing over an already-resolved promise is not enough on its own:
|
|
36
|
+
* {@link createSuspender} only leaves `pending` inside a `.then` callback, so
|
|
37
|
+
* the first read would still suspend for one microtask. Awaiting the returned
|
|
38
|
+
* promise resolves that race, because the callback registered by
|
|
39
|
+
* `createSuspender` runs before this one.
|
|
40
|
+
*
|
|
41
|
+
* @param key - Cache key, identical to the one the later read uses.
|
|
42
|
+
* @param loader - Invoked only when the key is not cached yet, so preloading a
|
|
43
|
+
* dictionary twice never issues a second request.
|
|
44
|
+
* @returns A promise that settles — never rejects — once the entry is readable.
|
|
45
|
+
*/
|
|
46
|
+
const preloadDynamic = (key, loader) => {
|
|
47
|
+
if (!cache.has(key)) cache.set(key, createSuspender(loader()));
|
|
48
|
+
return cache.get(key).settled;
|
|
49
|
+
};
|
|
24
50
|
|
|
25
51
|
//#endregion
|
|
52
|
+
exports.preloadDynamic = preloadDynamic;
|
|
26
53
|
exports.useLoadDynamic = useLoadDynamic;
|
|
27
54
|
//# sourceMappingURL=useLoadDynamic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.cjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string,
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.cjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\ntype Suspender<T> = {\n /**\n * Settles once the entry has left `pending`, never rejecting. Awaiting it\n * guarantees a subsequent {@link Suspender.read} returns without suspending.\n */\n settled: Promise<void>;\n read: () => T;\n};\n\nconst createSuspender = <T>(promise: Promise<T>): Suspender<T> => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n settled: suspender,\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, Suspender<unknown>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as Suspender<T>).read() as T;\n};\n\n/**\n * Fills the same cache {@link useLoadDynamic} reads, ahead of render.\n *\n * A component that reads a dictionary during render suspends whenever the entry\n * is still `pending`, and the nearest boundary shows its fallback. Awaiting this\n * before the render — in a router loader, or during app startup — makes that\n * read synchronous, so no boundary ever falls back.\n *\n * Handing over an already-resolved promise is not enough on its own:\n * {@link createSuspender} only leaves `pending` inside a `.then` callback, so\n * the first read would still suspend for one microtask. Awaiting the returned\n * promise resolves that race, because the callback registered by\n * `createSuspender` runs before this one.\n *\n * @param key - Cache key, identical to the one the later read uses.\n * @param loader - Invoked only when the key is not cached yet, so preloading a\n * dictionary twice never issues a second request.\n * @returns A promise that settles — never rejects — once the entry is readable.\n */\nexport const preloadDynamic = <T>(\n key: string,\n loader: () => Promise<T>\n): Promise<void> => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(loader()) as Suspender<unknown>);\n }\n\n return cache.get(key)!.settled;\n};\n"],"mappings":";;AAWA,MAAM,mBAAsB,YAAsC;CAChE,IAAI,SAAiB;CACrB,IAAI;CACJ,MAAM,YAAY,QAAQ,MACvB,MAAM;EACL,SAAS;EACT,SAAS;CACX,IACC,MAAM;EACL,SAAS;EACT,SAAS;CACX,CACF;CAEA,OAAO;EACL,SAAS;EACT,OAAO;GACL,IAAI,WAAW,WAAW,MAAM;GAChC,IAAI,WAAW,SAAS,MAAM;GAC9B,OAAO;EACT;CACF;AACF;AAEA,MAAM,wBAAQ,IAAI,IAAgC;AAElD,MAAa,kBAAqB,KAAa,YAA2B;CACxE,IAAI,CAAC,MAAM,IAAI,GAAG,GAChB,MAAM,IAAI,KAAK,gBAAgB,OAAO,CAAC;CAGzC,OAAQ,MAAM,IAAI,GAAG,CAAC,CAAmB,KAAK;AAChD;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,kBACX,KACA,WACkB;CAClB,IAAI,CAAC,MAAM,IAAI,GAAG,GAChB,MAAM,IAAI,KAAK,gBAAgB,OAAO,CAAC,CAAuB;CAGhE,OAAO,MAAM,IAAI,GAAG,CAAC,CAAE;AACzB"}
|
|
@@ -5,7 +5,7 @@ import { getDictionary } from "../getDictionary.mjs";
|
|
|
5
5
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
6
6
|
import { internationalization } from "@intlayer/config/built";
|
|
7
7
|
import { useContext } from "react";
|
|
8
|
-
import { isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveDictionaryArgument, resolveQualifiedDynamicContent } from "@intlayer/core/dictionaryManipulator";
|
|
8
|
+
import { getPreloadedDictionary, isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveDictionaryArgument, resolveQualifiedDynamicContent } from "@intlayer/core/dictionaryManipulator";
|
|
9
9
|
|
|
10
10
|
//#region src/client/useDictionaryDynamic.ts
|
|
11
11
|
/**
|
|
@@ -39,6 +39,8 @@ const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
|
39
39
|
loadChunk: (cacheKey, promise) => useLoadDynamic(cacheKey, promise),
|
|
40
40
|
transform: (dictionary) => getDictionary(dictionary, localeTarget)
|
|
41
41
|
});
|
|
42
|
+
const preloadedDictionary = getPreloadedDictionary(dictionaryPromise, localeTarget);
|
|
43
|
+
if (preloadedDictionary) return getDictionary(preloadedDictionary, localeTarget);
|
|
42
44
|
const plainLoaders = dictionaryPromise;
|
|
43
45
|
const dictionary = useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.());
|
|
44
46
|
return getDictionary(dictionary, 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 resolveDictionaryArgument,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\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 ?? 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":";;;;;;;;;;;;;;;;;;;;;
|
|
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 getPreloadedDictionary,\n isQualifiedDynamicLoaderMap,\n parseDictionarySelector,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryArgument,\n resolveQualifiedDynamicContent,\n} from '@intlayer/core/dictionaryManipulator';\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 ?? 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 // 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,qBAAqB;CAE1D,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,eAAe,cAAc,YAAY,YAAY;CACnE,CAAC;CAMH,MAAM,sBAAsB,uBAC1B,mBACA,YACF;CACA,IAAI,qBACF,OAAO,cAAc,qBAA0B,YAAY;CAG7D,MAAM,eAAe;CAIrB,MAAM,aAAaA,eACjB,GAAG,OAAO,GAAG,EAAE,GAAG,gBAClB,aAAa,aAA0C,GAAG,CAC5D;CAEA,OAAO,cAAc,YAAY,YAAY;AAC/C"}
|
|
@@ -9,18 +9,44 @@ const createSuspender = (promise) => {
|
|
|
9
9
|
status = "error";
|
|
10
10
|
result = e;
|
|
11
11
|
});
|
|
12
|
-
return {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
return {
|
|
13
|
+
settled: suspender,
|
|
14
|
+
read() {
|
|
15
|
+
if (status === "pending") throw suspender;
|
|
16
|
+
if (status === "error") throw result;
|
|
17
|
+
return result;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
17
20
|
};
|
|
18
21
|
const cache = /* @__PURE__ */ new Map();
|
|
19
22
|
const useLoadDynamic = (key, promise) => {
|
|
20
23
|
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
21
24
|
return cache.get(key).read();
|
|
22
25
|
};
|
|
26
|
+
/**
|
|
27
|
+
* Fills the same cache {@link useLoadDynamic} reads, ahead of render.
|
|
28
|
+
*
|
|
29
|
+
* A component that reads a dictionary during render suspends whenever the entry
|
|
30
|
+
* is still `pending`, and the nearest boundary shows its fallback. Awaiting this
|
|
31
|
+
* before the render — in a router loader, or during app startup — makes that
|
|
32
|
+
* read synchronous, so no boundary ever falls back.
|
|
33
|
+
*
|
|
34
|
+
* Handing over an already-resolved promise is not enough on its own:
|
|
35
|
+
* {@link createSuspender} only leaves `pending` inside a `.then` callback, so
|
|
36
|
+
* the first read would still suspend for one microtask. Awaiting the returned
|
|
37
|
+
* promise resolves that race, because the callback registered by
|
|
38
|
+
* `createSuspender` runs before this one.
|
|
39
|
+
*
|
|
40
|
+
* @param key - Cache key, identical to the one the later read uses.
|
|
41
|
+
* @param loader - Invoked only when the key is not cached yet, so preloading a
|
|
42
|
+
* dictionary twice never issues a second request.
|
|
43
|
+
* @returns A promise that settles — never rejects — once the entry is readable.
|
|
44
|
+
*/
|
|
45
|
+
const preloadDynamic = (key, loader) => {
|
|
46
|
+
if (!cache.has(key)) cache.set(key, createSuspender(loader()));
|
|
47
|
+
return cache.get(key).settled;
|
|
48
|
+
};
|
|
23
49
|
|
|
24
50
|
//#endregion
|
|
25
|
-
export { useLoadDynamic };
|
|
51
|
+
export { preloadDynamic, useLoadDynamic };
|
|
26
52
|
//# sourceMappingURL=useLoadDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string,
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\ntype Suspender<T> = {\n /**\n * Settles once the entry has left `pending`, never rejecting. Awaiting it\n * guarantees a subsequent {@link Suspender.read} returns without suspending.\n */\n settled: Promise<void>;\n read: () => T;\n};\n\nconst createSuspender = <T>(promise: Promise<T>): Suspender<T> => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n settled: suspender,\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, Suspender<unknown>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as Suspender<T>).read() as T;\n};\n\n/**\n * Fills the same cache {@link useLoadDynamic} reads, ahead of render.\n *\n * A component that reads a dictionary during render suspends whenever the entry\n * is still `pending`, and the nearest boundary shows its fallback. Awaiting this\n * before the render — in a router loader, or during app startup — makes that\n * read synchronous, so no boundary ever falls back.\n *\n * Handing over an already-resolved promise is not enough on its own:\n * {@link createSuspender} only leaves `pending` inside a `.then` callback, so\n * the first read would still suspend for one microtask. Awaiting the returned\n * promise resolves that race, because the callback registered by\n * `createSuspender` runs before this one.\n *\n * @param key - Cache key, identical to the one the later read uses.\n * @param loader - Invoked only when the key is not cached yet, so preloading a\n * dictionary twice never issues a second request.\n * @returns A promise that settles — never rejects — once the entry is readable.\n */\nexport const preloadDynamic = <T>(\n key: string,\n loader: () => Promise<T>\n): Promise<void> => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(loader()) as Suspender<unknown>);\n }\n\n return cache.get(key)!.settled;\n};\n"],"mappings":";AAWA,MAAM,mBAAsB,YAAsC;CAChE,IAAI,SAAiB;CACrB,IAAI;CACJ,MAAM,YAAY,QAAQ,MACvB,MAAM;EACL,SAAS;EACT,SAAS;CACX,IACC,MAAM;EACL,SAAS;EACT,SAAS;CACX,CACF;CAEA,OAAO;EACL,SAAS;EACT,OAAO;GACL,IAAI,WAAW,WAAW,MAAM;GAChC,IAAI,WAAW,SAAS,MAAM;GAC9B,OAAO;EACT;CACF;AACF;AAEA,MAAM,wBAAQ,IAAI,IAAgC;AAElD,MAAa,kBAAqB,KAAa,YAA2B;CACxE,IAAI,CAAC,MAAM,IAAI,GAAG,GAChB,MAAM,IAAI,KAAK,gBAAgB,OAAO,CAAC;CAGzC,OAAQ,MAAM,IAAI,GAAG,CAAC,CAAmB,KAAK;AAChD;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,kBACX,KACA,WACkB;CAClB,IAAI,CAAC,MAAM,IAAI,GAAG,GAChB,MAAM,IAAI,KAAK,gBAAgB,OAAO,CAAC,CAAuB;CAGhE,OAAO,MAAM,IAAI,GAAG,CAAC,CAAE;AACzB"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalesValues } from "../../intlayer/dist/types/index.js";
|
|
1
2
|
//#region src/client/format/useCompact.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* React client hook that provides a compact number formatter
|
|
@@ -10,7 +11,7 @@
|
|
|
10
11
|
* ```
|
|
11
12
|
*/
|
|
12
13
|
declare const useCompact: () => (value: string | number, options?: Intl.NumberFormatOptions & {
|
|
13
|
-
locale?:
|
|
14
|
+
locale?: LocalesValues;
|
|
14
15
|
}) => string;
|
|
15
16
|
//#endregion
|
|
16
17
|
export { useCompact };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../../src/client/format/useCompact.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCompact.d.ts","names":[],"sources":["../../../../src/client/format/useCompact.ts"],"mappings":";;;;;;;;;;;;cAgBa,mBAAU,wBAAA,UAAA,KAAA;WAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalesValues } from "../../intlayer/dist/types/index.js";
|
|
1
2
|
//#region src/client/format/useCurrency.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* React client hook that provides a currency formatter
|
|
@@ -24,7 +25,7 @@
|
|
|
24
25
|
* ```
|
|
25
26
|
*/
|
|
26
27
|
declare const useCurrency: () => (value: string | number, options?: Intl.NumberFormatOptions & {
|
|
27
|
-
locale?:
|
|
28
|
+
locale?: LocalesValues;
|
|
28
29
|
}) => string;
|
|
29
30
|
//#endregion
|
|
30
31
|
export { useCurrency };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../../src/client/format/useCurrency.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCurrency.d.ts","names":[],"sources":["../../../../src/client/format/useCurrency.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;cA8Ba,oBAAW,wBAAA,UAAA,KAAA;WAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalesValues } from "../../intlayer/dist/types/index.js";
|
|
1
2
|
//#region src/client/format/useList.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* React client hook that provides a list formatter
|
|
@@ -25,7 +26,7 @@ declare const useList: () => (values: (string | number)[], options?: {
|
|
|
25
26
|
type?: 'conjunction' | 'disjunction' | 'unit';
|
|
26
27
|
style?: 'long' | 'short' | 'narrow';
|
|
27
28
|
} & {
|
|
28
|
-
locale?:
|
|
29
|
+
locale?: LocalesValues;
|
|
29
30
|
}) => string;
|
|
30
31
|
//#endregion
|
|
31
32
|
export { useList };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.d.ts","names":[],"sources":["../../../../src/client/format/useList.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useList.d.ts","names":[],"sources":["../../../../src/client/format/useList.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;cA2Ba,gBAAO,6BAAA;;;;;WAAP"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalesValues } from "../../intlayer/dist/types/index.js";
|
|
1
2
|
//#region src/client/format/useNumber.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* React client hook that provides a localized number formatter.
|
|
@@ -22,7 +23,7 @@
|
|
|
22
23
|
* A number formatting function bound to the active locale.
|
|
23
24
|
*/
|
|
24
25
|
declare const useNumber: () => (value: string | number, args_1?: Intl.NumberFormatOptions & {
|
|
25
|
-
locale?:
|
|
26
|
+
locale?: LocalesValues;
|
|
26
27
|
}) => string;
|
|
27
28
|
//#endregion
|
|
28
29
|
export { useNumber };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.d.ts","names":[],"sources":["../../../../src/client/format/useNumber.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNumber.d.ts","names":[],"sources":["../../../../src/client/format/useNumber.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;cA4Ba,kBAAS,wBAAA,SAAA,KAAA;WAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalesValues } from "../../intlayer/dist/types/index.js";
|
|
1
2
|
//#region src/client/format/usePercentage.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* React hook to provide a percentage formatter function
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
* A function that formats numbers or numeric strings into localized percentages.
|
|
19
20
|
*/
|
|
20
21
|
declare const usePercentage: () => (value: string | number, args_1?: Intl.NumberFormatOptions & {
|
|
21
|
-
locale?:
|
|
22
|
+
locale?: LocalesValues;
|
|
22
23
|
}) => string;
|
|
23
24
|
//#endregion
|
|
24
25
|
export { usePercentage };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.d.ts","names":[],"sources":["../../../../src/client/format/usePercentage.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePercentage.d.ts","names":[],"sources":["../../../../src/client/format/usePercentage.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cAwBa,sBAAa,wBAAA,SAAA,KAAA;WAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalesValues } from "../../intlayer/dist/types/index.js";
|
|
1
2
|
//#region src/client/format/useRelativeTime.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* Client-side React hook for accessing a localized relative time formatter.
|
|
@@ -18,7 +19,7 @@
|
|
|
18
19
|
* bound to the current client locale.
|
|
19
20
|
*/
|
|
20
21
|
declare const useRelativeTime: () => (from: string | number | Date, to?: string | number | Date, options?: Intl.RelativeTimeFormatOptions & {
|
|
21
|
-
locale?:
|
|
22
|
+
locale?: LocalesValues;
|
|
22
23
|
unit?: Intl.RelativeTimeFormatUnit;
|
|
23
24
|
}) => string;
|
|
24
25
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.d.ts","names":[],"sources":["../../../../src/client/format/useRelativeTime.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRelativeTime.d.ts","names":[],"sources":["../../../../src/client/format/useRelativeTime.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;cAwBa,wBAAe,wBAAA,MAAA,uBAAA,MAAA,UAAA,KAAA;WAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { LocalesValues } from "../../intlayer/dist/types/index.js";
|
|
1
2
|
//#region src/client/format/useUnit.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* React hook that provides a unit formatting function
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
* @returns {Function} A unit formatting function that accepts a value and optional formatting options.
|
|
18
19
|
*/
|
|
19
20
|
declare const useUnit: () => (value: string | number, options?: Intl.NumberFormatOptions & {
|
|
20
|
-
locale?:
|
|
21
|
+
locale?: LocalesValues;
|
|
21
22
|
}) => string;
|
|
22
23
|
//#endregion
|
|
23
24
|
export { useUnit };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.d.ts","names":[],"sources":["../../../../src/client/format/useUnit.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUnit.d.ts","names":[],"sources":["../../../../src/client/format/useUnit.ts"],"mappings":";;;;;;;;;;;;;;;;;;;cAuBa,gBAAO,wBAAA,UAAA,KAAA;WAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"mappings":";;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../../src/client/useDictionaryDynamic.ts"],"mappings":";;;;;;;;;;;;;;;cAsCa,6BACL,UAAU,kBACV,UAAU,sBACV,UAAU,gBAAgB,yBAAyB,KAAK,iBAAe,mBAGzE,0BAA0B,QAAQ,MAClC,2BAAyB,KACxB,GAAC,mBACa"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DeepTransformContent } from "../plugins.js";
|
|
2
2
|
import { DeclaredLocales, DictionaryKeys, DictionaryRegistryContent } from "@intlayer/types/module_augmentation";
|
|
3
|
-
import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
4
3
|
import { GetSubPath } from "@intlayer/types/dictionary";
|
|
4
|
+
import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
5
5
|
//#region src/client/useI18n.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Hook that provides a translation function `t()` for accessing nested content by key.
|
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
//#region src/client/useLoadDynamic.d.ts
|
|
2
2
|
declare const useLoadDynamic: <T>(key: string, promise: Promise<T>) => T;
|
|
3
|
+
/**
|
|
4
|
+
* Fills the same cache {@link useLoadDynamic} reads, ahead of render.
|
|
5
|
+
*
|
|
6
|
+
* A component that reads a dictionary during render suspends whenever the entry
|
|
7
|
+
* is still `pending`, and the nearest boundary shows its fallback. Awaiting this
|
|
8
|
+
* before the render — in a router loader, or during app startup — makes that
|
|
9
|
+
* read synchronous, so no boundary ever falls back.
|
|
10
|
+
*
|
|
11
|
+
* Handing over an already-resolved promise is not enough on its own:
|
|
12
|
+
* {@link createSuspender} only leaves `pending` inside a `.then` callback, so
|
|
13
|
+
* the first read would still suspend for one microtask. Awaiting the returned
|
|
14
|
+
* promise resolves that race, because the callback registered by
|
|
15
|
+
* `createSuspender` runs before this one.
|
|
16
|
+
*
|
|
17
|
+
* @param key - Cache key, identical to the one the later read uses.
|
|
18
|
+
* @param loader - Invoked only when the key is not cached yet, so preloading a
|
|
19
|
+
* dictionary twice never issues a second request.
|
|
20
|
+
* @returns A promise that settles — never rejects — once the entry is readable.
|
|
21
|
+
*/
|
|
22
|
+
declare const preloadDynamic: <T>(key: string, loader: () => Promise<T>) => Promise<void>;
|
|
3
23
|
//#endregion
|
|
4
|
-
export { useLoadDynamic };
|
|
24
|
+
export { preloadDynamic, useLoadDynamic };
|
|
5
25
|
//# sourceMappingURL=useLoadDynamic.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.d.ts","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.d.ts","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"mappings":";cAqCa,iBAAkB,GAAC,aAAa,SAAW,QAAQ,OAAK;;;;;;;;;;;;;;;;;;;;cA2BxD,iBAAkB,GAAC,aACnB,cACG,QAAQ,OACrB"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { LocalesValues } from "../intlayer/dist/types/index.js";
|
|
1
2
|
//#region src/client/useLocaleBase.d.ts
|
|
2
3
|
/**
|
|
3
4
|
* On the client side, hook to get the current locale and all related fields
|
|
4
5
|
*/
|
|
5
6
|
declare const useLocaleBase: () => {
|
|
6
|
-
locale:
|
|
7
|
+
locale: LocalesValues;
|
|
7
8
|
defaultLocale: any;
|
|
8
9
|
availableLocales: any;
|
|
9
|
-
setLocale: (newLocale:
|
|
10
|
+
setLocale: (newLocale: LocalesValues) => void;
|
|
10
11
|
};
|
|
11
12
|
//#endregion
|
|
12
13
|
export { useLocaleBase };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleBase.d.ts","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocaleBase.d.ts","names":[],"sources":["../../../src/client/useLocaleBase.ts"],"mappings":";;;;;cAWa;UAAA;;;yBAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Locale } from "../intlayer/dist/types/index.js";
|
|
1
2
|
import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
2
3
|
//#region src/client/useLocaleStorage.d.ts
|
|
3
4
|
/**
|
|
@@ -6,13 +7,13 @@ import { LocalesValues } from "@intlayer/types/module_augmentation";
|
|
|
6
7
|
/**
|
|
7
8
|
* Get the locale cookie
|
|
8
9
|
*/
|
|
9
|
-
declare const localeInStorage:
|
|
10
|
+
declare const localeInStorage: Locale;
|
|
10
11
|
/**
|
|
11
12
|
* @deprecated Use localeInStorage instead
|
|
12
13
|
*
|
|
13
14
|
* Get the locale cookie
|
|
14
15
|
*/
|
|
15
|
-
declare const localeCookie:
|
|
16
|
+
declare const localeCookie: Locale;
|
|
16
17
|
/**
|
|
17
18
|
* Set the locale cookie
|
|
18
19
|
*/
|
|
@@ -27,7 +28,7 @@ declare const setLocaleCookie: typeof setLocaleInStorage;
|
|
|
27
28
|
* Hook that provides the locale cookie and a function to set it
|
|
28
29
|
*/
|
|
29
30
|
declare const useLocaleStorage: (isCookieEnabled?: boolean) => {
|
|
30
|
-
getLocale: () =>
|
|
31
|
+
getLocale: () => Locale;
|
|
31
32
|
setLocale: (locale: LocalesValues) => void;
|
|
32
33
|
};
|
|
33
34
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.d.ts","names":[],"sources":["../../../src/client/useLocaleStorage.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.d.ts","names":[],"sources":["../../../src/client/useLocaleStorage.ts"],"mappings":";;;;;;;;;cAea,iBAAA;;;;;;cAMA,cAAA;;;;cAKA,qBAAkB,QACrB,eAAa;;;;;;cAaV,wBAAe;;;;cAKf,mBAAgB;mBAAhB;sBAAA;;;;;;;;;cAiBA,wBAAe"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "@intlayer/core/interpreter";
|
|
2
|
+
import { LocalesValues as LocalesValues$1 } from "@intlayer/types/module_augmentation";
|
|
3
|
+
import "@intlayer/types/config";
|
|
4
|
+
import { Dictionary } from "@intlayer/types/dictionary";
|
|
5
|
+
import { Locale } from "@intlayer/types/allLocales";
|
|
6
|
+
import "@intlayer/types/locales";
|
|
7
|
+
import "@intlayer/config/built";
|
|
8
|
+
import "@intlayer/core/file";
|
|
9
|
+
import "@intlayer/core/formatters";
|
|
10
|
+
import "@intlayer/core/localization";
|
|
11
|
+
import "@intlayer/core/markdown";
|
|
12
|
+
import "@intlayer/core/transpiler";
|
|
13
|
+
import "@intlayer/core/utils";
|
|
14
|
+
export type { Locale, LocalesValues$1 as LocalesValues };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DeepTransformContent } from "../plugins.js";
|
|
2
2
|
import { DictionaryKeys, DictionaryRegistryContent, LocalesValues } from "@intlayer/types/module_augmentation";
|
|
3
|
-
import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
4
3
|
import { GetSubPath } from "@intlayer/types/dictionary";
|
|
4
|
+
import { ValidDotPathsFor } from "@intlayer/core/transpiler";
|
|
5
5
|
//#region src/server/useI18n.d.ts
|
|
6
6
|
/**
|
|
7
7
|
* Hook that provides a translation function `t()` for accessing nested content by key.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-intlayer",
|
|
3
|
-
"version": "9.3.
|
|
3
|
+
"version": "9.3.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your React applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -133,11 +133,11 @@
|
|
|
133
133
|
},
|
|
134
134
|
"dependencies": {
|
|
135
135
|
"@intlayer/api": "9.3.2",
|
|
136
|
-
"@intlayer/config": "9.3.
|
|
137
|
-
"@intlayer/core": "9.3.
|
|
138
|
-
"@intlayer/dictionaries-entry": "9.3.
|
|
139
|
-
"@intlayer/editor": "9.3.
|
|
140
|
-
"@intlayer/types": "9.3.
|
|
136
|
+
"@intlayer/config": "9.3.3",
|
|
137
|
+
"@intlayer/core": "9.3.3",
|
|
138
|
+
"@intlayer/dictionaries-entry": "9.3.3",
|
|
139
|
+
"@intlayer/editor": "9.3.3",
|
|
140
|
+
"@intlayer/types": "9.3.3"
|
|
141
141
|
},
|
|
142
142
|
"devDependencies": {
|
|
143
143
|
"@craco/types": "7.1.0",
|
|
@@ -151,14 +151,14 @@
|
|
|
151
151
|
"rimraf": "6.1.3",
|
|
152
152
|
"tsdown": "0.22.14",
|
|
153
153
|
"typescript": "7.0.2",
|
|
154
|
-
"vitest": "4.1.
|
|
154
|
+
"vitest": "4.1.11"
|
|
155
155
|
},
|
|
156
156
|
"peerDependencies": {
|
|
157
157
|
"react": ">=16.0.0",
|
|
158
158
|
"react-dom": ">=16.0.0"
|
|
159
159
|
},
|
|
160
160
|
"optionalDependencies": {
|
|
161
|
-
"@intlayer/analytics": "9.3.
|
|
161
|
+
"@intlayer/analytics": "9.3.3"
|
|
162
162
|
},
|
|
163
163
|
"engines": {
|
|
164
164
|
"node": ">=14.18"
|