preact-intlayer 9.8.5 → 9.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/useDictionaryAsync.cjs +6 -5
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +11 -21
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +9 -21
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +7 -6
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +13 -23
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +9 -21
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts +1 -1
- package/dist/types/client/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +3 -4
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useLoadDynamic.d.ts +4 -0
- package/dist/types/client/useLoadDynamic.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_getDictionary = require("../getDictionary.cjs");
|
|
2
3
|
const require_client_IntlayerProvider = require("./IntlayerProvider.cjs");
|
|
3
|
-
const require_client_useDictionary = require("./useDictionary.cjs");
|
|
4
4
|
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
5
|
let preact_hooks = require("preact/hooks");
|
|
6
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
6
7
|
|
|
7
8
|
// src/client/useDictionaryAsync.ts
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* Hook that loads the locale chunk of a dictionary and returns its content.
|
|
10
11
|
*
|
|
11
12
|
* If the locale is not provided, it will use the locale from the client context
|
|
12
13
|
*/
|
|
13
14
|
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
14
15
|
const { locale: currentLocale } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
15
|
-
const localeTarget =
|
|
16
|
-
const dictionary = await (0,
|
|
17
|
-
return
|
|
16
|
+
const localeTarget = locale ?? currentLocale ?? (0, _intlayer_core_interpreter.resolveInterpreterLocale)();
|
|
17
|
+
const dictionary = await (0, _intlayer_core_dictionaryManipulator.loadDynamicDictionary)(dictionaryPromise, localeTarget);
|
|
18
|
+
return require_getDictionary.getDictionary(dictionary, localeTarget);
|
|
18
19
|
};
|
|
19
20
|
|
|
20
21
|
exports.useDictionaryAsync = useDictionaryAsync;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.cjs","names":["useContext","IntlayerClientContext","
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["useContext","IntlayerClientContext","resolveInterpreterLocale","loadDynamicDictionary","getDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["import { loadDynamicDictionary } from '@intlayer/core/dictionaryManipulator';\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Hook that loads the locale chunk of a dictionary and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <const T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n // Read before the first `await`: a hook only runs synchronously in render\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n const localeTarget = locale ?? currentLocale ?? resolveInterpreterLocale();\n\n const dictionary = (await loadDynamicDictionary(\n dictionaryPromise,\n localeTarget\n )) as T;\n\n return getDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":";;;;;;;;;;;;;AAgBA,MAAa,qBAAqB,OAChC,mBACA,WACe;CAEf,MAAM,EAAE,QAAQ,sBAAkBA,yBAAWC,qDAAqB,KAAK,CAAC;CACxE,MAAM,eAAe,UAAU,qBAAiBC,qDAAyB;CAEzE,MAAM,aAAc,UAAMC,4DACxB,mBACA,YACF;CAEA,OAAOC,oCAAc,YAAY,YAAY;AAC/C"}
|
|
@@ -2,7 +2,6 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
2
2
|
const require_getDictionary = require("../getDictionary.cjs");
|
|
3
3
|
const require_client_IntlayerProvider = require("./IntlayerProvider.cjs");
|
|
4
4
|
const require_client_useLoadDynamic = require("./useLoadDynamic.cjs");
|
|
5
|
-
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
6
5
|
let preact_hooks = require("preact/hooks");
|
|
7
6
|
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
8
7
|
|
|
@@ -10,39 +9,30 @@ let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryMan
|
|
|
10
9
|
/**
|
|
11
10
|
* Preact hook that lazily loads a dictionary and returns its content.
|
|
12
11
|
*
|
|
13
|
-
* The
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* the selector targets are loaded.
|
|
12
|
+
* The locale, selector, chunk selection and transform are resolved by the
|
|
13
|
+
* shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only
|
|
14
|
+
* contributes the provider context and the Suspense cache.
|
|
17
15
|
*
|
|
18
16
|
* If the locale is not provided (directly or through the selector), the client
|
|
19
17
|
* context locale is used.
|
|
20
18
|
*/
|
|
21
19
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
22
20
|
const { locale: currentLocale, variant: contextVariant } = (0, preact_hooks.useContext)(require_client_IntlayerProvider.IntlayerClientContext) ?? {};
|
|
23
|
-
const
|
|
21
|
+
const dictionaryKey = String(key);
|
|
22
|
+
const { locale, selector } = (0, _intlayer_core_dictionaryManipulator.resolveDictionaryRead)({
|
|
24
23
|
localeOrSelector,
|
|
25
24
|
contextLocale: currentLocale,
|
|
26
25
|
contextVariant,
|
|
27
|
-
dictionaryKey
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
selector: void 0
|
|
31
|
-
};
|
|
32
|
-
const localeTarget = selectorLocale ?? currentLocale ?? (0, _intlayer_core_interpreter.resolveInterpreterLocale)();
|
|
33
|
-
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && (0, _intlayer_core_dictionaryManipulator.isQualifiedDynamicLoaderMap)(dictionaryPromise)) return (0, _intlayer_core_dictionaryManipulator.resolveQualifiedDynamicContent)({
|
|
26
|
+
dictionaryKey
|
|
27
|
+
});
|
|
28
|
+
return (0, _intlayer_core_dictionaryManipulator.resolveDynamicContent)({
|
|
34
29
|
loaderMap: dictionaryPromise,
|
|
35
|
-
key:
|
|
36
|
-
locale
|
|
30
|
+
key: dictionaryKey,
|
|
31
|
+
locale,
|
|
37
32
|
selector,
|
|
38
33
|
loadChunk: (cacheKey, promise) => require_client_useLoadDynamic.useLoadDynamic(cacheKey, promise),
|
|
39
|
-
transform: (dictionary) => require_getDictionary.getDictionary(dictionary,
|
|
34
|
+
transform: (dictionary, argument) => require_getDictionary.getDictionary(dictionary, argument)
|
|
40
35
|
});
|
|
41
|
-
const preloadedDictionary = (0, _intlayer_core_dictionaryManipulator.getPreloadedDictionary)(dictionaryPromise, localeTarget);
|
|
42
|
-
if (preloadedDictionary) return require_getDictionary.getDictionary(preloadedDictionary, localeTarget);
|
|
43
|
-
const plainLoaders = dictionaryPromise;
|
|
44
|
-
const dictionary = require_client_useLoadDynamic.useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.());
|
|
45
|
-
return require_getDictionary.getDictionary(dictionary, localeTarget);
|
|
46
36
|
};
|
|
47
37
|
|
|
48
38
|
exports.useDictionaryDynamic = useDictionaryDynamic;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.cjs","names":["useContext","IntlayerClientContext","
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["useContext","IntlayerClientContext","resolveDictionaryRead","resolveDynamicContent","loadDynamicChunk","getDictionary"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import {\n type DynamicLoaderMap,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryRead,\n resolveDynamicContent,\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 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n// `useLoadDynamic` is a suspender cache, not a hook — aliased to a non-hook\n// name so it can be invoked in loops / conditionally (collection chunks).\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Preact hook that lazily loads a dictionary and returns its content.\n *\n * The locale, selector, chunk selection and transform are resolved by the\n * shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only\n * contributes the provider context and the Suspense cache.\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 dictionaryKey = String(key);\n\n const { locale, selector } = resolveDictionaryRead({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey,\n });\n\n return resolveDynamicContent({\n loaderMap: dictionaryPromise as DynamicLoaderMap,\n key: dictionaryKey,\n locale,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary, argument) => getDictionary(dictionary, argument),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AA+BA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,eAAe,SAAS,uBACtCA,yBAAWC,qDAAqB,KAAK,CAAC;CAExC,MAAM,gBAAgB,OAAO,GAAG;CAEhC,MAAM,EAAE,QAAQ,iBAAaC,4DAAsB;EACjD;EACA,eAAe;EACf;EACA;CACF,CAAC;CAED,WAAOC,4DAAsB;EAC3B,WAAW;EACX,KAAK;EACL;EACA;EACA,YAAY,UAAU,YAAYC,6CAAiB,UAAU,OAAO;EACpE,YAAY,YAAY,aAAaC,oCAAc,YAAY,QAAQ;CACzE,CAAC;AACH"}
|
|
@@ -1,26 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
let _intlayer_core_dictionaryManipulator = require("@intlayer/core/dictionaryManipulator");
|
|
3
|
+
|
|
2
4
|
// src/client/useLoadDynamic.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
status = "error";
|
|
11
|
-
result = e;
|
|
12
|
-
});
|
|
13
|
-
return { read() {
|
|
14
|
-
if (status === "pending") throw suspender;
|
|
15
|
-
if (status === "error") throw result;
|
|
16
|
-
return result;
|
|
17
|
-
} };
|
|
18
|
-
};
|
|
19
|
-
const cache = /* @__PURE__ */ new Map();
|
|
20
|
-
const useLoadDynamic = (key, promise) => {
|
|
21
|
-
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
22
|
-
return cache.get(key).read();
|
|
23
|
-
};
|
|
5
|
+
/** Chunk cache read by every dynamic dictionary of the page. */
|
|
6
|
+
const chunkCache = (0, _intlayer_core_dictionaryManipulator.createChunkSuspenseCache)();
|
|
7
|
+
/**
|
|
8
|
+
* Reads a chunk the Suspense way: throws while `promise` is pending, then
|
|
9
|
+
* returns its value. Only the first `promise` given for a `key` is used.
|
|
10
|
+
*/
|
|
11
|
+
const useLoadDynamic = (key, promise) => chunkCache.read(key, promise);
|
|
24
12
|
|
|
25
13
|
exports.useLoadDynamic = useLoadDynamic;
|
|
26
14
|
//# sourceMappingURL=useLoadDynamic.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.cjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.cjs","names":["createChunkSuspenseCache"],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["import { createChunkSuspenseCache } from '@intlayer/core/dictionaryManipulator';\n\n/** Chunk cache read by every dynamic dictionary of the page. */\nconst chunkCache = createChunkSuspenseCache();\n\n/**\n * Reads a chunk the Suspense way: throws while `promise` is pending, then\n * returns its value. Only the first `promise` given for a `key` is used.\n */\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T =>\n chunkCache.read(key, promise);\n"],"mappings":";;;;;AAGA,MAAM,iBAAaA,+DAAyB;;;;;AAM5C,MAAa,kBAAqB,KAAa,YAC7C,WAAW,KAAK,KAAK,OAAO"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
+
import { getDictionary as getDictionary$1 } from "../getDictionary.mjs";
|
|
1
2
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
2
|
-
import { useDictionary } from "./useDictionary.mjs";
|
|
3
3
|
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
4
|
-
import { useContext
|
|
4
|
+
import { useContext } from "preact/hooks";
|
|
5
|
+
import { loadDynamicDictionary } from "@intlayer/core/dictionaryManipulator";
|
|
5
6
|
|
|
6
7
|
// src/client/useDictionaryAsync.ts
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
+
* Hook that loads the locale chunk of a dictionary and returns its content.
|
|
9
10
|
*
|
|
10
11
|
* If the locale is not provided, it will use the locale from the client context
|
|
11
12
|
*/
|
|
12
13
|
const useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
13
14
|
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
14
|
-
const localeTarget =
|
|
15
|
-
const dictionary = await
|
|
16
|
-
return
|
|
15
|
+
const localeTarget = locale ?? currentLocale ?? resolveInterpreterLocale();
|
|
16
|
+
const dictionary = await loadDynamicDictionary(dictionaryPromise, localeTarget);
|
|
17
|
+
return getDictionary$1(dictionary, localeTarget);
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
export { useDictionaryAsync };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.mjs","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["import { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":["getDictionary"],"sources":["../../../src/client/useDictionaryAsync.ts"],"sourcesContent":["import { loadDynamicDictionary } from '@intlayer/core/dictionaryManipulator';\nimport { resolveInterpreterLocale } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n LocalesValues,\n StrictModeLocaleMap,\n} from '@intlayer/types/module_augmentation';\nimport { useContext } from 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Hook that loads the locale chunk of a dictionary and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionaryAsync = async <const T extends Dictionary>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: LocalesValues\n): Promise<T> => {\n // Read before the first `await`: a hook only runs synchronously in render\n const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};\n const localeTarget = locale ?? currentLocale ?? resolveInterpreterLocale();\n\n const dictionary = (await loadDynamicDictionary(\n dictionaryPromise,\n localeTarget\n )) as T;\n\n return getDictionary(dictionary, localeTarget) as any;\n};\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,qBAAqB,OAChC,mBACA,WACe;CAEf,MAAM,EAAE,QAAQ,kBAAkB,WAAW,qBAAqB,KAAK,CAAC;CACxE,MAAM,eAAe,UAAU,iBAAiB,yBAAyB;CAEzE,MAAM,aAAc,MAAM,sBACxB,mBACA,YACF;CAEA,OAAOA,gBAAc,YAAY,YAAY;AAC/C"}
|
|
@@ -1,47 +1,37 @@
|
|
|
1
|
-
import { getDictionary
|
|
1
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
2
2
|
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
3
3
|
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
4
|
-
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
5
4
|
import { useContext } from "preact/hooks";
|
|
6
|
-
import {
|
|
5
|
+
import { resolveDictionaryRead, resolveDynamicContent } from "@intlayer/core/dictionaryManipulator";
|
|
7
6
|
|
|
8
7
|
// src/client/useDictionaryDynamic.ts
|
|
9
8
|
/**
|
|
10
9
|
* Preact hook that lazily loads a dictionary and returns its content.
|
|
11
10
|
*
|
|
12
|
-
* The
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* the selector targets are loaded.
|
|
11
|
+
* The locale, selector, chunk selection and transform are resolved by the
|
|
12
|
+
* shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only
|
|
13
|
+
* contributes the provider context and the Suspense cache.
|
|
16
14
|
*
|
|
17
15
|
* If the locale is not provided (directly or through the selector), the client
|
|
18
16
|
* context locale is used.
|
|
19
17
|
*/
|
|
20
18
|
const useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
21
19
|
const { locale: currentLocale, variant: contextVariant } = useContext(IntlayerClientContext) ?? {};
|
|
22
|
-
const
|
|
20
|
+
const dictionaryKey = String(key);
|
|
21
|
+
const { locale, selector } = resolveDictionaryRead({
|
|
23
22
|
localeOrSelector,
|
|
24
23
|
contextLocale: currentLocale,
|
|
25
24
|
contextVariant,
|
|
26
|
-
dictionaryKey
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
selector: void 0
|
|
30
|
-
};
|
|
31
|
-
const localeTarget = selectorLocale ?? currentLocale ?? resolveInterpreterLocale();
|
|
32
|
-
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && isQualifiedDynamicLoaderMap(dictionaryPromise)) return resolveQualifiedDynamicContent({
|
|
25
|
+
dictionaryKey
|
|
26
|
+
});
|
|
27
|
+
return resolveDynamicContent({
|
|
33
28
|
loaderMap: dictionaryPromise,
|
|
34
|
-
key:
|
|
35
|
-
locale
|
|
29
|
+
key: dictionaryKey,
|
|
30
|
+
locale,
|
|
36
31
|
selector,
|
|
37
32
|
loadChunk: (cacheKey, promise) => useLoadDynamic(cacheKey, promise),
|
|
38
|
-
transform: (dictionary) => getDictionary
|
|
33
|
+
transform: (dictionary, argument) => getDictionary(dictionary, argument)
|
|
39
34
|
});
|
|
40
|
-
const preloadedDictionary = getPreloadedDictionary(dictionaryPromise, localeTarget);
|
|
41
|
-
if (preloadedDictionary) return getDictionary$1(preloadedDictionary, localeTarget);
|
|
42
|
-
const plainLoaders = dictionaryPromise;
|
|
43
|
-
const dictionary = useLoadDynamic(`${String(key)}.${localeTarget}`, plainLoaders[localeTarget]?.());
|
|
44
|
-
return getDictionary$1(dictionary, localeTarget);
|
|
45
35
|
};
|
|
46
36
|
|
|
47
37
|
export { useDictionaryDynamic };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["loadDynamicChunk"],"sources":["../../../src/client/useDictionaryDynamic.ts"],"sourcesContent":["import {\n type DynamicLoaderMap,\n type QualifiedDynamicLoaderMap,\n resolveDictionaryRead,\n resolveDynamicContent,\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 'preact/hooks';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n// `useLoadDynamic` is a suspender cache, not a hook — aliased to a non-hook\n// name so it can be invoked in loops / conditionally (collection chunks).\nimport { useLoadDynamic as loadDynamicChunk } from './useLoadDynamic';\n\n/**\n * Preact hook that lazily loads a dictionary and returns its content.\n *\n * The locale, selector, chunk selection and transform are resolved by the\n * shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only\n * contributes the provider context and the Suspense cache.\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 dictionaryKey = String(key);\n\n const { locale, selector } = resolveDictionaryRead({\n localeOrSelector,\n contextLocale: currentLocale,\n contextVariant,\n dictionaryKey,\n });\n\n return resolveDynamicContent({\n loaderMap: dictionaryPromise as DynamicLoaderMap,\n key: dictionaryKey,\n locale,\n selector,\n loadChunk: (cacheKey, promise) => loadDynamicChunk(cacheKey, promise),\n transform: (dictionary, argument) => getDictionary(dictionary, argument),\n });\n};\n"],"mappings":";;;;;;;;;;;;;;;;;AA+BA,MAAa,wBAKX,mBAGA,KACA,qBACG;CACH,MAAM,EAAE,QAAQ,eAAe,SAAS,mBACtC,WAAW,qBAAqB,KAAK,CAAC;CAExC,MAAM,gBAAgB,OAAO,GAAG;CAEhC,MAAM,EAAE,QAAQ,aAAa,sBAAsB;EACjD;EACA,eAAe;EACf;EACA;CACF,CAAC;CAED,OAAO,sBAAsB;EAC3B,WAAW;EACX,KAAK;EACL;EACA;EACA,YAAY,UAAU,YAAYA,eAAiB,UAAU,OAAO;EACpE,YAAY,YAAY,aAAa,cAAc,YAAY,QAAQ;CACzE,CAAC;AACH"}
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
+
import { createChunkSuspenseCache } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
|
|
1
3
|
// src/client/useLoadDynamic.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
status = "error";
|
|
10
|
-
result = e;
|
|
11
|
-
});
|
|
12
|
-
return { read() {
|
|
13
|
-
if (status === "pending") throw suspender;
|
|
14
|
-
if (status === "error") throw result;
|
|
15
|
-
return result;
|
|
16
|
-
} };
|
|
17
|
-
};
|
|
18
|
-
const cache = /* @__PURE__ */ new Map();
|
|
19
|
-
const useLoadDynamic = (key, promise) => {
|
|
20
|
-
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
21
|
-
return cache.get(key).read();
|
|
22
|
-
};
|
|
4
|
+
/** Chunk cache read by every dynamic dictionary of the page. */
|
|
5
|
+
const chunkCache = createChunkSuspenseCache();
|
|
6
|
+
/**
|
|
7
|
+
* Reads a chunk the Suspense way: throws while `promise` is pending, then
|
|
8
|
+
* returns its value. Only the first `promise` given for a `key` is used.
|
|
9
|
+
*/
|
|
10
|
+
const useLoadDynamic = (key, promise) => chunkCache.read(key, promise);
|
|
23
11
|
|
|
24
12
|
export { useLoadDynamic };
|
|
25
13
|
//# sourceMappingURL=useLoadDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["import { createChunkSuspenseCache } from '@intlayer/core/dictionaryManipulator';\n\n/** Chunk cache read by every dynamic dictionary of the page. */\nconst chunkCache = createChunkSuspenseCache();\n\n/**\n * Reads a chunk the Suspense way: throws while `promise` is pending, then\n * returns its value. Only the first `promise` given for a `key` is used.\n */\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T =>\n chunkCache.read(key, promise);\n"],"mappings":";;;;AAGA,MAAM,aAAa,yBAAyB;;;;;AAM5C,MAAa,kBAAqB,KAAa,YAC7C,WAAW,KAAK,KAAK,OAAO"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LocalesValues, StrictModeLocaleMap } from "@intlayer/types/module_augmentation";
|
|
2
2
|
import { Dictionary } from "@intlayer/types/dictionary";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Hook that loads the locale chunk of a dictionary and returns its content.
|
|
5
5
|
*
|
|
6
6
|
* If the locale is not provided, it will use the locale from the client context
|
|
7
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionaryAsync.d.ts","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.d.ts","names":[],"sources":["../../../src/client/useDictionaryAsync.ts"],"mappings":";;;;;;;qBAgBa,2BAAkC,UAAU,YAAU,mBAC9C,0BAA0B,QAAQ,KAAG,SAC/C,kBACR,QAAQ"}
|
|
@@ -4,10 +4,9 @@ import { QualifiedDynamicLoaderMap } from "@intlayer/core/dictionaryManipulator"
|
|
|
4
4
|
/**
|
|
5
5
|
* Preact hook that lazily loads a dictionary and returns its content.
|
|
6
6
|
*
|
|
7
|
-
* The
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* the selector targets are loaded.
|
|
7
|
+
* The locale, selector, chunk selection and transform are resolved by the
|
|
8
|
+
* shared `resolveDictionaryRead` / `resolveDynamicContent`, so this hook only
|
|
9
|
+
* contributes the provider context and the Suspense cache.
|
|
11
10
|
*
|
|
12
11
|
* If the locale is not provided (directly or through the selector), the client
|
|
13
12
|
* context locale is used.
|
|
@@ -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":";;;;;;;;;;;;;qBA+Ba,6BACL,UAAU,kBACV,UAAU,sBACV,UAAU,gBAAgB,yBAAyB,KAAK,iBAAe,mBAGzE,0BAA0B,QAAQ,MAClC,2BAAyB,KACxB,GAAC,mBACa"}
|
|
@@ -1,2 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a chunk the Suspense way: throws while `promise` is pending, then
|
|
3
|
+
* returns its value. Only the first `promise` given for a `key` is used.
|
|
4
|
+
*/
|
|
1
5
|
export declare const useLoadDynamic: <T>(key: string, promise: Promise<T>) => T;
|
|
2
6
|
//# 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":";;;;qBASa,iBAAkB,GAAC,aAAa,SAAW,QAAQ,OAAK"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "preact-intlayer",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.9.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Easily internationalize i18n your Preact applications with type-safe multilingual content management.",
|
|
6
6
|
"keywords": [
|
|
@@ -101,12 +101,12 @@
|
|
|
101
101
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
102
102
|
},
|
|
103
103
|
"dependencies": {
|
|
104
|
-
"@intlayer/api": "9.
|
|
105
|
-
"@intlayer/config": "9.
|
|
106
|
-
"@intlayer/core": "9.
|
|
107
|
-
"@intlayer/editor": "9.
|
|
108
|
-
"@intlayer/engine": "9.
|
|
109
|
-
"@intlayer/types": "9.
|
|
104
|
+
"@intlayer/api": "9.9.1",
|
|
105
|
+
"@intlayer/config": "9.9.1",
|
|
106
|
+
"@intlayer/core": "9.9.1",
|
|
107
|
+
"@intlayer/editor": "9.9.1",
|
|
108
|
+
"@intlayer/engine": "9.9.1",
|
|
109
|
+
"@intlayer/types": "9.9.1"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
112
|
"@types/node": "^26",
|
|
@@ -117,13 +117,13 @@
|
|
|
117
117
|
"rimraf": "6.1.4",
|
|
118
118
|
"tsdown": "0.23.7",
|
|
119
119
|
"typescript": "7.0.2",
|
|
120
|
-
"vitest": "5.1.
|
|
120
|
+
"vitest": "5.1.2"
|
|
121
121
|
},
|
|
122
122
|
"peerDependencies": {
|
|
123
123
|
"preact": ">=8.0.0"
|
|
124
124
|
},
|
|
125
125
|
"optionalDependencies": {
|
|
126
|
-
"@intlayer/analytics": "9.
|
|
126
|
+
"@intlayer/analytics": "9.9.1"
|
|
127
127
|
},
|
|
128
128
|
"engines": {
|
|
129
129
|
"node": ">=14.18"
|