solid-intlayer 9.9.3-canary.1 → 9.9.4
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/IntlayerNode.cjs +11 -1
- package/dist/cjs/LoadingBoundary.cjs +26 -1
- package/dist/cjs/analytics/AnalyticsProvider.cjs +12 -1
- package/dist/cjs/analytics/exposureSink.cjs +23 -1
- package/dist/cjs/analytics/index.cjs +9 -1
- package/dist/cjs/analytics/useAnalytics.cjs +59 -1
- package/dist/cjs/analytics/useConversion.cjs +25 -1
- package/dist/cjs/analytics/useExperiment.cjs +59 -1
- package/dist/cjs/client/IntlayerProvider.cjs +91 -1
- package/dist/cjs/client/contentProxy.cjs +32 -1
- package/dist/cjs/client/getBrowserLocale.cjs +115 -1
- package/dist/cjs/client/index.cjs +35 -1
- package/dist/cjs/client/t.cjs +16 -1
- package/dist/cjs/client/useContent.cjs +16 -1
- package/dist/cjs/client/useDictionary.cjs +51 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +19 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +82 -1
- package/dist/cjs/client/useIntlayer.cjs +50 -1
- package/dist/cjs/client/useLoadDynamic.cjs +140 -1
- package/dist/cjs/client/useLocale.cjs +52 -1
- package/dist/cjs/client/useLocaleBase.cjs +19 -1
- package/dist/cjs/client/useLocaleStorage.cjs +59 -1
- package/dist/cjs/client/usePathname.cjs +41 -1
- package/dist/cjs/client/useRewriteURL.cjs +21 -1
- package/dist/cjs/client/useTraduction.cjs +32 -1
- package/dist/cjs/editor/ContentSelector.cjs +20 -1
- package/dist/cjs/editor/EditorProvider.cjs +8 -1
- package/dist/cjs/editor/createEditedContentSource.cjs +32 -1
- package/dist/cjs/editor/useEditor.cjs +38 -1
- package/dist/cjs/format/index.cjs +19 -1
- package/dist/cjs/format/useCompact.cjs +15 -1
- package/dist/cjs/format/useCurrency.cjs +16 -1
- package/dist/cjs/format/useDate.cjs +25 -1
- package/dist/cjs/format/useIntl.cjs +31 -1
- package/dist/cjs/format/useList.cjs +15 -1
- package/dist/cjs/format/useNumber.cjs +19 -1
- package/dist/cjs/format/usePercentage.cjs +16 -1
- package/dist/cjs/format/useRelativeTime.cjs +16 -1
- package/dist/cjs/format/useUnit.cjs +15 -1
- package/dist/cjs/getDictionary.cjs +17 -1
- package/dist/cjs/getIntlayer.cjs +14 -1
- package/dist/cjs/html/HTMLProvider.cjs +24 -1
- package/dist/cjs/html/HTMLRenderer.cjs +49 -1
- package/dist/cjs/html/index.cjs +8 -1
- package/dist/cjs/html/types.cjs +1 -1
- package/dist/cjs/index.cjs +48 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +47 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +56 -1
- package/dist/cjs/markdown/compiler.cjs +64 -1
- package/dist/cjs/markdown/index.cjs +13 -1
- package/dist/cjs/markdown/runtime.cjs +48 -1
- package/dist/cjs/plugins.cjs +266 -1
- package/dist/cjs/proxyKeys.cjs +14 -1
- package/dist/cjs/server/index.cjs +3 -1
- package/dist/cjs/server/useDictionary.cjs +30 -1
- package/dist/cjs/solidCompat.cjs +167 -1
- package/dist/cjs/solidElement/renderSolidElement.cjs +34 -1
- package/dist/cjs/solidTypes.cjs +1 -1
- package/dist/esm/IntlayerNode.mjs +8 -6
- package/dist/esm/LoadingBoundary.mjs +19 -6
- package/dist/esm/analytics/AnalyticsProvider.mjs +10 -3
- package/dist/esm/analytics/exposureSink.mjs +19 -5
- package/dist/esm/analytics/index.mjs +5 -5
- package/dist/esm/analytics/useAnalytics.mjs +52 -25
- package/dist/esm/analytics/useConversion.mjs +22 -6
- package/dist/esm/analytics/useExperiment.mjs +50 -22
- package/dist/esm/client/IntlayerProvider.mjs +75 -28
- package/dist/esm/client/contentProxy.mjs +26 -12
- package/dist/esm/client/getBrowserLocale.mjs +106 -71
- package/dist/esm/client/index.mjs +14 -14
- package/dist/esm/client/t.mjs +13 -7
- package/dist/esm/client/useContent.mjs +11 -8
- package/dist/esm/client/useDictionary.mjs +47 -25
- package/dist/esm/client/useDictionaryAsync.mjs +16 -9
- package/dist/esm/client/useDictionaryDynamic.mjs +72 -43
- package/dist/esm/client/useIntlayer.mjs +45 -15
- package/dist/esm/client/useLoadDynamic.mjs +128 -49
- package/dist/esm/client/useLocale.mjs +47 -16
- package/dist/esm/client/useLocaleBase.mjs +14 -10
- package/dist/esm/client/useLocaleStorage.mjs +51 -10
- package/dist/esm/client/usePathname.mjs +37 -12
- package/dist/esm/client/useRewriteURL.mjs +17 -11
- package/dist/esm/client/useTraduction.mjs +29 -8
- package/dist/esm/editor/ContentSelector.mjs +18 -15
- package/dist/esm/editor/EditorProvider.mjs +6 -3
- package/dist/esm/editor/createEditedContentSource.mjs +28 -17
- package/dist/esm/editor/useEditor.mjs +32 -22
- package/dist/esm/format/index.mjs +10 -10
- package/dist/esm/format/useCompact.mjs +11 -8
- package/dist/esm/format/useCurrency.mjs +12 -9
- package/dist/esm/format/useDate.mjs +19 -13
- package/dist/esm/format/useIntl.mjs +27 -9
- package/dist/esm/format/useList.mjs +11 -8
- package/dist/esm/format/useNumber.mjs +15 -9
- package/dist/esm/format/usePercentage.mjs +12 -9
- package/dist/esm/format/useRelativeTime.mjs +12 -9
- package/dist/esm/format/useUnit.mjs +11 -8
- package/dist/esm/getDictionary.mjs +14 -6
- package/dist/esm/getIntlayer.mjs +11 -6
- package/dist/esm/html/HTMLProvider.mjs +21 -12
- package/dist/esm/html/HTMLRenderer.mjs +44 -17
- package/dist/esm/html/index.mjs +3 -3
- package/dist/esm/index.mjs +20 -20
- package/dist/esm/markdown/MarkdownProvider.mjs +31 -24
- package/dist/esm/markdown/MarkdownRenderer.mjs +48 -37
- package/dist/esm/markdown/compiler.mjs +59 -23
- package/dist/esm/markdown/index.mjs +4 -4
- package/dist/esm/markdown/runtime.mjs +40 -13
- package/dist/esm/plugins.mjs +205 -156
- package/dist/esm/proxyKeys.mjs +7 -2
- package/dist/esm/server/useDictionary.mjs +25 -7
- package/dist/esm/solidCompat.mjs +146 -39
- package/dist/esm/solidElement/renderSolidElement.mjs +22 -19
- package/dist/rolldown-runtime-CmQyd0Gu.js +27 -0
- package/dist/solid/analytics/useAnalytics.jsx +3 -3
- package/dist/solid/analytics/useConversion.js +2 -2
- package/dist/solid/analytics/useExperiment.js +3 -3
- package/package.json +7 -7
- package/dist/esm-YGODKOLP.js +0 -1
- package/dist/esm-bdKnuomJ.mjs +0 -256
- package/dist/isEnabled-CuTKz0YA.js +0 -1
- package/dist/isEnabled-DVKEZ2He.mjs +0 -18
- package/dist/rolldown-runtime-BocRIvOZ.js +0 -1
- package/dist/solid/esm-1cHk4dPd.js +0 -644
- package/dist/solid/isEnabled-C5NUhdhZ.js +0 -100
package/dist/esm/client/t.mjs
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { getTranslation
|
|
2
|
-
import { useContext
|
|
3
|
-
import { IntlayerClientContext
|
|
1
|
+
import { getTranslation } from "@intlayer/core/interpreter";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
4
|
// src/client/t.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
/**
|
|
6
|
+
* On the client side, this function returns the translation of the provided multilang content.
|
|
7
|
+
*
|
|
8
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
9
|
+
*/
|
|
10
|
+
var t = (multilangContent, locale) => {
|
|
11
|
+
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
12
|
+
const localeTarget = locale ?? (typeof currentLocale === "function" ? currentLocale() : currentLocale);
|
|
13
|
+
return getTranslation(multilangContent, localeTarget);
|
|
8
14
|
};
|
|
9
|
-
export {
|
|
15
|
+
export { t };
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { useLocaleBase
|
|
2
|
-
import { useTranslation
|
|
1
|
+
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
2
|
+
import { useTranslation } from "./useTraduction.mjs";
|
|
3
3
|
// src/client/useContent.ts
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
/**
|
|
5
|
+
* On the client side, hook to get the translation content based on the locale
|
|
6
|
+
*/
|
|
7
|
+
var useContent = (languageContent) => {
|
|
8
|
+
const { locale } = useLocaleBase();
|
|
6
9
|
return {
|
|
7
|
-
locale
|
|
8
|
-
content:
|
|
9
|
-
t
|
|
10
|
+
locale,
|
|
11
|
+
content: useTranslation(languageContent),
|
|
12
|
+
t: useTranslation
|
|
10
13
|
};
|
|
11
14
|
};
|
|
12
|
-
export {
|
|
15
|
+
export { useContent };
|
|
@@ -1,28 +1,50 @@
|
|
|
1
|
-
import { resolveDictionaryArgument
|
|
2
|
-
import { collectTransformCacheWrites
|
|
3
|
-
import { createMemo
|
|
4
|
-
import { getDictionary as
|
|
5
|
-
import { getPlugins
|
|
6
|
-
import { createContentProxy
|
|
7
|
-
import { IntlayerClientContext
|
|
8
|
-
import { unwrapLoadable
|
|
1
|
+
import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
import { collectTransformCacheWrites, deleteTransformCacheWrites } from "@intlayer/core/interpreter";
|
|
3
|
+
import { createMemo, onCleanup, useContext } from "solid-js";
|
|
4
|
+
import { getDictionary as getDictionary$1 } from "../getDictionary.mjs";
|
|
5
|
+
import { getPlugins } from "../plugins.mjs";
|
|
6
|
+
import { createContentProxy } from "./contentProxy.mjs";
|
|
7
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
8
|
+
import { unwrapLoadable } from "./useLoadDynamic.mjs";
|
|
9
9
|
// src/client/useDictionary.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
/**
|
|
11
|
+
* On the client side, Hook that transforms a dictionary (or qualified
|
|
12
|
+
* dictionary group) and returns its reactive content.
|
|
13
|
+
*
|
|
14
|
+
* The second argument is either a locale or a selector object
|
|
15
|
+
* (`{ item }`, `{ variant }`, optionally with `locale`).
|
|
16
|
+
*
|
|
17
|
+
* If the locale is not provided (directly or through the selector), it will
|
|
18
|
+
* use the locale from the client context.
|
|
19
|
+
*/
|
|
20
|
+
var useDictionary = (dictionary, localeOrSelector) => {
|
|
21
|
+
const context = useContext(IntlayerClientContext) ?? {};
|
|
22
|
+
const instancePlugins = /* @__PURE__ */ new Map();
|
|
23
|
+
const getInstancePlugins = (locale) => {
|
|
24
|
+
const sharedPlugins = getPlugins(locale);
|
|
25
|
+
let ownPlugins = instancePlugins.get(sharedPlugins);
|
|
26
|
+
if (!ownPlugins) {
|
|
27
|
+
ownPlugins = [...sharedPlugins];
|
|
28
|
+
instancePlugins.set(sharedPlugins, ownPlugins);
|
|
29
|
+
}
|
|
30
|
+
return ownPlugins;
|
|
31
|
+
};
|
|
32
|
+
const interpret = () => {
|
|
33
|
+
const currentLocale = context?.locale?.();
|
|
34
|
+
const source = unwrapLoadable(dictionary) ?? dictionary;
|
|
35
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") return getDictionary$1(source, resolveDictionaryArgument({
|
|
36
|
+
localeOrSelector,
|
|
37
|
+
contextLocale: currentLocale,
|
|
38
|
+
contextVariant: context?.variant?.(),
|
|
39
|
+
dictionaryKey: dictionary.key
|
|
40
|
+
}), getInstancePlugins);
|
|
41
|
+
return getDictionary$1(source, localeOrSelector ?? currentLocale, getInstancePlugins);
|
|
42
|
+
};
|
|
43
|
+
const accessor = createMemo(() => {
|
|
44
|
+
const { result, writes } = collectTransformCacheWrites(interpret);
|
|
45
|
+
if (writes.length > 0) onCleanup(() => deleteTransformCacheWrites(writes));
|
|
46
|
+
return result;
|
|
25
47
|
});
|
|
26
|
-
return
|
|
48
|
+
return createContentProxy(accessor);
|
|
27
49
|
};
|
|
28
|
-
export {
|
|
50
|
+
export { useDictionary };
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
import { loadDynamicDictionary
|
|
2
|
-
import { resolveInterpreterLocale
|
|
3
|
-
import { useContext
|
|
4
|
-
import { IntlayerClientContext
|
|
5
|
-
import { useDictionary
|
|
1
|
+
import { loadDynamicDictionary } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
import { resolveInterpreterLocale } from "@intlayer/core/interpreter";
|
|
3
|
+
import { useContext } from "solid-js";
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
6
6
|
// src/client/useDictionaryAsync.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/**
|
|
8
|
+
* On the server side, Hook that transform a dictionary and return the content
|
|
9
|
+
*
|
|
10
|
+
* If the locale is not provided, it will use the locale from the client context
|
|
11
|
+
*/
|
|
12
|
+
var useDictionaryAsync = async (dictionaryPromise, locale) => {
|
|
13
|
+
const { locale: currentLocale } = useContext(IntlayerClientContext) ?? {};
|
|
14
|
+
const localeTarget = locale ?? currentLocale() ?? resolveInterpreterLocale();
|
|
15
|
+
const dictionary = await loadDynamicDictionary(dictionaryPromise, localeTarget);
|
|
16
|
+
return useDictionary(dictionary, localeTarget);
|
|
10
17
|
};
|
|
11
|
-
export {
|
|
18
|
+
export { useDictionaryAsync };
|
|
@@ -1,52 +1,81 @@
|
|
|
1
|
-
import { QUALIFIER_DYNAMIC_TYPES_KEY
|
|
2
|
-
import { createMemo
|
|
3
|
-
import { getDictionary
|
|
4
|
-
import { createAsyncValue
|
|
5
|
-
import { createContentProxy
|
|
6
|
-
import { IntlayerClientContext
|
|
7
|
-
import { useDictionary
|
|
8
|
-
import { seedDynamicValue
|
|
1
|
+
import { QUALIFIER_DYNAMIC_TYPES_KEY, getDictionarySelectorCacheKey, getDynamicChunkArgument, getPreloadedDictionary, isQualifiedDynamicLoaderMap, parseDictionarySelector, resolveDictionaryRead, resolveDynamicContentAsync } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
import { createMemo, useContext } from "solid-js";
|
|
3
|
+
import { getDictionary } from "../getDictionary.mjs";
|
|
4
|
+
import { createAsyncValue, trackAsyncValue } from "../solidCompat.mjs";
|
|
5
|
+
import { createContentProxy } from "./contentProxy.mjs";
|
|
6
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
7
|
+
import { useDictionary } from "./useDictionary.mjs";
|
|
8
|
+
import { seedDynamicValue, useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
9
9
|
// src/client/useDictionaryDynamic.ts
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Loaded chunks stay raw (serializable for hydration) and are interpreted
|
|
12
|
+
* inside the component owner. A collection's metadata is plain data, resolved
|
|
13
|
+
* right away — its index holds no dictionary to interpret anyway.
|
|
14
|
+
*/
|
|
15
|
+
var keepRawChunk = (dictionary) => dictionary;
|
|
16
|
+
var readChunkMetadata = (dictionary, argument) => getDictionary(dictionary, argument);
|
|
17
|
+
/**
|
|
18
|
+
* On the client side, Hook that lazily loads a dictionary and returns its
|
|
19
|
+
* reactive content.
|
|
20
|
+
*
|
|
21
|
+
* The locale, selector and chunk selection are resolved by the shared
|
|
22
|
+
* `resolveDictionaryRead` / `resolveDynamicContentAsync`; this hook only adds
|
|
23
|
+
* Solid's resources and owner-scoped interpretation.
|
|
24
|
+
*
|
|
25
|
+
* If the locale is not provided (directly or through the selector), it will
|
|
26
|
+
* use the locale from the client context.
|
|
27
|
+
*/
|
|
28
|
+
var useDictionaryDynamic = (dictionaryPromise, key, localeOrSelector) => {
|
|
29
|
+
const context = useContext(IntlayerClientContext) ?? {};
|
|
30
|
+
const dictionaryKey = String(key);
|
|
31
|
+
const loaderMap = dictionaryPromise;
|
|
32
|
+
const { locale: callLocale, selector: callSelector } = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? parseDictionarySelector(localeOrSelector) : {
|
|
33
|
+
locale: localeOrSelector,
|
|
13
34
|
selector: void 0
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
};
|
|
36
|
+
const readAccessor = () => resolveDictionaryRead({
|
|
37
|
+
localeOrSelector,
|
|
38
|
+
contextLocale: context.locale?.(),
|
|
39
|
+
contextVariant: context.variant?.(),
|
|
40
|
+
dictionaryKey
|
|
41
|
+
});
|
|
42
|
+
const sourceAccessor = () => {
|
|
43
|
+
const read = readAccessor();
|
|
44
|
+
const chunkSelectorId = process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" ? getDictionarySelectorCacheKey({
|
|
45
|
+
...read.selector,
|
|
22
46
|
metadataOnly: void 0
|
|
23
|
-
});
|
|
47
|
+
}) : "";
|
|
24
48
|
return {
|
|
25
|
-
...
|
|
26
|
-
cacheKey:
|
|
49
|
+
...read,
|
|
50
|
+
cacheKey: chunkSelectorId ? `${dictionaryKey}.${read.locale}.${chunkSelectorId}` : `${dictionaryKey}.${read.locale}`
|
|
27
51
|
};
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
};
|
|
53
|
+
const loadContent = (read, transform) => resolveDynamicContentAsync({
|
|
54
|
+
loaderMap,
|
|
55
|
+
key: dictionaryKey,
|
|
56
|
+
...read,
|
|
57
|
+
transform
|
|
58
|
+
});
|
|
59
|
+
const chunkArgument = getDynamicChunkArgument(callLocale, callSelector);
|
|
60
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && isQualifiedDynamicLoaderMap(loaderMap) && loaderMap[QUALIFIER_DYNAMIC_TYPES_KEY].includes("item") && callSelector?.item === void 0) {
|
|
61
|
+
const resolvedEntries = createAsyncValue(readAccessor, (read) => loadContent(read, callSelector?.metadataOnly ? readChunkMetadata : keepRawChunk));
|
|
62
|
+
const accessor = createMemo(() => {
|
|
63
|
+
const resolved = resolvedEntries();
|
|
64
|
+
if (!Array.isArray(resolved)) return [];
|
|
65
|
+
if (callSelector?.metadataOnly) return resolved;
|
|
66
|
+
const { locale } = readAccessor();
|
|
67
|
+
return resolved.map((dictionary) => getDictionary(dictionary, locale));
|
|
41
68
|
});
|
|
42
|
-
|
|
69
|
+
trackAsyncValue(resolvedEntries);
|
|
70
|
+
return createContentProxy(accessor);
|
|
43
71
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
72
|
+
const initialSource = sourceAccessor();
|
|
73
|
+
const preloadedDictionary = getPreloadedDictionary(loaderMap, initialSource.locale);
|
|
74
|
+
if (preloadedDictionary) seedDynamicValue(initialSource, preloadedDictionary);
|
|
75
|
+
const dictionary = useLoadDynamic(sourceAccessor, (source) => loadContent(source, keepRawChunk).then((resolved) => {
|
|
76
|
+
if (resolved === null) throw new Error(`No dynamic dictionary chunk found for key "${dictionaryKey}" and locale "${source.locale}".`);
|
|
77
|
+
return resolved;
|
|
49
78
|
}));
|
|
50
|
-
return
|
|
79
|
+
return useDictionary(dictionary, chunkArgument);
|
|
51
80
|
};
|
|
52
|
-
export {
|
|
81
|
+
export { useDictionaryDynamic };
|
|
@@ -1,19 +1,49 @@
|
|
|
1
|
-
import { resolveDictionaryArgument
|
|
2
|
-
import { createMemo
|
|
3
|
-
import { getIntlayer
|
|
4
|
-
import { createContentProxy
|
|
5
|
-
import { IntlayerClientContext
|
|
1
|
+
import { resolveDictionaryArgument } from "@intlayer/core/dictionaryManipulator";
|
|
2
|
+
import { createMemo, useContext } from "solid-js";
|
|
3
|
+
import { getIntlayer } from "../getIntlayer.mjs";
|
|
4
|
+
import { createContentProxy } from "./contentProxy.mjs";
|
|
5
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
6
6
|
// src/client/useIntlayer.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Solid hook that picks one dictionary by its key and returns its reactive content.
|
|
9
|
+
*
|
|
10
|
+
* The second argument is either a locale or a selector object:
|
|
11
|
+
* - `{ item: 2 }` — collection item (omit `item` to get every item as array)
|
|
12
|
+
* - `{ variant: 'black-friday' }` — named variant (omit for the `default` one)
|
|
13
|
+
* - `locale` composes with any selector and overrides the context locale
|
|
14
|
+
*
|
|
15
|
+
* Supports both direct property access and the accessor call form:
|
|
16
|
+
* - `content.myField.value` — reactive when used inside JSX or other Solid reactive contexts
|
|
17
|
+
* - `content()` — backward-compatible accessor form
|
|
18
|
+
*
|
|
19
|
+
* @param key - The unique key of the dictionary to retrieve.
|
|
20
|
+
* @param localeOrSelector - Optional locale or selector.
|
|
21
|
+
* @returns Reactive content accessible via property access or function call.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* import { useIntlayer } from 'solid-intlayer';
|
|
26
|
+
*
|
|
27
|
+
* const MyComponent = () => {
|
|
28
|
+
* const content = useIntlayer('my-dictionary-key');
|
|
29
|
+
* const faq2 = useIntlayer('faq', { item: 2 });
|
|
30
|
+
*
|
|
31
|
+
* return <div>{content.myField.value}</div>;
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
var useIntlayer = (key, localeOrSelector) => {
|
|
36
|
+
const context = useContext(IntlayerClientContext) ?? {};
|
|
37
|
+
const accessor = createMemo(() => {
|
|
38
|
+
const currentLocale = context?.locale?.();
|
|
39
|
+
if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false") return getIntlayer(key, resolveDictionaryArgument({
|
|
40
|
+
localeOrSelector,
|
|
41
|
+
contextLocale: currentLocale,
|
|
42
|
+
contextVariant: context?.variant?.(),
|
|
43
|
+
dictionaryKey: key
|
|
15
44
|
}));
|
|
45
|
+
return getIntlayer(key, localeOrSelector ?? currentLocale);
|
|
16
46
|
});
|
|
17
|
-
return
|
|
47
|
+
return createContentProxy(accessor);
|
|
18
48
|
};
|
|
19
|
-
export {
|
|
49
|
+
export { useIntlayer };
|
|
@@ -1,55 +1,134 @@
|
|
|
1
|
-
import { untrack
|
|
2
|
-
import { PROXY_RESERVED_KEYS
|
|
3
|
-
import { createAsyncValue
|
|
1
|
+
import { untrack } from "solid-js";
|
|
2
|
+
import { PROXY_RESERVED_KEYS } from "../proxyKeys.mjs";
|
|
3
|
+
import { createAsyncValue, trackAsyncValue } from "../solidCompat.mjs";
|
|
4
4
|
// src/client/useLoadDynamic.ts
|
|
5
|
-
var
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
5
|
+
var NO_PENDING_PRIMITIVE_FALLBACK = Symbol("NO_PENDING_PRIMITIVE_FALLBACK");
|
|
6
|
+
/**
|
|
7
|
+
* Property exposing the settled value behind a loadable proxy, or `undefined`
|
|
8
|
+
* while the chunk is still in flight. See {@link unwrapLoadable}.
|
|
9
|
+
*/
|
|
10
|
+
var LOADABLE_SETTLED_VALUE = Symbol("LOADABLE_SETTLED_VALUE");
|
|
11
|
+
/**
|
|
12
|
+
* Module-level cache to dedupe dynamic imports by key. Solid async primitives
|
|
13
|
+
* still own suspense, SSR serialization, hydration, and refetching on source
|
|
14
|
+
* change.
|
|
15
|
+
*/
|
|
16
|
+
var cache = /* @__PURE__ */ new Map();
|
|
17
|
+
var getDynamicSourceCacheKey = (source) => typeof source === "string" ? source : source.cacheKey;
|
|
18
|
+
var readValueAtPath = (value, path) => path.reduce((currentValue, property) => {
|
|
19
|
+
if (currentValue === null || currentValue === void 0) return void 0;
|
|
20
|
+
return Reflect.get(Object(currentValue), property);
|
|
21
|
+
}, value);
|
|
22
|
+
var resolveDynamicLoader = (loader, source) => typeof loader === "function" ? loader(source) : loader;
|
|
23
|
+
var loadDynamicValue = (source, loader) => {
|
|
24
|
+
const key = getDynamicSourceCacheKey(source);
|
|
25
|
+
const cachedEntry = cache.get(key);
|
|
26
|
+
if (cachedEntry?.status === "success") return cachedEntry.value;
|
|
27
|
+
if (cachedEntry?.status === "pending") return cachedEntry.promise;
|
|
28
|
+
const promise = resolveDynamicLoader(loader, source).then((value) => {
|
|
29
|
+
cache.set(key, {
|
|
30
|
+
status: "success",
|
|
31
|
+
value
|
|
32
|
+
});
|
|
33
|
+
return value;
|
|
34
|
+
}, (error) => {
|
|
35
|
+
cache.delete(key);
|
|
36
|
+
throw error;
|
|
16
37
|
});
|
|
17
|
-
|
|
38
|
+
cache.set(key, {
|
|
18
39
|
status: "pending",
|
|
19
|
-
promise
|
|
20
|
-
}), i;
|
|
21
|
-
}, d = (e, t) => {
|
|
22
|
-
let n = s(e);
|
|
23
|
-
o.has(n) || o.set(n, {
|
|
24
|
-
status: "success",
|
|
25
|
-
value: t
|
|
40
|
+
promise
|
|
26
41
|
});
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
}
|
|
42
|
+
return promise;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Records a value that is already available, so the next
|
|
46
|
+
* {@link loadDynamicValue} for this key returns it synchronously.
|
|
47
|
+
*
|
|
48
|
+
* Used for dictionaries a build-tool plugin awaited while their entry point
|
|
49
|
+
* evaluated: the async value resolves without ever entering a pending state,
|
|
50
|
+
* so the loading boundary is not triggered and the first render already has the content.
|
|
51
|
+
*
|
|
52
|
+
* An existing entry is never replaced — an in-flight load owns its key.
|
|
53
|
+
*/
|
|
54
|
+
var seedDynamicValue = (source, value) => {
|
|
55
|
+
const key = getDynamicSourceCacheKey(source);
|
|
56
|
+
if (cache.has(key)) return;
|
|
57
|
+
cache.set(key, {
|
|
58
|
+
status: "success",
|
|
59
|
+
value
|
|
47
60
|
});
|
|
48
|
-
return r([]);
|
|
49
|
-
}, h = (e) => {
|
|
50
|
-
if (!(e === null || typeof e != "object" && typeof e != "function")) return e[a];
|
|
51
|
-
}, g = (e, t) => {
|
|
52
|
-
let i = n(() => typeof e == "function" ? e() : e, (e) => u(e, t));
|
|
53
|
-
return r(i), m(i);
|
|
54
61
|
};
|
|
55
|
-
|
|
62
|
+
var bindPropertyValue = (value, propertyValue) => typeof propertyValue === "function" ? propertyValue.bind(value) : propertyValue;
|
|
63
|
+
var createPendingPrimitiveFallback = (property) => {
|
|
64
|
+
if (property === Symbol.toPrimitive) return () => "";
|
|
65
|
+
if (property === Symbol.iterator) return () => ({ next: () => ({
|
|
66
|
+
done: true,
|
|
67
|
+
value: void 0
|
|
68
|
+
}) });
|
|
69
|
+
if (property === "length") return 0;
|
|
70
|
+
if (property === PROXY_RESERVED_KEYS.toString) return () => "";
|
|
71
|
+
if (property === PROXY_RESERVED_KEYS.valueOf) return () => void 0;
|
|
72
|
+
if (property === PROXY_RESERVED_KEYS.value) return "";
|
|
73
|
+
return NO_PENDING_PRIMITIVE_FALLBACK;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Creates a stable callable proxy that re-reads the Solid async value on each
|
|
77
|
+
* property access. This keeps synchronous Intlayer access (`content.x.value`)
|
|
78
|
+
* safe while the Solid loading boundary owns the actual pending state.
|
|
79
|
+
*/
|
|
80
|
+
var createLoadableProxy = (read) => {
|
|
81
|
+
const createProxyAtPath = (path) => {
|
|
82
|
+
const target = () => void 0;
|
|
83
|
+
return new Proxy(target, {
|
|
84
|
+
get(_target, property) {
|
|
85
|
+
if (property === PROXY_RESERVED_KEYS.promiseThen) return void 0;
|
|
86
|
+
const currentValue = readValueAtPath(read(), path);
|
|
87
|
+
if (property === LOADABLE_SETTLED_VALUE) return currentValue;
|
|
88
|
+
if (currentValue !== null && currentValue !== void 0) {
|
|
89
|
+
if (property === Symbol.toPrimitive) return () => currentValue;
|
|
90
|
+
return bindPropertyValue(currentValue, Reflect.get(Object(currentValue), property));
|
|
91
|
+
}
|
|
92
|
+
const primitiveFallback = createPendingPrimitiveFallback(property);
|
|
93
|
+
if (primitiveFallback !== NO_PENDING_PRIMITIVE_FALLBACK) return primitiveFallback;
|
|
94
|
+
return createProxyAtPath([...path, property]);
|
|
95
|
+
},
|
|
96
|
+
apply(_target, thisArgument, argumentsList) {
|
|
97
|
+
const currentValue = readValueAtPath(read(), path);
|
|
98
|
+
if (typeof currentValue !== "function") {
|
|
99
|
+
if (argumentsList.length === 0) return currentValue ?? "";
|
|
100
|
+
return createLoadableProxy(() => {
|
|
101
|
+
const resolvedValue = readValueAtPath(read(), path);
|
|
102
|
+
if (typeof resolvedValue !== "function") return void 0;
|
|
103
|
+
return untrack(() => Reflect.apply(resolvedValue, thisArgument, argumentsList));
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
return Reflect.apply(currentValue, thisArgument, argumentsList);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
return createProxyAtPath([]);
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Returns the settled value a loadable proxy stands for, or `undefined` while
|
|
114
|
+
* its chunk is in flight — and for any value that is not a loadable proxy.
|
|
115
|
+
*
|
|
116
|
+
* The read stays tracked, so a caller inside a reactive scope re-runs once the
|
|
117
|
+
* chunk lands. Interpreting the settled dictionary rather than the stand-in is
|
|
118
|
+
* what lets `getDictionary` memoize the transform: the stand-in is created per
|
|
119
|
+
* component and its content changes over time, while the settled dictionary is
|
|
120
|
+
* one shared object every component resolves to.
|
|
121
|
+
*
|
|
122
|
+
* @param value - A loadable proxy, or any other value.
|
|
123
|
+
*/
|
|
124
|
+
var unwrapLoadable = (value) => {
|
|
125
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
|
|
126
|
+
return value[LOADABLE_SETTLED_VALUE];
|
|
127
|
+
};
|
|
128
|
+
var useLoadDynamic = (key, loader) => {
|
|
129
|
+
const keyAccessor = () => typeof key === "function" ? key() : key;
|
|
130
|
+
const asyncValue = createAsyncValue(keyAccessor, (resolvedSource) => loadDynamicValue(resolvedSource, loader));
|
|
131
|
+
trackAsyncValue(asyncValue);
|
|
132
|
+
return createLoadableProxy(asyncValue);
|
|
133
|
+
};
|
|
134
|
+
export { createLoadableProxy, getDynamicSourceCacheKey, loadDynamicValue, seedDynamicValue, unwrapLoadable, useLoadDynamic };
|
|
@@ -1,20 +1,51 @@
|
|
|
1
|
-
import { internationalization
|
|
2
|
-
import { useContext
|
|
3
|
-
import { createChangeEffect
|
|
4
|
-
import { IntlayerClientContext
|
|
5
|
-
import { setLocaleInStorage
|
|
1
|
+
import { internationalization } from "@intlayer/config/built";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { createChangeEffect } from "../solidCompat.mjs";
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
|
+
import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
6
6
|
// src/client/useLocale.ts
|
|
7
|
-
var { defaultLocale
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
var { defaultLocale, locales: availableLocales } = internationalization ?? {};
|
|
8
|
+
/**
|
|
9
|
+
* Solid hook to manage the current locale and related functions.
|
|
10
|
+
*
|
|
11
|
+
* @param props - Optional configuration for locale management.
|
|
12
|
+
* @returns An object containing the current locale (accessor), default locale, available locales, and a function to update the locale.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { useLocale } from 'solid-intlayer';
|
|
17
|
+
*
|
|
18
|
+
* const LocaleSwitcher = () => {
|
|
19
|
+
* const { locale, setLocale, availableLocales } = useLocale();
|
|
20
|
+
*
|
|
21
|
+
* return (
|
|
22
|
+
* <select value={locale()} onChange={(e) => setLocale(e.target.value)}>
|
|
23
|
+
* <For each={availableLocales}>
|
|
24
|
+
* {(loc) => <option value={loc}>{loc}</option>}
|
|
25
|
+
* </For>
|
|
26
|
+
* </select>
|
|
27
|
+
* );
|
|
28
|
+
* };
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
var useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
32
|
+
const context = useContext(IntlayerClientContext);
|
|
33
|
+
const setLocale = (locale) => {
|
|
34
|
+
if (!availableLocales?.map(String).includes(locale)) {
|
|
35
|
+
console.error(`Locale ${locale} is not available`);
|
|
36
|
+
return;
|
|
17
37
|
}
|
|
38
|
+
context?.setLocale(locale);
|
|
39
|
+
setLocaleInStorage(locale, isCookieEnabled ?? context?.isCookieEnabled ?? true);
|
|
40
|
+
};
|
|
41
|
+
createChangeEffect(() => context?.locale?.(), (currentLocale) => {
|
|
42
|
+
if (onLocaleChange && currentLocale !== void 0) onLocaleChange(currentLocale);
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
locale: context?.locale,
|
|
46
|
+
defaultLocale,
|
|
47
|
+
availableLocales,
|
|
48
|
+
setLocale
|
|
18
49
|
};
|
|
19
50
|
};
|
|
20
|
-
export {
|
|
51
|
+
export { useLocale };
|
|
@@ -1,14 +1,18 @@
|
|
|
1
|
-
import { internationalization
|
|
2
|
-
import { useContext
|
|
3
|
-
import { IntlayerClientContext
|
|
1
|
+
import { internationalization } from "@intlayer/config/built";
|
|
2
|
+
import { useContext } from "solid-js";
|
|
3
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
4
|
// src/client/useLocaleBase.ts
|
|
5
|
-
var { defaultLocale
|
|
6
|
-
|
|
5
|
+
var { defaultLocale, locales: availableLocales } = internationalization;
|
|
6
|
+
/**
|
|
7
|
+
* On the client side, hook to get the current locale and all related fields
|
|
8
|
+
*/
|
|
9
|
+
var useLocaleBase = () => {
|
|
10
|
+
const { locale, setLocale } = useContext(IntlayerClientContext) ?? {};
|
|
7
11
|
return {
|
|
8
|
-
locale
|
|
9
|
-
defaultLocale
|
|
10
|
-
availableLocales
|
|
11
|
-
setLocale
|
|
12
|
+
locale,
|
|
13
|
+
defaultLocale,
|
|
14
|
+
availableLocales,
|
|
15
|
+
setLocale
|
|
12
16
|
};
|
|
13
17
|
};
|
|
14
|
-
export {
|
|
18
|
+
export { useLocaleBase };
|