solid-intlayer 9.9.3 → 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.
Files changed (125) hide show
  1. package/dist/cjs/IntlayerNode.cjs +11 -1
  2. package/dist/cjs/LoadingBoundary.cjs +26 -1
  3. package/dist/cjs/analytics/AnalyticsProvider.cjs +12 -1
  4. package/dist/cjs/analytics/exposureSink.cjs +23 -1
  5. package/dist/cjs/analytics/index.cjs +9 -1
  6. package/dist/cjs/analytics/useAnalytics.cjs +59 -1
  7. package/dist/cjs/analytics/useConversion.cjs +25 -1
  8. package/dist/cjs/analytics/useExperiment.cjs +59 -1
  9. package/dist/cjs/client/IntlayerProvider.cjs +91 -1
  10. package/dist/cjs/client/contentProxy.cjs +32 -1
  11. package/dist/cjs/client/getBrowserLocale.cjs +115 -1
  12. package/dist/cjs/client/index.cjs +35 -1
  13. package/dist/cjs/client/t.cjs +16 -1
  14. package/dist/cjs/client/useContent.cjs +16 -1
  15. package/dist/cjs/client/useDictionary.cjs +51 -1
  16. package/dist/cjs/client/useDictionaryAsync.cjs +19 -1
  17. package/dist/cjs/client/useDictionaryDynamic.cjs +82 -1
  18. package/dist/cjs/client/useIntlayer.cjs +50 -1
  19. package/dist/cjs/client/useLoadDynamic.cjs +140 -1
  20. package/dist/cjs/client/useLocale.cjs +52 -1
  21. package/dist/cjs/client/useLocaleBase.cjs +19 -1
  22. package/dist/cjs/client/useLocaleStorage.cjs +59 -1
  23. package/dist/cjs/client/usePathname.cjs +41 -1
  24. package/dist/cjs/client/useRewriteURL.cjs +21 -1
  25. package/dist/cjs/client/useTraduction.cjs +32 -1
  26. package/dist/cjs/editor/ContentSelector.cjs +20 -1
  27. package/dist/cjs/editor/EditorProvider.cjs +8 -1
  28. package/dist/cjs/editor/createEditedContentSource.cjs +32 -1
  29. package/dist/cjs/editor/useEditor.cjs +38 -1
  30. package/dist/cjs/format/index.cjs +19 -1
  31. package/dist/cjs/format/useCompact.cjs +15 -1
  32. package/dist/cjs/format/useCurrency.cjs +16 -1
  33. package/dist/cjs/format/useDate.cjs +25 -1
  34. package/dist/cjs/format/useIntl.cjs +31 -1
  35. package/dist/cjs/format/useList.cjs +15 -1
  36. package/dist/cjs/format/useNumber.cjs +19 -1
  37. package/dist/cjs/format/usePercentage.cjs +16 -1
  38. package/dist/cjs/format/useRelativeTime.cjs +16 -1
  39. package/dist/cjs/format/useUnit.cjs +15 -1
  40. package/dist/cjs/getDictionary.cjs +17 -1
  41. package/dist/cjs/getIntlayer.cjs +14 -1
  42. package/dist/cjs/html/HTMLProvider.cjs +24 -1
  43. package/dist/cjs/html/HTMLRenderer.cjs +49 -1
  44. package/dist/cjs/html/index.cjs +8 -1
  45. package/dist/cjs/html/types.cjs +1 -1
  46. package/dist/cjs/index.cjs +48 -1
  47. package/dist/cjs/markdown/MarkdownProvider.cjs +47 -1
  48. package/dist/cjs/markdown/MarkdownRenderer.cjs +56 -1
  49. package/dist/cjs/markdown/compiler.cjs +64 -1
  50. package/dist/cjs/markdown/index.cjs +13 -1
  51. package/dist/cjs/markdown/runtime.cjs +48 -1
  52. package/dist/cjs/plugins.cjs +266 -1
  53. package/dist/cjs/proxyKeys.cjs +14 -1
  54. package/dist/cjs/server/index.cjs +3 -1
  55. package/dist/cjs/server/useDictionary.cjs +30 -1
  56. package/dist/cjs/solidCompat.cjs +167 -1
  57. package/dist/cjs/solidElement/renderSolidElement.cjs +34 -1
  58. package/dist/cjs/solidTypes.cjs +1 -1
  59. package/dist/esm/IntlayerNode.mjs +8 -6
  60. package/dist/esm/LoadingBoundary.mjs +19 -6
  61. package/dist/esm/analytics/AnalyticsProvider.mjs +10 -3
  62. package/dist/esm/analytics/exposureSink.mjs +19 -5
  63. package/dist/esm/analytics/index.mjs +5 -5
  64. package/dist/esm/analytics/useAnalytics.mjs +52 -25
  65. package/dist/esm/analytics/useConversion.mjs +22 -6
  66. package/dist/esm/analytics/useExperiment.mjs +50 -22
  67. package/dist/esm/client/IntlayerProvider.mjs +75 -28
  68. package/dist/esm/client/contentProxy.mjs +26 -12
  69. package/dist/esm/client/getBrowserLocale.mjs +106 -71
  70. package/dist/esm/client/index.mjs +14 -14
  71. package/dist/esm/client/t.mjs +13 -7
  72. package/dist/esm/client/useContent.mjs +11 -8
  73. package/dist/esm/client/useDictionary.mjs +47 -25
  74. package/dist/esm/client/useDictionaryAsync.mjs +16 -9
  75. package/dist/esm/client/useDictionaryDynamic.mjs +72 -43
  76. package/dist/esm/client/useIntlayer.mjs +45 -15
  77. package/dist/esm/client/useLoadDynamic.mjs +128 -49
  78. package/dist/esm/client/useLocale.mjs +47 -16
  79. package/dist/esm/client/useLocaleBase.mjs +14 -10
  80. package/dist/esm/client/useLocaleStorage.mjs +51 -10
  81. package/dist/esm/client/usePathname.mjs +37 -12
  82. package/dist/esm/client/useRewriteURL.mjs +17 -11
  83. package/dist/esm/client/useTraduction.mjs +29 -8
  84. package/dist/esm/editor/ContentSelector.mjs +18 -15
  85. package/dist/esm/editor/EditorProvider.mjs +6 -3
  86. package/dist/esm/editor/createEditedContentSource.mjs +28 -17
  87. package/dist/esm/editor/useEditor.mjs +32 -22
  88. package/dist/esm/format/index.mjs +10 -10
  89. package/dist/esm/format/useCompact.mjs +11 -8
  90. package/dist/esm/format/useCurrency.mjs +12 -9
  91. package/dist/esm/format/useDate.mjs +19 -13
  92. package/dist/esm/format/useIntl.mjs +27 -9
  93. package/dist/esm/format/useList.mjs +11 -8
  94. package/dist/esm/format/useNumber.mjs +15 -9
  95. package/dist/esm/format/usePercentage.mjs +12 -9
  96. package/dist/esm/format/useRelativeTime.mjs +12 -9
  97. package/dist/esm/format/useUnit.mjs +11 -8
  98. package/dist/esm/getDictionary.mjs +14 -6
  99. package/dist/esm/getIntlayer.mjs +11 -6
  100. package/dist/esm/html/HTMLProvider.mjs +21 -12
  101. package/dist/esm/html/HTMLRenderer.mjs +44 -17
  102. package/dist/esm/html/index.mjs +3 -3
  103. package/dist/esm/index.mjs +20 -20
  104. package/dist/esm/markdown/MarkdownProvider.mjs +31 -24
  105. package/dist/esm/markdown/MarkdownRenderer.mjs +48 -37
  106. package/dist/esm/markdown/compiler.mjs +59 -23
  107. package/dist/esm/markdown/index.mjs +4 -4
  108. package/dist/esm/markdown/runtime.mjs +40 -13
  109. package/dist/esm/plugins.mjs +205 -156
  110. package/dist/esm/proxyKeys.mjs +7 -2
  111. package/dist/esm/server/useDictionary.mjs +25 -7
  112. package/dist/esm/solidCompat.mjs +146 -39
  113. package/dist/esm/solidElement/renderSolidElement.mjs +22 -19
  114. package/dist/rolldown-runtime-CmQyd0Gu.js +27 -0
  115. package/dist/solid/analytics/useAnalytics.jsx +3 -3
  116. package/dist/solid/analytics/useConversion.js +2 -2
  117. package/dist/solid/analytics/useExperiment.js +3 -3
  118. package/package.json +7 -7
  119. package/dist/esm-YGODKOLP.js +0 -1
  120. package/dist/esm-bdKnuomJ.mjs +0 -256
  121. package/dist/isEnabled-CuTKz0YA.js +0 -1
  122. package/dist/isEnabled-DVKEZ2He.mjs +0 -18
  123. package/dist/rolldown-runtime-BocRIvOZ.js +0 -1
  124. package/dist/solid/esm-1cHk4dPd.js +0 -644
  125. package/dist/solid/isEnabled-C5NUhdhZ.js +0 -100
@@ -1,9 +1,15 @@
1
- import { getTranslation as e } from "@intlayer/core/interpreter";
2
- import { useContext as t } from "solid-js";
3
- import { IntlayerClientContext as n } from "./IntlayerProvider.mjs";
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
- var r = (r, i) => {
6
- let { locale: a } = t(n) ?? {}, o = i ?? (typeof a == "function" ? a() : a);
7
- return e(r, o);
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 { r as t };
15
+ export { t };
@@ -1,12 +1,15 @@
1
- import { useLocaleBase as e } from "./useLocaleBase.mjs";
2
- import { useTranslation as t } from "./useTraduction.mjs";
1
+ import { useLocaleBase } from "./useLocaleBase.mjs";
2
+ import { useTranslation } from "./useTraduction.mjs";
3
3
  // src/client/useContent.ts
4
- var n = (n) => {
5
- let { locale: r } = e();
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: r,
8
- content: t(n),
9
- t
10
+ locale,
11
+ content: useTranslation(languageContent),
12
+ t: useTranslation
10
13
  };
11
14
  };
12
- export { n as useContent };
15
+ export { useContent };
@@ -1,28 +1,50 @@
1
- import { resolveDictionaryArgument as e } from "@intlayer/core/dictionaryManipulator";
2
- import { collectTransformCacheWrites as t, deleteTransformCacheWrites as n } from "@intlayer/core/interpreter";
3
- import { createMemo as r, onCleanup as i, useContext as a } from "solid-js";
4
- import { getDictionary as o } from "../getDictionary.mjs";
5
- import { getPlugins as s } from "../plugins.mjs";
6
- import { createContentProxy as c } from "./contentProxy.mjs";
7
- import { IntlayerClientContext as l } from "./IntlayerProvider.mjs";
8
- import { unwrapLoadable as u } from "./useLoadDynamic.mjs";
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
- var d = (d, f) => {
11
- let p = a(l) ?? {}, m = /* @__PURE__ */ new Map(), h = (e) => {
12
- let t = s(e), n = m.get(t);
13
- return n || (n = [...t], m.set(t, n)), n;
14
- }, g = () => {
15
- let t = p?.locale?.(), n = u(d) ?? d;
16
- return process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? o(n, f ?? t, h) : o(n, e({
17
- localeOrSelector: f,
18
- contextLocale: t,
19
- contextVariant: p?.variant?.(),
20
- dictionaryKey: d.key
21
- }), h);
22
- }, _ = r(() => {
23
- let { result: e, writes: r } = t(g);
24
- return r.length > 0 && i(() => n(r)), e;
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 c(_);
48
+ return createContentProxy(accessor);
27
49
  };
28
- export { d as useDictionary };
50
+ export { useDictionary };
@@ -1,11 +1,18 @@
1
- import { loadDynamicDictionary as e } from "@intlayer/core/dictionaryManipulator";
2
- import { resolveInterpreterLocale as t } from "@intlayer/core/interpreter";
3
- import { useContext as n } from "solid-js";
4
- import { IntlayerClientContext as r } from "./IntlayerProvider.mjs";
5
- import { useDictionary as i } from "./useDictionary.mjs";
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
- var a = async (a, o) => {
8
- let { locale: s } = n(r) ?? {}, c = o ?? s() ?? t(), l = await e(a, c);
9
- return i(l, c);
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 { a as useDictionaryAsync };
18
+ export { useDictionaryAsync };
@@ -1,52 +1,81 @@
1
- import { QUALIFIER_DYNAMIC_TYPES_KEY as e, getDictionarySelectorCacheKey as t, getDynamicChunkArgument as n, getPreloadedDictionary as r, isQualifiedDynamicLoaderMap as i, parseDictionarySelector as a, resolveDictionaryRead as o, resolveDynamicContentAsync as s } from "@intlayer/core/dictionaryManipulator";
2
- import { createMemo as c, useContext as l } from "solid-js";
3
- import { getDictionary as u } from "../getDictionary.mjs";
4
- import { createAsyncValue as d, trackAsyncValue as f } from "../solidCompat.mjs";
5
- import { createContentProxy as p } from "./contentProxy.mjs";
6
- import { IntlayerClientContext as m } from "./IntlayerProvider.mjs";
7
- import { useDictionary as h } from "./useDictionary.mjs";
8
- import { seedDynamicValue as g, useLoadDynamic as _ } from "./useLoadDynamic.mjs";
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
- var v = (e) => e, y = (e, t) => u(e, t), b = (b, x, S) => {
11
- let C = l(m) ?? {}, w = String(x), T = b, { locale: E, selector: D } = process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? {
12
- locale: S,
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
- } : a(S), O = () => o({
15
- localeOrSelector: S,
16
- contextLocale: C.locale?.(),
17
- contextVariant: C.variant?.(),
18
- dictionaryKey: w
19
- }), k = () => {
20
- let e = O(), n = process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? "" : t({
21
- ...e.selector,
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
- ...e,
26
- cacheKey: n ? `${w}.${e.locale}.${n}` : `${w}.${e.locale}`
49
+ ...read,
50
+ cacheKey: chunkSelectorId ? `${dictionaryKey}.${read.locale}.${chunkSelectorId}` : `${dictionaryKey}.${read.locale}`
27
51
  };
28
- }, A = (e, t) => s({
29
- loaderMap: T,
30
- key: w,
31
- ...e,
32
- transform: t
33
- }), j = n(E, D);
34
- if (process.env.INTLAYER_DICTIONARY_SELECTOR !== "false" && i(T) && T[e].includes("item") && D?.item === void 0) {
35
- let e = d(O, (e) => A(e, D?.metadataOnly ? y : v)), t = c(() => {
36
- let t = e();
37
- if (!Array.isArray(t)) return [];
38
- if (D?.metadataOnly) return t;
39
- let { locale: n } = O();
40
- return t.map((e) => u(e, n));
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
- return f(e), p(t);
69
+ trackAsyncValue(resolvedEntries);
70
+ return createContentProxy(accessor);
43
71
  }
44
- let M = k(), N = r(T, M.locale);
45
- N && g(M, N);
46
- let P = _(k, (e) => A(e, v).then((t) => {
47
- if (t === null) throw Error(`No dynamic dictionary chunk found for key "${w}" and locale "${e.locale}".`);
48
- return t;
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 h(P, j);
79
+ return useDictionary(dictionary, chunkArgument);
51
80
  };
52
- export { b as useDictionaryDynamic };
81
+ export { useDictionaryDynamic };
@@ -1,19 +1,49 @@
1
- import { resolveDictionaryArgument as e } from "@intlayer/core/dictionaryManipulator";
2
- import { createMemo as t, useContext as n } from "solid-js";
3
- import { getIntlayer as r } from "../getIntlayer.mjs";
4
- import { createContentProxy as i } from "./contentProxy.mjs";
5
- import { IntlayerClientContext as a } from "./IntlayerProvider.mjs";
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
- var o = (o, s) => {
8
- let c = n(a) ?? {}, l = t(() => {
9
- let t = c?.locale?.();
10
- return process.env.INTLAYER_DICTIONARY_SELECTOR === "false" ? r(o, s ?? t) : r(o, e({
11
- localeOrSelector: s,
12
- contextLocale: t,
13
- contextVariant: c?.variant?.(),
14
- dictionaryKey: o
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 i(l);
47
+ return createContentProxy(accessor);
18
48
  };
19
- export { o as useIntlayer };
49
+ export { useIntlayer };
@@ -1,55 +1,134 @@
1
- import { untrack as e } from "solid-js";
2
- import { PROXY_RESERVED_KEYS as t } from "../proxyKeys.mjs";
3
- import { createAsyncValue as n, trackAsyncValue as r } from "../solidCompat.mjs";
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 i = Symbol("NO_PENDING_PRIMITIVE_FALLBACK"), a = Symbol("LOADABLE_SETTLED_VALUE"), o = /* @__PURE__ */ new Map(), s = (e) => typeof e == "string" ? e : e.cacheKey, c = (e, t) => t.reduce((e, t) => {
6
- if (e != null) return Reflect.get(Object(e), t);
7
- }, e), l = (e, t) => typeof e == "function" ? e(t) : e, u = (e, t) => {
8
- let n = s(e), r = o.get(n);
9
- if (r?.status === "success") return r.value;
10
- if (r?.status === "pending") return r.promise;
11
- let i = l(t, e).then((e) => (o.set(n, {
12
- status: "success",
13
- value: e
14
- }), e), (e) => {
15
- throw o.delete(n), e;
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
- return o.set(n, {
38
+ cache.set(key, {
18
39
  status: "pending",
19
- promise: i
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
- }, f = (e, t) => typeof t == "function" ? t.bind(e) : t, p = (e) => e === Symbol.toPrimitive ? () => "" : e === Symbol.iterator ? () => ({ next: () => ({
28
- done: !0,
29
- value: void 0
30
- }) }) : e === "length" ? 0 : e === t.toString ? () => "" : e === t.valueOf ? () => void 0 : e === t.value ? "" : i, m = (n) => {
31
- let r = (o) => new Proxy(() => void 0, {
32
- get(e, s) {
33
- if (s === t.promiseThen) return;
34
- let l = c(n(), o);
35
- if (s === a) return l;
36
- if (l != null) return s === Symbol.toPrimitive ? () => l : f(l, Reflect.get(Object(l), s));
37
- let u = p(s);
38
- return u === i ? r([...o, s]) : u;
39
- },
40
- apply(t, r, i) {
41
- let a = c(n(), o);
42
- return typeof a == "function" ? Reflect.apply(a, r, i) : i.length === 0 ? a ?? "" : m(() => {
43
- let t = c(n(), o);
44
- if (typeof t == "function") return e(() => Reflect.apply(t, r, i));
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
- export { m as createLoadableProxy, s as getDynamicSourceCacheKey, u as loadDynamicValue, d as seedDynamicValue, h as unwrapLoadable, g as useLoadDynamic };
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 as e } from "@intlayer/config/built";
2
- import { useContext as t } from "solid-js";
3
- import { createChangeEffect as n } from "../solidCompat.mjs";
4
- import { IntlayerClientContext as r } from "./IntlayerProvider.mjs";
5
- import { setLocaleInStorage as i } from "./useLocaleStorage.mjs";
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: a, locales: o } = e ?? {}, s = ({ isCookieEnabled: e, onLocaleChange: s } = {}) => {
8
- let c = t(r);
9
- return n(() => c?.locale?.(), (e) => {
10
- s && e !== void 0 && s(e);
11
- }), {
12
- locale: c?.locale,
13
- defaultLocale: a,
14
- availableLocales: o,
15
- setLocale: (t) => {
16
- o?.map(String).includes(t) ? (c?.setLocale(t), i(t, e ?? c?.isCookieEnabled ?? !0)) : console.error(`Locale ${t} is not available`);
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 { s as useLocale };
51
+ export { useLocale };
@@ -1,14 +1,18 @@
1
- import { internationalization as e } from "@intlayer/config/built";
2
- import { useContext as t } from "solid-js";
3
- import { IntlayerClientContext as n } from "./IntlayerProvider.mjs";
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: r, locales: i } = e, a = () => {
6
- let { locale: e, setLocale: a } = t(n) ?? {};
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: e,
9
- defaultLocale: r,
10
- availableLocales: i,
11
- setLocale: a
12
+ locale,
13
+ defaultLocale,
14
+ availableLocales,
15
+ setLocale
12
16
  };
13
17
  };
14
- export { a as useLocaleBase };
18
+ export { useLocaleBase };