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.
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,4 +1,11 @@
1
- import { useAnalytics as e } from "./useAnalytics.mjs";
1
+ import { useAnalytics } from "./useAnalytics.mjs";
2
2
  // src/analytics/AnalyticsProvider.tsx
3
- var t = ({ children: t }) => (e(), t);
4
- export { t as AnalyticsProvider };
3
+ /**
4
+ * Runs {@link useAnalytics} and renders its children unchanged. Mounted inside
5
+ * {@link IntlayerProvider} alongside `EditorProvider`.
6
+ */
7
+ var AnalyticsProvider = ({ children }) => {
8
+ useAnalytics();
9
+ return children;
10
+ };
11
+ export { AnalyticsProvider };
@@ -1,7 +1,21 @@
1
1
  // src/analytics/exposureSink.ts
2
- var e = null, t = (t) => {
3
- e = t;
4
- }, n = (t) => {
5
- e?.(t);
2
+ var sink = null;
3
+ /**
4
+ * Installs (or clears) the exposure sink. `useAnalytics` sets this once the
5
+ * analytics client has loaded, and clears it on unmount.
6
+ *
7
+ * @param next - The sink to install, or `null` to clear.
8
+ */
9
+ var setExposureSink = (next) => {
10
+ sink = next;
6
11
  };
7
- export { n as reportExposure, t as setExposureSink };
12
+ /**
13
+ * Forwards a content exposure to the installed sink. A cheap null-check when
14
+ * analytics is not running, so it is safe to call from every node resolution.
15
+ *
16
+ * @param input - The node metadata to report.
17
+ */
18
+ var reportExposure = (input) => {
19
+ sink?.(input);
20
+ };
21
+ export { reportExposure, setExposureSink };
@@ -1,5 +1,5 @@
1
- import { AnalyticsProvider as e } from "./AnalyticsProvider.mjs";
2
- import { useAnalytics as t } from "./useAnalytics.mjs";
3
- import { useConversion as n } from "./useConversion.mjs";
4
- import { useExperiment as r } from "./useExperiment.mjs";
5
- export { e as AnalyticsProvider, t as useAnalytics, n as useConversion, r as useExperiment };
1
+ import { AnalyticsProvider } from "./AnalyticsProvider.mjs";
2
+ import { useAnalytics } from "./useAnalytics.mjs";
3
+ import { useConversion } from "./useConversion.mjs";
4
+ import { useExperiment } from "./useExperiment.mjs";
5
+ export { AnalyticsProvider, useAnalytics, useConversion, useExperiment };
@@ -1,31 +1,58 @@
1
- import { t as e } from "../../isEnabled-DVKEZ2He.mjs";
2
- import { createSignal as t, onCleanup as n } from "solid-js";
3
- import { useIntlayerContext as r } from "../client/IntlayerProvider.mjs";
4
- import { createWatchEffect as i, onMounted as a } from "../solidCompat.mjs";
5
- import { setExposureSink as o } from "./exposureSink.mjs";
1
+ import { isEnabled } from "@intlayer/analytics/isEnabled";
2
+ import { createSignal, onCleanup } from "solid-js";
3
+ import { useIntlayerContext } from "../client/IntlayerProvider.mjs";
4
+ import { createWatchEffect, onMounted } from "../solidCompat.mjs";
5
+ import { setExposureSink } from "./exposureSink.mjs";
6
6
  // src/analytics/useAnalytics.tsx
7
- var s = () => {
8
- if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !e) return;
9
- let { locale: s } = r(), [c, l] = t(null), u = !1, d = !1;
10
- a(() => {
11
- import("../../esm-bdKnuomJ.mjs").then(({ initAnalyticsClient: e, buildContentExposure: t }) => {
12
- if (u) return;
13
- let n = e();
14
- d = !0;
15
- let r = s?.();
16
- r && n.setLocale(r), n.trackPageView({ reason: "initial" }), o((e) => n.trackContentExposure(t(e))), l(n);
7
+ /**
8
+ * Initializes the Intlayer analytics client singleton when analytics is enabled
9
+ * and keeps it aware of the current locale.
10
+ *
11
+ * Mirrors {@link useEditor}: the module is loaded via a dynamic `import()` so it
12
+ * ships as its own async chunk, off the critical rendering path. Apps that
13
+ * don't opt in (`analytics.enabled !== true`) pay nothing — the whole body is
14
+ * guarded by `INTLAYER_ANALYTICS_ENABLED` and dead-code-eliminated at build
15
+ * time.
16
+ */
17
+ var useAnalytics = () => {
18
+ if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !isEnabled) return;
19
+ const { locale } = useIntlayerContext();
20
+ const [client, setClient] = createSignal(null);
21
+ let cancelled = false;
22
+ let initialized = false;
23
+ onMounted(() => {
24
+ import("@intlayer/analytics").then(({ initAnalyticsClient, buildContentExposure }) => {
25
+ if (cancelled) return;
26
+ const clientInstance = initAnalyticsClient();
27
+ initialized = true;
28
+ const currentLocale = locale?.();
29
+ if (currentLocale) clientInstance.setLocale(currentLocale);
30
+ clientInstance.trackPageView({ reason: "initial" });
31
+ setExposureSink((input) => clientInstance.trackContentExposure(buildContentExposure(input)));
32
+ setClient(clientInstance);
17
33
  }).catch(() => {});
18
34
  });
19
- let f;
20
- i(() => ({
21
- clientInstance: c(),
22
- currentLocale: s?.()
23
- }), ({ clientInstance: e, currentLocale: t }) => {
24
- e && t && (f === void 0 ? f = t : f !== t && (f = t, e.setLocale(t), e.trackPageView({ reason: "locale_change" })));
25
- }), n(() => {
26
- u = !0, o(null), import("../../esm-bdKnuomJ.mjs").then(({ stopAnalyticsClient: e }) => {
27
- d && e();
35
+ let previousLocale;
36
+ createWatchEffect(() => ({
37
+ clientInstance: client(),
38
+ currentLocale: locale?.()
39
+ }), ({ clientInstance, currentLocale }) => {
40
+ if (!clientInstance || !currentLocale) return;
41
+ if (previousLocale === void 0) {
42
+ previousLocale = currentLocale;
43
+ return;
44
+ }
45
+ if (previousLocale === currentLocale) return;
46
+ previousLocale = currentLocale;
47
+ clientInstance.setLocale(currentLocale);
48
+ clientInstance.trackPageView({ reason: "locale_change" });
49
+ });
50
+ onCleanup(() => {
51
+ cancelled = true;
52
+ setExposureSink(null);
53
+ import("@intlayer/analytics").then(({ stopAnalyticsClient }) => {
54
+ if (initialized) stopAnalyticsClient();
28
55
  }).catch(() => {});
29
56
  });
30
57
  };
31
- export { s as useAnalytics };
58
+ export { useAnalytics };
@@ -1,8 +1,24 @@
1
- import { t as e } from "../../isEnabled-DVKEZ2He.mjs";
1
+ import { isEnabled } from "@intlayer/analytics/isEnabled";
2
2
  // src/analytics/useConversion.ts
3
- var t = () => (t) => {
4
- process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && e && import("../../esm-bdKnuomJ.mjs").then(({ getGlobalAnalyticsClient: e }) => {
5
- e()?.trackConversion(t);
6
- }).catch(() => {});
3
+ /**
4
+ * Returns a `trackConversion` callback for content A/B testing. Safe to call
5
+ * from any component: it resolves to a no-op when analytics is disabled or the
6
+ * client has not been initialized yet.
7
+ *
8
+ * @example
9
+ * ```tsx
10
+ * const trackConversion = useConversion();
11
+ * <button onClick={() => trackConversion({
12
+ * experimentKey: 'homepage-hero', variant: 'b', goal: 'cta_click',
13
+ * })}>Get started</button>
14
+ * ```
15
+ */
16
+ var useConversion = () => {
17
+ return (params) => {
18
+ if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !isEnabled) return;
19
+ import("@intlayer/analytics").then(({ getGlobalAnalyticsClient }) => {
20
+ getGlobalAnalyticsClient()?.trackConversion(params);
21
+ }).catch(() => {});
22
+ };
7
23
  };
8
- export { t as useConversion };
24
+ export { useConversion };
@@ -1,30 +1,58 @@
1
- import { t as e } from "../../isEnabled-DVKEZ2He.mjs";
2
- import { createSignal as t, onCleanup as n } from "solid-js";
3
- import { onMounted as r } from "../solidCompat.mjs";
1
+ import { isEnabled } from "@intlayer/analytics/isEnabled";
2
+ import { createSignal, onCleanup } from "solid-js";
3
+ import { onMounted } from "../solidCompat.mjs";
4
4
  // src/analytics/useExperiment.ts
5
- var i = (i, a, o) => {
6
- let [s, c] = t(a[0] ?? ""), [l, u] = t(!1), d = !1, f = !1;
7
- return r(() => {
8
- process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && e && import("../../esm-bdKnuomJ.mjs").then(({ initAnalyticsClient: e }) => {
9
- if (d) return;
10
- let t = e();
11
- f = !0;
12
- let n = t.getVariant(i, a, o);
13
- c(n), u(!0), t.trackContentExposure({
14
- dictionaryKey: i,
5
+ /**
6
+ * Assigns this session to a variant of an A/B experiment and records the
7
+ * exposure, scoped to `experimentKey`, so the backend can compute per-variant
8
+ * conversion rates against `useConversion` events.
9
+ *
10
+ * Assignment is deterministic per session (no server round-trip, stable across
11
+ * re-mounts). The exposure is recorded once per mount.
12
+ *
13
+ * @param experimentKey - Unique key identifying the experiment.
14
+ * @param variants - The candidate variant names; the first one is the control.
15
+ * @param weights - Optional relative weights, one per variant (e.g. `[9, 1]`).
16
+ * @returns The {@link ExperimentState} for this session.
17
+ *
18
+ * @example
19
+ * ```tsx
20
+ * const { variant } = useExperiment('homepage-hero', ['a', 'b']);
21
+ * const content = useIntlayer(variant() === 'b' ? 'hero-b' : 'hero');
22
+ * ```
23
+ */
24
+ var useExperiment = (experimentKey, variants, weights) => {
25
+ const [variant, setVariant] = createSignal(variants[0] ?? "");
26
+ const [isAssigned, setIsAssigned] = createSignal(false);
27
+ let cancelled = false;
28
+ let initialized = false;
29
+ onMounted(() => {
30
+ if (process.env.INTLAYER_ANALYTICS_ENABLED === "false" || !isEnabled) return;
31
+ import("@intlayer/analytics").then(({ initAnalyticsClient }) => {
32
+ if (cancelled) return;
33
+ const client = initAnalyticsClient();
34
+ initialized = true;
35
+ const assigned = client.getVariant(experimentKey, variants, weights);
36
+ setVariant(assigned);
37
+ setIsAssigned(true);
38
+ client.trackContentExposure({
39
+ dictionaryKey: experimentKey,
15
40
  keyPath: "",
16
41
  nodeType: "experiment",
17
- experimentKey: i,
18
- variant: n
42
+ experimentKey,
43
+ variant: assigned
19
44
  });
20
45
  }).catch(() => {});
21
- }), n(() => {
22
- d = !0, import("../../esm-bdKnuomJ.mjs").then(({ stopAnalyticsClient: e }) => {
23
- f && e();
46
+ });
47
+ onCleanup(() => {
48
+ cancelled = true;
49
+ import("@intlayer/analytics").then(({ stopAnalyticsClient }) => {
50
+ if (initialized) stopAnalyticsClient();
24
51
  }).catch(() => {});
25
- }), {
26
- variant: s,
27
- isAssigned: l
52
+ });
53
+ return {
54
+ variant,
55
+ isAssigned
28
56
  };
29
57
  };
30
- export { i as useExperiment };
58
+ export { useExperiment };
@@ -1,40 +1,87 @@
1
- import { createComponent as e, memo as t, mergeProps as n } from "solid-js/web";
2
- import { internationalization as r } from "@intlayer/config/built";
3
- import { setIntlayerIdentifier as i } from "@intlayer/config/client";
4
- import { localeResolver as a } from "@intlayer/core/localization";
5
- import { createContext as o, createMemo as s, untrack as c, useContext as l } from "solid-js";
6
- import { LoadingBoundary as u } from "../LoadingBoundary.mjs";
7
- import { createWritableMemo as d, getContextProvider as f, lazyComponent as p, onMounted as m, runInTransition as h } from "../solidCompat.mjs";
8
- import { getLocaleInStorage as g, setLocaleInStorage as _ } from "./useLocaleStorage.mjs";
1
+ import { createComponent, memo, mergeProps } from "solid-js/web";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { setIntlayerIdentifier } from "@intlayer/config/client";
4
+ import { localeResolver } from "@intlayer/core/localization";
5
+ import { createContext, createMemo, untrack, useContext } from "solid-js";
6
+ import { LoadingBoundary } from "../LoadingBoundary.mjs";
7
+ import { createWritableMemo, getContextProvider, lazyComponent, onMounted, runInTransition } from "../solidCompat.mjs";
8
+ import { getLocaleInStorage, setLocaleInStorage } from "./useLocaleStorage.mjs";
9
9
  // src/client/IntlayerProvider.tsx
10
- var v = process.env.INTLAYER_EDITOR_ENABLED === "false" ? null : p(() => import("../editor/EditorProvider.mjs").then((e) => ({ default: e.EditorProvider }))), y = process.env.INTLAYER_ANALYTICS_ENABLED === "false" ? null : p(() => import("../analytics/AnalyticsProvider.mjs").then((e) => ({ default: e.AnalyticsProvider }))), b = o({
11
- locale: () => g() ?? r?.defaultLocale,
10
+ var LazyEditorProvider = process.env.INTLAYER_EDITOR_ENABLED !== "false" ? lazyComponent(() => import("../editor/EditorProvider.mjs").then((m) => ({ default: m.EditorProvider }))) : null;
11
+ var LazyAnalyticsProvider = process.env.INTLAYER_ANALYTICS_ENABLED !== "false" ? lazyComponent(() => import("../analytics/AnalyticsProvider.mjs").then((m) => ({ default: m.AnalyticsProvider }))) : null;
12
+ /**
13
+ * Context that store the current locale on the client side
14
+ */
15
+ var IntlayerClientContext = createContext({
16
+ locale: () => getLocaleInStorage() ?? internationalization?.defaultLocale,
12
17
  setLocale: () => null
13
- }), x = f(b), S = () => l(b), C = (t) => {
14
- let { defaultLocale: n, locales: o } = r ?? {}, l = c(() => t.locale ?? g() ?? t.defaultLocale ?? n), [u, f] = d((e) => t.locale || e || l), p = t.setLocale ?? ((e) => {
15
- u().toString() !== e.toString() && (o?.map(String).includes(e) ? (h(() => f(e)), _(e, t.isCookieEnabled)) : console.error(`Locale ${e} is not available`));
16
- }), v = s(() => a(u()));
17
- return m(() => {
18
- i();
19
- }), e(x, {
18
+ });
19
+ var IntlayerClientContextProvider = getContextProvider(IntlayerClientContext);
20
+ /**
21
+ * Hook that provides the current locale
22
+ */
23
+ var useIntlayerContext = () => useContext(IntlayerClientContext);
24
+ /**
25
+ * Provider that store the current locale on the client side
26
+ */
27
+ var IntlayerProviderContent = (props) => {
28
+ const { defaultLocale: defaultLocaleConfig, locales: availableLocales } = internationalization ?? {};
29
+ const defaultLocale = untrack(() => props.locale ?? getLocaleInStorage() ?? props.defaultLocale ?? defaultLocaleConfig);
30
+ const [currentLocale, setCurrentLocale] = createWritableMemo((previousLocale) => props.locale || previousLocale || defaultLocale);
31
+ const setLocaleBase = (newLocale) => {
32
+ if (currentLocale().toString() === newLocale.toString()) return;
33
+ if (!availableLocales?.map(String).includes(newLocale)) {
34
+ console.error(`Locale ${newLocale} is not available`);
35
+ return;
36
+ }
37
+ runInTransition(() => setCurrentLocale(newLocale));
38
+ setLocaleInStorage(newLocale, props.isCookieEnabled);
39
+ };
40
+ const setLocale = props.setLocale ?? setLocaleBase;
41
+ const locale = createMemo(() => localeResolver(currentLocale()));
42
+ onMounted(() => {
43
+ setIntlayerIdentifier();
44
+ });
45
+ return createComponent(IntlayerClientContextProvider, {
20
46
  value: {
21
- locale: v,
22
- setLocale: p,
23
- variant: () => t.variant
47
+ locale,
48
+ setLocale,
49
+ variant: () => props.variant
24
50
  },
25
51
  get children() {
26
- return t.children;
52
+ return props.children;
27
53
  }
28
54
  });
29
- }, w = (r) => e(C, n(r, { get children() {
55
+ };
56
+ /**
57
+ * Main provider for Intlayer in Solid applications.
58
+ *
59
+ * It provides the Intlayer context to your application, allowing the use
60
+ * of hooks like `useIntlayer` and `useLocale`.
61
+ *
62
+ * @param props - The provider props.
63
+ * @returns The provider component.
64
+ *
65
+ * @example
66
+ * ```tsx
67
+ * import { IntlayerProvider } from 'solid-intlayer';
68
+ *
69
+ * const App = () => (
70
+ * <IntlayerProvider>
71
+ * <MyComponent />
72
+ * </IntlayerProvider>
73
+ * );
74
+ * ```
75
+ */
76
+ var IntlayerProvider = (props) => createComponent(IntlayerProviderContent, mergeProps(props, { get children() {
30
77
  return [
31
- t(() => t(() => !!(process.env.INTLAYER_EDITOR_ENABLED !== "false" && v))() && e(u, { get children() {
32
- return e(v, {});
78
+ memo(() => memo(() => !!(process.env.INTLAYER_EDITOR_ENABLED !== "false" && LazyEditorProvider))() && createComponent(LoadingBoundary, { get children() {
79
+ return createComponent(LazyEditorProvider, {});
33
80
  } })),
34
- t(() => t(() => !!(process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && y))() && e(u, { get children() {
35
- return e(y, {});
81
+ memo(() => memo(() => !!(process.env.INTLAYER_ANALYTICS_ENABLED !== "false" && LazyAnalyticsProvider))() && createComponent(LoadingBoundary, { get children() {
82
+ return createComponent(LazyAnalyticsProvider, {});
36
83
  } })),
37
- t(() => r.children)
84
+ memo(() => props.children)
38
85
  ];
39
86
  } }));
40
- export { b as IntlayerClientContext, w as IntlayerProvider, C as IntlayerProviderContent, S as useIntlayerContext };
87
+ export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext };
@@ -1,17 +1,31 @@
1
1
  // src/client/contentProxy.ts
2
- var e = (e) => new Proxy(e, {
3
- get(e, t) {
4
- let n = e();
5
- if (n == null) return;
6
- let r = Reflect.get(Object(n), t);
7
- return typeof r == "function" && !Object.hasOwn(n, t) ? r.bind(n) : r;
2
+ /**
3
+ * Exposes reactive content through a proxy that reads `accessor` on every
4
+ * access, so each field read stays tracked — shared by `useDictionary`,
5
+ * `useIntlayer` and the dynamic collection read.
6
+ *
7
+ * Collections must behave like real arrays: Solid 2's `<For>` copies its list
8
+ * with `list.slice(0)`, which checks every index with `in`. Answering those
9
+ * checks for the function target would yield holes (`undefined` rows), so `in`
10
+ * is answered for the content, and inherited methods (`slice`, `map`…) run
11
+ * against it. Own fields are returned untouched: content nodes carry their
12
+ * own properties (`.value`, `.raw`) that a bound copy would lose.
13
+ *
14
+ * @param accessor - Returns the current content (a memo).
15
+ */
16
+ var createContentProxy = (accessor) => new Proxy(accessor, {
17
+ get(target, property) {
18
+ const content = target();
19
+ if (content == null) return void 0;
20
+ const value = Reflect.get(Object(content), property);
21
+ return typeof value === "function" && !Object.hasOwn(content, property) ? value.bind(content) : value;
8
22
  },
9
- has(e, t) {
10
- let n = e();
11
- return typeof n == "object" && !!n && t in n;
23
+ has(target, property) {
24
+ const content = target();
25
+ return content != null && typeof content === "object" && property in content;
12
26
  },
13
- apply(e) {
14
- return e();
27
+ apply(target) {
28
+ return target();
15
29
  }
16
30
  });
17
- export { e as createContentProxy };
31
+ export { createContentProxy };
@@ -1,78 +1,113 @@
1
- import { internationalization as e } from "@intlayer/config/built";
2
- import { DEFAULT_LOCALE as t } from "@intlayer/config/defaultValues";
3
- import { localeDetector as n } from "@intlayer/core/localization";
4
- import { getLocaleFromStorageClient as r } from "@intlayer/core/utils";
1
+ import { internationalization } from "@intlayer/config/built";
2
+ import { DEFAULT_LOCALE } from "@intlayer/config/defaultValues";
3
+ import { localeDetector } from "@intlayer/core/localization";
4
+ import { getLocaleFromStorageClient } from "@intlayer/core/utils";
5
5
  // src/client/getBrowserLocale.tsx
6
- var i = /* @__PURE__ */ function(e) {
7
- return e.Querystring = "querystring", e.Storage = "storage", e.Navigator = "navigator", e.HtmlTag = "htmlTag", e;
8
- }({}), a = () => ({
9
- order: [
10
- "querystring",
11
- "storage",
12
- "navigator",
13
- "htmlTag"
14
- ],
15
- lookupQuerystring: "locale",
16
- htmlTag: typeof document < "u" ? document.documentElement : null
17
- }), o = (t, i) => {
18
- let a = {}, o = {
19
- querystring: () => {
20
- if (typeof window > "u") return;
21
- let e = window.location.search || "", t = new URLSearchParams(e).get(i.lookupQuerystring ?? "");
22
- t && (a.querystring = t);
23
- },
24
- storage: () => {
25
- if (typeof window > "u") return;
26
- let e = r({
27
- getCookie: (e) => {
28
- try {
29
- let t = document.cookie.split(";"), n = `${e}=`, r = t.find((e) => e.trim().startsWith(n));
30
- if (r) return r.split("=")[1].trim();
31
- } catch {}
32
- },
33
- getSessionStorage: (e) => {
34
- try {
35
- return window.sessionStorage.getItem(e) ?? void 0;
36
- } catch {}
37
- },
38
- getLocaleStorage: (e) => {
39
- try {
40
- return window.localStorage.getItem(e) ?? void 0;
41
- } catch {}
42
- }
43
- });
44
- e && (a.storage = e);
45
- },
46
- navigator: () => {
47
- if (typeof navigator > "u") return;
48
- let t = navigator.languages ?? [navigator.language], r = n({ "accept-language": t.join(",") }, e.locales, e.defaultLocale);
49
- r && (a.navigator = r);
50
- },
51
- htmlTag: () => {
52
- let t = i.htmlTag;
53
- if (t && typeof t.getAttribute == "function") {
54
- let r = t.getAttribute("lang");
55
- if (r) {
56
- let t = n({ "accept-language": r }, e.locales, e.defaultLocale);
57
- a.htmlTag = t;
58
- }
6
+ var LanguageDetector = /* @__PURE__ */ function(LanguageDetector) {
7
+ LanguageDetector["Querystring"] = "querystring";
8
+ LanguageDetector["Storage"] = "storage";
9
+ LanguageDetector["Navigator"] = "navigator";
10
+ LanguageDetector["HtmlTag"] = "htmlTag";
11
+ return LanguageDetector;
12
+ }({});
13
+ var getDefaultsOptions = () => {
14
+ return {
15
+ order: [
16
+ "querystring",
17
+ "storage",
18
+ "navigator",
19
+ "htmlTag"
20
+ ],
21
+ lookupQuerystring: "locale",
22
+ htmlTag: typeof document !== "undefined" ? document.documentElement : null
23
+ };
24
+ };
25
+ var detectLanguage = (order, options) => {
26
+ const detected = {};
27
+ const queryStringDetector = () => {
28
+ if (typeof window === "undefined") return;
29
+ const search = window.location.search || "";
30
+ const value = new URLSearchParams(search).get(options.lookupQuerystring ?? "");
31
+ if (value) detected["querystring"] = value;
32
+ };
33
+ const storageDetector = () => {
34
+ if (typeof window === "undefined") return;
35
+ const locale = getLocaleFromStorageClient({
36
+ getCookie: (name) => {
37
+ try {
38
+ const cookies = document.cookie.split(";");
39
+ const cookieName = `${name}=`;
40
+ const cookie = cookies.find((c) => c.trim().startsWith(cookieName));
41
+ if (cookie) return cookie.split("=")[1].trim();
42
+ } catch {}
43
+ },
44
+ getSessionStorage: (name) => {
45
+ try {
46
+ return window.sessionStorage.getItem(name) ?? void 0;
47
+ } catch {}
48
+ },
49
+ getLocaleStorage: (name) => {
50
+ try {
51
+ return window.localStorage.getItem(name) ?? void 0;
52
+ } catch {}
53
+ }
54
+ });
55
+ if (locale) detected["storage"] = locale;
56
+ };
57
+ const navigatorDetector = () => {
58
+ if (typeof navigator === "undefined") return;
59
+ const languages = navigator.languages ?? [navigator.language];
60
+ const locale = localeDetector({ "accept-language": languages.join(",") }, internationalization.locales, internationalization.defaultLocale);
61
+ if (locale) detected["navigator"] = locale;
62
+ };
63
+ const htmlTagDetector = () => {
64
+ const htmlTag = options.htmlTag;
65
+ if (htmlTag && typeof htmlTag.getAttribute === "function") {
66
+ const lang = htmlTag.getAttribute("lang");
67
+ if (lang) {
68
+ const locale = localeDetector({ "accept-language": lang }, internationalization.locales, internationalization.defaultLocale);
69
+ detected["htmlTag"] = locale;
59
70
  }
60
71
  }
61
72
  };
62
- return t.forEach((e) => {
63
- o[e]?.();
64
- }), a;
65
- }, s = (n, r) => {
66
- for (let t of r) {
67
- let r = n[t];
68
- if (r && e.locales.includes(r)) return r;
73
+ const detectors = {
74
+ ["querystring"]: queryStringDetector,
75
+ ["storage"]: storageDetector,
76
+ ["navigator"]: navigatorDetector,
77
+ ["htmlTag"]: htmlTagDetector
78
+ };
79
+ order.forEach((detectorName) => {
80
+ detectors[detectorName]?.();
81
+ });
82
+ return detected;
83
+ };
84
+ var getFirstAvailableLocale = (locales, order) => {
85
+ for (const detector of order) {
86
+ const locale = locales[detector];
87
+ if (locale && internationalization.locales.includes(locale)) return locale;
69
88
  }
70
- return e?.defaultLocale ?? t;
71
- }, c = (e = {}) => {
72
- let t = {
73
- ...a(),
74
- ...e
89
+ return internationalization?.defaultLocale ?? DEFAULT_LOCALE;
90
+ };
91
+ /**
92
+ * Core language detector function for browser environments.
93
+ *
94
+ * Detects the user's preferred locale by checking multiple sources in order:
95
+ * 1. Query string parameter
96
+ * 2. Storage (cookies, localStorage, sessionStorage) - uses getLocaleFromStorage
97
+ * 3. Navigator languages - uses localeDetector
98
+ * 4. HTML lang attribute - uses localeDetector
99
+ *
100
+ * @param userOptions - Optional configuration for detection order and lookup keys
101
+ * @returns The detected locale or the default locale
102
+ *
103
+ * @example
104
+ * const locale = getBrowserLocale({ order: [LanguageDetector.Storage, LanguageDetector.Navigator] });
105
+ */
106
+ var getBrowserLocale = (userOptions = {}) => {
107
+ const options = {
108
+ ...getDefaultsOptions(),
109
+ ...userOptions
75
110
  };
76
- return s(o(t.order ?? [], t), t.order ?? []);
111
+ return getFirstAvailableLocale(detectLanguage(options.order ?? [], options), options.order ?? []);
77
112
  };
78
- export { i as LanguageDetector, c as getBrowserLocale };
113
+ export { LanguageDetector, getBrowserLocale };
@@ -1,14 +1,14 @@
1
- import { getBrowserLocale as e } from "./getBrowserLocale.mjs";
2
- import { IntlayerClientContext as t, IntlayerProvider as n, IntlayerProviderContent as r, useIntlayerContext as i } from "./IntlayerProvider.mjs";
3
- import { t as a } from "./t.mjs";
4
- import { useDictionary as o } from "./useDictionary.mjs";
5
- import { useDictionaryAsync as s } from "./useDictionaryAsync.mjs";
6
- import { useDictionaryDynamic as c } from "./useDictionaryDynamic.mjs";
7
- import { useIntlayer as l } from "./useIntlayer.mjs";
8
- import { useLoadDynamic as u } from "./useLoadDynamic.mjs";
9
- import { useLocale as d } from "./useLocale.mjs";
10
- import { useLocaleBase as f } from "./useLocaleBase.mjs";
11
- import { localeCookie as p, localeInStorage as m, setLocaleCookie as h, setLocaleInStorage as g, useLocaleCookie as _, useLocaleStorage as v } from "./useLocaleStorage.mjs";
12
- import { usePathname as y } from "./usePathname.mjs";
13
- import { useRewriteURL as b } from "./useRewriteURL.mjs";
14
- export { t as IntlayerClientContext, n as IntlayerProvider, r as IntlayerProviderContent, e as getBrowserLocale, p as localeCookie, m as localeInStorage, h as setLocaleCookie, g as setLocaleInStorage, a as t, o as useDictionary, s as useDictionaryAsync, c as useDictionaryDynamic, l as useIntlayer, i as useIntlayerContext, u as useLoadDynamic, d as useLocale, f as useLocaleBase, _ as useLocaleCookie, v as useLocaleStorage, y as usePathname, b as useRewriteURL };
1
+ import { getBrowserLocale } from "./getBrowserLocale.mjs";
2
+ import { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext } from "./IntlayerProvider.mjs";
3
+ import { t } from "./t.mjs";
4
+ import { useDictionary } from "./useDictionary.mjs";
5
+ import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
6
+ import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
7
+ import { useIntlayer } from "./useIntlayer.mjs";
8
+ import { useLoadDynamic } from "./useLoadDynamic.mjs";
9
+ import { useLocale } from "./useLocale.mjs";
10
+ import { useLocaleBase } from "./useLocaleBase.mjs";
11
+ import { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage } from "./useLocaleStorage.mjs";
12
+ import { usePathname } from "./usePathname.mjs";
13
+ import { useRewriteURL } from "./useRewriteURL.mjs";
14
+ export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, getBrowserLocale, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useIntlayer, useIntlayerContext, useLoadDynamic, useLocale, useLocaleBase, useLocaleCookie, useLocaleStorage, usePathname, useRewriteURL };