solid-intlayer 9.8.1 → 9.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. package/dist/cjs/LoadingBoundary.cjs +1 -0
  2. package/dist/cjs/analytics/useAnalytics.cjs +1 -1
  3. package/dist/cjs/analytics/useExperiment.cjs +1 -1
  4. package/dist/cjs/client/IntlayerProvider.cjs +1 -1
  5. package/dist/cjs/client/getBrowserLocale.cjs +1 -1
  6. package/dist/cjs/client/t.cjs +1 -1
  7. package/dist/cjs/client/useDictionary.cjs +1 -1
  8. package/dist/cjs/client/useDictionaryAsync.cjs +1 -1
  9. package/dist/cjs/client/useDictionaryDynamic.cjs +1 -1
  10. package/dist/cjs/client/useLoadDynamic.cjs +1 -1
  11. package/dist/cjs/client/useLocale.cjs +1 -1
  12. package/dist/cjs/client/useLocaleStorage.cjs +1 -1
  13. package/dist/cjs/client/usePathname.cjs +1 -1
  14. package/dist/cjs/client/useRewriteURL.cjs +1 -1
  15. package/dist/cjs/client/useTraduction.cjs +1 -1
  16. package/dist/cjs/editor/useEditor.cjs +1 -1
  17. package/dist/cjs/getDictionary.cjs +1 -1
  18. package/dist/cjs/html/HTMLProvider.cjs +1 -1
  19. package/dist/cjs/html/HTMLRenderer.cjs +1 -1
  20. package/dist/cjs/markdown/MarkdownProvider.cjs +1 -1
  21. package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -1
  22. package/dist/cjs/markdown/runtime.cjs +1 -1
  23. package/dist/cjs/plugins.cjs +1 -1
  24. package/dist/cjs/server/useDictionary.cjs +1 -1
  25. package/dist/cjs/solidCompat.cjs +1 -0
  26. package/dist/cjs/solidElement/renderSolidElement.cjs +1 -1
  27. package/dist/esm/LoadingBoundary.mjs +12 -0
  28. package/dist/esm/analytics/useAnalytics.mjs +14 -11
  29. package/dist/esm/analytics/useExperiment.mjs +5 -4
  30. package/dist/esm/client/IntlayerProvider.mjs +28 -28
  31. package/dist/esm/client/getBrowserLocale.mjs +21 -21
  32. package/dist/esm/client/t.mjs +4 -4
  33. package/dist/esm/client/useDictionary.mjs +22 -14
  34. package/dist/esm/client/useDictionaryAsync.mjs +3 -3
  35. package/dist/esm/client/useDictionaryDynamic.mjs +26 -23
  36. package/dist/esm/client/useLoadDynamic.mjs +4 -5
  37. package/dist/esm/client/useLocale.mjs +15 -14
  38. package/dist/esm/client/useLocaleStorage.mjs +7 -7
  39. package/dist/esm/client/usePathname.mjs +9 -8
  40. package/dist/esm/client/useRewriteURL.mjs +6 -6
  41. package/dist/esm/client/useTraduction.mjs +5 -5
  42. package/dist/esm/editor/useEditor.mjs +11 -11
  43. package/dist/esm/getDictionary.mjs +3 -3
  44. package/dist/esm/html/HTMLProvider.mjs +5 -4
  45. package/dist/esm/html/HTMLRenderer.mjs +6 -6
  46. package/dist/esm/markdown/MarkdownProvider.mjs +20 -19
  47. package/dist/esm/markdown/MarkdownRenderer.mjs +27 -25
  48. package/dist/esm/markdown/runtime.mjs +8 -13
  49. package/dist/esm/plugins.mjs +76 -75
  50. package/dist/esm/server/useDictionary.mjs +9 -6
  51. package/dist/esm/solidCompat.mjs +48 -0
  52. package/dist/esm/solidElement/renderSolidElement.mjs +14 -16
  53. package/dist/rolldown-runtime-BocRIvOZ.js +1 -0
  54. package/dist/solid/IntlayerNode.jsx +10 -0
  55. package/dist/solid/LoadingBoundary.jsx +10 -0
  56. package/dist/solid/analytics/AnalyticsProvider.jsx +11 -0
  57. package/dist/solid/analytics/exposureSink.js +21 -0
  58. package/dist/solid/analytics/index.js +5 -0
  59. package/dist/solid/analytics/useAnalytics.jsx +58 -0
  60. package/dist/solid/analytics/useConversion.js +24 -0
  61. package/dist/solid/analytics/useExperiment.js +58 -0
  62. package/dist/solid/client/IntlayerProvider.jsx +81 -0
  63. package/dist/solid/client/getBrowserLocale.jsx +113 -0
  64. package/dist/solid/client/index.js +14 -0
  65. package/dist/solid/client/t.js +15 -0
  66. package/dist/solid/client/useContent.js +15 -0
  67. package/dist/solid/client/useDictionary.js +56 -0
  68. package/dist/solid/client/useDictionaryAsync.js +17 -0
  69. package/dist/solid/client/useDictionaryDynamic.js +105 -0
  70. package/dist/solid/client/useIntlayer.js +55 -0
  71. package/dist/solid/client/useLoadDynamic.js +134 -0
  72. package/dist/solid/client/useLocale.js +51 -0
  73. package/dist/solid/client/useLocaleBase.js +18 -0
  74. package/dist/solid/client/useLocaleStorage.js +52 -0
  75. package/dist/solid/client/usePathname.js +40 -0
  76. package/dist/solid/client/useRewriteURL.js +20 -0
  77. package/dist/solid/client/useTraduction.js +31 -0
  78. package/dist/solid/editor/ContentSelector.jsx +9 -0
  79. package/dist/solid/editor/EditorProvider.jsx +7 -0
  80. package/dist/solid/editor/useEditor.jsx +37 -0
  81. package/dist/solid/esm-BS5TZIsL.js +644 -0
  82. package/dist/solid/format/index.js +10 -0
  83. package/dist/solid/format/useCompact.js +14 -0
  84. package/dist/solid/format/useCurrency.js +15 -0
  85. package/dist/solid/format/useDate.js +24 -0
  86. package/dist/solid/format/useIntl.js +30 -0
  87. package/dist/solid/format/useList.js +14 -0
  88. package/dist/solid/format/useNumber.js +18 -0
  89. package/dist/solid/format/usePercentage.js +15 -0
  90. package/dist/solid/format/useRelativeTime.js +15 -0
  91. package/dist/solid/format/useUnit.js +14 -0
  92. package/dist/solid/getDictionary.js +16 -0
  93. package/dist/solid/getIntlayer.js +13 -0
  94. package/dist/solid/html/HTMLProvider.jsx +16 -0
  95. package/dist/solid/html/HTMLRenderer.jsx +45 -0
  96. package/dist/solid/html/index.js +3 -0
  97. package/dist/solid/html/types.js +0 -0
  98. package/dist/solid/index.js +21 -0
  99. package/dist/solid/isEnabled-C5NUhdhZ.js +100 -0
  100. package/dist/solid/markdown/MarkdownProvider.jsx +38 -0
  101. package/dist/solid/markdown/MarkdownRenderer.jsx +47 -0
  102. package/dist/solid/markdown/compiler.jsx +62 -0
  103. package/dist/solid/markdown/index.js +4 -0
  104. package/dist/solid/markdown/runtime.jsx +42 -0
  105. package/dist/solid/plugins.jsx +230 -0
  106. package/dist/solid/proxyKeys.js +13 -0
  107. package/dist/solid/server/index.js +1 -0
  108. package/dist/solid/server/useDictionary.js +29 -0
  109. package/dist/solid/solidCompat.js +155 -0
  110. package/dist/solid/solidElement/renderSolidElement.jsx +32 -0
  111. package/dist/types/LoadingBoundary.d.ts +12 -0
  112. package/dist/types/client/useDictionaryDynamic.d.ts +1 -1
  113. package/dist/types/client/useLoadDynamic.d.ts +4 -4
  114. package/dist/types/client/useLocaleStorage.d.ts +2 -2
  115. package/dist/types/format/useIntl.d.ts +1 -1
  116. package/dist/types/getDictionary.d.ts +5 -1
  117. package/dist/types/html/HTMLProvider.d.ts +1 -1
  118. package/dist/types/markdown/MarkdownProvider.d.ts +5 -1
  119. package/dist/types/server/useDictionary.d.ts +6 -6
  120. package/dist/types/solidCompat.d.ts +92 -0
  121. package/dist/types/solidElement/renderSolidElement.d.ts +1 -1
  122. package/package.json +25 -18
@@ -0,0 +1,18 @@
1
+ import { IntlayerClientContext } from "./IntlayerProvider.jsx";
2
+ import { internationalization } from "@intlayer/config/built";
3
+ import { useContext } from "solid-js";
4
+ // src/client/useLocaleBase.ts
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) ?? {};
11
+ return {
12
+ locale,
13
+ defaultLocale,
14
+ availableLocales,
15
+ setLocale
16
+ };
17
+ };
18
+ export { useLocaleBase };
@@ -0,0 +1,52 @@
1
+ import { LocaleStorageClient, getCachedLocaleFromStorageClient, getLocaleFromStorageClient, localeStorageOptions, setLocaleInStorageClient } from "@intlayer/core/utils";
2
+ import { createMemo } from "solid-js";
3
+ // src/client/useLocaleStorage.ts
4
+ /**
5
+ * Reads the locale persisted in the browser storage (cookie, localStorage…).
6
+ *
7
+ * Unlike `localeInStorage`, read on first call rather than at import, then
8
+ * cached until the next `setLocaleInStorage`. Never cached on the server.
9
+ */
10
+ var getLocaleInStorage = getCachedLocaleFromStorageClient;
11
+ /**
12
+ * Get the locale cookie
13
+ *
14
+ * Read once at import time; marked pure so bundlers drop the read when nothing
15
+ * imports it.
16
+ */
17
+ var localeInStorage = /* @__PURE__ */ getLocaleFromStorageClient(localeStorageOptions);
18
+ /**
19
+ * @deprecated Use localeInStorage instead
20
+ *
21
+ * Get the locale cookie
22
+ */
23
+ var localeCookie = localeInStorage;
24
+ /**
25
+ * Set the locale cookie
26
+ */
27
+ var setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorageClient(locale, {
28
+ ...localeStorageOptions,
29
+ isCookieEnabled
30
+ });
31
+ /**
32
+ * @deprecated Use setLocaleInStorage instead
33
+ *
34
+ * Set the locale cookie
35
+ */
36
+ var setLocaleCookie = setLocaleInStorage;
37
+ /**
38
+ * Hook that provides the locale storage and a function to set it
39
+ */
40
+ var useLocaleStorage = (isCookieEnabled) => createMemo(() => LocaleStorageClient({
41
+ ...localeStorageOptions,
42
+ isCookieEnabled
43
+ }));
44
+ /**
45
+ * @deprecated Use useLocaleStorage instead
46
+ *
47
+ * For GDPR compliance, use useLocaleStorage instead
48
+ *
49
+ * Hook that provides the locale cookie and a function to set it
50
+ */
51
+ var useLocaleCookie = useLocaleStorage;
52
+ export { getLocaleInStorage, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
@@ -0,0 +1,40 @@
1
+ import { onMounted } from "../solidCompat.js";
2
+ import { createSignal } from "solid-js";
3
+ import { getPathWithoutLocale } from "@intlayer/core/localization";
4
+ // src/client/usePathname.ts
5
+ /**
6
+ * Solid hook that returns an accessor containing the current pathname with
7
+ * the locale segment removed.
8
+ *
9
+ * Reacts to browser back/forward navigation via the `popstate` event.
10
+ * Falls back to an empty string during server-side rendering.
11
+ *
12
+ * @returns An accessor containing the current pathname without the locale prefix.
13
+ *
14
+ * @example
15
+ * ```tsx
16
+ * import { usePathname } from 'solid-intlayer';
17
+ *
18
+ * const NavItem = ({ href }: { href: string }) => {
19
+ * const pathname = usePathname();
20
+ * return (
21
+ * <a class={pathname() === href ? 'active' : ''} href={href}>
22
+ * {href}
23
+ * </a>
24
+ * );
25
+ * };
26
+ * ```
27
+ */
28
+ var usePathname = () => {
29
+ const [rawPathname, setRawPathname] = createSignal(typeof window !== "undefined" ? window.location.pathname : "");
30
+ onMounted(() => {
31
+ if (typeof window === "undefined") return;
32
+ const handleLocationChange = () => {
33
+ setRawPathname(window.location.pathname);
34
+ };
35
+ window.addEventListener("popstate", handleLocationChange);
36
+ return () => window.removeEventListener("popstate", handleLocationChange);
37
+ });
38
+ return () => getPathWithoutLocale(rawPathname());
39
+ };
40
+ export { usePathname };
@@ -0,0 +1,20 @@
1
+ import { createWatchEffect } from "../solidCompat.js";
2
+ import { useLocale } from "./useLocale.js";
3
+ import { routing } from "@intlayer/config/built";
4
+ import { getRewritePath } from "@intlayer/core/localization";
5
+ // src/client/useRewriteURL.ts
6
+ /**
7
+ * Client-side hook to manage URL rewrites in Solid without triggering a router navigation.
8
+ * It uses `window.history.replaceState` to update the URL in the address bar.
9
+ */
10
+ var useRewriteURL = () => {
11
+ const { locale } = useLocale();
12
+ const rewrite = routing?.rewrite;
13
+ createWatchEffect(locale, (loc) => {
14
+ if (typeof window === "undefined" || !rewrite) return;
15
+ const pathname = window.location.pathname;
16
+ const targetPath = getRewritePath(pathname, loc, rewrite);
17
+ if (targetPath && targetPath !== pathname) window.history.replaceState(window.history.state, "", targetPath + window.location.search + window.location.hash);
18
+ });
19
+ };
20
+ export { useRewriteURL };
@@ -0,0 +1,31 @@
1
+ import { IntlayerClientContext } from "./IntlayerProvider.jsx";
2
+ import { getTranslation } from "@intlayer/core/interpreter";
3
+ import { internationalization } from "@intlayer/config/built";
4
+ import { useContext } from "solid-js";
5
+ // src/client/useTraduction.ts
6
+ /**
7
+ * On the client side, Hook that picking one dictionary by its id and return the content.
8
+ *
9
+ * If not locale found, it will return the content related to the default locale.
10
+ *
11
+ * Return either the content editor, or the content itself depending on the configuration.
12
+ *
13
+ * Usage:
14
+ *
15
+ * ```tsx
16
+ * const content = useTranslation<string>({
17
+ * en: 'Hello',
18
+ * fr: 'Bonjour',
19
+ * }, 'fr');
20
+ * // 'Bonjour'
21
+ * ```
22
+ *
23
+ * Using TypeScript:
24
+ * - this function will require each locale to be defined if defined in the project configuration.
25
+ * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
26
+ */
27
+ var useTranslation = (languageContent) => {
28
+ const { locale } = useContext(IntlayerClientContext) ?? {};
29
+ return getTranslation(languageContent, locale?.() ?? internationalization.defaultLocale);
30
+ };
31
+ export { useTranslation };
@@ -0,0 +1,9 @@
1
+ import { isEnabled } from "@intlayer/editor/isEnabled";
2
+ // src/editor/ContentSelector.tsx
3
+ var ContentSelector = (props) => {
4
+ if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return props.children;
5
+ return <Dynamic component="intlayer-content-selector-wrapper" attr:key-path={JSON.stringify(props.keyPath)} attr:dictionary-key={props.dictionaryKey}>
6
+ {props.children}
7
+ </Dynamic>;
8
+ };
9
+ export { ContentSelector };
@@ -0,0 +1,7 @@
1
+ import { useEditor } from "./useEditor.jsx";
2
+ // src/editor/EditorProvider.tsx
3
+ var EditorProvider = ({ children }) => {
4
+ useEditor();
5
+ return children;
6
+ };
7
+ export { EditorProvider };
@@ -0,0 +1,37 @@
1
+ import { useIntlayerContext } from "../client/IntlayerProvider.jsx";
2
+ import { createWatchEffect, onMounted } from "../solidCompat.js";
3
+ import { createSignal, onCleanup } from "solid-js";
4
+ import { isEnabled } from "@intlayer/editor/isEnabled";
5
+ // src/editor/useEditor.tsx
6
+ /**
7
+ * Initialises the Intlayer editor client singleton when the editor is enabled.
8
+ * Syncs the current locale from the Intlayer context into the editor manager so
9
+ * the editor always knows which locale the app is displaying.
10
+ */
11
+ var useEditor = () => {
12
+ if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return;
13
+ const { locale, setLocale } = useIntlayerContext();
14
+ const [manager, setManager] = createSignal(null);
15
+ onMounted(() => {
16
+ import("@intlayer/editor").then(({ initEditorClient }) => {
17
+ const managerInstance = initEditorClient();
18
+ setManager(managerInstance);
19
+ }).catch(() => {});
20
+ });
21
+ createWatchEffect(manager, (managerInstance) => {
22
+ if (!managerInstance) return;
23
+ return managerInstance.onLocaleChangeRequested(setLocale);
24
+ });
25
+ createWatchEffect(() => ({
26
+ managerInstance: manager(),
27
+ currentLocale: locale()
28
+ }), ({ managerInstance, currentLocale }) => {
29
+ if (managerInstance && currentLocale) managerInstance.currentLocale.set(currentLocale);
30
+ });
31
+ onCleanup(() => {
32
+ import("@intlayer/editor").then(({ stopEditorClient }) => {
33
+ stopEditorClient();
34
+ }).catch(() => {});
35
+ });
36
+ };
37
+ export { useEditor };