react-intlayer 8.4.4 → 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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useI18n.mjs","names":[],"sources":["../../../src/client/useI18n.ts"],"sourcesContent":["'use client';\n\nimport { getIntlayer } from '@intlayer/core/interpreter';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { GetSubPath } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Hook that provides a translation function `t()` for accessing nested content by key.\n * This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.\n *\n * @param namespace - The dictionary key to scope translations to\n * @param locale - Optional locale override. If not provided, uses the current context locale\n * @returns A translation function `t(key)` that returns the translated content for the given key\n *\n * @example\n * ```tsx\n * const t = useI18n('IndexPage');\n * const title = t('title'); // Returns translated string for 'IndexPage.title'\n * const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'\n * // For attributes like `aria-label`, use `.value` to get the plain string\n * const ariaLabel = t('button.ariaLabel').value; // 'Close modal'\n * ```\n */\nexport const useI18n = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n namespace: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n // Get the dictionary content for the namespace\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const dictionaryContent: DeepTransformContent<DictionaryRegistryContent<T>> =\n useMemo(\n () => getIntlayer<T, L>(namespace, localeTarget as L),\n [namespace, localeTarget]\n );\n\n // Return the translation function\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const t = <P extends ValidDotPathsFor<T>>(\n path: P\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n ): GetSubPath<DeepTransformContent<DictionaryRegistryContent<T>>, P> => {\n if (!path) {\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return dictionaryContent as any;\n }\n\n const pathArray = (path as string).split('.');\n let current: any = dictionaryContent;\n\n for (const key of pathArray) {\n current = current?.[key];\n if (current === undefined) {\n // Return the whole dictionary as fallback if path is not found\n return dictionaryContent as any;\n }\n }\n\n return current;\n };\n\n return t;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useI18n.mjs","names":[],"sources":["../../../src/client/useI18n.ts"],"sourcesContent":["'use client';\n\nimport { getIntlayer } from '@intlayer/core/interpreter';\nimport type { ValidDotPathsFor } from '@intlayer/core/transpiler';\nimport type { GetSubPath } from '@intlayer/types/dictionary';\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n DictionaryRegistryContent,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport type { DeepTransformContent } from '../plugins';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Hook that provides a translation function `t()` for accessing nested content by key.\n * This hook mimics the pattern found in libraries like i18next, next-intl, and vue-i18n.\n *\n * @param namespace - The dictionary key to scope translations to\n * @param locale - Optional locale override. If not provided, uses the current context locale\n * @returns A translation function `t(key)` that returns the translated content for the given key\n *\n * @example\n * ```tsx\n * const t = useI18n('IndexPage');\n * const title = t('title'); // Returns translated string for 'IndexPage.title'\n * const nestedContent = t('section.subtitle'); // Returns 'IndexPage.section.subtitle'\n * // For attributes like `aria-label`, use `.value` to get the plain string\n * const ariaLabel = t('button.ariaLabel').value; // 'Close modal'\n * ```\n */\nexport const useI18n = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n namespace: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = useMemo(\n () => locale ?? currentLocale,\n [currentLocale, locale]\n );\n\n // Get the dictionary content for the namespace\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const dictionaryContent: DeepTransformContent<DictionaryRegistryContent<T>> =\n useMemo(\n () => getIntlayer<T, L>(namespace, localeTarget as L),\n [namespace, localeTarget]\n );\n\n // Return the translation function\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n const t = <P extends ValidDotPathsFor<T>>(\n path: P\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n ): GetSubPath<DeepTransformContent<DictionaryRegistryContent<T>>, P> => {\n if (!path) {\n // @ts-ignore Type instantiation is excessively deep and possibly infinite\n return dictionaryContent as any;\n }\n\n const pathArray = (path as string).split('.');\n let current: any = dictionaryContent;\n\n for (const key of pathArray) {\n current = current?.[key];\n if (current === undefined) {\n // Return the whole dictionary as fallback if path is not found\n return dictionaryContent as any;\n }\n }\n\n return current;\n };\n\n return t;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAgCA,MAAa,WAIX,WACA,WACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB;CACnE,MAAM,eAAe,cACb,UAAU,eAChB,CAAC,eAAe,OAAO,CACxB;CAID,MAAM,oBACJ,cACQ,YAAkB,WAAW,aAAkB,EACrD,CAAC,WAAW,aAAa,CAC1B;CAIH,MAAM,KACJ,SAEsE;AACtE,MAAI,CAAC,KAEH,QAAO;EAGT,MAAM,YAAa,KAAgB,MAAM,IAAI;EAC7C,IAAI,UAAe;AAEnB,OAAK,MAAM,OAAO,WAAW;AAC3B,aAAU,UAAU;AACpB,OAAI,YAAY,OAEd,QAAO;;AAIX,SAAO;;AAGT,QAAO"}
|
|
@@ -1,2 +1,41 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { getIntlayer } from "../getIntlayer.mjs";
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
|
+
import { useContext, useMemo } from "react";
|
|
6
|
+
|
|
7
|
+
//#region src/client/useIntlayer.ts
|
|
8
|
+
/**
|
|
9
|
+
* Client-side hook that picks one dictionary by its key and returns its content.
|
|
10
|
+
*
|
|
11
|
+
* If the locale is not provided, it will use the locale from the client context.
|
|
12
|
+
*
|
|
13
|
+
* @param key - The unique key of the dictionary to retrieve.
|
|
14
|
+
* @param locale - Optional locale to override the current context locale.
|
|
15
|
+
* @returns The dictionary content for the specified locale.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { useIntlayer } from 'react-intlayer';
|
|
20
|
+
*
|
|
21
|
+
* const MyComponent = () => {
|
|
22
|
+
* const content = useIntlayer('my-dictionary-key');
|
|
23
|
+
*
|
|
24
|
+
* return <div>{content.myField.value}</div>;
|
|
25
|
+
* };
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
const useIntlayer = (key, locale) => {
|
|
29
|
+
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
30
|
+
return useMemo(() => {
|
|
31
|
+
return getIntlayer(key, locale ?? currentLocale);
|
|
32
|
+
}, [
|
|
33
|
+
key,
|
|
34
|
+
currentLocale,
|
|
35
|
+
locale
|
|
36
|
+
]);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
export { useIntlayer };
|
|
2
41
|
//# sourceMappingURL=useIntlayer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The dictionary content for the specified locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? (currentLocale as L);\n\n return getIntlayer<T, L>(key, localeTarget);\n }, [key, currentLocale, locale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":[],"sources":["../../../src/client/useIntlayer.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n DictionaryKeys,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { useContext, useMemo } from 'react';\nimport { getIntlayer } from '../getIntlayer';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side hook that picks one dictionary by its key and returns its content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param key - The unique key of the dictionary to retrieve.\n * @param locale - Optional locale to override the current context locale.\n * @returns The dictionary content for the specified locale.\n *\n * @example\n * ```tsx\n * import { useIntlayer } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const content = useIntlayer('my-dictionary-key');\n *\n * return <div>{content.myField.value}</div>;\n * };\n * ```\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends LocalesValues = DeclaredLocales,\n>(\n key: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? (currentLocale as L);\n\n return getIntlayer<T, L>(key, localeTarget);\n }, [key, currentLocale, locale]);\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,eAIX,KACA,WACG;CACH,MAAM,EAAE,QAAQ,kBAAkB,WAAW,sBAAsB;AAEnE,QAAO,cAAc;AAGnB,SAAO,YAAkB,KAFJ,UAAW,cAEW;IAC1C;EAAC;EAAK;EAAe;EAAO,CAAC"}
|
|
@@ -1,2 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/client/useLoadDynamic.ts
|
|
2
|
+
const createSuspender = (promise) => {
|
|
3
|
+
let status = "pending";
|
|
4
|
+
let result;
|
|
5
|
+
const suspender = promise.then((r) => {
|
|
6
|
+
status = "success";
|
|
7
|
+
result = r;
|
|
8
|
+
}, (e) => {
|
|
9
|
+
status = "error";
|
|
10
|
+
result = e;
|
|
11
|
+
});
|
|
12
|
+
return { read() {
|
|
13
|
+
if (status === "pending") throw suspender;
|
|
14
|
+
if (status === "error") throw result;
|
|
15
|
+
return result;
|
|
16
|
+
} };
|
|
17
|
+
};
|
|
18
|
+
const cache = /* @__PURE__ */ new Map();
|
|
19
|
+
const useLoadDynamic = (key, promise) => {
|
|
20
|
+
if (!cache.has(key)) cache.set(key, createSuspender(promise));
|
|
21
|
+
return cache.get(key).read();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
//#endregion
|
|
25
|
+
export { useLoadDynamic };
|
|
2
26
|
//# sourceMappingURL=useLoadDynamic.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":"AAEA,MAAM,
|
|
1
|
+
{"version":3,"file":"useLoadDynamic.mjs","names":[],"sources":["../../../src/client/useLoadDynamic.ts"],"sourcesContent":["type Status = 'pending' | 'success' | 'error';\n\nconst createSuspender = <T>(promise: Promise<T>) => {\n let status: Status = 'pending';\n let result: T;\n const suspender = promise.then(\n (r) => {\n status = 'success';\n result = r;\n },\n (e) => {\n status = 'error';\n result = e as any;\n }\n );\n\n return {\n read() {\n if (status === 'pending') throw suspender;\n if (status === 'error') throw result;\n return result!;\n },\n };\n};\n\nconst cache = new Map<string, ReturnType<typeof createSuspender>>();\n\nexport const useLoadDynamic = <T>(key: string, promise: Promise<T>): T => {\n if (!cache.has(key)) {\n cache.set(key, createSuspender(promise));\n }\n\n return (cache.get(key)! as ReturnType<typeof createSuspender>).read() as T;\n};\n"],"mappings":";AAEA,MAAM,mBAAsB,YAAwB;CAClD,IAAI,SAAiB;CACrB,IAAI;CACJ,MAAM,YAAY,QAAQ,MACvB,MAAM;AACL,WAAS;AACT,WAAS;KAEV,MAAM;AACL,WAAS;AACT,WAAS;GAEZ;AAED,QAAO,EACL,OAAO;AACL,MAAI,WAAW,UAAW,OAAM;AAChC,MAAI,WAAW,QAAS,OAAM;AAC9B,SAAO;IAEV;;AAGH,MAAM,wBAAQ,IAAI,KAAiD;AAEnE,MAAa,kBAAqB,KAAa,YAA2B;AACxE,KAAI,CAAC,MAAM,IAAI,IAAI,CACjB,OAAM,IAAI,KAAK,gBAAgB,QAAQ,CAAC;AAG1C,QAAQ,MAAM,IAAI,IAAI,CAAyC,MAAM"}
|
|
@@ -1,2 +1,58 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { setLocaleInStorage } from "./useLocaleStorage.mjs";
|
|
4
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
5
|
+
import configuration from "@intlayer/config/built";
|
|
6
|
+
import { useCallback, useContext } from "react";
|
|
7
|
+
|
|
8
|
+
//#region src/client/useLocale.ts
|
|
9
|
+
/**
|
|
10
|
+
* Client-side hook to get the current locale and related locale management functions.
|
|
11
|
+
*
|
|
12
|
+
* @param props - Optional properties for the hook.
|
|
13
|
+
* @returns An object containing the current locale, default locale, available locales, and a function to update the locale.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```tsx
|
|
17
|
+
* import { useLocale } from 'react-intlayer';
|
|
18
|
+
*
|
|
19
|
+
* const LocaleSwitcher = () => {
|
|
20
|
+
* const { locale, setLocale, availableLocales } = useLocale();
|
|
21
|
+
*
|
|
22
|
+
* return (
|
|
23
|
+
* <select value={locale} onChange={(e) => setLocale(e.target.value)}>
|
|
24
|
+
* {availableLocales.map((loc) => (
|
|
25
|
+
* <option key={loc} value={loc}>{loc}</option>
|
|
26
|
+
* ))}
|
|
27
|
+
* </select>
|
|
28
|
+
* );
|
|
29
|
+
* };
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
const useLocale = ({ isCookieEnabled, onLocaleChange } = {}) => {
|
|
33
|
+
const { defaultLocale, locales: availableLocales } = configuration?.internationalization ?? {};
|
|
34
|
+
const { locale, setLocale: setLocaleState, isCookieEnabled: isCookieEnabledContext } = useContext(IntlayerClientContext);
|
|
35
|
+
return {
|
|
36
|
+
locale,
|
|
37
|
+
defaultLocale,
|
|
38
|
+
availableLocales,
|
|
39
|
+
setLocale: useCallback((locale) => {
|
|
40
|
+
if (!availableLocales?.map(String).includes(locale)) {
|
|
41
|
+
console.error(`Locale ${locale} is not available`);
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
setLocaleState(locale);
|
|
45
|
+
setLocaleInStorage(locale, isCookieEnabled ?? isCookieEnabledContext ?? true);
|
|
46
|
+
onLocaleChange?.(locale);
|
|
47
|
+
}, [
|
|
48
|
+
availableLocales,
|
|
49
|
+
onLocaleChange,
|
|
50
|
+
setLocaleState,
|
|
51
|
+
isCookieEnabled
|
|
52
|
+
])
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
//#endregion
|
|
57
|
+
export { useLocale };
|
|
2
58
|
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":[],"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.mjs","names":[],"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,qBAC9B,eAAe,wBAAwB,EAAE;CAE3C,MAAM,EACJ,QACA,WAAW,gBACX,iBAAiB,2BACf,WAAW,sBAAsB;AAmBrC,QAAO;EACL;EACA;EACA;EACA,WArBgB,aACf,WAA0B;AACzB,OAAI,CAAC,kBAAkB,IAAI,OAAO,CAAC,SAAS,OAAO,EAAE;AACnD,YAAQ,MAAM,UAAU,OAAO,mBAAmB;AAClD;;AAGF,kBAAe,OAAO;AACtB,sBACE,QACA,mBAAmB,0BAA0B,KAC9C;AACD,oBAAiB,OAA0B;KAE7C;GAAC;GAAkB;GAAgB;GAAgB;GAAgB,CACpE;EAOA"}
|
|
@@ -1,2 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
+
import configuration from "@intlayer/config/built";
|
|
5
|
+
import { useContext } from "react";
|
|
6
|
+
|
|
7
|
+
//#region src/client/useLocaleBase.ts
|
|
8
|
+
const { defaultLocale, locales: availableLocales } = configuration.internationalization;
|
|
9
|
+
/**
|
|
10
|
+
* On the client side, hook to get the current locale and all related fields
|
|
11
|
+
*/
|
|
12
|
+
const useLocaleBase = () => {
|
|
13
|
+
const { locale, setLocale } = useContext(IntlayerClientContext);
|
|
14
|
+
return {
|
|
15
|
+
locale,
|
|
16
|
+
defaultLocale,
|
|
17
|
+
availableLocales,
|
|
18
|
+
setLocale
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { useLocaleBase };
|
|
2
24
|
//# sourceMappingURL=useLocaleBase.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleBase.mjs","names":[],"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.mjs","names":[],"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,qBAC9B,cAAc;;;;AAKhB,MAAa,sBAAsB;CACjC,MAAM,EAAE,QAAQ,cAAc,WAAW,sBAAsB;AAE/D,QAAO;EACL;EACA;EACA;EACA;EACD"}
|
|
@@ -1,2 +1,56 @@
|
|
|
1
|
-
import{useMemo
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import { localeStorageOptions } from "@intlayer/core/localization";
|
|
3
|
+
import { LocaleStorage, getLocaleFromStorage, setLocaleInStorage as setLocaleInStorage$1 } from "@intlayer/core/utils";
|
|
4
|
+
|
|
5
|
+
//#region src/client/useLocaleStorage.ts
|
|
6
|
+
/**
|
|
7
|
+
* Get the locale cookie
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Get the locale cookie
|
|
11
|
+
*/
|
|
12
|
+
const localeInStorage = getLocaleFromStorage(localeStorageOptions);
|
|
13
|
+
/**
|
|
14
|
+
* @deprecated Use localeInStorage instead
|
|
15
|
+
*
|
|
16
|
+
* Get the locale cookie
|
|
17
|
+
*/
|
|
18
|
+
const localeCookie = localeInStorage;
|
|
19
|
+
/**
|
|
20
|
+
* Set the locale cookie
|
|
21
|
+
*/
|
|
22
|
+
const setLocaleInStorage = (locale, isCookieEnabled) => setLocaleInStorage$1(locale, {
|
|
23
|
+
...localeStorageOptions,
|
|
24
|
+
isCookieEnabled
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated Use setLocaleInStorage instead
|
|
28
|
+
*
|
|
29
|
+
* Set the locale cookie
|
|
30
|
+
*/
|
|
31
|
+
const setLocaleCookie = setLocaleInStorage;
|
|
32
|
+
/**
|
|
33
|
+
* Hook that provides the locale cookie and a function to set it
|
|
34
|
+
*/
|
|
35
|
+
const useLocaleStorage = (isCookieEnabled) => useMemo(() => LocaleStorage({
|
|
36
|
+
...localeStorageOptions,
|
|
37
|
+
isCookieEnabled
|
|
38
|
+
}), [isCookieEnabled]);
|
|
39
|
+
/**
|
|
40
|
+
* @deprecated Use useLocaleStorage instead
|
|
41
|
+
*
|
|
42
|
+
* For GDPR compliance, use useLocaleStorage instead
|
|
43
|
+
*
|
|
44
|
+
* Hook that provides the locale cookie and a function to set it
|
|
45
|
+
*/
|
|
46
|
+
const useLocaleCookie = (isCookieEnabled) => {
|
|
47
|
+
const storage = useLocaleStorage(isCookieEnabled);
|
|
48
|
+
return {
|
|
49
|
+
localeCookie: storage.getLocale(),
|
|
50
|
+
setLocaleCookie: storage.setLocale
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
//#endregion
|
|
55
|
+
export { localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, useLocaleCookie, useLocaleStorage };
|
|
2
56
|
//# sourceMappingURL=useLocaleStorage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocaleStorage.mjs","names":["setLocaleInStorageCore"],"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.mjs","names":["setLocaleInStorageCore"],"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,kBAAkB,qBAAqB,qBAAqB;;;;;;AAMzE,MAAa,eAAe;;;;AAK5B,MAAa,sBACX,QACA,oBAEAA,qBAAuB,QAAQ;CAC7B,GAAG;CACH;CACD,CAAC;;;;;;AAOJ,MAAa,kBAAkB;;;;AAK/B,MAAa,oBAAoB,oBAC/B,cAEI,cAAc;CACZ,GAAG;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,40 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useLocale } from "./useLocale.mjs";
|
|
4
|
+
import configuration from "@intlayer/config/built";
|
|
5
|
+
import { useEffect } from "react";
|
|
6
|
+
import { getRewritePath } from "@intlayer/core/localization";
|
|
7
|
+
|
|
8
|
+
//#region src/client/useRewriteURL.ts
|
|
9
|
+
/**
|
|
10
|
+
* Client-side hook to manage URL rewrites without triggering a router navigation.
|
|
11
|
+
* It uses `window.history.replaceState` to update the URL in the address bar.
|
|
12
|
+
*
|
|
13
|
+
* This hook is useful to "prettify" the URL when the user lands on a canonical path
|
|
14
|
+
* that has a localized alias defined in `intlayer.config.ts`.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* import { useRewriteURL } from 'react-intlayer';
|
|
19
|
+
*
|
|
20
|
+
* const MyComponent = () => {
|
|
21
|
+
* useRewriteURL();
|
|
22
|
+
*
|
|
23
|
+
* return <div>My Component</div>;
|
|
24
|
+
* };
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
const useRewriteURL = () => {
|
|
28
|
+
const { locale } = useLocale();
|
|
29
|
+
const rewrite = configuration?.routing?.rewrite;
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (typeof window === "undefined" || !rewrite) return;
|
|
32
|
+
const pathname = window.location.pathname;
|
|
33
|
+
const targetPath = getRewritePath(pathname, locale, rewrite);
|
|
34
|
+
if (targetPath && targetPath !== pathname) window.history.replaceState(window.history.state, "", targetPath + window.location.search + window.location.hash);
|
|
35
|
+
}, [locale, rewrite]);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
//#endregion
|
|
39
|
+
export { useRewriteURL };
|
|
2
40
|
//# sourceMappingURL=useRewriteURL.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRewriteURL.mjs","names":[],"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.mjs","names":[],"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,WAAW,WAAW;CAC9B,MAAM,UAAU,eAAe,SAAS;AAExC,iBAAgB;AACd,MAAI,OAAO,WAAW,eAAe,CAAC,QAAS;EAE/C,MAAM,WAAW,OAAO,SAAS;EACjC,MAAM,aAAa,eAAe,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,34 @@
|
|
|
1
|
-
import{IntlayerClientContext
|
|
1
|
+
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
2
|
+
import { getTranslation } from "@intlayer/core/interpreter";
|
|
3
|
+
import { useContext, useMemo } from "react";
|
|
4
|
+
|
|
5
|
+
//#region 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
|
+
const useTranslation = (languageContent) => {
|
|
28
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
29
|
+
return useMemo(() => getTranslation(languageContent, locale), [languageContent, locale]);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { useTranslation };
|
|
2
34
|
//# sourceMappingURL=useTraduction.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTraduction.mjs","names":[],"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.mjs","names":[],"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,WAAW,WAAW,sBAAsB;AAEpD,QAAO,cACC,eAAe,iBAAiB,OAAO,EAC7C,CAAC,iBAAiB,OAAO,CAC1B"}
|
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
import { isEnabled } from "@intlayer/editor/isEnabled";
|
|
5
|
+
|
|
6
|
+
//#region src/editor/ContentSelector.tsx
|
|
7
|
+
const ContentSelector = ({ children, dictionaryKey, keyPath }) => {
|
|
8
|
+
if (isEnabled) return createElement("intlayer-content-selector-wrapper", {
|
|
9
|
+
"key-path": JSON.stringify(keyPath),
|
|
10
|
+
"dictionary-key": dictionaryKey
|
|
11
|
+
}, children);
|
|
12
|
+
return children;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
//#endregion
|
|
16
|
+
export { ContentSelector };
|
|
2
17
|
//# sourceMappingURL=ContentSelector.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContentSelector.mjs","names":[],"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.mjs","names":[],"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,KAAI,UACF,QAAO,cACL,qCACA;EACE,YAAY,KAAK,UAAU,QAAQ;EACnC,kBAAkB;EACnB,EACD,SACD;AAGH,QAAO"}
|
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
import{useEditor
|
|
1
|
+
import { useEditor } from "./useEditor.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/editor/EditorProvider.tsx
|
|
4
|
+
const EditorProvider = ({ children }) => {
|
|
5
|
+
useEditor();
|
|
6
|
+
return children;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
//#endregion
|
|
10
|
+
export { EditorProvider };
|
|
2
11
|
//# sourceMappingURL=EditorProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorProvider.mjs","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.mjs","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,YAAW;AAEX,QAAO"}
|
|
@@ -1,2 +1,38 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { IntlayerClientContext } from "../client/IntlayerProvider.mjs";
|
|
4
|
+
import { useContext, useEffect, useRef } from "react";
|
|
5
|
+
import { isEnabled } from "@intlayer/editor/isEnabled";
|
|
6
|
+
|
|
7
|
+
//#region src/editor/useEditor.tsx
|
|
8
|
+
/**
|
|
9
|
+
* Initializes the Intlayer editor client singleton when the editor is enabled.
|
|
10
|
+
* Syncs the current locale from the Intlayer context into the editor manager so
|
|
11
|
+
* the editor always knows which locale the app is displaying.
|
|
12
|
+
*/
|
|
13
|
+
const useEditor = () => {
|
|
14
|
+
const { locale } = useContext(IntlayerClientContext);
|
|
15
|
+
const managerRef = useRef(null);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (process.env.INTLAYER_EDITOR_ENABLED === "false" || !isEnabled) return;
|
|
18
|
+
import("@intlayer/editor").then(({ initEditorClient }) => {
|
|
19
|
+
const manager = initEditorClient();
|
|
20
|
+
managerRef.current = manager;
|
|
21
|
+
if (locale) manager.currentLocale.set(locale);
|
|
22
|
+
});
|
|
23
|
+
return () => {
|
|
24
|
+
managerRef.current = null;
|
|
25
|
+
import("@intlayer/editor").then(({ stopEditorClient }) => {
|
|
26
|
+
stopEditorClient();
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
}, []);
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!locale || !managerRef.current) return;
|
|
32
|
+
managerRef.current.currentLocale.set(locale);
|
|
33
|
+
}, [locale]);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
//#endregion
|
|
37
|
+
export { useEditor };
|
|
2
38
|
//# sourceMappingURL=useEditor.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditor.mjs","names":[],"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.mjs","names":[],"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,WAAW,WAAW,sBAAsB;CACpD,MAAM,aAAa,OAAkC,KAAK;AAE1D,iBAAgB;AACd,MAAI,QAAQ,IAAI,4BAA4B,WAAW,CAAC,UAAW;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,iBAAgB;AACd,MAAI,CAAC,UAAU,CAAC,WAAW,QAAS;AAEpC,aAAW,QAAQ,cAAc,IAAI,OAAiB;IACrD,CAAC,OAAO,CAAC"}
|
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import{getPlugins
|
|
1
|
+
import { getPlugins } from "./plugins.mjs";
|
|
2
|
+
import { getDictionary as getDictionary$1 } from "@intlayer/core/interpreter";
|
|
3
|
+
|
|
4
|
+
//#region src/getDictionary.ts
|
|
5
|
+
const getDictionary = (dictionary, locale) => getDictionary$1(dictionary, locale, getPlugins(locale));
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getDictionary };
|
|
2
9
|
//# sourceMappingURL=getDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDictionary.mjs","names":["getDictionaryCore"],"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.mjs","names":["getDictionaryCore"],"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,WAEAA,gBAAkB,YAAY,QAAQ,WAAW,OAAO,CAAC"}
|
package/dist/esm/getIntlayer.mjs
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
import{getPlugins
|
|
1
|
+
import { getPlugins } from "./plugins.mjs";
|
|
2
|
+
import { getIntlayer as getIntlayer$1 } from "@intlayer/core/interpreter";
|
|
3
|
+
|
|
4
|
+
//#region src/getIntlayer.ts
|
|
5
|
+
const getIntlayer = (key, locale) => getIntlayer$1(key, locale, getPlugins(locale));
|
|
6
|
+
|
|
7
|
+
//#endregion
|
|
8
|
+
export { getIntlayer };
|
|
2
9
|
//# sourceMappingURL=getIntlayer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getIntlayer.mjs","names":["getIntlayerCore"],"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.mjs","names":["getIntlayerCore"],"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,WAEAA,cAAgB,KAAK,QAAQ,WAAW,OAAO,CAAC"}
|
|
@@ -1,2 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { createContext, useContext } from "react";
|
|
4
|
+
import { jsx } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/html/HTMLProvider.tsx
|
|
7
|
+
const HTMLContext = createContext(void 0);
|
|
8
|
+
const useHTMLContext = () => useContext(HTMLContext);
|
|
9
|
+
const HTMLProvider = ({ children, components }) => /* @__PURE__ */ jsx(HTMLContext.Provider, {
|
|
10
|
+
value: { components },
|
|
11
|
+
children
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { HTMLProvider, useHTMLContext };
|
|
2
16
|
//# sourceMappingURL=HTMLProvider.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HTMLProvider.mjs","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.mjs","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,cAAc,cAA4C,OAAU;AAE1E,MAAa,uBAAuB,WAAW,YAAY;AAE3D,MAAa,gBAAuC,EAClD,UACA,iBAEA,oBAAC,YAAY,UAAb;CAAsB,OAAO,EAAE,YAAY;CAAG;CAAgC"}
|