react-intlayer 8.1.2 → 8.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/IntlayerNode.cjs +1 -17
- package/dist/cjs/IntlayerNode.cjs.map +1 -1
- package/dist/cjs/UI/ContentSelector.cjs +1 -96
- package/dist/cjs/UI/ContentSelector.cjs.map +1 -1
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/client/IntlayerProvider.cjs +1 -92
- package/dist/cjs/client/IntlayerProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +1 -20
- package/dist/cjs/client/format/useCompact.cjs +1 -29
- package/dist/cjs/client/format/useCompact.cjs.map +1 -1
- package/dist/cjs/client/format/useCurrency.cjs +1 -43
- package/dist/cjs/client/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/client/format/useDate.cjs +1 -45
- package/dist/cjs/client/format/useDate.cjs.map +1 -1
- package/dist/cjs/client/format/useIntl.cjs +1 -45
- package/dist/cjs/client/format/useIntl.cjs.map +1 -1
- package/dist/cjs/client/format/useList.cjs +1 -40
- package/dist/cjs/client/format/useList.cjs.map +1 -1
- package/dist/cjs/client/format/useNumber.cjs +1 -41
- package/dist/cjs/client/format/useNumber.cjs.map +1 -1
- package/dist/cjs/client/format/usePercentage.cjs +1 -37
- package/dist/cjs/client/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/client/format/useRelativeTime.cjs +1 -37
- package/dist/cjs/client/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/client/format/useUnit.cjs +1 -36
- package/dist/cjs/client/format/useUnit.cjs.map +1 -1
- package/dist/cjs/client/index.cjs +1 -34
- package/dist/cjs/client/t.cjs +1 -40
- package/dist/cjs/client/t.cjs.map +1 -1
- package/dist/cjs/client/useDictionary.cjs +1 -27
- package/dist/cjs/client/useDictionary.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryAsync.cjs +1 -24
- package/dist/cjs/client/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/client/useDictionaryDynamic.cjs +1 -25
- package/dist/cjs/client/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/client/useI18n.cjs +1 -45
- package/dist/cjs/client/useI18n.cjs.map +1 -1
- package/dist/cjs/client/useIntlayer.cjs +1 -42
- package/dist/cjs/client/useIntlayer.cjs.map +1 -1
- package/dist/cjs/client/useLoadDynamic.cjs +1 -27
- package/dist/cjs/client/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +1 -60
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocaleBase.cjs +1 -26
- package/dist/cjs/client/useLocaleBase.cjs.map +1 -1
- package/dist/cjs/client/useLocaleStorage.cjs +1 -61
- package/dist/cjs/client/useLocaleStorage.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -42
- package/dist/cjs/client/useRewriteURL.cjs.map +1 -1
- package/dist/cjs/client/useTraduction.cjs +1 -35
- package/dist/cjs/client/useTraduction.cjs.map +1 -1
- package/dist/cjs/editor/ContentSelectorWrapper.cjs +1 -55
- package/dist/cjs/editor/ContentSelectorWrapper.cjs.map +1 -1
- package/dist/cjs/editor/IntlayerEditorProvider.cjs +1 -61
- package/dist/cjs/editor/IntlayerEditorProvider.cjs.map +1 -1
- package/dist/cjs/editor/index.cjs +1 -4
- package/dist/cjs/editor/useEditedContentRenderer.cjs +1 -40
- package/dist/cjs/editor/useEditedContentRenderer.cjs.map +1 -1
- package/dist/cjs/getDictionary.cjs +1 -19
- package/dist/cjs/getDictionary.cjs.map +1 -1
- package/dist/cjs/getIntlayer.cjs +1 -19
- package/dist/cjs/getIntlayer.cjs.map +1 -1
- package/dist/cjs/html/HTMLProvider.cjs +1 -18
- package/dist/cjs/html/HTMLProvider.cjs.map +1 -1
- package/dist/cjs/html/HTMLRenderer.cjs +1 -59
- package/dist/cjs/html/HTMLRenderer.cjs.map +1 -1
- package/dist/cjs/html/HTMLRendererPlugin.cjs +1 -36
- package/dist/cjs/html/HTMLRendererPlugin.cjs.map +1 -1
- package/dist/cjs/html/index.cjs +1 -12
- package/dist/cjs/index.cjs +1 -52
- package/dist/cjs/markdown/MarkdownProvider.cjs +1 -77
- package/dist/cjs/markdown/MarkdownProvider.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRenderer.cjs +1 -199
- package/dist/cjs/markdown/MarkdownRenderer.cjs.map +1 -1
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs +1 -33
- package/dist/cjs/markdown/MarkdownRendererPlugin.cjs.map +1 -1
- package/dist/cjs/markdown/index.cjs +1 -25
- package/dist/cjs/markdown/processor.cjs +1 -66
- package/dist/cjs/markdown/processor.cjs.map +1 -1
- package/dist/cjs/markdown/runtime.cjs +1 -43
- package/dist/cjs/markdown/runtime.cjs.map +1 -1
- package/dist/cjs/plugins.cjs +1 -179
- package/dist/cjs/plugins.cjs.map +1 -1
- package/dist/cjs/reactElement/renderReactElement.cjs +1 -52
- package/dist/cjs/reactElement/renderReactElement.cjs.map +1 -1
- package/dist/cjs/server/IntlayerServerProvider.cjs +1 -34
- package/dist/cjs/server/IntlayerServerProvider.cjs.map +1 -1
- package/dist/cjs/server/format/index.cjs +1 -18
- package/dist/cjs/server/format/useCompact.cjs +1 -27
- package/dist/cjs/server/format/useCompact.cjs.map +1 -1
- package/dist/cjs/server/format/useCurrency.cjs +1 -38
- package/dist/cjs/server/format/useCurrency.cjs.map +1 -1
- package/dist/cjs/server/format/useDate.cjs +1 -43
- package/dist/cjs/server/format/useDate.cjs.map +1 -1
- package/dist/cjs/server/format/useIntl.cjs +1 -44
- package/dist/cjs/server/format/useIntl.cjs.map +1 -1
- package/dist/cjs/server/format/useList.cjs +1 -35
- package/dist/cjs/server/format/useList.cjs.map +1 -1
- package/dist/cjs/server/format/useNumber.cjs +1 -39
- package/dist/cjs/server/format/useNumber.cjs.map +1 -1
- package/dist/cjs/server/format/usePercentage.cjs +1 -35
- package/dist/cjs/server/format/usePercentage.cjs.map +1 -1
- package/dist/cjs/server/format/useRelativeTime.cjs +1 -35
- package/dist/cjs/server/format/useRelativeTime.cjs.map +1 -1
- package/dist/cjs/server/format/useUnit.cjs +1 -34
- package/dist/cjs/server/format/useUnit.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +1 -24
- package/dist/cjs/server/serverContext.cjs +1 -58
- package/dist/cjs/server/serverContext.cjs.map +1 -1
- package/dist/cjs/server/t.cjs +1 -35
- package/dist/cjs/server/t.cjs.map +1 -1
- package/dist/cjs/server/useDictionary.cjs +1 -17
- package/dist/cjs/server/useDictionary.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryAsync.cjs +1 -21
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -1
- package/dist/cjs/server/useDictionaryDynamic.cjs +1 -22
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -1
- package/dist/cjs/server/useI18n.cjs +1 -38
- package/dist/cjs/server/useI18n.cjs.map +1 -1
- package/dist/cjs/server/useIntlayer.cjs +1 -17
- package/dist/cjs/server/useIntlayer.cjs.map +1 -1
- package/dist/cjs/server/useLoadDynamic.cjs +1 -14
- package/dist/cjs/server/useLoadDynamic.cjs.map +1 -1
- package/dist/cjs/server/useLocale.cjs +1 -24
- package/dist/cjs/server/useLocale.cjs.map +1 -1
- package/dist/esm/IntlayerNode.mjs +1 -15
- package/dist/esm/IntlayerNode.mjs.map +1 -1
- package/dist/esm/UI/ContentSelector.mjs +1 -94
- package/dist/esm/UI/ContentSelector.mjs.map +1 -1
- package/dist/esm/client/IntlayerProvider.mjs +1 -86
- package/dist/esm/client/IntlayerProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +1 -11
- package/dist/esm/client/format/useCompact.mjs +1 -27
- package/dist/esm/client/format/useCompact.mjs.map +1 -1
- package/dist/esm/client/format/useCurrency.mjs +1 -41
- package/dist/esm/client/format/useCurrency.mjs.map +1 -1
- package/dist/esm/client/format/useDate.mjs +1 -43
- package/dist/esm/client/format/useDate.mjs.map +1 -1
- package/dist/esm/client/format/useIntl.mjs +1 -43
- package/dist/esm/client/format/useIntl.mjs.map +1 -1
- package/dist/esm/client/format/useList.mjs +1 -38
- package/dist/esm/client/format/useList.mjs.map +1 -1
- package/dist/esm/client/format/useNumber.mjs +1 -39
- package/dist/esm/client/format/useNumber.mjs.map +1 -1
- package/dist/esm/client/format/usePercentage.mjs +1 -35
- package/dist/esm/client/format/usePercentage.mjs.map +1 -1
- package/dist/esm/client/format/useRelativeTime.mjs +1 -35
- package/dist/esm/client/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/client/format/useUnit.mjs +1 -34
- package/dist/esm/client/format/useUnit.mjs.map +1 -1
- package/dist/esm/client/index.mjs +1 -14
- package/dist/esm/client/t.mjs +1 -38
- package/dist/esm/client/t.mjs.map +1 -1
- package/dist/esm/client/useDictionary.mjs +1 -25
- package/dist/esm/client/useDictionary.mjs.map +1 -1
- package/dist/esm/client/useDictionaryAsync.mjs +1 -21
- package/dist/esm/client/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/client/useDictionaryDynamic.mjs +1 -22
- package/dist/esm/client/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/client/useI18n.mjs +1 -43
- package/dist/esm/client/useI18n.mjs.map +1 -1
- package/dist/esm/client/useIntlayer.mjs +1 -40
- package/dist/esm/client/useIntlayer.mjs.map +1 -1
- package/dist/esm/client/useLoadDynamic.mjs +1 -25
- package/dist/esm/client/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +1 -57
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocaleBase.mjs +1 -23
- package/dist/esm/client/useLocaleBase.mjs.map +1 -1
- package/dist/esm/client/useLocaleStorage.mjs +1 -54
- package/dist/esm/client/useLocaleStorage.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +1 -39
- package/dist/esm/client/useRewriteURL.mjs.map +1 -1
- package/dist/esm/client/useTraduction.mjs +1 -33
- package/dist/esm/client/useTraduction.mjs.map +1 -1
- package/dist/esm/editor/ContentSelectorWrapper.mjs +1 -53
- package/dist/esm/editor/ContentSelectorWrapper.mjs.map +1 -1
- package/dist/esm/editor/IntlayerEditorProvider.mjs +1 -58
- package/dist/esm/editor/IntlayerEditorProvider.mjs.map +1 -1
- package/dist/esm/editor/index.mjs +1 -3
- package/dist/esm/editor/useEditedContentRenderer.mjs +1 -37
- package/dist/esm/editor/useEditedContentRenderer.mjs.map +1 -1
- package/dist/esm/getDictionary.mjs +1 -17
- package/dist/esm/getDictionary.mjs.map +1 -1
- package/dist/esm/getIntlayer.mjs +1 -17
- package/dist/esm/getIntlayer.mjs.map +1 -1
- package/dist/esm/html/HTMLProvider.mjs +1 -15
- package/dist/esm/html/HTMLProvider.mjs.map +1 -1
- package/dist/esm/html/HTMLRenderer.mjs +1 -54
- package/dist/esm/html/HTMLRenderer.mjs.map +1 -1
- package/dist/esm/html/HTMLRendererPlugin.mjs +1 -34
- package/dist/esm/html/HTMLRendererPlugin.mjs.map +1 -1
- package/dist/esm/html/index.mjs +1 -5
- package/dist/esm/index.mjs +1 -21
- package/dist/esm/markdown/MarkdownProvider.mjs +1 -74
- package/dist/esm/markdown/MarkdownProvider.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRenderer.mjs +1 -195
- package/dist/esm/markdown/MarkdownRenderer.mjs.map +1 -1
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs +1 -30
- package/dist/esm/markdown/MarkdownRendererPlugin.mjs.map +1 -1
- package/dist/esm/markdown/index.mjs +1 -7
- package/dist/esm/markdown/processor.mjs +1 -58
- package/dist/esm/markdown/processor.mjs.map +1 -1
- package/dist/esm/markdown/runtime.mjs +1 -39
- package/dist/esm/markdown/runtime.mjs.map +1 -1
- package/dist/esm/plugins.mjs +1 -172
- package/dist/esm/plugins.mjs.map +1 -1
- package/dist/esm/reactElement/renderReactElement.mjs +1 -50
- package/dist/esm/reactElement/renderReactElement.mjs.map +1 -1
- package/dist/esm/server/IntlayerServerProvider.mjs +1 -28
- package/dist/esm/server/IntlayerServerProvider.mjs.map +1 -1
- package/dist/esm/server/format/index.mjs +1 -10
- package/dist/esm/server/format/useCompact.mjs +1 -25
- package/dist/esm/server/format/useCompact.mjs.map +1 -1
- package/dist/esm/server/format/useCurrency.mjs +1 -36
- package/dist/esm/server/format/useCurrency.mjs.map +1 -1
- package/dist/esm/server/format/useDate.mjs +1 -41
- package/dist/esm/server/format/useDate.mjs.map +1 -1
- package/dist/esm/server/format/useIntl.mjs +1 -41
- package/dist/esm/server/format/useIntl.mjs.map +1 -1
- package/dist/esm/server/format/useList.mjs +1 -33
- package/dist/esm/server/format/useList.mjs.map +1 -1
- package/dist/esm/server/format/useNumber.mjs +1 -37
- package/dist/esm/server/format/useNumber.mjs.map +1 -1
- package/dist/esm/server/format/usePercentage.mjs +1 -33
- package/dist/esm/server/format/usePercentage.mjs.map +1 -1
- package/dist/esm/server/format/useRelativeTime.mjs +1 -33
- package/dist/esm/server/format/useRelativeTime.mjs.map +1 -1
- package/dist/esm/server/format/useUnit.mjs +1 -32
- package/dist/esm/server/format/useUnit.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -12
- package/dist/esm/server/serverContext.mjs +1 -54
- package/dist/esm/server/serverContext.mjs.map +1 -1
- package/dist/esm/server/t.mjs +1 -33
- package/dist/esm/server/t.mjs.map +1 -1
- package/dist/esm/server/useDictionary.mjs +1 -16
- package/dist/esm/server/useDictionary.mjs.map +1 -1
- package/dist/esm/server/useDictionaryAsync.mjs +1 -18
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -1
- package/dist/esm/server/useDictionaryDynamic.mjs +1 -19
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -1
- package/dist/esm/server/useI18n.mjs +1 -37
- package/dist/esm/server/useI18n.mjs.map +1 -1
- package/dist/esm/server/useIntlayer.mjs +1 -16
- package/dist/esm/server/useIntlayer.mjs.map +1 -1
- package/dist/esm/server/useLoadDynamic.mjs +1 -11
- package/dist/esm/server/useLoadDynamic.mjs.map +1 -1
- package/dist/esm/server/useLocale.mjs +1 -21
- package/dist/esm/server/useLocale.mjs.map +1 -1
- package/dist/types/IntlayerNode.d.ts +1 -1
- package/dist/types/client/format/useDate.d.ts +1 -1
- package/dist/types/client/useDictionary.d.ts +2 -2
- package/dist/types/client/useDictionary.d.ts.map +1 -1
- package/dist/types/client/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/client/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/client/useI18n.d.ts +3 -3
- package/dist/types/client/useI18n.d.ts.map +1 -1
- package/dist/types/client/useIntlayer.d.ts +2 -2
- package/dist/types/client/useIntlayer.d.ts.map +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts +1 -1
- package/dist/types/editor/ContentSelectorWrapper.d.ts.map +1 -1
- package/dist/types/getDictionary.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts +1 -1
- package/dist/types/getIntlayer.d.ts.map +1 -1
- package/dist/types/html/HTMLComponentTypes.d.ts +1 -1
- package/dist/types/html/HTMLRenderer.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/markdown/MarkdownRendererPlugin.d.ts.map +1 -1
- package/dist/types/markdown/processor.d.ts +1 -1
- package/dist/types/markdown/runtime.d.ts +1 -1
- package/dist/types/plugins.d.ts +1 -1
- package/dist/types/plugins.d.ts.map +1 -1
- package/dist/types/server/format/useCompact.d.ts +1 -1
- package/dist/types/server/format/useCurrency.d.ts +1 -1
- package/dist/types/server/format/useDate.d.ts +1 -1
- package/dist/types/server/format/useList.d.ts +1 -1
- package/dist/types/server/format/useNumber.d.ts +1 -1
- package/dist/types/server/format/usePercentage.d.ts +1 -1
- package/dist/types/server/format/useRelativeTime.d.ts +1 -1
- package/dist/types/server/format/useUnit.d.ts +1 -1
- package/dist/types/server/useDictionary.d.ts +2 -2
- package/dist/types/server/useDictionary.d.ts.map +1 -1
- package/dist/types/server/useDictionaryAsync.d.ts +2 -2
- package/dist/types/server/useDictionaryAsync.d.ts.map +1 -1
- package/dist/types/server/useDictionaryDynamic.d.ts +2 -2
- package/dist/types/server/useDictionaryDynamic.d.ts.map +1 -1
- package/dist/types/server/useI18n.d.ts +3 -3
- package/dist/types/server/useI18n.d.ts.map +1 -1
- package/dist/types/server/useIntlayer.d.ts +2 -2
- package/dist/types/server/useIntlayer.d.ts.map +1 -1
- package/package.json +9 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { localeResolver } from '@intlayer/core';\nimport { MessageKey, useCrossFrameState } from '@intlayer/editor-react';\nimport type { LocalesValues } from '@intlayer/types';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useEffect,\n} from 'react';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n isCookieEnabled: true,\n disableEditor: false,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { internationalization } = configuration ?? {};\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n const initialLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] = useCrossFrameState(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n initialLocale\n );\n\n // Sync the prop to state if the prop changes from the parent\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp]);\n\n const setLocaleBase = (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale);\n setLocaleInStorage(newLocale, isCookieEnabled);\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n disableEditor,\n }}\n >\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in React applications.\n *\n * It includes the editor provider by default, allowing for live content editing\n * if configured.\n *\n * @param props - The provider props.\n * @returns The provider component with editor support.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n);\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IntlayerProvider.mjs","names":[],"sources":["../../../src/client/IntlayerProvider.tsx"],"sourcesContent":["'use client';\n\nimport configuration from '@intlayer/config/built';\nimport { localeResolver } from '@intlayer/core/localization';\nimport { MessageKey, useCrossFrameState } from '@intlayer/editor-react';\nimport type { LocalesValues } from '@intlayer/types';\nimport {\n createContext,\n type FC,\n type PropsWithChildren,\n useContext,\n useEffect,\n} from 'react';\nimport { IntlayerEditorProvider } from '../editor/IntlayerEditorProvider';\nimport { localeInStorage, setLocaleInStorage } from './useLocaleStorage';\n\ntype IntlayerValue = {\n locale: LocalesValues;\n setLocale: (newLocale: LocalesValues) => void;\n disableEditor?: boolean;\n isCookieEnabled?: boolean;\n};\n\n/**\n * Context that stores the current locale on the client side.\n */\nexport const IntlayerClientContext = createContext<IntlayerValue>({\n locale: localeInStorage ?? configuration?.internationalization?.defaultLocale,\n setLocale: () => null,\n isCookieEnabled: true,\n disableEditor: false,\n});\n\n/**\n * Hook that provides the current Intlayer client context.\n *\n * @returns The current Intlayer context values.\n */\nexport const useIntlayerContext = () => useContext(IntlayerClientContext);\n\n/**\n * Props for the IntlayerProvider component.\n */\nexport type IntlayerProviderProps = PropsWithChildren<{\n /**\n * The locale to use. If not provided, it will be detected from storage or configuration.\n */\n locale?: LocalesValues;\n /**\n * The default locale to use as a fallback.\n */\n defaultLocale?: LocalesValues;\n /**\n * Function to set the locale.\n */\n setLocale?: (locale: LocalesValues) => void;\n /**\n * Whether to disable the editor.\n */\n disableEditor?: boolean;\n /**\n * Whether to enable cookies for storing the locale.\n */\n isCookieEnabled?: boolean;\n}>;\n\n/**\n * Provider that stores the current locale on the client side.\n *\n * This component is focused on content delivery without the editor features.\n *\n * @param props - The provider props.\n * @returns The provider component.\n */\nexport const IntlayerProviderContent: FC<IntlayerProviderProps> = ({\n locale: localeProp,\n defaultLocale: defaultLocaleProp,\n children,\n setLocale: setLocaleProp,\n disableEditor,\n isCookieEnabled,\n}) => {\n const { internationalization } = configuration ?? {};\n const { locales: availableLocales, defaultLocale: defaultLocaleConfig } =\n internationalization ?? {};\n\n const initialLocale =\n localeProp ?? localeInStorage ?? defaultLocaleProp ?? defaultLocaleConfig;\n\n const [currentLocale, setCurrentLocale] = useCrossFrameState(\n MessageKey.INTLAYER_CURRENT_LOCALE,\n initialLocale\n );\n\n // Sync the prop to state if the prop changes from the parent\n useEffect(() => {\n if (localeProp && localeProp !== currentLocale) {\n setCurrentLocale(localeProp);\n }\n }, [localeProp]);\n\n const setLocaleBase = (newLocale: LocalesValues) => {\n if (currentLocale.toString() === newLocale.toString()) return;\n\n if (!availableLocales?.map(String).includes(newLocale)) {\n console.error(`Locale ${newLocale} is not available`);\n return;\n }\n\n setCurrentLocale(newLocale);\n setLocaleInStorage(newLocale, isCookieEnabled);\n };\n\n const setLocale = setLocaleProp ?? setLocaleBase;\n\n // Resolve based on currentLocale (the state), not the prop directly\n const resolvedLocale = localeResolver(currentLocale);\n\n return (\n <IntlayerClientContext.Provider\n value={{\n locale: resolvedLocale,\n setLocale,\n disableEditor,\n }}\n >\n {children}\n </IntlayerClientContext.Provider>\n );\n};\n\n/**\n * Main provider for Intlayer in React applications.\n *\n * It includes the editor provider by default, allowing for live content editing\n * if configured.\n *\n * @param props - The provider props.\n * @returns The provider component with editor support.\n *\n * @example\n * ```tsx\n * import { IntlayerProvider } from 'react-intlayer';\n *\n * const App = () => (\n * <IntlayerProvider>\n * <MyComponent />\n * </IntlayerProvider>\n * );\n * ```\n */\nexport const IntlayerProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerEditorProvider>\n <IntlayerProviderContent {...props} />\n </IntlayerEditorProvider>\n);\n"],"mappings":"wcA0BA,MAAa,EAAwB,EAA6B,CAChE,OAAQ,GAAmB,GAAe,sBAAsB,cAChE,cAAiB,KACjB,gBAAiB,GACjB,cAAe,GAChB,CAAC,CAOW,MAA2B,EAAW,EAAsB,CAoC5D,GAAsD,CACjE,OAAQ,EACR,cAAe,EACf,WACA,UAAW,EACX,gBACA,qBACI,CACJ,GAAM,CAAE,wBAAyB,GAAiB,EAAE,CAC9C,CAAE,QAAS,EAAkB,cAAe,GAChD,GAAwB,EAAE,CAEtB,EACJ,GAAc,GAAmB,GAAqB,EAElD,CAAC,EAAe,GAAoB,EACxC,EAAW,wBACX,EACD,CAGD,MAAgB,CACV,GAAc,IAAe,GAC/B,EAAiB,EAAW,EAE7B,CAAC,EAAW,CAAC,CAchB,IAAM,EAAY,IAZK,GAA6B,CAC9C,KAAc,UAAU,GAAK,EAAU,UAAU,CAErD,IAAI,CAAC,GAAkB,IAAI,OAAO,CAAC,SAAS,EAAU,CAAE,CACtD,QAAQ,MAAM,UAAU,EAAU,mBAAmB,CACrD,OAGF,EAAiB,EAAU,CAC3B,EAAmB,EAAW,EAAgB,IAM1C,EAAiB,EAAe,EAAc,CAEpD,OACE,EAAC,EAAsB,SAAA,CACrB,MAAO,CACL,OAAQ,EACR,YACA,gBACD,CAEA,YAC8B,EAwBxB,EAA+C,GAC1D,EAAC,EAAA,CAAA,SACC,EAAC,EAAA,CAAwB,GAAI,EAAA,CAAS,CAAA,CACf"}
|
|
@@ -1,11 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useCompact } from "./useCompact.mjs";
|
|
3
|
-
import { useCurrency } from "./useCurrency.mjs";
|
|
4
|
-
import { useDate } from "./useDate.mjs";
|
|
5
|
-
import { useList } from "./useList.mjs";
|
|
6
|
-
import { useNumber } from "./useNumber.mjs";
|
|
7
|
-
import { usePercentage } from "./usePercentage.mjs";
|
|
8
|
-
import { useRelativeTime } from "./useRelativeTime.mjs";
|
|
9
|
-
import { useUnit } from "./useUnit.mjs";
|
|
10
|
-
|
|
11
|
-
export { useCompact, useCurrency, useDate, useIntl, useList, useNumber, usePercentage, useRelativeTime, useUnit };
|
|
1
|
+
import{useIntl as e}from"./useIntl.mjs";import{useCompact as t}from"./useCompact.mjs";import{useCurrency as n}from"./useCurrency.mjs";import{useDate as r}from"./useDate.mjs";import{useList as i}from"./useList.mjs";import{useNumber as a}from"./useNumber.mjs";import{usePercentage as o}from"./usePercentage.mjs";import{useRelativeTime as s}from"./useRelativeTime.mjs";import{useUnit as c}from"./useUnit.mjs";export{t as useCompact,n as useCurrency,r as useDate,e as useIntl,i as useList,a as useNumber,o as usePercentage,s as useRelativeTime,c as useUnit};
|
|
@@ -1,28 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
4
|
-
import { useCallback, useContext } from "react";
|
|
5
|
-
import { compact } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/format/useCompact.ts
|
|
8
|
-
/**
|
|
9
|
-
* React client hook that provides a compact number formatter
|
|
10
|
-
* bound to the current application locale.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```tsx
|
|
14
|
-
* const formatCompact = useCompact();
|
|
15
|
-
* formatCompact(1500); // "1.5K"
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
const useCompact = () => {
|
|
19
|
-
const { locale } = useContext(IntlayerClientContext);
|
|
20
|
-
return useCallback((...args) => compact(args[0], {
|
|
21
|
-
...args[1],
|
|
22
|
-
locale: args[1]?.locale ?? locale
|
|
23
|
-
}), [locale]);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
//#endregion
|
|
27
|
-
export { useCompact };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"react";import{compact as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useCompact};
|
|
28
2
|
//# sourceMappingURL=useCompact.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCompact.mjs","names":[],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":["'use client';\n\nimport { compact } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCompact.mjs","names":[],"sources":["../../../../src/client/format/useCompact.ts"],"sourcesContent":["'use client';\n\nimport { compact } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a compact number formatter\n * bound to the current application locale.\n *\n * @example\n * ```tsx\n * const formatCompact = useCompact();\n * formatCompact(1500); // \"1.5K\"\n * ```\n */\nexport const useCompact = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof compact>) =>\n compact(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"qLAgBA,MAAa,MAAmB,CAC9B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAQ,EAAK,GAAI,CACf,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,42 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
4
|
-
import { useCallback, useContext } from "react";
|
|
5
|
-
import { currency } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/format/useCurrency.ts
|
|
8
|
-
/**
|
|
9
|
-
* React client hook that provides a currency formatter
|
|
10
|
-
* bound to the current application locale.
|
|
11
|
-
*
|
|
12
|
-
* @returns {(value: string | number, options?: CurrencyProps) => string}
|
|
13
|
-
* A function to format numbers into localized currency strings.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const formatCurrency = useCurrency();
|
|
18
|
-
*
|
|
19
|
-
* formatCurrency(1500, { currency: "USD" });
|
|
20
|
-
* // "$1,500.00"
|
|
21
|
-
*
|
|
22
|
-
* formatCurrency(1500, { currency: "EUR", locale: "de-DE" });
|
|
23
|
-
* // "1.500,00 €"
|
|
24
|
-
*
|
|
25
|
-
* formatCurrency(9876543.21, {
|
|
26
|
-
* currency: "JPY",
|
|
27
|
-
* fractionDigits: 0,
|
|
28
|
-
* });
|
|
29
|
-
* // "¥9,876,543"
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
const useCurrency = () => {
|
|
33
|
-
const { locale } = useContext(IntlayerClientContext);
|
|
34
|
-
return useCallback((...args) => currency(args[0], {
|
|
35
|
-
...args[1],
|
|
36
|
-
locale: args[1]?.locale ?? locale
|
|
37
|
-
}), [locale]);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
//#endregion
|
|
41
|
-
export { useCurrency };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"react";import{currency as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useCurrency};
|
|
42
2
|
//# sourceMappingURL=useCurrency.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCurrency.mjs","names":[],"sources":["../../../../src/client/format/useCurrency.ts"],"sourcesContent":["'use client';\n\nimport { currency } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a currency formatter\n * bound to the current application locale.\n *\n * @returns {(value: string | number, options?: CurrencyProps) => string}\n * A function to format numbers into localized currency strings.\n *\n * @example\n * ```tsx\n * const formatCurrency = useCurrency();\n *\n * formatCurrency(1500, { currency: \"USD\" });\n * // \"$1,500.00\"\n *\n * formatCurrency(1500, { currency: \"EUR\", locale: \"de-DE\" });\n * // \"1.500,00 €\"\n *\n * formatCurrency(9876543.21, {\n * currency: \"JPY\",\n * fractionDigits: 0,\n * });\n * // \"¥9,876,543\"\n * ```\n */\nexport const useCurrency = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useCurrency.mjs","names":[],"sources":["../../../../src/client/format/useCurrency.ts"],"sourcesContent":["'use client';\n\nimport { currency } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a currency formatter\n * bound to the current application locale.\n *\n * @returns {(value: string | number, options?: CurrencyProps) => string}\n * A function to format numbers into localized currency strings.\n *\n * @example\n * ```tsx\n * const formatCurrency = useCurrency();\n *\n * formatCurrency(1500, { currency: \"USD\" });\n * // \"$1,500.00\"\n *\n * formatCurrency(1500, { currency: \"EUR\", locale: \"de-DE\" });\n * // \"1.500,00 €\"\n *\n * formatCurrency(9876543.21, {\n * currency: \"JPY\",\n * fractionDigits: 0,\n * });\n * // \"¥9,876,543\"\n * ```\n */\nexport const useCurrency = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof currency>) =>\n currency(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"sLA8BA,MAAa,MAAoB,CAC/B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAS,EAAK,GAAI,CAChB,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
4
|
-
import { useContext } from "react";
|
|
5
|
-
import { date } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/format/useDate.ts
|
|
8
|
-
/**
|
|
9
|
-
* React client hook that provides a localized date/time formatter
|
|
10
|
-
* bound to the current application locale.
|
|
11
|
-
*
|
|
12
|
-
* @returns {(date: Date | string | number, options?: DateProps) => string}
|
|
13
|
-
* A function to format dates or timestamps into localized date/time strings.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const formatDate = useDate();
|
|
18
|
-
*
|
|
19
|
-
* formatDate(new Date("2025-01-01"));
|
|
20
|
-
* // "Jan 1, 2025"
|
|
21
|
-
*
|
|
22
|
-
* formatDate("2025-01-01T15:30:00Z", {
|
|
23
|
-
* dateStyle: "full",
|
|
24
|
-
* timeStyle: "short",
|
|
25
|
-
* });
|
|
26
|
-
* // "Wednesday, January 1, 2025 at 3:30 PM"
|
|
27
|
-
*
|
|
28
|
-
* formatDate(1735689600000, { locale: "fr-FR", dateStyle: "long" });
|
|
29
|
-
* // "1 janvier 2025"
|
|
30
|
-
* ```
|
|
31
|
-
*
|
|
32
|
-
* @see createDate
|
|
33
|
-
*/
|
|
34
|
-
const useDate = () => {
|
|
35
|
-
const { locale } = useContext(IntlayerClientContext);
|
|
36
|
-
return (...args) => date(args[0], {
|
|
37
|
-
...args[1],
|
|
38
|
-
locale: args[1]?.locale ?? locale
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
export { useDate };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useContext as t}from"react";import{date as n}from"@intlayer/core/formatters";const r=()=>{let{locale:r}=t(e);return(...e)=>n(e[0],{...e[1],locale:e[1]?.locale??r})};export{r as useDate};
|
|
44
2
|
//# sourceMappingURL=useDate.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDate.mjs","names":[],"sources":["../../../../src/client/format/useDate.ts"],"sourcesContent":["'use client';\n\nimport { date } from '@intlayer/core';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return (...args: Parameters<typeof date>) =>\n date(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDate.mjs","names":[],"sources":["../../../../src/client/format/useDate.ts"],"sourcesContent":["'use client';\n\nimport { date } from '@intlayer/core/formatters';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized date/time formatter\n * bound to the current application locale.\n *\n * @returns {(date: Date | string | number, options?: DateProps) => string}\n * A function to format dates or timestamps into localized date/time strings.\n *\n * @example\n * ```tsx\n * const formatDate = useDate();\n *\n * formatDate(new Date(\"2025-01-01\"));\n * // \"Jan 1, 2025\"\n *\n * formatDate(\"2025-01-01T15:30:00Z\", {\n * dateStyle: \"full\",\n * timeStyle: \"short\",\n * });\n * // \"Wednesday, January 1, 2025 at 3:30 PM\"\n *\n * formatDate(1735689600000, { locale: \"fr-FR\", dateStyle: \"long\" });\n * // \"1 janvier 2025\"\n * ```\n *\n * @see createDate\n */\nexport const useDate = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return (...args: Parameters<typeof date>) =>\n date(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n });\n};\n"],"mappings":"iKAgCA,MAAa,MAAgB,CAC3B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAQ,GAAG,IACT,EAAK,EAAK,GAAI,CACZ,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC"}
|
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
4
|
-
import { useContext, useMemo } from "react";
|
|
5
|
-
import { bindIntl } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/format/useIntl.ts
|
|
8
|
-
/**
|
|
9
|
-
* React client hook that provides a locale-bound `Intl` object.
|
|
10
|
-
*
|
|
11
|
-
* It acts exactly like the native `Intl` object, but acts as a proxy to:
|
|
12
|
-
* 1. Inject the current locale automatically if none is provided.
|
|
13
|
-
* 2. Use the performance-optimized `CachedIntl` under the hood.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const intl = useIntl(); // uses context locale
|
|
18
|
-
*
|
|
19
|
-
* // Standard API, but no need to pass 'en-US' as the first argument
|
|
20
|
-
* const formatted = new intl.NumberFormat({
|
|
21
|
-
* style: 'currency',
|
|
22
|
-
* currency: 'USD'
|
|
23
|
-
* }).format(123.45);
|
|
24
|
-
* ```
|
|
25
|
-
*
|
|
26
|
-
* @example
|
|
27
|
-
* ```tsx
|
|
28
|
-
* const intl = useIntl();
|
|
29
|
-
*
|
|
30
|
-
* // You can still override the locale if needed
|
|
31
|
-
* const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());
|
|
32
|
-
* // or
|
|
33
|
-
* const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
|
-
const useIntl = (locale) => {
|
|
37
|
-
const { locale: contextLocale } = useContext(IntlayerClientContext);
|
|
38
|
-
const currentLocale = locale ?? contextLocale;
|
|
39
|
-
return useMemo(() => bindIntl(currentLocale), [currentLocale]);
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
export { useIntl };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useContext as t,useMemo as n}from"react";import{bindIntl as r}from"@intlayer/core/formatters";const i=i=>{let{locale:a}=t(e),o=i??a;return n(()=>r(o),[o])};export{i as useIntl};
|
|
44
2
|
//# sourceMappingURL=useIntl.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["'use client';\n\nimport { bindIntl } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useIntl.mjs","names":[],"sources":["../../../../src/client/format/useIntl.ts"],"sourcesContent":["'use client';\n\nimport { bindIntl } from '@intlayer/core/formatters';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a locale-bound `Intl` object.\n *\n * It acts exactly like the native `Intl` object, but acts as a proxy to:\n * 1. Inject the current locale automatically if none is provided.\n * 2. Use the performance-optimized `CachedIntl` under the hood.\n *\n * @example\n * ```tsx\n * const intl = useIntl(); // uses context locale\n *\n * // Standard API, but no need to pass 'en-US' as the first argument\n * const formatted = new intl.NumberFormat({\n * style: 'currency',\n * currency: 'USD'\n * }).format(123.45);\n * ```\n *\n * @example\n * ```tsx\n * const intl = useIntl();\n *\n * // You can still override the locale if needed\n * const date = new intl.DateTimeFormat({ locale: 'fr-FR' }).format(new Date());\n * // or\n * const date2 = new intl.DateTimeFormat('fr-FR').format(new Date());\n * ```\n */\nexport const useIntl = (locale?: LocalesValues) => {\n const { locale: contextLocale } = useContext(IntlayerClientContext);\n const currentLocale = locale ?? contextLocale;\n\n return useMemo(() => bindIntl(currentLocale), [currentLocale]);\n};\n"],"mappings":"kLAmCA,MAAa,EAAW,GAA2B,CACjD,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAC7D,EAAgB,GAAU,EAEhC,OAAO,MAAc,EAAS,EAAc,CAAE,CAAC,EAAc,CAAC"}
|
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
4
|
-
import { useCallback, useContext } from "react";
|
|
5
|
-
import { list } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/format/useList.ts
|
|
8
|
-
/**
|
|
9
|
-
* React client hook that provides a list formatter
|
|
10
|
-
* bound to the current application locale.
|
|
11
|
-
*
|
|
12
|
-
* @returns {(values: (string | number)[], options?: ListProps) => string}
|
|
13
|
-
* A function to format arrays into localized list strings.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const formatList = useList();
|
|
18
|
-
*
|
|
19
|
-
* formatList(['apple', 'banana', 'orange']);
|
|
20
|
-
* // "apple, banana, and orange"
|
|
21
|
-
*
|
|
22
|
-
* formatList(['red', 'green', 'blue'], { type: 'disjunction' });
|
|
23
|
-
* // "red, green, or blue"
|
|
24
|
-
*
|
|
25
|
-
* formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });
|
|
26
|
-
* // "1, 2 und 3"
|
|
27
|
-
* ```
|
|
28
|
-
*/
|
|
29
|
-
const useList = () => {
|
|
30
|
-
const { locale } = useContext(IntlayerClientContext);
|
|
31
|
-
return useCallback((...args) => list(args[0], {
|
|
32
|
-
...args[1],
|
|
33
|
-
locale: args[1]?.locale ?? locale
|
|
34
|
-
}), [locale]);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
export { useList };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"react";import{list as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useList};
|
|
39
2
|
//# sourceMappingURL=useList.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useList.mjs","names":[],"sources":["../../../../src/client/format/useList.ts"],"sourcesContent":["'use client';\n\nimport { list } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a list formatter\n * bound to the current application locale.\n *\n * @returns {(values: (string | number)[], options?: ListProps) => string}\n * A function to format arrays into localized list strings.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useList.mjs","names":[],"sources":["../../../../src/client/format/useList.ts"],"sourcesContent":["'use client';\n\nimport { list } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a list formatter\n * bound to the current application locale.\n *\n * @returns {(values: (string | number)[], options?: ListProps) => string}\n * A function to format arrays into localized list strings.\n *\n * @example\n * ```tsx\n * const formatList = useList();\n *\n * formatList(['apple', 'banana', 'orange']);\n * // \"apple, banana, and orange\"\n *\n * formatList(['red', 'green', 'blue'], { type: 'disjunction' });\n * // \"red, green, or blue\"\n *\n * formatList([1, 2, 3], { type: 'unit', locale: 'de-DE' });\n * // \"1, 2 und 3\"\n * ```\n */\nexport const useList = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof list>) =>\n list(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"kLA2BA,MAAa,MAAgB,CAC3B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAK,EAAK,GAAI,CACZ,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,40 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
4
|
-
import { useCallback, useContext } from "react";
|
|
5
|
-
import { number } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/format/useNumber.ts
|
|
8
|
-
/**
|
|
9
|
-
* React client hook that provides a localized number formatter.
|
|
10
|
-
*
|
|
11
|
-
* Uses the current locale from {@link useLocaleBase} and returns
|
|
12
|
-
* a function that can be used to format numbers consistently
|
|
13
|
-
* according to the user's locale.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const formatNumber = useNumber();
|
|
18
|
-
*
|
|
19
|
-
* formatNumber(12345);
|
|
20
|
-
* // e.g. "12,345" (en-US)
|
|
21
|
-
* // e.g. "12 345" (fr-FR)
|
|
22
|
-
*
|
|
23
|
-
* formatNumber(0.75, { style: "percent" });
|
|
24
|
-
* // e.g. "75%"
|
|
25
|
-
* ```
|
|
26
|
-
*
|
|
27
|
-
* @returns {(value: string | number, options?: import("../createNumber").NumberProps) => string}
|
|
28
|
-
* A number formatting function bound to the active locale.
|
|
29
|
-
*/
|
|
30
|
-
const useNumber = () => {
|
|
31
|
-
const { locale } = useContext(IntlayerClientContext);
|
|
32
|
-
return useCallback((...args) => number(args[0], {
|
|
33
|
-
...args[1],
|
|
34
|
-
locale: args[1]?.locale ?? locale
|
|
35
|
-
}), [locale]);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
//#endregion
|
|
39
|
-
export { useNumber };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"react";import{number as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useNumber};
|
|
40
2
|
//# sourceMappingURL=useNumber.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["'use client';\n\nimport { number } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useNumber.mjs","names":[],"sources":["../../../../src/client/format/useNumber.ts"],"sourcesContent":["'use client';\n\nimport { number } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React client hook that provides a localized number formatter.\n *\n * Uses the current locale from {@link useLocaleBase} and returns\n * a function that can be used to format numbers consistently\n * according to the user's locale.\n *\n * @example\n * ```tsx\n * const formatNumber = useNumber();\n *\n * formatNumber(12345);\n * // e.g. \"12,345\" (en-US)\n * // e.g. \"12 345\" (fr-FR)\n *\n * formatNumber(0.75, { style: \"percent\" });\n * // e.g. \"75%\"\n * ```\n *\n * @returns {(value: string | number, options?: import(\"../createNumber\").NumberProps) => string}\n * A number formatting function bound to the active locale.\n */\nexport const useNumber = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof number>) =>\n number(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"oLA4BA,MAAa,MAAkB,CAC7B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAO,EAAK,GAAI,CACd,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
4
|
-
import { useCallback, useContext } from "react";
|
|
5
|
-
import { percentage } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/format/usePercentage.ts
|
|
8
|
-
/**
|
|
9
|
-
* React hook to provide a percentage formatter function
|
|
10
|
-
* based on the current application locale.
|
|
11
|
-
*
|
|
12
|
-
* This hook retrieves the active locale using {@link useLocaleBase}
|
|
13
|
-
* and memoizes a `createPercentage` instance for that locale.
|
|
14
|
-
*
|
|
15
|
-
* @example
|
|
16
|
-
* ```tsx
|
|
17
|
-
* const formatPercentage = usePercentage();
|
|
18
|
-
*
|
|
19
|
-
* const result = formatPercentage(0.875, { maximumFractionDigits: 1 });
|
|
20
|
-
* // "87.5%" (depending on locale)
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @returns {(value: string | number, options?: Omit<PercentageOptions, "value">) => string}
|
|
24
|
-
* A function that formats numbers or numeric strings into localized percentages.
|
|
25
|
-
*/
|
|
26
|
-
const usePercentage = () => {
|
|
27
|
-
const { locale } = useContext(IntlayerClientContext);
|
|
28
|
-
return useCallback((...args) => percentage(args[0], {
|
|
29
|
-
...args[1],
|
|
30
|
-
locale: args[1]?.locale ?? locale
|
|
31
|
-
}), [locale]);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
export { usePercentage };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"react";import{percentage as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as usePercentage};
|
|
36
2
|
//# sourceMappingURL=usePercentage.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["'use client';\n\nimport { percentage } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"usePercentage.mjs","names":[],"sources":["../../../../src/client/format/usePercentage.ts"],"sourcesContent":["'use client';\n\nimport { percentage } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook to provide a percentage formatter function\n * based on the current application locale.\n *\n * This hook retrieves the active locale using {@link useLocaleBase}\n * and memoizes a `createPercentage` instance for that locale.\n *\n * @example\n * ```tsx\n * const formatPercentage = usePercentage();\n *\n * const result = formatPercentage(0.875, { maximumFractionDigits: 1 });\n * // \"87.5%\" (depending on locale)\n * ```\n *\n * @returns {(value: string | number, options?: Omit<PercentageOptions, \"value\">) => string}\n * A function that formats numbers or numeric strings into localized percentages.\n */\nexport const usePercentage = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof percentage>) =>\n percentage(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"wLAwBA,MAAa,MAAsB,CACjC,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAW,EAAK,GAAI,CAClB,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,36 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
4
|
-
import { useCallback, useContext } from "react";
|
|
5
|
-
import { relativeTime } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/format/useRelativeTime.ts
|
|
8
|
-
/**
|
|
9
|
-
* Client-side React hook for accessing a localized relative time formatter.
|
|
10
|
-
*
|
|
11
|
-
* This hook:
|
|
12
|
-
* - Reads the current locale from {@link useLocaleBase}.
|
|
13
|
-
* - Creates a new relative time formatter with {@link createRelativeTime}.
|
|
14
|
-
* - Returns a function that can format time differences into localized strings.
|
|
15
|
-
*
|
|
16
|
-
* Example:
|
|
17
|
-
* ```tsx
|
|
18
|
-
* const relativeTime = useRelativeTime();
|
|
19
|
-
* const formatted = relativeTime(new Date("2024-08-01"), new Date());
|
|
20
|
-
* // e.g., "2 weeks ago"
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function
|
|
24
|
-
* bound to the current client locale.
|
|
25
|
-
*/
|
|
26
|
-
const useRelativeTime = () => {
|
|
27
|
-
const { locale } = useContext(IntlayerClientContext);
|
|
28
|
-
return useCallback((...args) => relativeTime(args[0], args[1], {
|
|
29
|
-
...args[2],
|
|
30
|
-
locale: args[2]?.locale ?? locale
|
|
31
|
-
}), [locale]);
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
//#endregion
|
|
35
|
-
export { useRelativeTime };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"react";import{relativeTime as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],e[1],{...e[2],locale:e[2]?.locale??i}),[i])};export{i as useRelativeTime};
|
|
36
2
|
//# sourceMappingURL=useRelativeTime.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["'use client';\n\nimport { relativeTime } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useRelativeTime.mjs","names":[],"sources":["../../../../src/client/format/useRelativeTime.ts"],"sourcesContent":["'use client';\n\nimport { relativeTime } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * Client-side React hook for accessing a localized relative time formatter.\n *\n * This hook:\n * - Reads the current locale from {@link useLocaleBase}.\n * - Creates a new relative time formatter with {@link createRelativeTime}.\n * - Returns a function that can format time differences into localized strings.\n *\n * Example:\n * ```tsx\n * const relativeTime = useRelativeTime();\n * const formatted = relativeTime(new Date(\"2024-08-01\"), new Date());\n * // e.g., \"2 weeks ago\"\n * ```\n *\n * @returns {ReturnType<typeof createRelativeTime>} A relative time formatting function\n * bound to the current client locale.\n */\nexport const useRelativeTime = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof relativeTime>) =>\n relativeTime(args[0], args[1], {\n ...args[2],\n locale: args[2]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"0LAwBA,MAAa,MAAwB,CACnC,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAa,EAAK,GAAI,EAAK,GAAI,CAC7B,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,35 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "../IntlayerProvider.mjs";
|
|
4
|
-
import { useCallback, useContext } from "react";
|
|
5
|
-
import { units } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/format/useUnit.ts
|
|
8
|
-
/**
|
|
9
|
-
* React hook that provides a unit formatting function
|
|
10
|
-
* based on the current locale from {@link useLocaleBase}.
|
|
11
|
-
*
|
|
12
|
-
* This hook wraps {@link createUnit} to return a formatter
|
|
13
|
-
* that can convert values into human-readable localized units
|
|
14
|
-
* (e.g., "10 km", "5 lbs").
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* const formatUnit = useUnit();
|
|
19
|
-
* const distance = formatUnit(10, { unit: "kilometer" });
|
|
20
|
-
* // "10 km" (depending on locale)
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @returns {Function} A unit formatting function that accepts a value and optional formatting options.
|
|
24
|
-
*/
|
|
25
|
-
const useUnit = () => {
|
|
26
|
-
const { locale } = useContext(IntlayerClientContext);
|
|
27
|
-
return useCallback((...args) => units(args[0], {
|
|
28
|
-
...args[1],
|
|
29
|
-
locale: args[1]?.locale ?? locale
|
|
30
|
-
}), [locale]);
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
export { useUnit };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"../IntlayerProvider.mjs";import{useCallback as t,useContext as n}from"react";import{units as r}from"@intlayer/core/formatters";const i=()=>{let{locale:i}=n(e);return t((...e)=>r(e[0],{...e[1],locale:e[1]?.locale??i}),[i])};export{i as useUnit};
|
|
35
2
|
//# sourceMappingURL=useUnit.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["'use client';\n\nimport { units } from '@intlayer/core';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useUnit.mjs","names":[],"sources":["../../../../src/client/format/useUnit.ts"],"sourcesContent":["'use client';\n\nimport { units } from '@intlayer/core/formatters';\nimport { useCallback, useContext } from 'react';\nimport { IntlayerClientContext } from '../IntlayerProvider';\n\n/**\n * React hook that provides a unit formatting function\n * based on the current locale from {@link useLocaleBase}.\n *\n * This hook wraps {@link createUnit} to return a formatter\n * that can convert values into human-readable localized units\n * (e.g., \"10 km\", \"5 lbs\").\n *\n * @example\n * ```tsx\n * const formatUnit = useUnit();\n * const distance = formatUnit(10, { unit: \"kilometer\" });\n * // \"10 km\" (depending on locale)\n * ```\n *\n * @returns {Function} A unit formatting function that accepts a value and optional formatting options.\n */\nexport const useUnit = () => {\n const { locale } = useContext(IntlayerClientContext);\n\n return useCallback(\n (...args: Parameters<typeof units>) =>\n units(args[0], {\n ...args[1],\n locale: args[1]?.locale ?? locale,\n }),\n [locale]\n );\n};\n"],"mappings":"mLAuBA,MAAa,MAAgB,CAC3B,GAAM,CAAE,UAAW,EAAW,EAAsB,CAEpD,OAAO,GACJ,GAAG,IACF,EAAM,EAAK,GAAI,CACb,GAAG,EAAK,GACR,OAAQ,EAAK,IAAI,QAAU,EAC5B,CAAC,CACJ,CAAC,EAAO,CACT"}
|
|
@@ -1,14 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, useIntlayerContext } from "./IntlayerProvider.mjs";
|
|
3
|
-
import { t } from "./t.mjs";
|
|
4
|
-
import { useDictionary } from "./useDictionary.mjs";
|
|
5
|
-
import { useDictionaryAsync } from "./useDictionaryAsync.mjs";
|
|
6
|
-
import { useLoadDynamic } from "./useLoadDynamic.mjs";
|
|
7
|
-
import { useDictionaryDynamic } from "./useDictionaryDynamic.mjs";
|
|
8
|
-
import { useI18n } from "./useI18n.mjs";
|
|
9
|
-
import { useIntlayer } from "./useIntlayer.mjs";
|
|
10
|
-
import { useLocale } from "./useLocale.mjs";
|
|
11
|
-
import { useLocaleBase } from "./useLocaleBase.mjs";
|
|
12
|
-
import { useRewriteURL } from "./useRewriteURL.mjs";
|
|
13
|
-
|
|
14
|
-
export { IntlayerClientContext, IntlayerProvider, IntlayerProviderContent, localeCookie, localeInStorage, setLocaleCookie, setLocaleInStorage, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntlayer, useIntlayerContext, useLoadDynamic, useLocale, useLocaleBase, useLocaleCookie, useLocaleStorage, useRewriteURL };
|
|
1
|
+
import{localeCookie as e,localeInStorage as t,setLocaleCookie as n,setLocaleInStorage as r,useLocaleCookie as i,useLocaleStorage as a}from"./useLocaleStorage.mjs";import{IntlayerClientContext as o,IntlayerProvider as s,IntlayerProviderContent as c,useIntlayerContext as l}from"./IntlayerProvider.mjs";import{t as u}from"./t.mjs";import{useDictionary as d}from"./useDictionary.mjs";import{useDictionaryAsync as f}from"./useDictionaryAsync.mjs";import{useLoadDynamic as p}from"./useLoadDynamic.mjs";import{useDictionaryDynamic as m}from"./useDictionaryDynamic.mjs";import{useI18n as h}from"./useI18n.mjs";import{useIntlayer as g}from"./useIntlayer.mjs";import{useLocale as _}from"./useLocale.mjs";import{useLocaleBase as v}from"./useLocaleBase.mjs";import{useRewriteURL as y}from"./useRewriteURL.mjs";export{o as IntlayerClientContext,s as IntlayerProvider,c as IntlayerProviderContent,e as localeCookie,t as localeInStorage,n as setLocaleCookie,r as setLocaleInStorage,u as t,d as useDictionary,f as useDictionaryAsync,m as useDictionaryDynamic,h as useI18n,g as useIntlayer,l as useIntlayerContext,p as useLoadDynamic,_ as useLocale,v as useLocaleBase,i as useLocaleCookie,a as useLocaleStorage,y as useRewriteURL};
|
package/dist/esm/client/t.mjs
CHANGED
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
-
import { useContext } from "react";
|
|
5
|
-
import { getTranslation } from "@intlayer/core";
|
|
6
|
-
|
|
7
|
-
//#region src/client/t.ts
|
|
8
|
-
/**
|
|
9
|
-
* Client-side translation function that returns the translation of the provided multilang content.
|
|
10
|
-
*
|
|
11
|
-
* If the locale is not provided, it will use the locale from the client context.
|
|
12
|
-
*
|
|
13
|
-
* @param multilangContent - An object mapping locales to their respective content.
|
|
14
|
-
* @param locale - Optional locale to override the current context locale.
|
|
15
|
-
* @returns The translation for the specified locale.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* import { t } from 'react-intlayer';
|
|
20
|
-
*
|
|
21
|
-
* const MyComponent = () => {
|
|
22
|
-
* const greeting = t({
|
|
23
|
-
* en: 'Hello',
|
|
24
|
-
* fr: 'Bonjour',
|
|
25
|
-
* es: 'Hola',
|
|
26
|
-
* });
|
|
27
|
-
*
|
|
28
|
-
* return <h1>{greeting}</h1>;
|
|
29
|
-
* };
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
|
-
const t = (multilangContent, locale) => {
|
|
33
|
-
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
34
|
-
return getTranslation(multilangContent, locale ?? currentLocale);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
//#endregion
|
|
38
|
-
export { t };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{useContext as t}from"react";import{getTranslation as n}from"@intlayer/core/interpreter";const r=(r,i)=>{let{locale:a}=t(e);return n(r,i??a)};export{r as t};
|
|
39
2
|
//# sourceMappingURL=t.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"t.mjs","names":[],"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport { getTranslation } from '@intlayer/core';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side translation function that returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param multilangContent - An object mapping locales to their respective content.\n * @param locale - Optional locale to override the current context locale.\n * @returns The translation for the specified locale.\n *\n * @example\n * ```tsx\n * import { t } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * es: 'Hola',\n * });\n *\n * return <h1>{greeting}</h1>;\n * };\n * ```\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"t.mjs","names":[],"sources":["../../../src/client/t.ts"],"sourcesContent":["'use client';\n\nimport { getTranslation } from '@intlayer/core/interpreter';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { useContext } from 'react';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * Client-side translation function that returns the translation of the provided multilang content.\n *\n * If the locale is not provided, it will use the locale from the client context.\n *\n * @param multilangContent - An object mapping locales to their respective content.\n * @param locale - Optional locale to override the current context locale.\n * @returns The translation for the specified locale.\n *\n * @example\n * ```tsx\n * import { t } from 'react-intlayer';\n *\n * const MyComponent = () => {\n * const greeting = t({\n * en: 'Hello',\n * fr: 'Bonjour',\n * es: 'Hola',\n * });\n *\n * return <h1>{greeting}</h1>;\n * };\n * ```\n */\nexport const t = <Content = string>(\n multilangContent: StrictModeLocaleMap<Content>,\n locale?: LocalesValues\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n const localeTarget = locale ?? currentLocale;\n\n return getTranslation<Content>(multilangContent, localeTarget);\n};\n"],"mappings":"2KA+BA,MAAa,GACX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAGnE,OAAO,EAAwB,EAFV,GAAU,EAE+B"}
|
|
@@ -1,26 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerClientContext } from "./IntlayerProvider.mjs";
|
|
4
|
-
import { getDictionary } from "../getDictionary.mjs";
|
|
5
|
-
import { useContext, useMemo } from "react";
|
|
6
|
-
|
|
7
|
-
//#region src/client/useDictionary.ts
|
|
8
|
-
/**
|
|
9
|
-
* On the server side, Hook that transform a dictionary and return the content
|
|
10
|
-
*
|
|
11
|
-
* If the locale is not provided, it will use the locale from the client context
|
|
12
|
-
*/
|
|
13
|
-
const useDictionary = (dictionary, locale) => {
|
|
14
|
-
const { locale: currentLocale } = useContext(IntlayerClientContext);
|
|
15
|
-
return useMemo(() => {
|
|
16
|
-
return getDictionary(dictionary, locale ?? currentLocale);
|
|
17
|
-
}, [
|
|
18
|
-
dictionary,
|
|
19
|
-
currentLocale,
|
|
20
|
-
locale
|
|
21
|
-
]);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
//#endregion
|
|
25
|
-
export { useDictionary };
|
|
1
|
+
"use client";import{IntlayerClientContext as e}from"./IntlayerProvider.mjs";import{getDictionary as t}from"../getDictionary.mjs";import{useContext as n,useMemo as r}from"react";const i=(i,a)=>{let{locale:o}=n(e);return r(()=>t(i,a??o),[i,o,a])};export{i as useDictionary};
|
|
26
2
|
//# sourceMappingURL=useDictionary.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n }, [dictionary, currentLocale, locale]);\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":[],"sources":["../../../src/client/useDictionary.ts"],"sourcesContent":["'use client';\n\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { useContext, useMemo } from 'react';\nimport { getDictionary } from '../getDictionary';\nimport { IntlayerClientContext } from './IntlayerProvider';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the client context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends LocalesValues = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n) => {\n const { locale: currentLocale } = useContext(IntlayerClientContext);\n\n return useMemo(() => {\n const localeTarget = locale ?? currentLocale;\n\n return getDictionary<T, L>(dictionary, localeTarget as L);\n }, [dictionary, currentLocale, locale]);\n};\n"],"mappings":"iLAgBA,MAAa,GAIX,EACA,IACG,CACH,GAAM,CAAE,OAAQ,GAAkB,EAAW,EAAsB,CAEnE,OAAO,MAGE,EAAoB,EAFN,GAAU,EAE0B,CACxD,CAAC,EAAY,EAAe,EAAO,CAAC"}
|