react-intlayer 8.4.3 → 8.4.5
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 +17 -1
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +96 -1
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +29 -1
- package/dist/cjs/client/IntlayerProvider.cjs +92 -1
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +20 -1
- package/dist/cjs/client/format/useCompact.cjs +29 -1
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +43 -1
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +45 -1
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +45 -1
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +40 -1
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +41 -1
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +37 -1
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +37 -1
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +36 -1
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +34 -1
- package/dist/cjs/client/t.cjs +40 -1
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +27 -1
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +24 -1
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +25 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useI18n.cjs +45 -1
- package/dist/cjs/client/useI18n.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +42 -1
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +27 -1
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +60 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +26 -1
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +62 -1
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +42 -1
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +35 -1
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelector.cjs +18 -1
- package/dist/cjs/editor/ContentSelector.cjs.map +1 -1
- package/dist/cjs/editor/EditorProvider.cjs +11 -1
- package/dist/cjs/editor/EditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/useEditor.cjs +39 -1
- package/dist/cjs/editor/useEditor.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +10 -1
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +10 -1
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +18 -1
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +60 -1
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/HTMLRendererPlugin.cjs +23 -1
- package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +12 -1
- package/dist/cjs/index.cjs +52 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs +80 -1
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +201 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +17 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +24 -1
- package/dist/cjs/markdown/processor.cjs +66 -1
- package/dist/cjs/markdown/processor.cjs.map +1 -1
- package/dist/cjs/markdown/runtime.cjs +43 -1
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +200 -1
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/reactElement/renderReactElement.cjs +52 -1
- package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs +34 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/format/index.cjs +18 -1
- package/dist/cjs/server/format/useCompact.cjs +27 -1
- package/dist/cjs/server/format/useCompact.cjs.map +1 -1
- package/dist/cjs/server/format/useCurrency.cjs +38 -1
- package/dist/cjs/server/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/server/format/useDate.cjs +43 -1
- package/dist/cjs/server/format/useDate.cjs.map +1 -1
- package/dist/cjs/server/format/useIntl.cjs +44 -1
- package/dist/cjs/server/format/useIntl.cjs.map +1 -1
- package/dist/cjs/server/format/useList.cjs +35 -1
- package/dist/cjs/server/format/useList.cjs.map +1 -1
- package/dist/cjs/server/format/useNumber.cjs +39 -1
- package/dist/cjs/server/format/useNumber.cjs.map +1 -1
- package/dist/cjs/server/format/usePercentage.cjs +35 -1
- package/dist/cjs/server/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/server/format/useRelativeTime.cjs +35 -1
- package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/server/format/useUnit.cjs +34 -1
- package/dist/cjs/server/format/useUnit.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +24 -1
- package/dist/cjs/server/serverContext.cjs +58 -1
- package/dist/cjs/server/serverContext.cjs.map +1 -1
- package/dist/cjs/server/t.cjs +35 -1
- package/dist/cjs/server/t.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +17 -1
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +21 -1
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +22 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useI18n.cjs +38 -1
- package/dist/cjs/server/useI18n.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +17 -1
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useLoadDynamic.cjs +14 -1
- package/dist/cjs/server/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/server/useLocale.cjs +24 -1
- package/dist/cjs/server/useLocale.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +15 -1
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +94 -1
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +86 -1
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +11 -1
- package/dist/esm/client/format/useCompact.mjs +27 -1
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +41 -1
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +43 -1
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +43 -1
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +38 -1
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +39 -1
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +35 -1
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +35 -1
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +34 -1
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +14 -1
- package/dist/esm/client/t.mjs +38 -1
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +25 -1
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +21 -1
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +22 -1
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useI18n.mjs +43 -1
- package/dist/esm/client/useI18n.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +40 -1
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +25 -1
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +57 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +23 -1
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +55 -1
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +39 -1
- package/dist/esm/client/useRewriteURL.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +33 -1
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelector.mjs +16 -1
- package/dist/esm/editor/ContentSelector.mjs.map +1 -1
- package/dist/esm/editor/EditorProvider.mjs +10 -1
- package/dist/esm/editor/EditorProvider.mjs.map +1 -1
- package/dist/esm/editor/useEditor.mjs +37 -1
- package/dist/esm/editor/useEditor.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +8 -1
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +8 -1
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +15 -1
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +55 -1
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/HTMLRendererPlugin.mjs +21 -1
- package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -1
- package/dist/esm/html/index.mjs +5 -1
- package/dist/esm/index.mjs +21 -1
- package/dist/esm/markdown/MarkdownProvider.mjs +77 -1
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +197 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +16 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +7 -1
- package/dist/esm/markdown/processor.mjs +58 -1
- package/dist/esm/markdown/processor.mjs.map +1 -1
- package/dist/esm/markdown/runtime.mjs +39 -1
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +190 -1
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/reactElement/renderReactElement.mjs +50 -1
- package/dist/esm/reactElement/renderReactElement.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +28 -1
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/format/index.mjs +10 -1
- package/dist/esm/server/format/useCompact.mjs +25 -1
- package/dist/esm/server/format/useCompact.mjs.map +1 -1
- package/dist/esm/server/format/useCurrency.mjs +36 -1
- package/dist/esm/server/format/useCurrency.mjs.map +1 -1
- package/dist/esm/server/format/useDate.mjs +41 -1
- package/dist/esm/server/format/useDate.mjs.map +1 -1
- package/dist/esm/server/format/useIntl.mjs +41 -1
- package/dist/esm/server/format/useIntl.mjs.map +1 -1
- package/dist/esm/server/format/useList.mjs +33 -1
- package/dist/esm/server/format/useList.mjs.map +1 -1
- package/dist/esm/server/format/useNumber.mjs +37 -1
- package/dist/esm/server/format/useNumber.mjs.map +1 -1
- package/dist/esm/server/format/usePercentage.mjs +33 -1
- package/dist/esm/server/format/usePercentage.mjs.map +1 -1
- package/dist/esm/server/format/useRelativeTime.mjs +33 -1
- package/dist/esm/server/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/server/format/useUnit.mjs +32 -1
- package/dist/esm/server/format/useUnit.mjs.map +1 -1
- package/dist/esm/server/index.mjs +12 -1
- package/dist/esm/server/serverContext.mjs +54 -1
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/t.mjs +33 -1
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +16 -1
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs +18 -1
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +19 -1
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useI18n.mjs +37 -1
- package/dist/esm/server/useI18n.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +16 -1
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useLoadDynamic.mjs +11 -1
- package/dist/esm/server/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/server/useLocale.mjs +21 -1
- package/dist/esm/server/useLocale.mjs.map +1 -1
- package/dist/types/html/HTMLRenderer.d.ts +1 -1
- package/dist/types/plugins.d.ts +4 -3
- package/dist/types/plugins.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1,2 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_client_useLocaleStorage = require('./useLocaleStorage.cjs');
|
|
6
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
7
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
8
|
+
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
9
|
+
let react = require("react");
|
|
10
|
+
|
|
11
|
+
//#region src/client/useLocale.ts
|
|
12
|
+
/**
|
|
13
|
+
* Client-side hook to get the current locale and related locale management functions.
|
|
14
|
+
*
|
|
15
|
+
* @param props - Optional properties for the hook.
|
|
16
|
+
* @returns An object containing the current locale, default locale, available locales, and a function to update the locale.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* import { useLocale } from 'react-intlayer';
|
|
21
|
+
*
|
|
22
|
+
* const LocaleSwitcher = () => {
|
|
23
|
+
* const { locale, setLocale, availableLocales } = useLocale();
|
|
24
|
+
*
|
|
25
|
+
* return (
|
|
26
|
+
* <select value={locale} onChange={(e) => setLocale(e.target.value)}>
|
|
27
|
+
* {availableLocales.map((loc) => (
|
|
28
|
+
* <option key={loc} value={loc}>{loc}</option>
|
|
29
|
+
* ))}
|
|
30
|
+
* </select>
|
|
31
|
+
* );
|
|
32
|
+
* };
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
36
|
+
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.default?.internationalization ?? {};
|
|
37
|
+
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
38
|
+
return {
|
|
39
|
+
locale,
|
|
40
|
+
defaultLocale,
|
|
41
|
+
availableLocales,
|
|
42
|
+
setLocale: (0, react.useCallback)((locale) => {
|
|
43
|
+
if (!availableLocales?.map(String).includes(locale)) {
|
|
44
|
+
console.error(`Locale ${locale} is not available`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
setLocaleState(locale);
|
|
48
|
+
require_client_useLocaleStorage.setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
|
|
49
|
+
onLocaleChange?.(locale);
|
|
50
|
+
}, [
|
|
51
|
+
availableLocales,
|
|
52
|
+
onLocaleChange,
|
|
53
|
+
setLocaleState,
|
|
54
|
+
isCookieEnabled
|
|
55
|
+
])
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
//#endregion
|
|
60
|
+
exports.useLocale = useLocale;
|
|
2
61
|
//# sourceMappingURL=useLocale.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":["configuration","IntlayerClientContext"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\ntype UseLocaleResult = {\n locale: LocalesValues;\n defaultLocale: LocalesValues;\n availableLocales: LocalesValues[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Client-side hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'react-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = useCallback(\n (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale as DeclaredLocales);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n } as UseLocaleResult;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":["configuration","IntlayerClientContext"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport type { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\nimport { setLocaleInStorage } from './useLocaleStorage';\n\ntype UseLocaleProps = {\n isCookieEnabled?: boolean;\n onLocaleChange?: (locale: LocalesValues) => void;\n};\n\ntype UseLocaleResult = {\n locale: LocalesValues;\n defaultLocale: LocalesValues;\n availableLocales: LocalesValues[];\n setLocale: (locale: LocalesValues) => void;\n};\n\n/**\n * Client-side hook to get the current locale and related locale management functions.\n *\n * @param props - Optional properties for the hook.\n * @returns An object containing the current locale, default locale, available locales, and a function to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocale } from 'react-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { locale, setLocale, availableLocales } = useLocale();\n *\n * return (\n * <select value={locale} onChange={(e) => setLocale(e.target.value)}>\n * {availableLocales.map((loc) => (\n * <option key={loc} value={loc}>{loc}</option>\n * ))}\n * </select>\n * );\n * };\n * ```\n */\nexport const useLocale = ({\n isCookieEnabled,\n onLocaleChange,\n}: UseLocaleProps = {}): UseLocaleResult => {\n const { defaultLocale, locales: availableLocales } =\n configuration?.internationalization ?? {};\n\n const {\n locale,\n setLocale: setLocaleState,\n isCookieEnabled: isCookieEnabledContext,\n } = useContext(IntlayerClientContext);\n\n const setLocale = useCallback(\n (locale: LocalesValues) => {\n if (!availableLocales?.map(String).includes(locale)) {\n console.error(`Locale ${locale} is not available`);\n return;\n }\n\n setLocaleState(locale);\n setLocaleInStorage(\n locale,\n isCookieEnabled ?? isCookieEnabledContext ?? true\n );\n onLocaleChange?.(locale as DeclaredLocales);\n },\n [availableLocales, onLocaleChange, setLocaleState, isCookieEnabled]\n );\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n } as UseLocaleResult;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,aAAa,EACxB,iBACA,mBACkB,EAAE,KAAsB;CAC1C,MAAM,EAAE,eAAe,SAAS,qBAC9BA,gCAAe,wBAAwB,EAAE;CAE3C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,iDACJC,sDAAsB;AAmBrC,QAAO;EACL;EACA;EACA;EACA,mCApBC,WAA0B;AACzB,OAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,OAAO,EAAE;AACnD,YAAQ,MAAM,UAAU,OAAO,mBAAmB;AAClD;;AAGF,kBAAe,OAAO;AACtB,sDACE,QACA,mBAAmB,0BAA0B,KAC9C;AACD,oBAAiB,OAA0B;KAE7C;GAAC;GAAkB;GAAgB;GAAgB;GAAgB,CACpE;EAOA"}
|
|
@@ -1,2 +1,27 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
6
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
7
|
+
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
8
|
+
let react = require("react");
|
|
9
|
+
|
|
10
|
+
//#region src/client/useLocaleBase.ts
|
|
11
|
+
const { defaultLocale, locales: availableLocales } = _intlayer_config_built.default.internationalization;
|
|
12
|
+
/**
|
|
13
|
+
* On the client side, hook to get the current locale and all related fields
|
|
14
|
+
*/
|
|
15
|
+
const useLocaleBase = () => {
|
|
16
|
+
const { locale, setLocale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
17
|
+
return {
|
|
18
|
+
locale,
|
|
19
|
+
defaultLocale,
|
|
20
|
+
availableLocales,
|
|
21
|
+
setLocale
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.useLocaleBase = useLocaleBase;
|
|
2
27
|
//# sourceMappingURL=useLocaleBase.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleBase.cjs","names":["configuration","IntlayerClientContext"],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocaleBase.cjs","names":["configuration","IntlayerClientContext"],"sources":["../../../src/client/useLocaleBase.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\nconst { defaultLocale, locales: availableLocales } =\n configuration.internationalization;\n\n/**\n * On the client side, hook to get the current locale and all related fields\n */\nexport const useLocaleBase = () => {\n const { locale, setLocale } = useContext(IntlayerClientContext);\n\n return {\n locale, // Current locale\n defaultLocale, // Principal locale defined in config\n availableLocales, // List of the available locales defined in config\n setLocale, // Function to set the locale\n };\n};\n"],"mappings":";;;;;;;;;;AAMA,MAAM,EAAE,eAAe,SAAS,qBAC9BA,+BAAc;;;;AAKhB,MAAa,sBAAsB;CACjC,MAAM,EAAE,QAAQ,oCAAyBC,sDAAsB;AAE/D,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -1,2 +1,63 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
let react = require("react");
|
|
4
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
5
|
+
let _intlayer_core_utils = require("@intlayer/core/utils");
|
|
6
|
+
|
|
7
|
+
//#region src/client/useLocaleStorage.ts
|
|
8
|
+
/**
|
|
9
|
+
* Get the locale cookie
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Get the locale cookie
|
|
13
|
+
*/
|
|
14
|
+
const localeInStorage = (0, _intlayer_core_utils.getLocaleFromStorage)(_intlayer_core_localization.localeStorageOptions);
|
|
15
|
+
/**
|
|
16
|
+
* @deprecated Use localeInStorage instead
|
|
17
|
+
*
|
|
18
|
+
* Get the locale cookie
|
|
19
|
+
*/
|
|
20
|
+
const localeCookie = localeInStorage;
|
|
21
|
+
/**
|
|
22
|
+
* Set the locale cookie
|
|
23
|
+
*/
|
|
24
|
+
const setLocaleInStorage = (locale, isCookieEnabled) => (0, _intlayer_core_utils.setLocaleInStorage)(locale, {
|
|
25
|
+
..._intlayer_core_localization.localeStorageOptions,
|
|
26
|
+
isCookieEnabled
|
|
27
|
+
});
|
|
28
|
+
/**
|
|
29
|
+
* @deprecated Use setLocaleInStorage instead
|
|
30
|
+
*
|
|
31
|
+
* Set the locale cookie
|
|
32
|
+
*/
|
|
33
|
+
const setLocaleCookie = setLocaleInStorage;
|
|
34
|
+
/**
|
|
35
|
+
* Hook that provides the locale cookie and a function to set it
|
|
36
|
+
*/
|
|
37
|
+
const useLocaleStorage = (isCookieEnabled) => (0, react.useMemo)(() => (0, _intlayer_core_utils.LocaleStorage)({
|
|
38
|
+
..._intlayer_core_localization.localeStorageOptions,
|
|
39
|
+
isCookieEnabled
|
|
40
|
+
}), [isCookieEnabled]);
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use useLocaleStorage instead
|
|
43
|
+
*
|
|
44
|
+
* For GDPR compliance, use useLocaleStorage instead
|
|
45
|
+
*
|
|
46
|
+
* Hook that provides the locale cookie and a function to set it
|
|
47
|
+
*/
|
|
48
|
+
const useLocaleCookie = (isCookieEnabled) => {
|
|
49
|
+
const storage = useLocaleStorage(isCookieEnabled);
|
|
50
|
+
return {
|
|
51
|
+
localeCookie: storage.getLocale(),
|
|
52
|
+
setLocaleCookie: storage.setLocale
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.localeCookie = localeCookie;
|
|
58
|
+
exports.localeInStorage = localeInStorage;
|
|
59
|
+
exports.setLocaleCookie = setLocaleCookie;
|
|
60
|
+
exports.setLocaleInStorage = setLocaleInStorage;
|
|
61
|
+
exports.useLocaleCookie = useLocaleCookie;
|
|
62
|
+
exports.useLocaleStorage = useLocaleStorage;
|
|
2
63
|
//# sourceMappingURL=useLocaleStorage.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorage,\n LocaleStorage,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useMemo } from 'react';\n\n/**\n * Get the locale cookie\n */\n/**\n * Get the locale cookie\n */\nexport const localeInStorage = getLocaleFromStorage(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled?: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n useMemo(\n () =>\n LocaleStorage({\n ...localeStorageOptions,\n isCookieEnabled,\n }),\n [isCookieEnabled]\n );\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = (isCookieEnabled?: boolean) => {\n const storage = useLocaleStorage(isCookieEnabled);\n\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocaleStorage.cjs","names":["localeStorageOptions"],"sources":["../../../src/client/useLocaleStorage.ts"],"sourcesContent":["import { localeStorageOptions } from '@intlayer/core/localization';\nimport {\n getLocaleFromStorage,\n LocaleStorage,\n setLocaleInStorage as setLocaleInStorageCore,\n} from '@intlayer/core/utils';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { useMemo } from 'react';\n\n/**\n * Get the locale cookie\n */\n/**\n * Get the locale cookie\n */\nexport const localeInStorage = getLocaleFromStorage(localeStorageOptions);\n/**\n * @deprecated Use localeInStorage instead\n *\n * Get the locale cookie\n */\nexport const localeCookie = localeInStorage;\n\n/**\n * Set the locale cookie\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n isCookieEnabled?: boolean\n) =>\n setLocaleInStorageCore(locale, {\n ...localeStorageOptions,\n isCookieEnabled,\n });\n\n/**\n * @deprecated Use setLocaleInStorage instead\n *\n * Set the locale cookie\n */\nexport const setLocaleCookie = setLocaleInStorage;\n\n/**\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleStorage = (isCookieEnabled?: boolean) =>\n useMemo(\n () =>\n LocaleStorage({\n ...localeStorageOptions,\n isCookieEnabled,\n }),\n [isCookieEnabled]\n );\n\n/**\n * @deprecated Use useLocaleStorage instead\n *\n * For GDPR compliance, use useLocaleStorage instead\n *\n * Hook that provides the locale cookie and a function to set it\n */\nexport const useLocaleCookie = (isCookieEnabled?: boolean) => {\n const storage = useLocaleStorage(isCookieEnabled);\n\n return {\n localeCookie: storage.getLocale(),\n setLocaleCookie: storage.setLocale,\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAeA,MAAa,iEAAuCA,iDAAqB;;;;;;AAMzE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,iEAEuB,QAAQ;CAC7B,GAAGA;CACH;CACD,CAAC;;;;;;AAOJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,qFAGb;CACZ,GAAGA;CACH;CACD,CAAC,EACJ,CAAC,gBAAgB,CAClB;;;;;;;;AASH,MAAa,mBAAmB,oBAA8B;CAC5D,MAAM,UAAU,iBAAiB,gBAAgB;AAEjD,QAAO;EACL,cAAc,QAAQ,WAAW;EACjC,iBAAiB,QAAQ;EAC1B"}
|
|
@@ -1,2 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_client_useLocale = require('./useLocale.cjs');
|
|
6
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
7
|
+
_intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
|
|
8
|
+
let react = require("react");
|
|
9
|
+
let _intlayer_core_localization = require("@intlayer/core/localization");
|
|
10
|
+
|
|
11
|
+
//#region src/client/useRewriteURL.ts
|
|
12
|
+
/**
|
|
13
|
+
* Client-side hook to manage URL rewrites without triggering a router navigation.
|
|
14
|
+
* It uses `window.history.replaceState` to update the URL in the address bar.
|
|
15
|
+
*
|
|
16
|
+
* This hook is useful to "prettify" the URL when the user lands on a canonical path
|
|
17
|
+
* that has a localized alias defined in `intlayer.config.ts`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { useRewriteURL } from 'react-intlayer';
|
|
22
|
+
*
|
|
23
|
+
* const MyComponent = () => {
|
|
24
|
+
* useRewriteURL();
|
|
25
|
+
*
|
|
26
|
+
* return <div>My Component</div>;
|
|
27
|
+
* };
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
const useRewriteURL = () => {
|
|
31
|
+
const { locale } = require_client_useLocale.useLocale();
|
|
32
|
+
const rewrite = _intlayer_config_built.default?.routing?.rewrite;
|
|
33
|
+
(0, react.useEffect)(() => {
|
|
34
|
+
if (typeof window === "undefined" || !rewrite) return;
|
|
35
|
+
const pathname = window.location.pathname;
|
|
36
|
+
const targetPath = (0, _intlayer_core_localization.getRewritePath)(pathname, locale, rewrite);
|
|
37
|
+
if (targetPath && targetPath !== pathname) window.history.replaceState(window.history.state, "", targetPath + window.location.search + window.location.hash);
|
|
38
|
+
}, [locale, rewrite]);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
//#endregion
|
|
42
|
+
exports.useRewriteURL = useRewriteURL;
|
|
2
43
|
//# sourceMappingURL=useRewriteURL.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRewriteURL.cjs","names":["useLocale","configuration"],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * useRewriteURL();\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n const { locale } = useLocale();\n const rewrite = configuration?.routing?.rewrite;\n\n useEffect(() => {\n if (typeof window === 'undefined' || !rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(pathname, locale as Locale, rewrite);\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n }, [locale, rewrite]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRewriteURL.cjs","names":["useLocale","configuration"],"sources":["../../../src/client/useRewriteURL.ts"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { getRewritePath } from '@intlayer/core/localization';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useEffect } from 'react';\nimport { useLocale } from './useLocale';\n\n/**\n * Client-side hook to manage URL rewrites without triggering a router navigation.\n * It uses `window.history.replaceState` to update the URL in the address bar.\n *\n * This hook is useful to \"prettify\" the URL when the user lands on a canonical path\n * that has a localized alias defined in `intlayer.config.ts`.\n *\n * @example\n * ```tsx\n * import { useRewriteURL } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * useRewriteURL();\n *\n * return <div>My Component</div>;\n * };\n * ```\n */\nexport const useRewriteURL = (): void => {\n const { locale } = useLocale();\n const rewrite = configuration?.routing?.rewrite;\n\n useEffect(() => {\n if (typeof window === 'undefined' || !rewrite) return;\n\n const pathname = window.location.pathname;\n const targetPath = getRewritePath(pathname, locale as Locale, rewrite);\n\n if (targetPath && targetPath !== pathname) {\n window.history.replaceState(\n window.history.state,\n '',\n targetPath + window.location.search + window.location.hash\n );\n }\n }, [locale, rewrite]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,sBAA4B;CACvC,MAAM,EAAE,WAAWA,oCAAW;CAC9B,MAAM,UAAUC,gCAAe,SAAS;AAExC,4BAAgB;AACd,MAAI,OAAO,WAAW,eAAe,CAAC,QAAS;EAE/C,MAAM,WAAW,OAAO,SAAS;EACjC,MAAM,6DAA4B,UAAU,QAAkB,QAAQ;AAEtE,MAAI,cAAc,eAAe,SAC/B,QAAO,QAAQ,aACb,OAAO,QAAQ,OACf,IACA,aAAa,OAAO,SAAS,SAAS,OAAO,SAAS,KACvD;IAEF,CAAC,QAAQ,QAAQ,CAAC"}
|
|
@@ -1,2 +1,36 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_client_IntlayerProvider = require('./IntlayerProvider.cjs');
|
|
4
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
|
|
7
|
+
//#region src/client/useTraduction.ts
|
|
8
|
+
/**
|
|
9
|
+
* On the client side, Hook that picking one dictionary by its id and return the content.
|
|
10
|
+
*
|
|
11
|
+
* If not locale found, it will return the content related to the default locale.
|
|
12
|
+
*
|
|
13
|
+
* Return either the content editor, or the content itself depending on the configuration.
|
|
14
|
+
*
|
|
15
|
+
* Usage:
|
|
16
|
+
*
|
|
17
|
+
* ```tsx
|
|
18
|
+
* const content = useTranslation<string>({
|
|
19
|
+
* en: 'Hello',
|
|
20
|
+
* fr: 'Bonjour',
|
|
21
|
+
* }, 'fr');
|
|
22
|
+
* // 'Bonjour'
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* Using TypeScript:
|
|
26
|
+
* - this function will require each locale to be defined if defined in the project configuration.
|
|
27
|
+
* - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.
|
|
28
|
+
*/
|
|
29
|
+
const useTranslation = (languageContent) => {
|
|
30
|
+
const { locale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
31
|
+
return (0, react.useMemo)(() => (0, _intlayer_core_interpreter.getTranslation)(languageContent, locale), [languageContent, locale]);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
//#endregion
|
|
35
|
+
exports.useTranslation = useTranslation;
|
|
2
36
|
//# sourceMappingURL=useTraduction.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTraduction.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useTraduction.cjs","names":["IntlayerClientContext"],"sources":["../../../src/client/useTraduction.ts"],"sourcesContent":["import { getTranslation } from '@intlayer/core/interpreter';\nimport type { StrictModeLocaleMap } from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the client side, Hook that picking one dictionary by its id and return the content.\n *\n * If not locale found, it will return the content related to the default locale.\n *\n * Return either the content editor, or the content itself depending on the configuration.\n *\n * Usage:\n *\n * ```tsx\n * const content = useTranslation<string>({\n * en: 'Hello',\n * fr: 'Bonjour',\n * }, 'fr');\n * // 'Bonjour'\n * ```\n *\n * Using TypeScript:\n * - this function will require each locale to be defined if defined in the project configuration.\n * - If a locale is missing, it will make each existing locale optional and raise an error if the locale is not found.\n */\nexport const useTranslation = <Content = string>(\n languageContent: StrictModeLocaleMap<Content>\n): Content => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useMemo(\n () => getTranslation(languageContent, locale),\n [languageContent, locale]\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0BA,MAAa,kBACX,oBACY;CACZ,MAAM,EAAE,iCAAsBA,sDAAsB;AAEpD,gFACuB,iBAAiB,OAAO,EAC7C,CAAC,iBAAiB,OAAO,CAC1B"}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
7
|
+
|
|
8
|
+
//#region src/editor/ContentSelector.tsx
|
|
9
|
+
const ContentSelector = ({ children, dictionaryKey, keyPath }) => {
|
|
10
|
+
if (_intlayer_editor_isEnabled.isEnabled) return (0, react.createElement)("intlayer-content-selector-wrapper", {
|
|
11
|
+
"key-path": JSON.stringify(keyPath),
|
|
12
|
+
"dictionary-key": dictionaryKey
|
|
13
|
+
}, children);
|
|
14
|
+
return children;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
//#endregion
|
|
18
|
+
exports.ContentSelector = ContentSelector;
|
|
2
19
|
//# sourceMappingURL=ContentSelector.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelector.cjs","names":["isEnabled"],"sources":["../../../src/editor/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport type { NodeProps } from '@intlayer/core/interpreter';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport { createElement, type FC, type HTMLAttributes } from 'react';\n\nexport type ContentSelectorProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n if (isEnabled) {\n return createElement(\n 'intlayer-content-selector-wrapper',\n {\n 'key-path': JSON.stringify(keyPath),\n 'dictionary-key': dictionaryKey,\n },\n children\n );\n }\n\n return children;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContentSelector.cjs","names":["isEnabled"],"sources":["../../../src/editor/ContentSelector.tsx"],"sourcesContent":["'use client';\n\nimport type { NodeProps } from '@intlayer/core/interpreter';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport { createElement, type FC, type HTMLAttributes } from 'react';\n\nexport type ContentSelectorProps = NodeProps &\n Omit<HTMLAttributes<HTMLDivElement>, 'children'>;\n\nexport const ContentSelector: FC<ContentSelectorProps> = ({\n children,\n dictionaryKey,\n keyPath,\n}) => {\n if (isEnabled) {\n return createElement(\n 'intlayer-content-selector-wrapper',\n {\n 'key-path': JSON.stringify(keyPath),\n 'dictionary-key': dictionaryKey,\n },\n children\n );\n }\n\n return children;\n};\n"],"mappings":";;;;;;;;AASA,MAAa,mBAA6C,EACxD,UACA,eACA,cACI;AACJ,KAAIA,qCACF,iCACE,qCACA;EACE,YAAY,KAAK,UAAU,QAAQ;EACnC,kBAAkB;EACnB,EACD,SACD;AAGH,QAAO"}
|
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_editor_useEditor = require('./useEditor.cjs');
|
|
3
|
+
|
|
4
|
+
//#region src/editor/EditorProvider.tsx
|
|
5
|
+
const EditorProvider = ({ children }) => {
|
|
6
|
+
require_editor_useEditor.useEditor();
|
|
7
|
+
return children;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.EditorProvider = EditorProvider;
|
|
2
12
|
//# sourceMappingURL=EditorProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorProvider.cjs","names":[],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport { useEditor } from './useEditor';\n\nexport const EditorProvider: FC<PropsWithChildren> = ({ children }) => {\n useEditor();\n\n return children;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"EditorProvider.cjs","names":[],"sources":["../../../src/editor/EditorProvider.tsx"],"sourcesContent":["import type { FC, PropsWithChildren } from 'react';\nimport { useEditor } from './useEditor';\n\nexport const EditorProvider: FC<PropsWithChildren> = ({ children }) => {\n useEditor();\n\n return children;\n};\n"],"mappings":";;;;AAGA,MAAa,kBAAyC,EAAE,eAAe;AACrE,qCAAW;AAEX,QAAO"}
|
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_client_IntlayerProvider = require('../client/IntlayerProvider.cjs');
|
|
6
|
+
let react = require("react");
|
|
7
|
+
let _intlayer_editor_isEnabled = require("@intlayer/editor/isEnabled");
|
|
8
|
+
|
|
9
|
+
//#region src/editor/useEditor.tsx
|
|
10
|
+
/**
|
|
11
|
+
* Initializes the Intlayer editor client singleton when the editor is enabled.
|
|
12
|
+
* Syncs the current locale from the Intlayer context into the editor manager so
|
|
13
|
+
* the editor always knows which locale the app is displaying.
|
|
14
|
+
*/
|
|
15
|
+
const useEditor = () => {
|
|
16
|
+
const { locale } = (0, react.useContext)(require_client_IntlayerProvider.IntlayerClientContext);
|
|
17
|
+
const managerRef = (0, react.useRef)(null);
|
|
18
|
+
(0, react.useEffect)(() => {
|
|
19
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !_intlayer_editor_isEnabled.isEnabled) return;
|
|
20
|
+
import("@intlayer/editor").then(({ initEditorClient }) => {
|
|
21
|
+
const manager = initEditorClient();
|
|
22
|
+
managerRef.current = manager;
|
|
23
|
+
if (locale) manager.currentLocale.set(locale);
|
|
24
|
+
});
|
|
25
|
+
return () => {
|
|
26
|
+
managerRef.current = null;
|
|
27
|
+
import("@intlayer/editor").then(({ stopEditorClient }) => {
|
|
28
|
+
stopEditorClient();
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
}, []);
|
|
32
|
+
(0, react.useEffect)(() => {
|
|
33
|
+
if (!locale || !managerRef.current) return;
|
|
34
|
+
managerRef.current.currentLocale.set(locale);
|
|
35
|
+
}, [locale]);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
exports.useEditor = useEditor;
|
|
2
40
|
//# sourceMappingURL=useEditor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.cjs","names":["IntlayerClientContext","isEnabled"],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'react';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initializes the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext);\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n });\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n };\n }, []);\n\n useEffect(() => {\n if (!locale || !managerRef.current) return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useEditor.cjs","names":["IntlayerClientContext","isEnabled"],"sources":["../../../src/editor/useEditor.tsx"],"sourcesContent":["'use client';\n\nimport type { EditorStateManager } from '@intlayer/editor';\nimport { isEnabled } from '@intlayer/editor/isEnabled';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { useContext, useEffect, useRef } from 'react';\nimport { IntlayerClientContext } from '../client/IntlayerProvider';\n\n/**\n * Initializes the Intlayer editor client singleton when the editor is enabled.\n * Syncs the current locale from the Intlayer context into the editor manager so\n * the editor always knows which locale the app is displaying.\n */\nexport const useEditor = () => {\n const { locale } = useContext(IntlayerClientContext);\n const managerRef = useRef<EditorStateManager | null>(null);\n\n useEffect(() => {\n if (process.env.INTLAYER_EDITOR_ENABLED === 'false' || !isEnabled) return;\n\n import('@intlayer/editor').then(({ initEditorClient }) => {\n const manager = initEditorClient();\n managerRef.current = manager;\n\n if (locale) manager.currentLocale.set(locale as Locale);\n });\n\n return () => {\n managerRef.current = null;\n import('@intlayer/editor').then(({ stopEditorClient }) => {\n stopEditorClient();\n });\n };\n }, []);\n\n useEffect(() => {\n if (!locale || !managerRef.current) return;\n\n managerRef.current.currentLocale.set(locale as Locale);\n }, [locale]);\n};\n"],"mappings":";;;;;;;;;;;;;;AAaA,MAAa,kBAAkB;CAC7B,MAAM,EAAE,iCAAsBA,sDAAsB;CACpD,MAAM,+BAA+C,KAAK;AAE1D,4BAAgB;AACd,MAAI,QAAQ,IAAI,4BAA4B,WAAW,CAACC,qCAAW;AAEnE,SAAO,oBAAoB,MAAM,EAAE,uBAAuB;GACxD,MAAM,UAAU,kBAAkB;AAClC,cAAW,UAAU;AAErB,OAAI,OAAQ,SAAQ,cAAc,IAAI,OAAiB;IACvD;AAEF,eAAa;AACX,cAAW,UAAU;AACrB,UAAO,oBAAoB,MAAM,EAAE,uBAAuB;AACxD,sBAAkB;KAClB;;IAEH,EAAE,CAAC;AAEN,4BAAgB;AACd,MAAI,CAAC,UAAU,CAAC,WAAW,QAAS;AAEpC,aAAW,QAAQ,cAAc,IAAI,OAAiB;IACrD,CAAC,OAAO,CAAC"}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_plugins = require('./plugins.cjs');
|
|
4
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
|
+
|
|
6
|
+
//#region src/getDictionary.ts
|
|
7
|
+
const getDictionary = (dictionary, locale) => (0, _intlayer_core_interpreter.getDictionary)(dictionary, locale, require_plugins.getPlugins(locale));
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.getDictionary = getDictionary;
|
|
2
11
|
//# sourceMappingURL=getDictionary.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): DeepTransformContent<T['content'], L> =>\n getDictionaryCore(dictionary, locale, getPlugins(locale)) as any;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDictionary.cjs","names":["getPlugins"],"sources":["../../src/getDictionary.ts"],"sourcesContent":["import { getDictionary as getDictionaryCore } from '@intlayer/core/interpreter';\nimport type { Dictionary } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): DeepTransformContent<T['content'], L> =>\n getDictionaryCore(dictionary, locale, getPlugins(locale)) as any;\n"],"mappings":";;;;;;AAQA,MAAa,iBAIX,YACA,yDAEkB,YAAY,QAAQA,2BAAW,OAAO,CAAC"}
|
package/dist/cjs/getIntlayer.cjs
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_plugins = require('./plugins.cjs');
|
|
4
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
5
|
+
|
|
6
|
+
//#region src/getIntlayer.ts
|
|
7
|
+
const getIntlayer = (key, locale) => (0, _intlayer_core_interpreter.getIntlayer)(key, locale, require_plugins.getPlugins(locale));
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.getIntlayer = getIntlayer;
|
|
2
11
|
//# sourceMappingURL=getIntlayer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n): DeepTransformContent<DictionaryRegistryContent<T>, L> =>\n getIntlayerCore(key, locale, getPlugins(locale)) as any;\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"getIntlayer.cjs","names":["getPlugins"],"sources":["../../src/getIntlayer.ts"],"sourcesContent":["import { getIntlayer as getIntlayerCore } from '@intlayer/core/interpreter';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { type DeepTransformContent, getPlugins } from './plugins';\n\nexport const getIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n): DeepTransformContent<DictionaryRegistryContent<T>, L> =>\n getIntlayerCore(key, locale, getPlugins(locale)) as any;\n"],"mappings":";;;;;;AASA,MAAa,eAIX,KACA,uDAEgB,KAAK,QAAQA,2BAAW,OAAO,CAAC"}
|
|
@@ -1,2 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
let react = require("react");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
|
|
8
|
+
//#region src/html/HTMLProvider.tsx
|
|
9
|
+
const HTMLContext = (0, react.createContext)(void 0);
|
|
10
|
+
const useHTMLContext = () => (0, react.useContext)(HTMLContext);
|
|
11
|
+
const HTMLProvider = ({ children, components }) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(HTMLContext.Provider, {
|
|
12
|
+
value: { components },
|
|
13
|
+
children
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.HTMLProvider = HTMLProvider;
|
|
18
|
+
exports.useHTMLContext = useHTMLContext;
|
|
2
19
|
//# sourceMappingURL=HTMLProvider.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLProvider.cjs","names":[],"sources":["../../../src/html/HTMLProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\nimport type { HTMLComponents } from './HTMLComponentTypes';\n\ntype HTMLContextValue = {\n components?: HTMLComponents<'permissive', {}>;\n};\n\ntype HTMLProviderProps = PropsWithChildren<{\n /**\n * Component overrides for HTML tags.\n */\n components?: HTMLComponents<'permissive', {}>;\n}>;\n\nconst HTMLContext = createContext<HTMLContextValue | undefined>(undefined);\n\nexport const useHTMLContext = () => useContext(HTMLContext);\n\nexport const HTMLProvider: FC<HTMLProviderProps> = ({\n children,\n components,\n}) => (\n <HTMLContext.Provider value={{ components }}>{children}</HTMLContext.Provider>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HTMLProvider.cjs","names":[],"sources":["../../../src/html/HTMLProvider.tsx"],"sourcesContent":["'use client';\n\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n} from 'react';\nimport type { HTMLComponents } from './HTMLComponentTypes';\n\ntype HTMLContextValue = {\n components?: HTMLComponents<'permissive', {}>;\n};\n\ntype HTMLProviderProps = PropsWithChildren<{\n /**\n * Component overrides for HTML tags.\n */\n components?: HTMLComponents<'permissive', {}>;\n}>;\n\nconst HTMLContext = createContext<HTMLContextValue | undefined>(undefined);\n\nexport const useHTMLContext = () => useContext(HTMLContext);\n\nexport const HTMLProvider: FC<HTMLProviderProps> = ({\n children,\n components,\n}) => (\n <HTMLContext.Provider value={{ components }}>{children}</HTMLContext.Provider>\n);\n"],"mappings":";;;;;;;;AAqBA,MAAM,uCAA0D,OAAU;AAE1E,MAAa,6CAAkC,YAAY;AAE3D,MAAa,gBAAuC,EAClD,UACA,iBAEA,2CAAC,YAAY,UAAb;CAAsB,OAAO,EAAE,YAAY;CAAG;CAAgC"}
|
|
@@ -1,2 +1,61 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_html_HTMLProvider = require('./HTMLProvider.cjs');
|
|
6
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
7
|
+
let react = require("react");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
let _intlayer_core_transpiler = require("@intlayer/core/transpiler");
|
|
10
|
+
|
|
11
|
+
//#region src/html/HTMLRenderer.tsx
|
|
12
|
+
const createDefaultHTMLComponents = () => {
|
|
13
|
+
const components = {};
|
|
14
|
+
for (const tag of _intlayer_core_transpiler.HTML_TAGS) components[tag] = ({ children, ...props }) => (0, react.createElement)(tag, props, children);
|
|
15
|
+
return components;
|
|
16
|
+
};
|
|
17
|
+
const defaultHTMLComponents = createDefaultHTMLComponents();
|
|
18
|
+
/**
|
|
19
|
+
* Renders HTML-like content to JSX with the provided components.
|
|
20
|
+
*
|
|
21
|
+
* This function does not use context from HTMLProvider. Use `useHTMLRenderer`
|
|
22
|
+
* hook if you want to leverage provider context.
|
|
23
|
+
*/
|
|
24
|
+
const renderHTML = (content, { components } = {}) => {
|
|
25
|
+
const mergedComponents = {
|
|
26
|
+
...defaultHTMLComponents,
|
|
27
|
+
...components
|
|
28
|
+
};
|
|
29
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Fragment, { children: (0, _intlayer_core_interpreter.getHTML)(content, Object.fromEntries(Object.entries(mergedComponents).filter(([, Component]) => Component).map(([key, Component]) => [key, (props) => (0, react.createElement)(Component, props)]))) });
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Hook that returns a function to render HTML content.
|
|
33
|
+
*
|
|
34
|
+
* This hook considers the configuration from the `HTMLProvider` context if available,
|
|
35
|
+
* falling back to the provided components.
|
|
36
|
+
*/
|
|
37
|
+
const useHTMLRenderer = ({ components } = {}) => {
|
|
38
|
+
const context = require_html_HTMLProvider.useHTMLContext();
|
|
39
|
+
return (content) => {
|
|
40
|
+
return renderHTML(content, { components: {
|
|
41
|
+
...context?.components,
|
|
42
|
+
...components
|
|
43
|
+
} });
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* React component that renders HTML-like content to JSX.
|
|
48
|
+
*
|
|
49
|
+
* This component uses the components from the `HTMLProvider` context
|
|
50
|
+
* if available.
|
|
51
|
+
*/
|
|
52
|
+
const HTMLRenderer = ({ children = "", components }) => {
|
|
53
|
+
return useHTMLRenderer({ components })(children);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
exports.HTMLRenderer = HTMLRenderer;
|
|
58
|
+
exports.defaultHTMLComponents = defaultHTMLComponents;
|
|
59
|
+
exports.renderHTML = renderHTML;
|
|
60
|
+
exports.useHTMLRenderer = useHTMLRenderer;
|
|
2
61
|
//# sourceMappingURL=HTMLRenderer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLRenderer.cjs","names":["HTML_TAGS","Fragment","useHTMLContext"],"sources":["../../../src/html/HTMLRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { getHTML } from '@intlayer/core/interpreter';\nimport { HTML_TAGS } from '@intlayer/core/transpiler';\nimport { createElement, type FC, Fragment, type JSX } from 'react';\nimport type { HTMLComponents } from './HTMLComponentTypes';\nimport { useHTMLContext } from './HTMLProvider';\n\nconst createDefaultHTMLComponents = (): HTMLComponents<'permissive', {}> => {\n const components: HTMLComponents = {};\n\n for (const tag of HTML_TAGS) {\n components[tag] = ({ children, ...props }) =>\n createElement(tag, props as any, children);\n }\n\n return components as HTMLComponents<'permissive', {}>;\n};\n\nexport const defaultHTMLComponents = createDefaultHTMLComponents();\n\nexport type RenderHTMLProps = {\n /**\n * Component overrides for HTML tags.\n * Allows you to customize how specific HTML elements are rendered.\n */\n components?: HTMLComponents<'permissive', {}>;\n};\n\n/**\n * Renders HTML-like content to JSX with the provided components.\n *\n * This function does not use context from HTMLProvider. Use `useHTMLRenderer`\n * hook if you want to leverage provider context.\n */\nexport const renderHTML = (\n content: string,\n { components }: RenderHTMLProps = {}\n): JSX.Element => {\n const mergedComponents = {\n ...defaultHTMLComponents,\n ...components,\n };\n\n // Wrap all components to ensure they are rendered via React.createElement\n const wrappedComponents = Object.fromEntries(\n Object.entries(mergedComponents)\n .filter(([, Component]) => Component)\n .map(([key, Component]) => [\n key,\n (props: any) => createElement(Component as any, props),\n ])\n );\n\n return <Fragment>{getHTML(content, wrappedComponents)}</Fragment>;\n};\n\n/**\n * Hook that returns a function to render HTML content.\n *\n * This hook considers the configuration from the `HTMLProvider` context if available,\n * falling back to the provided components.\n */\nexport const useHTMLRenderer = ({ components }: RenderHTMLProps = {}) => {\n const context = useHTMLContext();\n\n return (content: string) => {\n return renderHTML(content, {\n components: {\n ...context?.components,\n ...components,\n },\n });\n };\n};\n\nexport type HTMLRendererProps = RenderHTMLProps & {\n /**\n * The HTML content to render as a string.\n */\n children: string;\n};\n\n/**\n * React component that renders HTML-like content to JSX.\n *\n * This component uses the components from the `HTMLProvider` context\n * if available.\n */\nexport const HTMLRenderer: FC<HTMLRendererProps> = ({\n children = '',\n components,\n}) => {\n const render = useHTMLRenderer({ components });\n\n return render(children);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"HTMLRenderer.cjs","names":["HTML_TAGS","Fragment","useHTMLContext"],"sources":["../../../src/html/HTMLRenderer.tsx"],"sourcesContent":["'use client';\n\nimport { getHTML } from '@intlayer/core/interpreter';\nimport { HTML_TAGS } from '@intlayer/core/transpiler';\nimport { createElement, type FC, Fragment, type JSX } from 'react';\nimport type { HTMLComponents } from './HTMLComponentTypes';\nimport { useHTMLContext } from './HTMLProvider';\n\nconst createDefaultHTMLComponents = (): HTMLComponents<'permissive', {}> => {\n const components: HTMLComponents = {};\n\n for (const tag of HTML_TAGS) {\n components[tag] = ({ children, ...props }) =>\n createElement(tag, props as any, children);\n }\n\n return components as HTMLComponents<'permissive', {}>;\n};\n\nexport const defaultHTMLComponents = createDefaultHTMLComponents();\n\nexport type RenderHTMLProps = {\n /**\n * Component overrides for HTML tags.\n * Allows you to customize how specific HTML elements are rendered.\n */\n components?: HTMLComponents<'permissive', {}>;\n};\n\n/**\n * Renders HTML-like content to JSX with the provided components.\n *\n * This function does not use context from HTMLProvider. Use `useHTMLRenderer`\n * hook if you want to leverage provider context.\n */\nexport const renderHTML = (\n content: string,\n { components }: RenderHTMLProps = {}\n): JSX.Element => {\n const mergedComponents = {\n ...defaultHTMLComponents,\n ...components,\n };\n\n // Wrap all components to ensure they are rendered via React.createElement\n const wrappedComponents = Object.fromEntries(\n Object.entries(mergedComponents)\n .filter(([, Component]) => Component)\n .map(([key, Component]) => [\n key,\n (props: any) => createElement(Component as any, props),\n ])\n );\n\n return <Fragment>{getHTML(content, wrappedComponents)}</Fragment>;\n};\n\n/**\n * Hook that returns a function to render HTML content.\n *\n * This hook considers the configuration from the `HTMLProvider` context if available,\n * falling back to the provided components.\n */\nexport const useHTMLRenderer = ({ components }: RenderHTMLProps = {}) => {\n const context = useHTMLContext();\n\n return (content: string) => {\n return renderHTML(content, {\n components: {\n ...context?.components,\n ...components,\n },\n });\n };\n};\n\nexport type HTMLRendererProps = RenderHTMLProps & {\n /**\n * The HTML content to render as a string.\n */\n children: string;\n};\n\n/**\n * React component that renders HTML-like content to JSX.\n *\n * This component uses the components from the `HTMLProvider` context\n * if available.\n */\nexport const HTMLRenderer: FC<HTMLRendererProps> = ({\n children = '',\n components,\n}) => {\n const render = useHTMLRenderer({ components });\n\n return render(children);\n};\n"],"mappings":";;;;;;;;;;;AAQA,MAAM,oCAAsE;CAC1E,MAAM,aAA6B,EAAE;AAErC,MAAK,MAAM,OAAOA,oCAChB,YAAW,QAAQ,EAAE,UAAU,GAAG,qCAClB,KAAK,OAAc,SAAS;AAG9C,QAAO;;AAGT,MAAa,wBAAwB,6BAA6B;;;;;;;AAgBlE,MAAa,cACX,SACA,EAAE,eAAgC,EAAE,KACpB;CAChB,MAAM,mBAAmB;EACvB,GAAG;EACH,GAAG;EACJ;AAYD,QAAO,2CAACC,gBAAD,oDAAmB,SATA,OAAO,YAC/B,OAAO,QAAQ,iBAAiB,CAC7B,QAAQ,GAAG,eAAe,UAAU,CACpC,KAAK,CAAC,KAAK,eAAe,CACzB,MACC,mCAA6B,WAAkB,MAAM,CACvD,CAAC,CACL,CAEoD,EAAY;;;;;;;;AASnE,MAAa,mBAAmB,EAAE,eAAgC,EAAE,KAAK;CACvE,MAAM,UAAUC,0CAAgB;AAEhC,SAAQ,YAAoB;AAC1B,SAAO,WAAW,SAAS,EACzB,YAAY;GACV,GAAG,SAAS;GACZ,GAAG;GACJ,EACF,CAAC;;;;;;;;;AAiBN,MAAa,gBAAuC,EAClD,WAAW,IACX,iBACI;AAGJ,QAFe,gBAAgB,EAAE,YAAY,CAAC,CAEhC,SAAS"}
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
+
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
5
|
+
const require_html_HTMLProvider = require('./HTMLProvider.cjs');
|
|
6
|
+
const require_html_HTMLRenderer = require('./HTMLRenderer.cjs');
|
|
7
|
+
let _intlayer_core_interpreter = require("@intlayer/core/interpreter");
|
|
8
|
+
let react = require("react");
|
|
9
|
+
|
|
10
|
+
//#region src/html/HTMLRendererPlugin.tsx
|
|
11
|
+
const HTMLRendererPlugin = (props) => {
|
|
12
|
+
const { html, userComponents } = props;
|
|
13
|
+
const globalComponents = require_html_HTMLProvider.useHTMLContext()?.components || {};
|
|
14
|
+
const mergedComponents = {
|
|
15
|
+
...require_html_HTMLRenderer.defaultHTMLComponents,
|
|
16
|
+
...globalComponents,
|
|
17
|
+
...userComponents
|
|
18
|
+
};
|
|
19
|
+
return (0, _intlayer_core_interpreter.getHTML)(html, Object.fromEntries(Object.entries(mergedComponents).filter(([, Component]) => Component).map(([key, Component]) => [key, (props) => (0, react.createElement)(Component, props)])));
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
exports.HTMLRendererPlugin = HTMLRendererPlugin;
|
|
2
24
|
//# sourceMappingURL=HTMLRendererPlugin.cjs.map
|